diff --git a/packages/core/src/components/cartesian/markers/CartesianMarkersItem.js b/packages/core/src/components/cartesian/markers/CartesianMarkersItem.js index 18cd34c3e..a45ea9bbd 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 = 'top-right', legendOffsetX = 14, legendOffsetY = 14, @@ -191,8 +192,7 @@ const CartesianMarkersItem = ({ y2 = height } - let legendNode = null - if (legend) { + if (legend && !legendNode) { const legendProps = computeLabel({ axis, width, diff --git a/packages/line/tests/Line.test.js b/packages/line/tests/Line.test.js index b6c133d7a..49af2d27b 100644 --- a/packages/line/tests/Line.test.js +++ b/packages/line/tests/Line.test.js @@ -292,6 +292,43 @@ 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`] = `