Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom legendNode for markers #2432

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const CartesianMarkersItem = ({
lineStyle,
textStyle,
legend,
legendNode,
legendPosition = 'top-right',
legendOffsetX = 14,
legendOffsetY = 14,
Expand All @@ -191,8 +192,7 @@ const CartesianMarkersItem = ({
y2 = height
}

let legendNode = null
if (legend) {
if (legend && !legendNode) {
const legendProps = computeLabel({
axis,
width,
Expand Down
37 changes: 37 additions & 0 deletions packages/line/tests/Line.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: (
<foreignObject x={0} y={0} width={32} height={32}>
<div>😎</div>
</foreignObject>
),
},
]

const component = renderer.create(
<Line width={500} height={300} data={data} animate={false} markers={markers} />
)

let tree = component.toJSON()
expect(tree).toMatchSnapshot()
})

describe('curve interpolation', () => {
const curveInterpolations = [
'basis',
Expand Down
Loading
Loading