From b110c0aa3399fe1f09d423c610a81ac42669f6e7 Mon Sep 17 00:00:00 2001 From: Deepak Kumar Date: Mon, 14 Feb 2022 18:07:15 +0530 Subject: [PATCH] Fix legend alignment issue in Chrome, many thanks @Spacarar, see #1852, #1855, #1856 --- spec/legend-spec.js | 3 +-- src/charts/legend.ts | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/spec/legend-spec.js b/spec/legend-spec.js index 39e9453e1..ee0a3d396 100644 --- a/spec/legend-spec.js +++ b/spec/legend-spec.js @@ -53,8 +53,7 @@ describe('dc.legend', () => { expect(chart.selectAll('g.dc-legend g.dc-legend-item text').size()).toBe(3); }); - // The following test has started failing on Chrome Headless 96.0.4664.110 - xit('should position the legend labels', () => { + it('should position the legend labels', () => { expect(legendLabel(0).attr('x')).toBeWithinDelta(15, 2); expect(legendLabel(0).attr('y')).toBeWithinDelta(11.75, 2); expect(legendLabel(1).attr('x')).toBeWithinDelta(15, 2); diff --git a/src/charts/legend.ts b/src/charts/legend.ts index ebece37b9..a35d88386 100644 --- a/src/charts/legend.ts +++ b/src/charts/legend.ts @@ -289,9 +289,8 @@ export class Legend { .text(self._legendText) .attr('x', self._itemHeight + LABEL_GAP) .attr('y', function () { - return ( - self._itemHeight / 2 + (this.clientHeight ? this.clientHeight : 13) / 2 - 2 - ); + const clientHeight = this.getBoundingClientRect().height || 13; + return self._itemHeight / 2 + clientHeight / 2 - 2; }); }