Skip to content

Commit 1ce58a5

Browse files
BigoodMaen Juganaikloo
and
Maen Juganaikloo
authored
feat(core): Allow custom legendNode for markers (#2432)
* Update CartesianMarkersItem.js Allow `legendNode` props for finer control over legend customization for markers * feat(test): added test for marker legend node * chore(Line): run prettier on new legend node feature --------- Co-authored-by: Maen Juganaikloo <[email protected]>
1 parent 0f5ac2f commit 1ce58a5

File tree

3 files changed

+986
-2
lines changed

3 files changed

+986
-2
lines changed

packages/core/src/components/cartesian/markers/CartesianMarkersItem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ const CartesianMarkersItem = ({
171171
lineStyle,
172172
textStyle,
173173
legend,
174+
legendNode,
174175
legendPosition = 'top-right',
175176
legendOffsetX = 14,
176177
legendOffsetY = 14,
@@ -191,8 +192,7 @@ const CartesianMarkersItem = ({
191192
y2 = height
192193
}
193194

194-
let legendNode = null
195-
if (legend) {
195+
if (legend && !legendNode) {
196196
const legendProps = computeLabel({
197197
axis,
198198
width,

packages/line/tests/Line.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,43 @@ it('should call the custom label callback for each point', () => {
292292
}
293293
})
294294

295+
it('should display a custom legendNode for marker', () => {
296+
const data = [
297+
{
298+
id: 'A',
299+
data: [
300+
{ x: 0, y: 3 },
301+
{ x: 1, y: 7 },
302+
{ x: 2, y: 11 },
303+
{ x: 3, y: 9 },
304+
{ x: 4, y: 8 },
305+
],
306+
},
307+
]
308+
const markers = [
309+
{
310+
axis: 'x',
311+
lineStyle: {
312+
stroke: 'lightblue',
313+
strokeWidth: 5,
314+
},
315+
legendPosition: 'top',
316+
legendNode: (
317+
<foreignObject x={0} y={0} width={32} height={32}>
318+
<div>😎</div>
319+
</foreignObject>
320+
),
321+
},
322+
]
323+
324+
const component = renderer.create(
325+
<Line width={500} height={300} data={data} animate={false} markers={markers} />
326+
)
327+
328+
let tree = component.toJSON()
329+
expect(tree).toMatchSnapshot()
330+
})
331+
295332
describe('curve interpolation', () => {
296333
const curveInterpolations = [
297334
'basis',

0 commit comments

Comments
 (0)