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

[charts] Is it possible to have a customised highlighted MarkElement for LineChart? #11326

Closed
brnguyenn opened this issue Dec 7, 2023 · 4 comments
Labels
component: charts This is the name of the generic UI component, not the React module! new feature New feature or request support: commercial Support request from paid users

Comments

@brnguyenn
Copy link

brnguyenn commented Dec 7, 2023

The problem in depth 🔍

The goal is to have the highlighted mark visually different as well as the ability for an onClick event. e.g:

Screen Shot 2023-12-07 at 2 47 55 pm

Your environment 🌎

No response

Search keywords: MarkElement, LineChart
Order ID: 79128

@brnguyenn brnguyenn added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Dec 7, 2023
@michelengelen michelengelen changed the title [question] Is it possible to have a customised highlighted MarkElement for LineChart? [charts] Is it possible to have a customised highlighted MarkElement for LineChart? Dec 7, 2023
@michelengelen
Copy link
Member

@alexfauquette Please correct me if I am wrong.

It is possible to inject a custom MarkElement component into the charts using the slots.mark prop. If I am not mistaken it needs to be a path component, though. This essentially can take an onClick prop.

I tested this and it is possible to do that, but it is pretty hard to hit the path with that click. @alexfauquette Maybe we can improve on this one and provide a bigger invisible click-area and allow for an onClick handler to be passed as props?

@michelengelen michelengelen added new feature New feature or request component: charts This is the name of the generic UI component, not the React module! labels Dec 7, 2023
@alexfauquette
Copy link
Member

For the line mark, it's a bit special. You have a lineHighlight slot that renders on top of the usual mark when it's highlight.

The reason behind this choice is to allow rendering a line, and a mark highlight without having to render all marks.

I assume the lineHighlight his blocking you click.

If I am not mistaken it needs to be a path component, though. This essentially can take an onClick prop.

What make you think it needs to be a path?

For the lineHighlight it's default component is defined here: https://github.com/mui/mui-x/blob/029d4c106455d2b3f62816663f4f179445dd4aec/packages/x-charts/src/LineChart/LineHighlightElement.tsx

You get the x/y coordinate in props, and then can put whatever SVG element thanks to the CSS translate.

@alexfauquette alexfauquette removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 7, 2023
@michelengelen
Copy link
Member

If I am not mistaken it needs to be a path component, though. This essentially can take an onClick prop.

What make you think it needs to be a path?

I thought it had to be a path due to this type definition:

export type MarkElementProps = Omit<MarkElementOwnerState, 'isFaded' | 'isHighlighted'> &
React.ComponentPropsWithoutRef<'path'> & {
/**
* The shape of the marker.
*/
shape: 'circle' | 'cross' | 'diamond' | 'square' | 'star' | 'triangle' | 'wye';
/**
* The index to the element in the series' data array.
*/
dataIndex: number;
highlightScope?: Partial<HighlightScope>;
};

But when it can be any valid svg element its even better. Thanks for pointing that out

@brnguyenn
Copy link
Author

Thank you for your replies @michelengelen and @alexfauquette

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module! new feature New feature or request support: commercial Support request from paid users
Projects
None yet
Development

No branches or pull requests

3 participants