Skip to content

Commit

Permalink
[charts] Fix zoom panning (#16407)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Jan 30, 2025
1 parent f8eaf22 commit b02722e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { AxisId, DefaultizedZoomOptions } from '@mui/x-charts/internals';
import { AxisConfig, ChartsXAxisProps, ChartsYAxisProps, ScaleName } from '@mui/x-charts/models';
import { defaultizeZoom } from './defaultizeZoom';

export const creatZoomLookup = (
axes: AxisConfig<ScaleName, any, ChartsXAxisProps | ChartsYAxisProps>[],
) =>
axes.reduce<Record<AxisId, DefaultizedZoomOptions>>((acc, v) => {
const { zoom, id: axisId } = v;
const defaultizedZoom = defaultizeZoom(zoom, axisId, 'x');
if (defaultizedZoom) {
acc[axisId] = defaultizedZoom;
}
return acc;
}, {});
export const creatZoomLookup =
(axisDirection: 'x' | 'y') =>
(axes: AxisConfig<ScaleName, any, ChartsXAxisProps | ChartsYAxisProps>[]) =>
axes.reduce<Record<AxisId, DefaultizedZoomOptions>>((acc, v) => {
const { zoom, id: axisId } = v;
const defaultizedZoom = defaultizeZoom(zoom, axisId, axisDirection);
if (defaultizedZoom) {
acc[axisId] = defaultizedZoom;
}
return acc;
}, {});
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { creatZoomLookup } from './creatZoomLookup';
export const selectorChartZoomState: ChartRootSelector<UseChartProZoomSignature> = (state) =>
state.zoom;

const selectorChartXZoomOptionsLookup = createSelector(selectorChartRawXAxis, creatZoomLookup);
const selectorChartXZoomOptionsLookup = createSelector(selectorChartRawXAxis, creatZoomLookup('x'));

const selectorChartYZoomOptionsLookup = createSelector(selectorChartRawYAxis, creatZoomLookup);
const selectorChartYZoomOptionsLookup = createSelector(selectorChartRawYAxis, creatZoomLookup('y'));

export const selectorChartZoomOptionsLookup = createSelector(
[selectorChartXZoomOptionsLookup, selectorChartYZoomOptionsLookup],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ useChartProZoom.params = {

useChartProZoom.getDefaultizedParams = ({ params }) => {
const optionsLookup = {
...creatZoomLookup(params.defaultizedXAxis),
...creatZoomLookup(params.defaultizedYAxis),
...creatZoomLookup('x')(params.defaultizedXAxis),
...creatZoomLookup('y')(params.defaultizedYAxis),
};

return {
Expand Down

0 comments on commit b02722e

Please sign in to comment.