Skip to content

[charts] createAxisFilterMapper does not respect domain limit #17561

Open
@PatoGuereque

Description

@PatoGuereque

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/sandbox/x-charts-pro-domain-limit-zoom-k6ztx7

Current behavior

#15294 introduced a new domainLimit option to axis config. This allows the configuration of the axis scale domain, as described in the docs https://mui.com/x/api/charts/axis-config/#axis-config-prop-domainLimit

This is used by computeAxisValue

const domainLimit = axis.domainLimit ?? 'nice';
const axisExtremums = [axis.min ?? minData, axis.max ?? maxData];
if (typeof domainLimit === 'function') {
const { min, max } = domainLimit(minData, maxData);
axisExtremums[0] = min;
axisExtremums[1] = max;
}
const rawTickNumber = getTickNumber({ ...axis, range, domain: axisExtremums });
const tickNumber = rawTickNumber / ((zoomRange[1] - zoomRange[0]) / 100);
const zoomedRange = zoomScaleRange(range, zoomRange);
const scale = getScale(scaleType, axisExtremums, zoomedRange);
const finalScale = domainLimit === 'nice' ? scale.nice(rawTickNumber) : scale;
const [minDomain, maxDomain] = finalScale.domain();
const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];

However, createAxisFilterMapper does not take into account this domain limit

[min, max] = getScale(continuousScaleType, extremums, [0, 100]).nice().domain();

The zoom and pan feature depends on the createAxisFilterMapper function. This results in a desync between what the zoom feature thinks the current domain is vs what the actual domain is, as it assumes it's set to nice.

The code sandbox has the zoom set to 90%-100%, to show the cases where scaling is a factor.

Expected behavior

No response

Context

No response

Your environment

Search keywords: charts domain limit zoom

Order ID: 96664

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something doesn't workcomponent: chartsThis is the name of the generic UI component, not the React module!support: pro standardSupport request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions