Skip to content

Commit 4dbb17e

Browse files
feat(Charts): stabilize new charts and deprecate old charts (#507)
1 parent 6004c8c commit 4dbb17e

37 files changed

+325
-159
lines changed

docs/MigrationGuide.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,88 @@
11
# Migration Guide
22

3+
## 0.9.5 - Charts Migration
4+
With version v0.9.5 of `@ui5/webcomponents-react-charts` we replace the canvas based charts with SVG based charts and
5+
streamlined the ChartAPI to work similar to the `AnalyticalTable` API.
6+
This requires a couple of changes on your side:
7+
8+
1. Change the import from `@ui5/webcomponents-react-charts/lib/[ChartType]` to `@ui5/webcomponents-react-charts/lib/[ChartType]`
9+
2. Don't split the dataset into labels and single dataset entries as before, you can pass your dataset "as-is" to the chart.
10+
3. Your labels are now part of the dataset, but you need to tell the chart which element of the data is your dimension
11+
Use the `dimensions` prop for that.
12+
4. Instead of passing multiple datasets with their own data into the datasets prop, define your `measures` by specifying at least the `accessor`.
13+
14+
To illustrate the required changes, you can find the migration of a bar chart with two bars per dimension below:
15+
16+
Old Bar Chart:
17+
```jsx
18+
import React from 'react';
19+
import { BarChart } from '@ui5/webcomponents-react-charts/lib/BarChart';
20+
21+
const MyComponent = () => {
22+
return (
23+
<BarChart
24+
labels={['January', 'February', 'March']}
25+
datasets={[
26+
{
27+
label: 'Existing Customers',
28+
data: [65, 59, 80]
29+
},
30+
31+
{
32+
label: 'New Customers',
33+
data: [5, 9, 8]
34+
}
35+
]}
36+
/>
37+
);
38+
};
39+
```
40+
41+
New Bar Chart:
42+
```jsx
43+
import React from 'react';
44+
import { BarChart } from '@ui5/webcomponents-react-charts/lib/next/BarChart';
45+
46+
const MyComponent = () => {
47+
return (
48+
<BarChart
49+
dimensions={[
50+
{
51+
accessor: 'month'
52+
}
53+
]}
54+
measures={[
55+
{
56+
accessor: 'existingCustomers',
57+
label: 'Existing Customers'
58+
},
59+
{
60+
accessor: 'newCustomers',
61+
label: 'New Customers'
62+
}
63+
]}
64+
dataset={[
65+
{
66+
month: 'January',
67+
existingCustomers: 65,
68+
newCustomers: 5
69+
},
70+
{
71+
month: 'February',
72+
existingCustomers: 59,
73+
newCustomers: 9
74+
},
75+
{
76+
month: 'March',
77+
existingCustomers: 80,
78+
newCustomers: 8
79+
}
80+
]}
81+
/>
82+
);
83+
};
84+
```
85+
386
## Migrating from 0.8.X to 0.9.0
487
Migrating your app from 0.8.X to 0.9.0 requires a few updates to the API properties, this includes dependencies, theming, event handling and prop changes.
588

packages/charts/src/components/BarChart/BarChart.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export interface BarChartProps extends RechartBaseProps {
9191

9292
/**
9393
* <code>import { BarChart } from '@ui5/webcomponents-react-charts/lib/next/BarChart';</code>
94-
* **This component is under active development. The API is not stable yet and might change without further notice.**
9594
*/
9695
const BarChart: FC<BarChartProps> = forwardRef((props: BarChartProps, ref: Ref<any>) => {
9796
const {
@@ -119,6 +118,7 @@ const BarChart: FC<BarChartProps> = forwardRef((props: BarChartProps, ref: Ref<a
119118
legendHorizontalAlign: 'left',
120119
barGap: 3,
121120
zoomingTool: false,
121+
resizeDebounce: 250,
122122
...props.chartConfig
123123
};
124124
}, [props.chartConfig]);
@@ -174,6 +174,7 @@ const BarChart: FC<BarChartProps> = forwardRef((props: BarChartProps, ref: Ref<a
174174
className={className}
175175
tooltip={tooltip}
176176
slot={slot}
177+
resizeDebounce={chartConfig.resizeDebounce}
177178
>
178179
<BarChartLib
179180
margin={marginChart}

packages/charts/src/components/BarChart/BarRechart.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React from 'react';
55
import { complexDataSet, secondaryDimensionDataSet, simpleDataSet } from '../../resources/DemoProps';
66

77
export default {
8-
title: 'Charts - Unstable / BarChart',
8+
title: 'Charts / BarChart',
99
component: BarChart
1010
};
1111

packages/charts/src/components/BarChart/demo.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const options = {
3535
};
3636

3737
export default {
38-
title: 'Charts / BarChart',
38+
title: 'Charts - Deprecated / BarChart',
3939
component: BarChart
4040
};
4141

packages/charts/src/components/BarChart/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
import { getTheme } from '@ui5/webcomponents-base/dist/config/Theme';
12
import { useConsolidatedRef } from '@ui5/webcomponents-react-base/lib/useConsolidatedRef';
3+
import { deprecationNotice } from '@ui5/webcomponents-react-base/lib/Utils';
4+
import { getTextWidth } from '@ui5/webcomponents-react-charts/lib/Utils';
25
import { withChartContainer } from '@ui5/webcomponents-react-charts/lib/withChartContainer';
36
import bestContrast from 'get-best-contrast-color';
4-
import React, { FC, forwardRef, Ref, useMemo } from 'react';
7+
import React, { FC, forwardRef, Ref, useEffect, useMemo } from 'react';
58
import { HorizontalBar } from 'react-chartjs-2';
6-
import { getTheme } from '@ui5/webcomponents-base/dist/config/Theme';
79
import { DEFAULT_OPTIONS } from '../../config';
810
import { ChartBaseProps } from '../../interfaces/ChartBaseProps';
911
import { InternalProps } from '../../interfaces/InternalProps';
1012
import { useLegend, useLegendItemClickHandler } from '../../internal/ChartLegend';
1113
import { getCssVariableValue } from '../../themes/Utils';
1214
import { ChartBaseDefaultProps } from '../../util/ChartBaseDefaultProps';
1315
import { useChartData } from '../../util/populateData';
14-
import { getTextWidth } from '@ui5/webcomponents-react-charts/lib/Utils';
1516
import { formatAxisCallback, formatDataLabel, formatTooltipLabel, useMergedConfig } from '../../util/utils_deprecated';
1617
import { BarChartPlaceholder } from './Placeholder';
1718

@@ -33,6 +34,13 @@ const BarChartComponent = forwardRef((props: BarChartPropTypes, ref: Ref<any>) =
3334
legendRef
3435
} = props as BarChartPropTypes & InternalProps;
3536

37+
useEffect(() => {
38+
deprecationNotice(
39+
'BarChart',
40+
"This component is deprecated and will be removed with v0.10.0. Please use '@ui5/webcomponents-react-charts/lib/next/BarChart' instead."
41+
);
42+
}, []);
43+
3644
const theme = getTheme();
3745
const data = useChartData(labels, datasets, colors, theme);
3846

@@ -115,6 +123,8 @@ const BarChartComponent = forwardRef((props: BarChartPropTypes, ref: Ref<any>) =
115123
BarChartComponent.LoadingPlaceholder = BarChartPlaceholder;
116124
/**
117125
* <code>import { BarChart } from '@ui5/webcomponents-react-charts/lib/BarChart';</code>
126+
* <br />
127+
* <b>This component is deprecated and will be removed with v0.10.0. Please use [this component](https://sap.github.io/ui5-webcomponents-react/?path=/docs/charts-barchart) instead.</b>
118128
*/
119129
const BarChart: FC<BarChartPropTypes> = withChartContainer(BarChartComponent);
120130

packages/charts/src/components/ColumnChart/ColumnChart.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ const measureDefaults = {
8989

9090
/**
9191
* <code>import { ColumnChart } from '@ui5/webcomponents-react-charts/lib/next/ColumnChart';</code>
92-
* **This component is under active development. The API is not stable yet and might change without further notice.**
9392
*/
9493
const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, ref: Ref<any>) => {
9594
const {
@@ -116,6 +115,7 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
116115
legendHorizontalAlign: 'left',
117116
barGap: 3,
118117
zoomingTool: false,
118+
resizeDebounce: 250,
119119
...props.chartConfig
120120
};
121121
}, [props.chartConfig]);
@@ -179,6 +179,7 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r
179179
className={className}
180180
tooltip={tooltip}
181181
slot={slot}
182+
resizeDebounce={chartConfig.resizeDebounce}
182183
>
183184
<ColumnChartLib
184185
margin={marginChart}

packages/charts/src/components/ColumnChart/ColumnRechart.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React from 'react';
55
import { complexDataSet, secondaryDimensionDataSet, simpleDataSet } from '../../resources/DemoProps';
66

77
export default {
8-
title: 'Charts - Unstable / ColumnChart',
8+
title: 'Charts / ColumnChart',
99
component: ColumnChart
1010
};
1111

@@ -148,7 +148,7 @@ renderCustomDataLabelStory.story = {
148148
name: 'With formatter'
149149
};
150150

151-
export const loadingPlaceholder = () => <ColumnChart style={{ width: '30%' }} dimensions={[]} measures={[]}/>;
151+
export const loadingPlaceholder = () => <ColumnChart style={{ width: '30%' }} dimensions={[]} measures={[]} />;
152152

153153
loadingPlaceholder.story = {
154154
name: 'Loading placeholder'

packages/charts/src/components/ColumnChart/demo.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const growthLineOptions = {
6868
};
6969

7070
export default {
71-
title: 'Charts / ColumnChart',
71+
title: 'Charts - Deprecated / ColumnChart',
7272
component: ColumnChart
7373
};
7474

packages/charts/src/components/ColumnChart/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { getTheme } from '@ui5/webcomponents-base/dist/config/Theme';
2+
import { deprecationNotice } from '@ui5/webcomponents-react-base/lib/Utils';
23
import { useConsolidatedRef } from '@ui5/webcomponents-react-base/lib/useConsolidatedRef';
34
import { getTextHeight, getTextWidth } from '@ui5/webcomponents-react-charts/lib/Utils';
45
import { withChartContainer } from '@ui5/webcomponents-react-charts/lib/withChartContainer';
56
import bestContrast from 'get-best-contrast-color';
6-
import React, { FC, forwardRef, Ref, useMemo } from 'react';
7+
import React, { FC, forwardRef, Ref, useEffect, useMemo } from 'react';
78
import { Bar } from 'react-chartjs-2';
89
import { DEFAULT_OPTIONS } from '../../config';
910
import { ChartBaseProps } from '../../interfaces/ChartBaseProps';
@@ -33,6 +34,13 @@ const ColumnChartComponent = forwardRef((props: ColumnChartPropTypes, ref: Ref<a
3334
legendRef
3435
} = props as ColumnChartPropTypes & InternalProps;
3536

37+
useEffect(() => {
38+
deprecationNotice(
39+
'ColumnChart',
40+
"This component is deprecated and will be removed with v0.10.0. Please use '@ui5/webcomponents-react-charts/lib/next/ColumnChart' instead."
41+
);
42+
}, []);
43+
3644
const theme = getTheme();
3745
const data = useChartData(labels, datasets, colors, theme);
3846

@@ -118,6 +126,8 @@ const ColumnChartComponent = forwardRef((props: ColumnChartPropTypes, ref: Ref<a
118126
ColumnChartComponent.LoadingPlaceholder = ColumnChartPlaceholder;
119127
/**
120128
* <code>import { ColumnChart } from '@ui5/webcomponents-react-charts/lib/ColumnChart';</code>
129+
* <br />
130+
* <b>This component is deprecated and will be removed with v0.10.0. Please use [this component](https://sap.github.io/ui5-webcomponents-react/?path=/docs/charts-columnchart) instead.</b>
121131
*/
122132
const ColumnChart: FC<ColumnChartPropTypes> = withChartContainer(ColumnChartComponent);
123133

packages/charts/src/components/ComposedChart/ComposedChart.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { bigDataSet, complexDataSet, secondaryDimensionDataSet, simpleDataSet }
55
import { boolean, select } from '@storybook/addon-knobs';
66

77
export default {
8-
title: 'Charts - Unstable / ComposedChart',
8+
title: 'Charts / ComposedChart',
99
component: ComposedChart
1010
};
1111

packages/charts/src/components/ComposedChart/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ type AvailableChartTypes = 'line' | 'bar' | 'area' | string;
106106

107107
/**
108108
* <code>import { ComposedChart } from '@ui5/webcomponents-react-charts/lib/next/ComposedChart';</code>
109-
* **This component is under active development. The API is not stable yet and might change without further notice.**
110109
*/
111110
const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartProps, ref: Ref<any>) => {
112111
const {
@@ -135,6 +134,7 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
135134
legendPosition: 'bottom',
136135
legendHorizontalAlign: 'left',
137136
zoomingTool: false,
137+
resizeDebounce: 250,
138138
...props.chartConfig
139139
};
140140
}, [props.chartConfig]);
@@ -223,6 +223,7 @@ const ComposedChart: FC<ComposedChartProps> = forwardRef((props: ComposedChartPr
223223
className={className}
224224
tooltip={tooltip}
225225
slot={slot}
226+
resizeDebounce={chartConfig.resizeDebounce}
226227
>
227228
<ComposedChartLib
228229
margin={marginChart}

0 commit comments

Comments
 (0)