From 16ecb26baaf8dfbce301ae43e7ff4b4beb79c413 Mon Sep 17 00:00:00 2001 From: Bigood Date: Wed, 20 Sep 2023 16:52:55 +0200 Subject: [PATCH 1/3] Update CartesianMarkersItem.js Allow `legendNode` props for finer control over legend customization for markers --- .../src/components/cartesian/markers/CartesianMarkersItem.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/components/cartesian/markers/CartesianMarkersItem.js b/packages/core/src/components/cartesian/markers/CartesianMarkersItem.js index ce9cc7d61..fb9ac1514 100644 --- a/packages/core/src/components/cartesian/markers/CartesianMarkersItem.js +++ b/packages/core/src/components/cartesian/markers/CartesianMarkersItem.js @@ -171,6 +171,7 @@ const CartesianMarkersItem = ({ lineStyle, textStyle, legend, + legendNode, legendPosition, legendOffsetX, legendOffsetY, @@ -191,8 +192,7 @@ const CartesianMarkersItem = ({ y2 = height } - let legendNode = null - if (legend) { + if (legend && !legendNode) { const legendProps = computeLabel({ axis, width, From c5b78c0f1bf611841a396e9d8579e79837db78dd Mon Sep 17 00:00:00 2001 From: Maen Juganaikloo Date: Wed, 9 Oct 2024 15:56:39 +0200 Subject: [PATCH 2/3] feat(test): added test for marker legend node --- packages/line/tests/Line.test.js | 30 + .../tests/__snapshots__/Line.test.js.snap | 947 ++++++++++++++++++ 2 files changed, 977 insertions(+) diff --git a/packages/line/tests/Line.test.js b/packages/line/tests/Line.test.js index b6c133d7a..f855708e1 100644 --- a/packages/line/tests/Line.test.js +++ b/packages/line/tests/Line.test.js @@ -292,6 +292,36 @@ it('should call the custom label callback for each point', () => { } }) +it('should display a custom legendNode for marker', () => { + const data = [ + { + id: 'A', + data: [ + { x: 0, y: 3 }, + { x: 1, y: 7 }, + { x: 2, y: 11 }, + { x: 3, y: 9 }, + { x: 4, y: 8 }, + ], + }, + ] + const markers = [{ + axis: "x", + lineStyle: { + stroke: "lightblue", + strokeWidth: 5 + }, + legendPosition: "top", + legendNode:
😎
, + }] + + const component = renderer.create() + + let tree = component.toJSON() + expect(tree).toMatchSnapshot() + +}) + describe('curve interpolation', () => { const curveInterpolations = [ 'basis', diff --git a/packages/line/tests/__snapshots__/Line.test.js.snap b/packages/line/tests/__snapshots__/Line.test.js.snap index 0ee2a68da..d97ab407a 100644 --- a/packages/line/tests/__snapshots__/Line.test.js.snap +++ b/packages/line/tests/__snapshots__/Line.test.js.snap @@ -7620,6 +7620,953 @@ exports[`curve interpolation should support stepBefore curve interpolation 1`] = `; +exports[`should display a custom legendNode for marker 1`] = ` +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 😎 +
+
+
+ + + + + 0 + + + + + + 1 + + + + + + 2 + + + + + + 3 + + + + + + 4 + + + + + + + + + 0 + + + + + + 1 + + + + + + 2 + + + + + + 3 + + + + + + 4 + + + + + + 5 + + + + + + 6 + + + + + + 7 + + + + + + 8 + + + + + + 9 + + + + + + 10 + + + + + + 11 + + + + + + + + + + + + + + + + + + + + + + +
+
+
+`; + exports[`should render a basic line chart 1`] = `
Date: Tue, 22 Oct 2024 13:27:00 +0200 Subject: [PATCH 3/3] chore(Line): run prettier on new legend node feature --- packages/line/tests/Line.test.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/line/tests/Line.test.js b/packages/line/tests/Line.test.js index f855708e1..49af2d27b 100644 --- a/packages/line/tests/Line.test.js +++ b/packages/line/tests/Line.test.js @@ -305,21 +305,28 @@ it('should display a custom legendNode for marker', () => { ], }, ] - const markers = [{ - axis: "x", - lineStyle: { - stroke: "lightblue", - strokeWidth: 5 + const markers = [ + { + axis: 'x', + lineStyle: { + stroke: 'lightblue', + strokeWidth: 5, + }, + legendPosition: 'top', + legendNode: ( + +
😎
+
+ ), }, - legendPosition: "top", - legendNode:
😎
, - }] + ] - const component = renderer.create() + const component = renderer.create( + + ) let tree = component.toJSON() expect(tree).toMatchSnapshot() - }) describe('curve interpolation', () => {