Skip to content
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

[docs] Divide charts tooltip and highlighting pages #14824

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 62 additions & 0 deletions docs/data/charts/highlighting/highlighting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: Charts - Highlighting
productId: x-charts
components: ChartsAxisHighlight
---

# Charts - Highlighting

<p class="description">Highlighting data offers quick visual feedback for chart users.</p>

It can be used to emphasize a specific data point or series, or to fade out the rest of the chart.
And it can be controlled by the user or synchronized across multiple charts.

## Highlighting

### Highlighting axis

You can highlight data based on mouse position.
By default, those highlights are lines, but it can also be a vertical band if your x-axis use `scaleType: 'band'`.

On the chart, to customize this behavior, you can use:

```jsx
axisHighlight={{
x: 'line', // Or 'none', or 'band'
y: 'line', // Or 'none'
}}
```

{{"demo": "BandHighlight.js" }}

### Highlighting series

In parallel with the tooltip, you can highlight and fade elements.

This kind of interaction is controlled by series properties `highlightScope` which contains two options:

- `highlighted` Indicates which item to highlight. Its value can be
- `'none'` Do nothing (default one).
- `'item'` Only highlight the item itself.
- `'series'` Highlight all items of the series.
- `faded` Indicates which item to fade (if they are not already highlighted). Its value can be
- `'none'` Do nothing (default one).
- `'series'` Fade all the items of the series.
- `'global'` Fade all the items of the chart.

{{"demo": "ElementHighlights.js"}}

### Controlled highlight

The highlight can be controlled by the user when they set `highlightedItem` and `onHighlightChange`.

You can set the `highlightedItem` value based on inputs, and sync it when the user hover over an item themselves.

{{"demo": "ControlledHighlight.js"}}

#### Synchronizing highlights

Having a controlled highlight allows you to control it in multiple charts at the same time.
You need to ensure that the `series` has the same `ids` and the data is in the same order.

{{"demo": "SyncHighlight.js"}}
2 changes: 1 addition & 1 deletion docs/data/charts/pie/pie.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Arcs with angles smaller than the value (in deg) will not have labels.
## Highlight

Pie series can get `highlightScope` property to manage element highlighting.
Its behavior is described in the [dedicated page](/x/react-charts/tooltip/#highlighting-series).
Its behavior is described in the [dedicated page](/x/react-charts/highlighting/#highlighting-series).

When elements are highlighted or faded they can be customized with dedicated CSS classes: `.MuiPieArc-faded` and `.MuiPieArc-highlighted`.

Expand Down
54 changes: 2 additions & 52 deletions docs/data/charts/tooltip/tooltip.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Charts - Tooltip
productId: x-charts
components: ChartsTooltip, DefaultChartsAxisTooltipContent, DefaultChartsItemTooltipContent, ChartsAxisHighlight
components: ChartsTooltip, DefaultChartsAxisTooltipContent, DefaultChartsItemTooltipContent
---

# Charts - Tooltip
Expand All @@ -21,56 +21,6 @@ The tooltip can be triggered by two kinds of events:

{{"demo": "Interaction.js"}}

## Highlights

### Highlighting axis

You can highlight data based on mouse position.
By default, those highlights are lines, but it can also be a vertical band if your x-axis use `scaleType: 'band'`.

On the chart, to customize this behavior, you can use:

```jsx
axisHighlight={{
x: 'line', // Or 'none', or 'band'
y: 'line', // Or 'none'
}}
```

{{"demo": "BandHighlight.js" }}

### Highlighting series

In parallel with the tooltip, you can highlight and fade elements.

This kind of interaction is controlled by series properties `highlightScope` which contains two options:

- `highlighted` Indicates which item to highlight. Its value can be
- `'none'` Do nothing (default one).
- `'item'` Only highlight the item itself.
- `'series'` Highlight all items of the series.
- `faded` Indicates which item to fade (if they are not already highlighted). Its value can be
- `'none'` Do nothing (default one).
- `'series'` Fade all the items of the series.
- `'global'` Fade all the items of the chart.

{{"demo": "ElementHighlights.js"}}

### Controlled Highlight

The highlight can be controlled by the user when they set `highlightedItem` and `onHighlightChange`.

You can set the `highlightedItem` value based on inputs, and sync it when the user hover over an item themselves.

{{"demo": "ControlledHighlight.js"}}

#### Synchronizing Highlights

Having a controlled highlight allows you to control it in multiple charts at the same time.
You just need to ensure that the `series` have the same `ids` and the data is in the same order.

{{"demo": "SyncHighlight.js"}}

## Customization

### Formatting
Expand Down Expand Up @@ -169,7 +119,7 @@ The second one when trigger is set to `"axis"`.
If you're using composition, by default, the axis will be listening for mouse events to get its current x/y values.
If you don't need it, you can disable those listeners with the `disableAxisListener` prop.

You need those listeners if you are using [axes highlight](/x/react-charts/tooltip/#highlighting-axis) or you have a tooltip [triggered by axis](/x/react-charts/tooltip/#tooltip-trigger).
You need those listeners if you are using [axes highlight](/x/react-charts/highlighting/#highlighting-axis) or you have a tooltip [triggered by axis](/x/react-charts/tooltip/#tooltip-trigger).

```jsx
<ChartContainer {...} disableAxisListener>
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/zoom-and-pan/zoom-and-pan.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: Zoom & Pan
title: Charts - Zooming and panning
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
productId: x-charts
components: ScatterChartPro, BarChartPro, LineChartPro
---

# Zoom & Pan [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')
# Charts - Zooming and panning [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')

<p class="description">Enables zooming and panning on specific charts or axis.</p>

Expand Down
7 changes: 4 additions & 3 deletions docs/data/pages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MuiPage } from 'docs/src/MuiPage';
import chartsComponentApi from './charts-component-api-pages';
import dataGridComponentApi from './data-grid-component-api-pages';
import pickersComponentApi from './date-pickers-component-api-pages';
import chartsComponentApi from './charts-component-api-pages';
import treeViewComponentApi from './tree-view-component-api-pages';

const pages: MuiPage[] = [
Expand Down Expand Up @@ -438,10 +438,11 @@ const pages: MuiPage[] = [
{ pathname: '/x/react-charts/legend' },
{ pathname: '/x/react-charts/stacking' },
{ pathname: '/x/react-charts/styling' },
{ pathname: '/x/react-charts/tooltip', title: 'Tooltips and highlights' },
{ pathname: '/x/react-charts/tooltip' },
{ pathname: '/x/react-charts/highlighting' },
{
pathname: '/x/react-charts/zoom-and-pan',
title: 'Zooming and panning',
title: 'Zoom and pan',
plan: 'pro',
unstable: true,
},
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/x/api/charts/bar-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"description": "{ x?: 'band'<br>&#124;&nbsp;'line'<br>&#124;&nbsp;'none', y?: 'band'<br>&#124;&nbsp;'line'<br>&#124;&nbsp;'none' }"
},
"seeMoreLink": {
"url": "https://mui.com/x/react-charts/tooltip/#highlights",
"text": "highlight docs"
"url": "https://mui.com/x/react-charts/highlighting",
"text": "highlighting docs"
}
},
"barLabel": { "type": { "name": "union", "description": "'value'<br>&#124;&nbsp;func" } },
Expand Down Expand Up @@ -132,6 +132,6 @@
"muiName": "MuiBarChartPro",
"filename": "/packages/x-charts-pro/src/BarChartPro/BarChartPro.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/x/react-charts/bars/\">Charts - Bars</a></li>\n<li><a href=\"/x/react-charts/zoom-and-pan/\">Zoom &amp; Pan <a href=\"/x/introduction/licensing/#pro-plan\" title=\"Pro plan\"><span class=\"plan-pro\"></span></a></a></li></ul>",
"demos": "<ul><li><a href=\"/x/react-charts/bars/\">Charts - Bars</a></li>\n<li><a href=\"/x/react-charts/zoom-and-pan/\">Charts - Zooming and panning <a href=\"/x/introduction/licensing/#pro-plan\" title=\"Pro plan\"><span class=\"plan-pro\"></span></a></a></li></ul>",
"cssComponent": false
}
4 changes: 2 additions & 2 deletions docs/pages/x/api/charts/bar-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"description": "{ x?: 'band'<br>&#124;&nbsp;'line'<br>&#124;&nbsp;'none', y?: 'band'<br>&#124;&nbsp;'line'<br>&#124;&nbsp;'none' }"
},
"seeMoreLink": {
"url": "https://mui.com/x/react-charts/tooltip/#highlights",
"text": "highlight docs"
"url": "https://mui.com/x/react-charts/highlighting",
"text": "highlighting docs"
}
},
"barLabel": { "type": { "name": "union", "description": "'value'<br>&#124;&nbsp;func" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/charts-axis-highlight.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"muiName": "MuiChartsAxisHighlight",
"filename": "/packages/x-charts/src/ChartsAxisHighlight/ChartsAxisHighlight.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/x/react-charts/tooltip/\">Charts - Tooltip</a></li></ul>",
"demos": "<ul><li><a href=\"/x/react-charts/highlighting/\">Charts - Highlighting</a></li></ul>",
"cssComponent": false
}
6 changes: 3 additions & 3 deletions docs/pages/x/api/charts/line-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"default": "{ x: 'line' }",
"seeMoreLink": {
"url": "https://mui.com/x/react-charts/tooltip/#highlights",
"text": "highlight docs"
"url": "https://mui.com/x/react-charts/highlighting",
"text": "highlighting docs"
}
},
"bottomAxis": {
Expand Down Expand Up @@ -126,6 +126,6 @@
"muiName": "MuiLineChartPro",
"filename": "/packages/x-charts-pro/src/LineChartPro/LineChartPro.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/x/react-charts/lines/\">Charts - Lines</a></li>\n<li><a href=\"/x/react-charts/zoom-and-pan/\">Zoom &amp; Pan <a href=\"/x/introduction/licensing/#pro-plan\" title=\"Pro plan\"><span class=\"plan-pro\"></span></a></a></li></ul>",
"demos": "<ul><li><a href=\"/x/react-charts/lines/\">Charts - Lines</a></li>\n<li><a href=\"/x/react-charts/zoom-and-pan/\">Charts - Zooming and panning <a href=\"/x/introduction/licensing/#pro-plan\" title=\"Pro plan\"><span class=\"plan-pro\"></span></a></a></li></ul>",
"cssComponent": false
}
4 changes: 2 additions & 2 deletions docs/pages/x/api/charts/line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"default": "{ x: 'line' }",
"seeMoreLink": {
"url": "https://mui.com/x/react-charts/tooltip/#highlights",
"text": "highlight docs"
"url": "https://mui.com/x/react-charts/highlighting",
"text": "highlighting docs"
}
},
"bottomAxis": {
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/x/api/charts/pie-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"default": "{ x: 'none', y: 'none' }",
"seeMoreLink": {
"url": "https://mui.com/x/react-charts/tooltip/#highlights",
"text": "highlight docs"
"url": "https://mui.com/x/react-charts/highlighting",
"text": "highlighting docs"
}
},
"bottomAxis": {
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/x/api/charts/scatter-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"default": "{ x: 'none', y: 'none' }",
"seeMoreLink": {
"url": "https://mui.com/x/react-charts/tooltip/#highlights",
"text": "highlight docs"
"url": "https://mui.com/x/react-charts/highlighting",
"text": "highlighting docs"
}
},
"bottomAxis": {
Expand Down Expand Up @@ -128,6 +128,6 @@
"muiName": "MuiScatterChartPro",
"filename": "/packages/x-charts-pro/src/ScatterChartPro/ScatterChartPro.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/x/react-charts/scatter/\">Charts - Scatter</a></li>\n<li><a href=\"/x/react-charts/zoom-and-pan/\">Zoom &amp; Pan <a href=\"/x/introduction/licensing/#pro-plan\" title=\"Pro plan\"><span class=\"plan-pro\"></span></a></a></li></ul>",
"demos": "<ul><li><a href=\"/x/react-charts/scatter/\">Charts - Scatter</a></li>\n<li><a href=\"/x/react-charts/zoom-and-pan/\">Charts - Zooming and panning <a href=\"/x/introduction/licensing/#pro-plan\" title=\"Pro plan\"><span class=\"plan-pro\"></span></a></a></li></ul>",
"cssComponent": false
}
4 changes: 2 additions & 2 deletions docs/pages/x/api/charts/scatter-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"default": "{ x: 'none', y: 'none' }",
"seeMoreLink": {
"url": "https://mui.com/x/react-charts/tooltip/#highlights",
"text": "highlight docs"
"url": "https://mui.com/x/react-charts/highlighting",
"text": "highlighting docs"
}
},
"bottomAxis": {
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/x/react-charts/highlighting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import * as pageProps from 'docsx/data/charts/highlighting/highlighting.md?muiMarkdown';

export default function Page() {
return <MarkdownDocs {...pageProps} />;
}
2 changes: 1 addition & 1 deletion packages/x-charts-pro/src/BarChartPro/BarChartPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ BarChartPro.propTypes = {
* The configuration of axes highlight.
* Default is set to 'band' in the bar direction.
* Depends on `layout` prop.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting/ highlighting docs} for more details.

Fixed in 23646d8

A side note, we will move to non-trailing URLs, at one point mui/mui-public#248.

*/
axisHighlight: PropTypes.shape({
x: PropTypes.oneOf(['band', 'line', 'none']),
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts-pro/src/LineChartPro/LineChartPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ LineChartPro.propTypes = {
// ----------------------------------------------------------------------
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @default { x: 'line' }
*/
axisHighlight: PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ScatterChartPro.propTypes = {
// ----------------------------------------------------------------------
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @default { x: 'none', y: 'none' }
*/
axisHighlight: PropTypes.shape({
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface BarChartProps
* The configuration of axes highlight.
* Default is set to 'band' in the bar direction.
* Depends on `layout` prop.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
*
*/
axisHighlight?: ChartsAxisHighlightProps;
Expand Down Expand Up @@ -155,7 +155,7 @@ BarChart.propTypes = {
* The configuration of axes highlight.
* Default is set to 'band' in the bar direction.
* Depends on `layout` prop.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
*/
axisHighlight: PropTypes.shape({
x: PropTypes.oneOf(['band', 'line', 'none']),
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface LineChartProps
grid?: Pick<ChartsGridProps, 'vertical' | 'horizontal'>;
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @default { x: 'line' }
*/
axisHighlight?: ChartsAxisHighlightProps;
Expand Down Expand Up @@ -192,7 +192,7 @@ LineChart.propTypes = {
// ----------------------------------------------------------------------
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @default { x: 'line' }
*/
axisHighlight: PropTypes.shape({
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/PieChart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface PieChartProps
tooltip?: ChartsTooltipProps<'pie'>;
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @default { x: 'none', y: 'none' }
*/
axisHighlight?: ChartsAxisHighlightProps;
Expand Down Expand Up @@ -222,7 +222,7 @@ PieChart.propTypes = {
// ----------------------------------------------------------------------
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @default { x: 'none', y: 'none' }
*/
axisHighlight: PropTypes.shape({
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/ScatterChart/ScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface ScatterChartProps
tooltip?: ChartsTooltipProps<'scatter'>;
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @default { x: 'none', y: 'none' }
*/
axisHighlight?: ChartsAxisHighlightProps;
Expand Down Expand Up @@ -162,7 +162,7 @@ ScatterChart.propTypes = {
// ----------------------------------------------------------------------
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
* @default { x: 'none', y: 'none' }
*/
axisHighlight: PropTypes.shape({
Expand Down