Skip to content

Conversation

bernardobelchior
Copy link
Member

Refactored the functions for creating the axis filters. Now there's one for discrete scales and another one for continuous ones. It makes them easier to test and reason about IMO.

Also added tests.

I did this refactor as a precursor to a bug fix (PR here), but I want to test that PR more thoroughly first, so I moved the refactor into this PR.

@mui-bot
Copy link

mui-bot commented Jul 31, 2025

Deploy preview: https://deploy-preview-18998--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%) ▼-4B(0.00%)
@mui/x-data-grid-pro/DataGridPro 0B(0.00%) ▼-3B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) ▼-3B(0.00%)
@mui/x-data-grid-premium/DataGridPremium 0B(0.00%) ▼-3B(0.00%)
@mui/x-charts 🔺+79B(+0.03%) 🔺+25B(+0.03%)
@mui/x-charts-pro 🔺+79B(+0.02%) 🔺+21B(+0.02%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) ▼-6B(-0.01%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) ▼-2B(-0.01%)

Details of bundle changes

Generated by 🚫 dangerJS against c4c0217

const axisData = ['I0', 'I1', 'I2', 'I3'];
const filter = createDiscreteScaleGetAxisFilter(axisData, 24, 76, 'y');

expect(filter({ x: null, y: 'I0' }, 0)).toBe(false);
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I0 and I3 are partially visible, so they should be included.

This is fixed in #18992.

@bernardobelchior bernardobelchior changed the title [charts-pro] Refactor createAxisFilterMapper [charts-pro] Refactor createAxisFilterMapper Jul 31, 2025
@bernardobelchior bernardobelchior added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: charts Changes related to the charts. labels Jul 31, 2025
@bernardobelchior bernardobelchior marked this pull request as ready for review July 31, 2025 07:24
Copy link

codspeed-hq bot commented Jul 31, 2025

CodSpeed Performance Report

Merging #18998 will not alter performance

Comparing bernardobelchior:axis-filter-refactor (c4c0217) with master (312a6c0)

Summary

✅ 10 untouched benchmarks

Copy link
Member

@alexfauquette alexfauquette left a comment

Choose a reason for hiding this comment

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

Much clearer 👍

Comment on lines 89 to 92
const max = (axisData?.length ?? 1) - 1;

[min, max] = getScale(continuousScaleType, extremums, [0, 100]).nice().domain();
const minVal = (zoomStart * max) / 100;
const maxVal = (zoomEnd * max) / 100;
Copy link
Member

Choose a reason for hiding this comment

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

Just to clarify what kind of max it is

Suggested change
const max = (axisData?.length ?? 1) - 1;
[min, max] = getScale(continuousScaleType, extremums, [0, 100]).nice().domain();
const minVal = (zoomStart * max) / 100;
const maxVal = (zoomEnd * max) / 100;
const maxIndex = (axisData?.length ?? 1) - 1;
const minVal = (zoomStart * maxIndex) / 100;
const maxVal = (zoomEnd * maxIndex) / 100;

@bernardobelchior bernardobelchior merged commit 359c486 into mui:master Jul 31, 2025
23 checks passed
@bernardobelchior bernardobelchior deleted the axis-filter-refactor branch July 31, 2025 13:11
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: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants