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

[charts] Add color prop to Sparkline and deprecate colors #16477

Merged
merged 6 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 18 additions & 0 deletions docs/data/charts/sparkline/ColorCustomization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { SparkLineChart } from '@mui/x-charts/SparkLineChart';

const settings = {
height: 100,
yAxis: { min: 0, max: 100 },
};

const values = [0, 2, 3, 4, 6, 8, 7, 9, 15, 6, 8, 7, 12];

export default function ColorCustomization() {
return (
<Stack sx={{ width: '100%' }}>
<SparkLineChart data={values} color="green" {...settings} />
</Stack>
);
}
18 changes: 18 additions & 0 deletions docs/data/charts/sparkline/ColorCustomization.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { SparkLineChart } from '@mui/x-charts/SparkLineChart';

const settings = {
height: 100,
yAxis: { min: 0, max: 100 },
} as const;

const values = [0, 2, 3, 4, 6, 8, 7, 9, 15, 6, 8, 7, 12];

export default function ColorCustomization() {
return (
<Stack sx={{ width: '100%' }}>
<SparkLineChart data={values} color="green" {...settings} />
</Stack>
);
}
1 change: 1 addition & 0 deletions docs/data/charts/sparkline/ColorCustomization.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<SparkLineChart data={values} color="green" {...settings} />
22 changes: 22 additions & 0 deletions docs/data/charts/sparkline/ColorCustomizationMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { SparkLineChart } from '@mui/x-charts/SparkLineChart';

const settings = {
height: 100,
yAxis: { min: 0, max: 100 },
};

const values = [0, 2, 3, 4, 6, 8, 7, 9, 15, 6, 8, 7, 12];

export default function ColorCustomizationMode() {
return (
<Stack sx={{ width: '100%' }}>
<SparkLineChart
data={values}
color={(mode) => (mode === 'light' ? 'black' : 'white')}
{...settings}
/>
</Stack>
);
}
22 changes: 22 additions & 0 deletions docs/data/charts/sparkline/ColorCustomizationMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import { SparkLineChart } from '@mui/x-charts/SparkLineChart';

const settings = {
height: 100,
yAxis: { min: 0, max: 100 },
} as const;

const values = [0, 2, 3, 4, 6, 8, 7, 9, 15, 6, 8, 7, 12];

export default function ColorCustomizationMode() {
return (
<Stack sx={{ width: '100%' }}>
<SparkLineChart
data={values}
color={(mode) => (mode === 'light' ? 'black' : 'white')}
{...settings}
/>
</Stack>
);
}
5 changes: 5 additions & 0 deletions docs/data/charts/sparkline/ColorCustomizationMode.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<SparkLineChart
data={values}
color={(mode) => (mode === 'light' ? 'black' : 'white')}
{...settings}
/>
12 changes: 12 additions & 0 deletions docs/data/charts/sparkline/sparkline.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ The demo below shows different ways to set the y-axis range.
They always display the same data, going from -15 to 92, but with different `domainLimit` settings.

{{"demo": "CustomDomainYAxis.js"}}

## Color Customization

You can customize the color of the sparkline by providing a color to the `color` prop.

{{"demo": "ColorCustomization.js"}}

The `color` prop also accepts a function that is called with the mode (`'light'` or `'dark'`), so you can adapt the color to user preferences.

The following example shows a white line if this page is in dark mode, or a black one if it is in light mode.

{{"demo": "ColorCustomizationMode.js"}}
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 @@ -22,7 +22,7 @@
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/bar-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/chart-container.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"props": {
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/chart-data-provider-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"props": {
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/chart-data-provider.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"props": {
"colors": { "type": { "name": "any" }, "default": "rainbowSurgePalette" },
"colors": { "type": { "name": "any" }, "default": "blueberryTwilightPalette" },
"dataset": { "type": { "name": "any" } },
"height": { "type": { "name": "any" } },
"id": { "type": { "name": "any" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/heatmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/line-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/pie-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"height": { "type": { "name": "number" } },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/scatter-chart-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/scatter-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "blueberryTwilightPalette"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
8 changes: 7 additions & 1 deletion docs/pages/x/api/charts/spark-line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
"required": true
},
"area": { "type": { "name": "bool" }, "default": "false" },
"color": {
"type": { "name": "union", "description": "func<br>&#124;&nbsp;string" },
"default": "rainbowSurgePalette[0]"
},
"colors": {
"type": { "name": "union", "description": "Array&lt;string&gt;<br>&#124;&nbsp;func" },
"default": "rainbowSurgePalette"
"default": "rainbowSurgePalette",
"deprecated": true,
"deprecationInfo": "use the <code>color</code> prop instead"
},
"dataset": { "type": { "name": "arrayOf", "description": "Array&lt;object&gt;" } },
"disableAxisListener": { "type": { "name": "bool" }, "default": "false" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"area": {
"description": "Set to <code>true</code> to fill spark line area. Has no effect if plotType=&#39;bar&#39;."
},
"color": { "description": "Color used to colorize the sparkline." },
"colors": { "description": "Color palette used to colorize multiple series." },
"data": { "description": "Data to plot." },
"dataset": {
Expand Down
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 @@ -168,7 +168,7 @@ BarChartPro.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ChartDataProviderPro.propTypes = {
children: PropTypes.node,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed from rainbowSurgePalette to blueberryTwilightPalette? Rainbow surge is the new one and should be the default

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, it wasn't intended.

Before I had the update to the default color in this PR as well, but when I moved it into a different one I must have messed something up. It's fixed now!

*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts-pro/src/Heatmap/Heatmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Heatmap.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
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 @@ -224,7 +224,7 @@ LineChartPro.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ScatterChartPro.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ BarChart.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/ChartContainer/ChartContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ChartContainer.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ChartDataProvider.propTypes = {
children: PropTypes.node,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.any,
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ LineChart.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/PieChart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ PieChart.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/ScatterChart/ScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ ScatterChart.propTypes = {
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default rainbowSurgePalette
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
Expand Down
Loading