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] Support UTC date formatting in tooltip #11943

Merged
Changes from 4 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 @@ -18,7 +18,18 @@ function DefaultChartsAxisTooltipContent(props: ChartsAxisContentProps) {
if (dataIndex == null) {
return null;
}
const axisFormatter = axis.valueFormatter ?? ((v) => v.toLocaleString());

const utcFormatter = (v: string | number | Date): string => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value can also be null. Maybe we can move this function definition outside of the component since it does not require any prop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you check the previous implementation null case of v was not considered

const axisFormatter = axis.valueFormatter ?? ((v) => v.toLocaleString());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectively, I forgot this axisValue != null && !axis.hideTooltip condition

if (v instanceof Date) {
return v.toUTCString();
}
return v.toLocaleString();
};

const axisFormatter =
axis.valueFormatter ??
((v: any) => (axis?.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString()));
shaharyar-shamshi marked this conversation as resolved.
Show resolved Hide resolved

return (
<ChartsTooltipPaper sx={sx} className={classes.root}>
<ChartsTooltipTable className={classes.table}>
Expand Down
Loading