Skip to content

Conversation

alexfauquette
Copy link
Member

While adding the controlled version, I took a bad shortcut: I assumed if no axis index get is available, then no value corresponds to the current pointer.

@alexfauquette alexfauquette added type: regression A bug, but worse, it used to behave as expected. scope: charts Changes related to the charts. labels Jul 30, 2025
@mui-bot
Copy link

mui-bot commented Jul 30, 2025

Deploy preview: https://deploy-preview-18985--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed Size Gzip Size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid/DataGrid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro/DataGridPro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium/DataGridPremium 0B(0.00%) 🔺+1B(0.00%)
@mui/x-charts ▼-3B(0.00%) 🔺+1B(0.00%)
@mui/x-charts-pro ▼-3B(0.00%) 🔺+4B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 80a4c14

Comment on lines +33 to +38
{xAxisHighlight && xAxisHighlight !== 'none' && (
<ChartsXHighlight type={xAxisHighlight} classes={classes} />
)}
{yAxisHighlight && yAxisHighlight !== 'none' && (
<ChartsYHighlight type={yAxisHighlight} classes={classes} />
)}
Copy link
Member Author

Choose a reason for hiding this comment

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

While debugging, I noticed 'none' renders the component which is bad because we call the x/y-axis highlight selector to simply return null at the end

Copy link

codspeed-hq bot commented Jul 30, 2025

CodSpeed Performance Report

Merging #18985 will not alter performance

Comparing alexfauquette:fix-highlight-axis (80a4c14) with master (a213c4e)

Summary

✅ 10 untouched benchmarks

@@ -181,4 +182,29 @@ describe('useChartCartesianAxis - axis highlight', () => {
]);
},
);

it.skipIf(isJSDOM)('should allow to highlight axes without data', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Should we have a test case for a continuous scale as well? The implementation seems to be different for discrete and continuous scales.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. I added a test for the x-axis which is a band scale 👍

Copy link
Member

Choose a reason for hiding this comment

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

This test uses a band scale, but the new one as well. Shouldn't the new one use a continuous scale (e.g., linear)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both tests have the same chart config.

  • The first one display y-axis highlight (on a continuous scale without data)
  • The first one display x-axis highlight (on a band scale with data)

We could also have "continuous scale without data" but "band scale without data" does not exist

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right. Missed that 👍

Comment on lines 70 to 77
if (!isBandScale(scale)) {
const value = scale.invert(pointerValue);

if (dataIndex < 0) {
if (dataIndex === null) {
return value;
}
return axisData![dataIndex];
}
Copy link
Member

Choose a reason for hiding this comment

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

We can avoid inverting if dataIndex !== null:

Suggested change
if (!isBandScale(scale)) {
const value = scale.invert(pointerValue);
if (dataIndex < 0) {
if (dataIndex === null) {
return value;
}
return axisData![dataIndex];
}
if (!isBandScale(scale)) {
if (dataIndex === null) {
return scale.invert(pointerValue);
}
return axisData![dataIndex];
}

});
});

it.skipIf(isJSDOM)('should allow to highlight axes with data', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

optional: all the tests in this file are using skipIf, we can move the skipIf to the top describe if we want. describe.skipIf(isJSDOM)

@alexfauquette alexfauquette merged commit 7db0f6f into mui:master Aug 8, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: charts Changes related to the charts. type: regression A bug, but worse, it used to behave as expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants