Skip to content

Conversation

bernardobelchior
Copy link
Member

@bernardobelchior bernardobelchior commented Aug 15, 2025

Refactored ChartsXAxis and ChartsYAxis.

The shared logic that was previous in ChartsYAxis was moved back into it. ChartsYAxis is responsible for rendering the axis itself, the line and the label, and it also decides whether to render ChartsSingleYAxis or ChartsGroupedYAxis. ChartsSingleYAxis and ChartsGroupedYAxis now only render ticks according to their logic. The same logic applies to the x axis.

@mui-bot
Copy link

mui-bot commented Aug 15, 2025

Deploy preview: https://deploy-preview-19198--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-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts ▼-330B(-0.11%) ▼-204B(-0.21%)
@mui/x-charts-pro ▼-312B(-0.08%) ▼-184B(-0.15%)
@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 c95e459

import { isInfinity } from '../internals/isInfinity';

export const useAxisProps = (inProps: ChartsYAxisProps) => {
export function useAxisTicksProps(inProps: ChartsYAxisProps) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This hook is now only for ticks

*
* - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
*/
function ChartsYAxis(inProps: ChartsYAxisProps) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved most of the shared logic back to ChartsYAxis. No need to abstract it into a hook if it's just used here.

Now ChartsSingleYAxis and ChartsGroupedYAxis are only responsible for rendering ticks.

Copy link
Member

Choose a reason for hiding this comment

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

A lot of the logic can be kept in a hook IMO. Makes the component "cleaner"

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that we can probably make this component cleaner, but I'm not sure if moving all the logic to a hook is the best way to do it. We'd have a big hook with many parameters returning an object with a bunch of values. That hides the complexity, but doesn't reduce it. I think a better way might be to separate the logic into smaller pieces, which I can try to do in a follow-up PR.

@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 Aug 15, 2025
Copy link

codspeed-hq bot commented Aug 15, 2025

CodSpeed Performance Report

Merging #19198 will not alter performance

Comparing bernardobelchior:improve-charts-y-axis-code-reuse (c95e459) with master (4be419e)

Summary

✅ 10 untouched benchmarks

@bernardobelchior bernardobelchior force-pushed the improve-charts-y-axis-code-reuse branch from b236920 to 5b49f62 Compare August 15, 2025 13:02
@bernardobelchior bernardobelchior changed the title [charts] Improve code reuse in ChartsYAxis [charts] Improve code reuse in ChartsXAxis and ChartsYAxis Aug 15, 2025
@bernardobelchior bernardobelchior marked this pull request as ready for review August 15, 2025 14:40
Copy link
Member

@JCQuintas JCQuintas left a comment

Choose a reason for hiding this comment

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

We should probably append Ticks to ChartsGrouped*Axis, ChartsGrouped*Axis if we are only rendering the ticks

/* Gap between the axis label and tick labels. */
export const AXIS_LABEL_TICK_LABEL_GAP = 2;

export const YAxisRoot = styled(AxisRoot, {
Copy link
Member

Choose a reason for hiding this comment

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

Might as well remove the XAxisRoot from the x version, no?

*
* - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
*/
function ChartsYAxis(inProps: ChartsYAxisProps) {
Copy link
Member

Choose a reason for hiding this comment

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

A lot of the logic can be kept in a hook IMO. Makes the component "cleaner"

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 3, 2025
Copy link

github-actions bot commented Sep 3, 2025

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@bernardobelchior bernardobelchior force-pushed the improve-charts-y-axis-code-reuse branch from 5b49f62 to 37f9fe7 Compare September 8, 2025 10:50
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 8, 2025
Comment on lines 53 to 54
const drawingArea = useDrawingArea();
const { left, top, width, height } = drawingArea;
Copy link
Member

Choose a reason for hiding this comment

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

Looks weird

Suggested change
const drawingArea = useDrawingArea();
const { left, top, width, height } = drawingArea;
const { left, top, width, height } = useDrawingArea();

@bernardobelchior bernardobelchior merged commit 3f4237d into mui:master Sep 9, 2025
22 checks passed
@bernardobelchior bernardobelchior deleted the improve-charts-y-axis-code-reuse branch September 9, 2025 07:44
JCQuintas pushed a commit to JCQuintas/mui-x that referenced this pull request Sep 15, 2025
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