Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
705d8c2
initial tap and pan draft
JCQuintas Sep 17, 2025
93d453c
rename
JCQuintas Sep 17, 2025
655d76f
improves
JCQuintas Sep 18, 2025
4afbcf4
add test
JCQuintas Sep 18, 2025
9ac7adc
instruction
JCQuintas Sep 18, 2025
9ee14b3
simplify
JCQuintas Sep 18, 2025
1ee4f57
remove run
JCQuintas Sep 18, 2025
ab3f52a
fix tests
JCQuintas Sep 18, 2025
04273f6
add behavioru
JCQuintas Sep 19, 2025
d48f320
use composed behavior
JCQuintas Sep 26, 2025
88e78d5
fix
JCQuintas Sep 26, 2025
e832e52
proper names and fixes
JCQuintas Sep 26, 2025
b8f93d5
fix updating
JCQuintas Sep 26, 2025
654b6cc
add docs
JCQuintas Sep 26, 2025
c38d394
scripts
JCQuintas Sep 26, 2025
800958b
fix
JCQuintas Sep 26, 2025
39202ee
titles
JCQuintas Sep 26, 2025
a307c1c
tests
JCQuintas Sep 26, 2025
5fe74fa
Merge branch 'master' into tap-and-pan
JCQuintas Sep 26, 2025
5439beb
fix tests
JCQuintas Sep 26, 2025
9277f9d
Merge commit 'fd427c347301d5c0de5532dcf20d9680e4a919df' into tap-and-pan
JCQuintas Sep 27, 2025
4e610e7
fixes
JCQuintas Sep 27, 2025
91a9ca9
desc
JCQuintas Sep 29, 2025
2f60355
remove margin
JCQuintas Sep 29, 2025
678094c
fix touchAction
JCQuintas Sep 29, 2025
21d1832
Merge commit 'ce0fddc3bfe994423437ebc58ba60dd1fc659e5d' into tap-and-pan
JCQuintas Sep 29, 2025
aae46a6
Merge branch 'master' into tap-and-pan
JCQuintas Sep 29, 2025
ad43a12
add fix and test case for deltaY issue
JCQuintas Sep 29, 2025
2d0bbc7
fix ios issue
JCQuintas Sep 29, 2025
3b8cbca
remove redundant style change
JCQuintas Sep 29, 2025
83088fa
Merge branch 'master' into tap-and-pan
JCQuintas Sep 29, 2025
b7d138d
replace binding
JCQuintas Sep 30, 2025
d29af54
remove unused
JCQuintas Sep 30, 2025
463800e
Merge branch 'master' into tap-and-pan
JCQuintas Sep 30, 2025
df4916a
fix ts node
JCQuintas Sep 30, 2025
fcf5386
func
JCQuintas Sep 30, 2025
3ac336e
handle return outside
JCQuintas Sep 30, 2025
d45201a
decrease timeout
JCQuintas Sep 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions docs/data/charts/zoom-and-pan/ZoomAndPanInteractions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import * as React from 'react';
import { ScatterChartPro } from '@mui/x-charts-pro/ScatterChartPro';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';

const knobs = {
// Zoom interactions
wheel: {
displayName: 'Wheel',
knob: 'switch',
defaultValue: true,
},
pinch: {
displayName: 'Pinch',
knob: 'switch',
defaultValue: true,
},
tapAndDrag: {
displayName: 'Tap and drag',
knob: 'switch',
defaultValue: false,
},
// Pan interactions
drag: {
displayName: 'Drag',
knob: 'switch',
defaultValue: true,
},
};

export default function ZoomAndPanInteractions() {
return (
<ChartsUsageDemo
componentName="Zoom and Pan Interactions demo"
data={knobs}
renderDemo={(props) => {
// Build zoom interactions array
const zoomInteractions = [];
if (props.wheel) {
zoomInteractions.push('wheel');
}
if (props.pinch) {
zoomInteractions.push('pinch');
}
if (props.tapAndDrag) {
zoomInteractions.push('tapAndDrag');
}

// Build pan interactions array
const panInteractions = [];
if (props.drag) {
panInteractions.push('drag');
}

const zoomInteractionConfig = {
zoom: zoomInteractions,
pan: panInteractions,
};

return (
<div style={{ width: '100%' }}>
<ScatterChartPro
height={300}
xAxis={[
{
data: data.map((v, i) => i),
zoom: true,
},
]}
yAxis={[
{
zoom: true,
width: 40,
},
]}
series={series}
zoomInteractionConfig={zoomInteractionConfig}
/>
</div>
);
}}
getCode={({ props }) => {
// Build zoom interactions array for code generation
const zoomInteractions = [];
if (props.wheel) {
zoomInteractions.push('wheel');
}
if (props.pinch) {
zoomInteractions.push('pinch');
}
if (props.tapAndDrag) {
zoomInteractions.push('tapAndDrag');
}

// Build pan interactions array
const panInteractions = [];
if (props.drag) {
panInteractions.push('drag');
}

const zoomConfig =
zoomInteractions.length > 0
? `["${zoomInteractions.join('", "')}"]`
: '[]';
const panConfig =
panInteractions.length > 0 ? `["${panInteractions.join('", "')}"]` : '[]';

return `import { ScatterChartPro } from '@mui/x-charts-pro/ScatterChartPro';

<ScatterChartPro
// ...
zoomInteractionConfig={{
zoom: ${zoomConfig},
pan: ${panConfig},
}}
/>`;
}}
/>
);
}

const data = [
{
x: 443,
y: 153,
},
{
x: 110,
y: 217,
},
{
x: 175,
y: 286,
},
{
x: 195,
y: 325,
},
{
x: 351,
y: 144,
},
{
x: 43,
y: 146,
},
{
x: 376,
y: 309,
},
{
x: 31,
y: 236,
},
{
x: 231,
y: 440,
},
{
x: 108,
y: 20,
},
];

const series = [
{
label: 'Series A',
data,
},
];
170 changes: 170 additions & 0 deletions docs/data/charts/zoom-and-pan/ZoomAndPanInteractions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import * as React from 'react';
import { ScatterChartPro } from '@mui/x-charts-pro/ScatterChartPro';
import ChartsUsageDemo from 'docsx/src/modules/components/ChartsUsageDemo';

const knobs = {
// Zoom interactions
wheel: {
displayName: 'Wheel',
knob: 'switch',
defaultValue: true,
},
pinch: {
displayName: 'Pinch',
knob: 'switch',
defaultValue: true,
},
tapAndDrag: {
displayName: 'Tap and drag',
knob: 'switch',
defaultValue: false,
},

// Pan interactions
drag: {
displayName: 'Drag',
knob: 'switch',
defaultValue: true,
},
} as const;

export default function ZoomAndPanInteractions() {
return (
<ChartsUsageDemo
componentName="Zoom and Pan Interactions demo"
data={knobs}
renderDemo={(props) => {
// Build zoom interactions array
const zoomInteractions: any[] = [];
if (props.wheel) {
zoomInteractions.push('wheel');
}
if (props.pinch) {
zoomInteractions.push('pinch');
}
if (props.tapAndDrag) {
zoomInteractions.push('tapAndDrag');
}

// Build pan interactions array
const panInteractions: any[] = [];
if (props.drag) {
panInteractions.push('drag');
}

const zoomInteractionConfig = {
zoom: zoomInteractions,
pan: panInteractions,
};

return (
<div style={{ width: '100%' }}>
<ScatterChartPro
height={300}
xAxis={[
{
data: data.map((v, i) => i),
zoom: true,
},
]}
yAxis={[
{
zoom: true,
width: 40,
},
]}
series={series}
zoomInteractionConfig={zoomInteractionConfig}
/>
</div>
);
}}
getCode={({ props }) => {
// Build zoom interactions array for code generation
const zoomInteractions: any[] = [];
if (props.wheel) {
zoomInteractions.push('wheel');
}
if (props.pinch) {
zoomInteractions.push('pinch');
}
if (props.tapAndDrag) {
zoomInteractions.push('tapAndDrag');
}

// Build pan interactions array
const panInteractions: any[] = [];
if (props.drag) {
panInteractions.push('drag');
}

const zoomConfig =
zoomInteractions.length > 0
? `["${zoomInteractions.join('", "')}"]`
: '[]';
const panConfig =
panInteractions.length > 0 ? `["${panInteractions.join('", "')}"]` : '[]';

return `import { ScatterChartPro } from '@mui/x-charts-pro/ScatterChartPro';

<ScatterChartPro
// ...
zoomInteractionConfig={{
zoom: ${zoomConfig},
pan: ${panConfig},
}}
/>`;
}}
/>
);
}

const data = [
{
x: 443,
y: 153,
},
{
x: 110,
y: 217,
},
{
x: 175,
y: 286,
},
{
x: 195,
y: 325,
},
{
x: 351,
y: 144,
},
{
x: 43,
y: 146,
},
{
x: 376,
y: 309,
},
{
x: 31,
y: 236,
},
{
x: 231,
y: 440,
},
{
x: 108,
y: 20,
},
];

const series = [
{
label: 'Series A',
data,
},
];
22 changes: 19 additions & 3 deletions docs/data/charts/zoom-and-pan/zoom-and-pan.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ To enable zooming and panning, set the `zoom` prop to `true` on the wanted axis.

Enabling zoom will enable all the interactions, which are made to be as intuitive as possible.

The following actions are supported:
The following actions are enabled by default:

- **Scroll**: Zoom in/out by scrolling the mouse wheel.
- **Drag**: Pan the chart by dragging the mouse.
- **Pinch**: Zoom in/out by pinching the chart.

Additional zoom interactions can be enabled through configuration:

- **Tap and drag**: Zoom in/out by tapping twice and then dragging vertically.

{{"demo": "ZoomScatterChart.js"}}
{{"demo": "ZoomBarChart.js"}}
{{"demo": "ZoomLineChart.js"}}
Expand Down Expand Up @@ -143,14 +147,26 @@ The `zoomInteractionConfig` prop allows you to specify which interactions are en
```jsx
<BarChartPro
zoomInteractionConfig={{
// Enable both wheel and pinch zoom
zoom: ['wheel', 'pinch'],
// Enable wheel, pinch, and tap-and-drag zoom
zoom: ['wheel', 'pinch', 'tapAndDrag'],
// Enable drag panning
pan: ['drag'],
}}
/>
```

**Zoom** interactions:

- **`wheel`**: Zoom in/out by scrolling the mouse wheel (default)
- **`pinch`**: Zoom in/out by pinching on touch devices (default)
- **`tapAndDrag`**: Zoom in/out by tapping twice and then dragging vertically. Dragging up zooms in, dragging down zooms out.

**Pan** interactions:

- **`drag`**: Pan the chart by dragging with the mouse or touch (default)

{{"demo": "ZoomAndPanInteractions.js"}}

### Key modifiers

Some interactions allow setting up required keys to be pressed to enable the interaction.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/bar-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"zoomInteractionConfig": {
"type": {
"name": "shape",
"description": "{ pan?: Array&lt;'drag'<br>&#124;&nbsp;{ pointerMode?: 'mouse'<br>&#124;&nbsp;'touch', requiredKeys?: Array&lt;string&gt;, type: 'drag' }&gt;, zoom?: Array&lt;'pinch'<br>&#124;&nbsp;'wheel'<br>&#124;&nbsp;{ pointerMode?: any, requiredKeys?: Array&lt;string&gt;, type: 'wheel' }<br>&#124;&nbsp;{ pointerMode?: any, requiredKeys?: array, type: 'pinch' }&gt; }"
"description": "{ pan?: Array&lt;'drag'<br>&#124;&nbsp;{ pointerMode?: 'mouse'<br>&#124;&nbsp;'touch', requiredKeys?: Array&lt;string&gt;, type: 'drag' }&gt;, zoom?: Array&lt;'pinch'<br>&#124;&nbsp;'tapAndDrag'<br>&#124;&nbsp;'wheel'<br>&#124;&nbsp;{ pointerMode?: any, requiredKeys?: Array&lt;string&gt;, type: 'wheel' }<br>&#124;&nbsp;{ pointerMode?: any, requiredKeys?: array, type: 'pinch' }<br>&#124;&nbsp;{ pointerMode?: 'mouse'<br>&#124;&nbsp;'touch', requiredKeys?: Array&lt;string&gt;, type: 'tapAndDrag' }&gt; }"
}
}
},
Expand Down
Loading
Loading