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] Deprecate xAxisKey /zAxisKey in favor of xAxisId/zAxisId #13940

Merged
merged 6 commits into from
Jul 24, 2024
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
6 changes: 3 additions & 3 deletions docs/data/charts/axis/AxisWithComposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ export default function AxisWithComposition() {
{
type: 'line',
id: 'revenue',
yAxisKey: 'money',
yAxisId: 'money',
data: [5645, 7542, 9135, 12221],
},
{
type: 'bar',
id: 'cookies',
yAxisKey: 'quantities',
yAxisId: 'quantities',
data: [3205, 2542, 3135, 8374],
},
{
type: 'bar',
id: 'icecream',
yAxisKey: 'quantities',
yAxisId: 'quantities',
data: [1645, 5542, 5146, 3735],
},
]}
Expand Down
6 changes: 3 additions & 3 deletions docs/data/charts/axis/AxisWithComposition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ export default function AxisWithComposition() {
{
type: 'line',
id: 'revenue',
yAxisKey: 'money',
yAxisId: 'money',
data: [5645, 7542, 9135, 12221],
},
{
type: 'bar',
id: 'cookies',
yAxisKey: 'quantities',
yAxisId: 'quantities',
data: [3205, 2542, 3135, 8374],
},
{
type: 'bar',
id: 'icecream',
yAxisKey: 'quantities',
yAxisId: 'quantities',
data: [1645, 5542, 5146, 3735],
},
]}
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/axis/ReverseExampleNoSnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const dataset = [
const series = [
{ type: 'line', dataKey: 'min', color: '#577399' },
{ type: 'line', dataKey: 'max', color: '#fe5f55' },
{ type: 'bar', dataKey: 'precip', color: '#bfdbf7', yAxisKey: 'rightAxis' },
{ type: 'bar', dataKey: 'precip', color: '#bfdbf7', yAxisId: 'rightAxis' },
];

export default function ReverseExampleNoSnap() {
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/axis/ScaleExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default function ScaleExample() {
{ id: 'logAxis', scaleType: 'log' },
]}
series={[
{ yAxisKey: 'linearAxis', data: sample, label: 'linear' },
{ yAxisKey: 'logAxis', data: sample, label: 'log' },
{ yAxisId: 'linearAxis', data: sample, label: 'linear' },
{ yAxisId: 'logAxis', data: sample, label: 'log' },
]}
leftAxis="linearAxis"
rightAxis="logAxis"
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/axis/ScaleExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default function ScaleExample() {
{ id: 'logAxis', scaleType: 'log' },
]}
series={[
{ yAxisKey: 'linearAxis', data: sample, label: 'linear' },
{ yAxisKey: 'logAxis', data: sample, label: 'log' },
{ yAxisId: 'linearAxis', data: sample, label: 'linear' },
{ yAxisId: 'logAxis', data: sample, label: 'log' },
]}
leftAxis="linearAxis"
rightAxis="logAxis"
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/axis/ScaleExample.tsx.preview
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{ id: 'logAxis', scaleType: 'log' },
]}
series={[
{ yAxisKey: 'linearAxis', data: sample, label: 'linear' },
{ yAxisKey: 'logAxis', data: sample, label: 'log' },
{ yAxisId: 'linearAxis', data: sample, label: 'linear' },
{ yAxisId: 'logAxis', data: sample, label: 'log' },
]}
leftAxis="linearAxis"
rightAxis="logAxis"
Expand Down
6 changes: 3 additions & 3 deletions docs/data/charts/axis/axis.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ Here is a demonstration with two lines with the same data.
But one uses a linear, and the other a log axis.

Each axis definition is identified by its property `id`.
And series specify the axis they use with `xAxisKey` and `yAxisKey` properties.
And series specify the axis they use with `xAxisId` and `yAxisId` properties.

{{"demo": "ScaleExample.js"}}

:::info
The management of those ids is for advanced use cases, such as charts with multiple axes.
Or customized axes.

If you do not provide a `xAxisKey` or `yAxisKey`, the series will use the first axis defined.
If you do not provide a `xAxisId` or `yAxisId`, the series will use the first axis defined.

That's why in most of the demonstrations with single x and y axis you will not see definitions of axis `id`, `xAxisKey`, or `yAxisKey`.
That's why in most of the demonstrations with single x and y axis you will not see definitions of axis `id`, `xAxisId`, or `yAxisId`.
Those demonstrations use the defaultized values.
:::

Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/bar-demo/BiaxialBarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export default function BiaxialBarChart() {
data: pData,
label: 'pv',
id: 'pvId',
yAxisKey: 'leftAxisId',
yAxisId: 'leftAxisId',
},
{
data: uData,
label: 'uv',
id: 'uvId',
yAxisKey: 'rightAxisId',
yAxisId: 'rightAxisId',
},
]}
xAxis={[{ data: xLabels, scaleType: 'band' }]}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/bar-demo/BiaxialBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export default function BiaxialBarChart() {
label: 'pv',
id: 'pvId',

yAxisKey: 'leftAxisId',
yAxisId: 'leftAxisId',
},
{
data: uData,
label: 'uv',
id: 'uvId',

yAxisKey: 'rightAxisId',
yAxisId: 'rightAxisId',
},
]}
xAxis={[{ data: xLabels, scaleType: 'band' }]}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/components/ScaleDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ export default function ScaleDemo() {
{
type: 'line',
data: [5, 15, 20, 24, 30, 38, 40, 51, 52, 61],
yAxisKey: 'left_axis_id',
yAxisId: 'left_axis_id',
},
{
type: 'line',
data: [
50134, 48361, 46362, 44826, 42376, 40168, 38264, 36159, 34259, 32168,
],
yAxisKey: 'right_axis_id',
yAxisId: 'right_axis_id',
},
]}
xAxis={[{ data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], scaleType: 'point' }]}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/components/ScaleDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ export default function ScaleDemo() {
{
type: 'line',
data: [5, 15, 20, 24, 30, 38, 40, 51, 52, 61],
yAxisKey: 'left_axis_id',
yAxisId: 'left_axis_id',
},
{
type: 'line',
data: [
50134, 48361, 46362, 44826, 42376, 40168, 38264, 36159, 34259, 32168,
],
yAxisKey: 'right_axis_id',
yAxisId: 'right_axis_id',
},
]}
xAxis={[{ data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], scaleType: 'point' }]}
Expand Down
6 changes: 3 additions & 3 deletions docs/data/charts/getting-started/Combining.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ const series = [
{
type: 'bar',
stack: '',
yAxisKey: 'eco',
yAxisId: 'eco',
data: [2, 5, 3, 4, 1],
},
{
type: 'bar',
stack: '',
yAxisKey: 'eco',
yAxisId: 'eco',
data: [5, 6, 2, 8, 9],
},
{
type: 'line',
yAxisKey: 'pib',
yAxisId: 'pib',
color: 'red',
data: [1000, 1500, 3000, 5000, 10000],
},
Expand Down
6 changes: 3 additions & 3 deletions docs/data/charts/getting-started/Combining.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ const series = [
{
type: 'bar',
stack: '',
yAxisKey: 'eco',
yAxisId: 'eco',
data: [2, 5, 3, 4, 1],
},
{
type: 'bar',
stack: '',
yAxisKey: 'eco',
yAxisId: 'eco',
data: [5, 6, 2, 8, 9],
},
{
type: 'line',
yAxisKey: 'pib',
yAxisId: 'pib',
color: 'red',
data: [1000, 1500, 3000, 5000, 10000],
},
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/line-demo/BiaxialLineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default function BiaxialLineChart() {
width={500}
height={300}
series={[
{ data: pData, label: 'pv', yAxisKey: 'leftAxisId' },
{ data: uData, label: 'uv', yAxisKey: 'rightAxisId' },
{ data: pData, label: 'pv', yAxisId: 'leftAxisId' },
{ data: uData, label: 'uv', yAxisId: 'rightAxisId' },
]}
xAxis={[{ scaleType: 'point', data: xLabels }]}
yAxis={[{ id: 'leftAxisId' }, { id: 'rightAxisId' }]}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/line-demo/BiaxialLineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default function BiaxialLineChart() {
width={500}
height={300}
series={[
{ data: pData, label: 'pv', yAxisKey: 'leftAxisId' },
{ data: uData, label: 'uv', yAxisKey: 'rightAxisId' },
{ data: pData, label: 'pv', yAxisId: 'leftAxisId' },
{ data: uData, label: 'uv', yAxisId: 'rightAxisId' },
]}
xAxis={[{ scaleType: 'point', data: xLabels }]}
yAxis={[{ id: 'leftAxisId' }, { id: 'rightAxisId' }]}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/line-demo/BiaxialLineChart.tsx.preview
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
width={500}
height={300}
series={[
{ data: pData, label: 'pv', yAxisKey: 'leftAxisId' },
{ data: uData, label: 'uv', yAxisKey: 'rightAxisId' },
{ data: pData, label: 'pv', yAxisId: 'leftAxisId' },
{ data: uData, label: 'uv', yAxisId: 'rightAxisId' },
]}
xAxis={[{ scaleType: 'point', data: xLabels }]}
yAxis={[{ id: 'leftAxisId' }, { id: 'rightAxisId' }]}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/scatter-demo/MultipleYAxesScatterChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export default function MultipleYAxesScatterChart() {
series={[
{
data: data1,
yAxisKey: 'leftAxis',
yAxisId: 'leftAxis',
valueFormatter: ({ x, y }) => `${x}cm, ${y}kg`,
},
{
data: data2,
yAxisKey: 'rightAxis',
yAxisId: 'rightAxis',
valueFormatter: ({ x, y }) => `${x}cm, ${y}kg`,
},
]}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/charts/scatter-demo/MultipleYAxesScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export default function MultipleYAxesScatterChart() {
series={[
{
data: data1,
yAxisKey: 'leftAxis',
yAxisId: 'leftAxis',

valueFormatter: ({ x, y }) => `${x}cm, ${y}kg`,
},
{
data: data2,
yAxisKey: 'rightAxis',
yAxisId: 'rightAxis',

valueFormatter: ({ x, y }) => `${x}cm, ${y}kg`,
},
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/x/api/charts/bar-series-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"stackOffset": { "type": { "description": "StackOffsetType" }, "default": "'diverging'" },
"stackOrder": { "type": { "description": "StackOrderType" }, "default": "'none'" },
"valueFormatter": { "type": { "description": "SeriesValueFormatter<TValue>" } },
"xAxisId": { "type": { "description": "string" } },
"xAxisKey": { "type": { "description": "string" } },
"yAxisId": { "type": { "description": "string" } },
"yAxisKey": { "type": { "description": "string" } }
}
}
2 changes: 2 additions & 0 deletions docs/pages/x/api/charts/line-series-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"stackOffset": { "type": { "description": "StackOffsetType" }, "default": "'none'" },
"stackOrder": { "type": { "description": "StackOrderType" }, "default": "'none'" },
"valueFormatter": { "type": { "description": "SeriesValueFormatter<TValue>" } },
"xAxisId": { "type": { "description": "string" } },
"xAxisKey": { "type": { "description": "string" } },
"yAxisId": { "type": { "description": "string" } },
"yAxisKey": { "type": { "description": "string" } }
}
}
3 changes: 3 additions & 0 deletions docs/pages/x/api/charts/scatter-series-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
},
"markerSize": { "type": { "description": "number" } },
"valueFormatter": { "type": { "description": "SeriesValueFormatter<TValue>" } },
"xAxisId": { "type": { "description": "string" } },
"xAxisKey": { "type": { "description": "string" } },
"yAxisId": { "type": { "description": "string" } },
"yAxisKey": { "type": { "description": "string" } },
"zAxisId": { "type": { "description": "string" } },
"zAxisKey": { "type": { "description": "string" } }
}
}
2 changes: 2 additions & 0 deletions docs/translations/api-docs/charts/bar-series-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"valueFormatter": {
"description": "Formatter used to render values in tooltip or other data display."
},
"xAxisId": { "description": "The id of the x-axis used to render the series." },
"xAxisKey": { "description": "The id of the x-axis used to render the series." },
"yAxisId": { "description": "The id of the y-axis used to render the series." },
"yAxisKey": { "description": "The id of the y-axis used to render the series." }
}
}
2 changes: 2 additions & 0 deletions docs/translations/api-docs/charts/line-series-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"valueFormatter": {
"description": "Formatter used to render values in tooltip or other data display."
},
"xAxisId": { "description": "The id of the x-axis used to render the series." },
"xAxisKey": { "description": "The id of the x-axis used to render the series." },
"yAxisId": { "description": "The id of the y-axis used to render the series." },
"yAxisKey": { "description": "The id of the y-axis used to render the series." }
}
}
3 changes: 3 additions & 0 deletions docs/translations/api-docs/charts/scatter-series-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
"valueFormatter": {
"description": "Formatter used to render values in tooltip or other data display."
},
"xAxisId": { "description": "The id of the x-axis used to render the series." },
"xAxisKey": { "description": "The id of the x-axis used to render the series." },
"yAxisId": { "description": "The id of the y-axis used to render the series." },
"yAxisKey": { "description": "The id of the y-axis used to render the series." },
"zAxisId": { "description": "The id of the z-axis used to render the series." },
"zAxisKey": { "description": "The id of the z-axis used to render the series." }
}
}
20 changes: 8 additions & 12 deletions packages/x-charts/src/BarChart/BarPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ const useAggregatedData = (): {

const data = stackingGroups.flatMap(({ ids: groupIds }, groupIndex) => {
return groupIds.flatMap((seriesId) => {
const xAxisKey = series[seriesId].xAxisKey ?? defaultXAxisId;
const yAxisKey = series[seriesId].yAxisKey ?? defaultYAxisId;
const xAxisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey ?? defaultXAxisId;
const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey ?? defaultYAxisId;

const xAxisConfig = xAxis[xAxisKey];
const yAxisConfig = yAxis[yAxisKey];
const xAxisConfig = xAxis[xAxisId];
const yAxisConfig = yAxis[yAxisId];

const verticalLayout = series[seriesId].layout === 'vertical';

checkScaleErrors(verticalLayout, seriesId, xAxisKey, xAxis, yAxisKey, yAxis);
checkScaleErrors(verticalLayout, seriesId, xAxisId, xAxis, yAxisId, yAxis);

const baseScaleConfig = (
verticalLayout ? xAxisConfig : yAxisConfig
Expand All @@ -118,7 +118,7 @@ const useAggregatedData = (): {
const xScale = xAxisConfig.scale;
const yScale = yAxisConfig.scale;

const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
const colorGetter = getColor(series[seriesId], xAxis[xAxisId], yAxis[yAxisId]);
const bandWidth = baseScaleConfig.scale.bandwidth();

const { barWidth, offset } = getBandSize({
Expand All @@ -142,12 +142,8 @@ const useAggregatedData = (): {
seriesId,
dataIndex,
layout: series[seriesId].layout,
x: verticalLayout
? xScale(xAxis[xAxisKey].data?.[dataIndex])! + barOffset
: minValueCoord,
y: verticalLayout
? minValueCoord
: yScale(yAxis[yAxisKey].data?.[dataIndex])! + barOffset,
x: verticalLayout ? xScale(xAxis[xAxisId].data?.[dataIndex])! + barOffset : minValueCoord,
y: verticalLayout ? minValueCoord : yScale(yAxis[yAxisId].data?.[dataIndex])! + barOffset,
xOrigin: xScale(0)!,
yOrigin: yScale(0)!,
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
Expand Down
Loading