-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[charts] Allow zoom on Y axis and add zoom options to configure zooming behaviour #13726
Conversation
Deploy preview: https://deploy-preview-13726--material-ui-x.netlify.app/ Updated pages: |
The With the props Side note: At first I was concerned by the approach because I thought "If we do a mapping 1 axis to 2 zoom config, how can we handle zoom interaction across axes such that zooming in the x axis impacts the y axis" But I realized the notion of https://echarts.apache.org/en/option.html#dataZoom-inside.filterMode About the I thought about something like this, but did not thaught deep about it. {
xZoom: {
id1: [min, max],
},
yZoom: {
id1: [min, max],
}
} My main ideas were:
|
@alexfauquette my current line of thinking is to have the options be a configuration, while the export type ZoomOptions = {
min?: number;
max?: number;
step?: number;
minSpan?: number;
maxSpan?: number;
panning?: boolean;
};
export type ZoomData = {
min: number;
max: number;
axisId: AxisId;
};
export type ZoomProps = {
zoom: ZoomData[];
onZoomChange: (zoom: ZoomData[]) => void;
}; |
Regarding the |
Btw the code is currently working if you want to pull it and test it out. Playground Codeimport * as React from 'react';
import { Box } from '@mui/material';
import { DEFAULT_X_AXIS_KEY } from '@mui/x-charts/constants';
import { ScatterChartPro } from '@mui/x-charts-pro/ScatterChartPro';
import { LineChartPro } from '@mui/x-charts-pro/LineChartPro';
import { BarChartPro } from '@mui/x-charts-pro/BarChartPro';
import { Chance } from 'chance';
import Layout from './components/Layout';
import '@mui/x-charts-pro/typeOverloads';
const chance = new Chance(42);
const v = 25;
const min = -v;
const max = v;
const data = [
...Array.from({ length: 200 }, () => ({
x: chance.floating({ min: min, max: max }),
y: chance.floating({ min: min, max: max }),
})).map((d, index) => ({ ...d, id: index })),
{ x: 0, y: 0, id: 200 },
{ x: min, y: min, id: 201 },
{ x: max, y: max, id: 202 },
{ x: max, y: min, id: 203 },
{ x: min, y: max, id: 204 },
{ x: 0, y: max, id: 205 },
{ x: 0, y: min, id: 206 },
{ x: min, y: 0, id: 207 },
{ x: max, y: 0, id: 208 },
];
const chartSetting = {
height: 300,
tooltip: { trigger: 'none' as const },
slotProps: { legend: {} },
};
const dataset = [
[59, 57, 86, 21, 'Jan'],
[50, 52, 78, 28, 'Fev'],
[47, 53, 106, 41, 'Mar'],
[54, 56, 92, 73, 'Apr'],
// [57, 69, 92, 99, 'May'],
// [60, 63, 103, 144, 'June'],
// [59, 60, 105, 319, 'July'],
// [65, 60, 106, 249, 'Aug'],
// [51, 51, 95, 131, 'Sept'],
// [60, 65, 97, 55, 'Oct'],
// [67, 64, 76, 48, 'Nov'],
// [61, 70, 103, 25, 'Dec'],
].map(([london, paris, newYork, seoul, month]) => ({ london, paris, newYork, seoul, month }));
function BarsDataset() {
return (
<Box>
<BarChartPro
dataset={dataset}
xAxis={[{ scaleType: 'band', dataKey: 'month', position: 'top', zoom: true }]}
yAxis={[{ label: 'rainfall (mm)', zoom: true }]}
series={[
{
dataKey: 'london',
label: 'London',
},
{
dataKey: 'paris',
label: 'Paris',
},
{
dataKey: 'newYork',
label: 'New York',
},
{
dataKey: 'seoul',
label: 'Seoul',
},
]}
{...chartSetting}
/>
<ScatterChartPro
series={[
{
type: 'scatter',
id: 'linear',
data,
},
]}
topAxis={{
axisId: DEFAULT_X_AXIS_KEY,
disableLine: false,
disableTicks: false,
label: 'My axis',
tickSize: 6,
}}
xAxis={[
{
zoom: {
min: 25,
max: 75,
minSpan: 50,
maxSpan: 50,
},
},
]}
yAxis={[
{
zoom: {
min: 25,
max: 75,
minSpan: 50,
maxSpan: 50,
},
},
]}
{...chartSetting}
/>
<LineChartPro
{...chartSetting}
series={[
{
data: [4000, 3000, 2000, 2780, 1890, 2390, 3490],
label: 'pv',
},
{
data: [2400, 1398, 9800, 3908, 4800, 3800, 4300],
label: 'uv',
area: true,
},
]}
xAxis={[
{
scaleType: 'point',
data: ['Page A', 'Page B', 'Page C', 'Page D', 'Page E', 'Page F', 'Page G'],
zoom: true,
},
]}
yAxis={[
{
zoom: true,
},
]}
/>
<LineChartPro
xAxis={[{ data: [1, 10, 30, 50, 70, 90, 100] }]}
yAxis={[
{ id: 'linearAxis', scaleType: 'linear' },
{ id: 'logAxis', scaleType: 'linear' },
]}
series={[
{ yAxisKey: 'linearAxis', data: [1, 10, 30, 50, 70, 90, 100], label: 'linear' },
{ yAxisKey: 'logAxis', data: [1, 10, 30, 50, 70, 90, 100], label: 'log' },
]}
leftAxis="linearAxis"
rightAxis="logAxis"
height={400}
/>
</Box>
);
}
export default function Page() {
return (
<Layout>
<BarsDataset />
</Layout>
);
} |
packages/x-charts-pro/src/context/ZoomProvider/defaultizeZoom.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR 🎉
Most of the comments are about small improvement for code readablity and DX, but the over all structure looks very good
packages/x-charts-pro/src/context/ZoomProvider/ZoomProvider.tsx
Outdated
Show resolved
Hide resolved
packages/x-charts-pro/src/context/ZoomProvider/defaultizeZoom.ts
Outdated
Show resolved
Hide resolved
packages/x-charts-pro/src/context/ZoomProvider/defaultizeZoom.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Signed-off-by: Jose C Quintas Jr <juniorquintas@gmail.com>
Co-authored-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Signed-off-by: Jose C Quintas Jr <juniorquintas@gmail.com>
Co-authored-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com> Signed-off-by: Jose C Quintas Jr <juniorquintas@gmail.com>
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
…ng behaviour (mui#13726) Signed-off-by: Jose C Quintas Jr <juniorquintas@gmail.com> Co-authored-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
…ng behaviour (mui#13726) Signed-off-by: Jose C Quintas Jr <juniorquintas@gmail.com> Co-authored-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
Add zoom options
The main idea is to have
ZoomOptions
inside theChartsAxisProps
so we can set an option for each axis.Zoom is then controlled by a different prop when it is implemented in a future PR. The goal is to have it as a root prop called
zoom
andonZoomChange
min/max
controls the possible range, it works like the zoom when set at first render.step
changes the sensitivity of the zoomminSpan/maxSpan
determines the min/max span size.span = (currentMaxZoom-currentMinZoon)
panning
enable/disableAllow Y Axis zooming
Simply enable it on a Y axis.
"filterMode"
to work nicelyControllable
Not controllable yet. Will be in a future PR.