Skip to content

Commit c37dc0e

Browse files
committed
Scatter chart: new demo props, added layout
1 parent 3666beb commit c37dc0e

File tree

3 files changed

+159
-33
lines changed

3 files changed

+159
-33
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { action } from '@storybook/addon-actions';
22
import { boolean } from '@storybook/addon-knobs';
33
import React from 'react';
44
import { ScatterChart } from '../../lib/ScatterChart';
5-
import { bigDataSet, complexDataSet, secondaryDimensionDataSet, simpleDataSet } from '../../resources/DemoProps';
5+
import {
6+
bigDataSet,
7+
complexDataSet,
8+
scatterComplexDataSet,
9+
secondaryDimensionDataSet,
10+
simpleDataSet
11+
} from '../../resources/DemoProps';
612

713
export default {
814
title: 'Charts / ScatterChart',
@@ -16,15 +22,12 @@ export const renderStory = () => (
1622
noAnimation={boolean('noAnimation', false)}
1723
onDataPointClick={action('onDataPointClick')}
1824
onLegendClick={action('onLegendClick')}
19-
dataset={complexDataSet}
25+
dataset={scatterComplexDataSet}
2026
style={{ width: '100%' }}
21-
dimensions={[
22-
{
23-
accessor: 'name',
24-
formatter: (d) => `${d} 2019`,
25-
interval: 0
26-
}
27-
]}
27+
dimension={{
28+
accessor: 'volume',
29+
formatter: (e) => e + 'test'
30+
}}
2831
measures={[
2932
{
3033
accessor: 'users',
@@ -34,12 +37,7 @@ export const renderStory = () => (
3437
{
3538
accessor: 'sessions',
3639
label: 'Active Sessions',
37-
formatter: (val) => `${val} sessions`,
3840
hideDataLabel: true
39-
},
40-
{
41-
accessor: 'volume',
42-
label: 'Vol.'
4341
}
4442
]}
4543
/>
@@ -55,9 +53,9 @@ export const renderStoryWithCustomColor = () => (
5553
noLegend={boolean('noLegend', false)}
5654
noAnimation={boolean('noAnimation', false)}
5755
onDataPointClick={action('onDataPointClick')}
58-
dimensions={[{ accessor: 'name' }]}
56+
dimensions={{ accessor: 'name' }}
5957
measures={[{ accessor: 'users', color: 'red' }]}
60-
dataset={simpleDataSet}
58+
dataset={scatterComplexDataSet}
6159
style={{ width: '95%', height: '40vh' }}
6260
/>
6361
);

packages/charts/src/components/ScatterChart/ScatterChart.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
Tooltip,
1919
XAxis,
2020
YAxis,
21-
ZAxis
21+
ZAxis,
22+
Line
2223
} from 'recharts';
2324
import { useChartMargin } from '../../hooks/useChartMargin';
2425
import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel';
@@ -48,8 +49,9 @@ interface DimensionConfig extends IChartDimension {
4849
interval?: number;
4950
}
5051

51-
export interface LineChartProps extends IChartBaseProps {
52+
export interface ScatterChartProps extends IChartBaseProps {
5253
dimension: DimensionConfig;
54+
dataset?: Record<string, any>[][];
5355
/**
5456
* An array of config objects. Each object is defining one line in the chart.
5557
*
@@ -84,7 +86,7 @@ const measureDefaults = {
8486
/**
8587
* <code>import { LineChart } from '@ui5/webcomponents-react-charts/lib/LineChart';</code>
8688
*/
87-
const ScatterChart: FC<LineChartProps> = forwardRef((props: LineChartProps, ref: Ref<any>) => {
89+
const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps, ref: Ref<any>) => {
8890
const {
8991
dataset,
9092
loading,
@@ -161,9 +163,9 @@ const ScatterChart: FC<LineChartProps> = forwardRef((props: LineChartProps, ref:
161163
const isBigDataSet = dataset?.length > 30 ?? false;
162164
const primaryDimensionAccessor = primaryDimension?.accessor;
163165

164-
const [yAxisWidth, legendPosition] = useLongestYAxisLabel(dataset, measures);
166+
const [yAxisWidth, legendPosition] = useLongestYAxisLabel(dataset[0], measures);
165167
const marginChart = useChartMargin(chartConfig.margin, chartConfig.zoomingTool);
166-
const xAxisHeights = useObserveXAxisHeights(chartRef, props.dimensions.length);
168+
// const xAxisHeights = useObserveXAxisHeights(chartRef, props.dimensions.length);
167169

168170
return (
169171
<ChartContainer
@@ -195,10 +197,7 @@ const ScatterChart: FC<LineChartProps> = forwardRef((props: LineChartProps, ref:
195197
dataKey={measures[0].accessor}
196198
interval={measures[0]?.interval ?? (isBigDataSet ? 'preserveStart' : 0)}
197199
tick={<XAxisTicks config={measures[0]} />}
198-
// tickLine={index < 1}
199-
// axisLine={index < 1}
200200
padding={xAxisPadding}
201-
// allowDuplicatedCategory={index === 0}
202201
/>
203202
)}
204203
<YAxis
@@ -213,15 +212,17 @@ const ScatterChart: FC<LineChartProps> = forwardRef((props: LineChartProps, ref:
213212
tick={<YAxisTicks config={measures[1]} />}
214213
width={yAxisWidth}
215214
/>
216-
<ZAxis
217-
name={dimension.accessor}
218-
dataKey={dimension.accessor}
219-
axisLine={chartConfig.yAxisVisible}
220-
tickLine={tickLineConfig}
221-
key={dimension.accessor}
222-
tickFormatter={dimension?.formatter}
223-
/>
224-
<Scatter data={dataset} name={dimension.accessor} />
215+
<ZAxis name={dimension.accessor} dataKey={dimension.accessor} range={[0, 5000]} key={dimension.accessor} />
216+
{dataset.map((data, index) => {
217+
return (
218+
<Scatter
219+
data={data}
220+
name={dimension.accessor}
221+
fill={`var(--sapChart_OrderedColor_${(index % 11) + 1})`}
222+
isAnimationActive={noAnimation === false}
223+
/>
224+
);
225+
})}
225226
{!noLegend && (
226227
<Legend
227228
verticalAlign={chartConfig.legendPosition}

packages/charts/src/resources/DemoProps.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,133 @@ export const secondaryDimensionDataSet = [
172172
}
173173
];
174174

175+
export const scatterComplexDataSet = [
176+
[
177+
{
178+
users: 120,
179+
sessions: 330,
180+
volume: 744
181+
},
182+
{
183+
users: 213,
184+
sessions: 313,
185+
volume: 881
186+
},
187+
{
188+
users: 241,
189+
sessions: 424,
190+
volume: 670
191+
},
192+
{
193+
users: 328,
194+
sessions: 83,
195+
volume: 630
196+
},
197+
{
198+
users: 102,
199+
sessions: 302,
200+
volume: 126
201+
},
202+
{
203+
users: 233,
204+
sessions: 304,
205+
volume: 880
206+
},
207+
{
208+
users: 202,
209+
sessions: 47,
210+
volume: 452
211+
},
212+
{
213+
users: 222,
214+
sessions: 18,
215+
volume: 500
216+
},
217+
{
218+
users: 210,
219+
sessions: 362,
220+
volume: 892
221+
},
222+
{
223+
users: 215,
224+
sessions: 510,
225+
volume: 2022
226+
},
227+
{
228+
users: 242,
229+
sessions: 402,
230+
volume: 70
231+
},
232+
{
233+
users: 20,
234+
sessions: 10,
235+
volume: 60
236+
}
237+
],
238+
[
239+
{
240+
users: 100,
241+
sessions: 300,
242+
volume: 756
243+
},
244+
{
245+
users: 230,
246+
sessions: 330,
247+
volume: 880
248+
},
249+
{
250+
users: 240,
251+
sessions: 404,
252+
volume: 700
253+
},
254+
{
255+
users: 280,
256+
sessions: 80,
257+
volume: 604
258+
},
259+
{
260+
users: 100,
261+
sessions: 300,
262+
volume: 756
263+
},
264+
{
265+
users: 230,
266+
sessions: 330,
267+
volume: 880
268+
},
269+
{
270+
users: 20,
271+
sessions: 470,
272+
volume: 450
273+
},
274+
{
275+
users: 220,
276+
sessions: 180,
277+
volume: 5000
278+
},
279+
{
280+
users: 200,
281+
sessions: 360,
282+
volume: 879
283+
},
284+
{
285+
users: 250,
286+
sessions: 500,
287+
volume: 200
288+
},
289+
{
290+
users: 240,
291+
sessions: 404,
292+
volume: 700
293+
},
294+
{
295+
users: 280,
296+
sessions: 80,
297+
volume: 604
298+
}
299+
]
300+
];
301+
175302
const concatYear = (array, year) => array.map((item) => ({ ...item, name: `${item.name} ${year}` }));
176303

177304
export const bigDataSet = [

0 commit comments

Comments
 (0)