Skip to content

Commit 3b7ae4a

Browse files
committed
migrate ScatterChart
1 parent c4b665c commit 3b7ae4a

File tree

4 files changed

+102
-102
lines changed

4 files changed

+102
-102
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ControlsWithNote, DocsHeader, Footer } from '@sb/components';
2+
import { Canvas, Meta } from '@storybook/addon-docs';
3+
import * as ComponentStories from './ScatterChart.stories';
4+
5+
<Meta of={ComponentStories} />
6+
7+
<DocsHeader />
8+
9+
## Example
10+
11+
<Canvas of={ComponentStories.Default} />
12+
13+
## Properties
14+
15+
<ControlsWithNote of={ComponentStories.Default} />
16+
17+
<br />
18+
<br />
19+
20+
## More Examples
21+
22+
### With Custom Color
23+
24+
<Canvas of={ComponentStories.WithCustomColor} />
25+
26+
### Loading Placeholder
27+
28+
<Canvas of={ComponentStories.LoadingPlaceholder} />
29+
30+
<Footer />

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

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import { ScatterChart } from './ScatterChart.js';
3+
import { scatterColorDataSet, scatterComplexDataSet } from '../../resources/DemoProps.js';
4+
5+
const meta = {
6+
title: 'ScatterChart',
7+
component: ScatterChart,
8+
argTypes: {
9+
children: {
10+
control: { disable: true }
11+
}
12+
},
13+
args: {
14+
dataset: scatterComplexDataSet,
15+
measures: [
16+
{
17+
accessor: 'users',
18+
label: 'Users',
19+
axis: 'x'
20+
},
21+
{
22+
accessor: 'sessions',
23+
label: 'Sessions',
24+
formatter: (val) => `${val}k`,
25+
axis: 'y'
26+
},
27+
{
28+
accessor: 'volume',
29+
axis: 'z'
30+
}
31+
]
32+
}
33+
} satisfies Meta<typeof ScatterChart>;
34+
35+
export default meta;
36+
type Story = StoryObj<typeof meta>;
37+
38+
export const Default: Story = {};
39+
40+
export const WithCustomColor: Story = {
41+
args: {
42+
dataset: scatterColorDataSet,
43+
measures: [
44+
{
45+
accessor: 'users',
46+
label: 'Users',
47+
axis: 'x'
48+
},
49+
{
50+
accessor: 'sessions',
51+
label: 'Sessions',
52+
axis: 'y'
53+
},
54+
{
55+
accessor: 'volume',
56+
axis: 'z'
57+
}
58+
]
59+
}
60+
};
61+
62+
export const LoadingPlaceholder: Story = {
63+
args: {
64+
dataset: []
65+
}
66+
};

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ export interface ScatterChartProps extends Omit<IChartBaseProps<IScatterChartCon
6868
/**
6969
* An array of dataset objects. Each object defines a dataset which is displayed.
7070
*
71-
* #### Required properties
71+
* **Required properties**
7272
* - `data`: array of objects which contains the data.
7373
*
74-
* #### Optional properties
74+
* **Optional properties**
7575
* - `label`: string containing the label of the dataset which is also displayed in the legend.
7676
* - `color`: any valid CSS color or CSS variable. Defaults to the `sapChart_Ordinal` colors.
7777
* - `opacity`: number contains value of opacity of dataset
7878
*
79-
* #### Example of dataset:
79+
* **Example of dataset:**
8080
*
8181
* <code>
8282
* <pre>
@@ -105,12 +105,12 @@ export interface ScatterChartProps extends Omit<IChartBaseProps<IScatterChartCon
105105
/**
106106
* An array of config objects. Each object is defining one axis in the chart.
107107
*
108-
* #### Required properties
108+
* **Required properties**
109109
* - `accessor`: string containing the path to the dataset key this line should display. Supports object structures by using <code>'parent.child'</code>.
110110
* Can also be a getter.
111111
* - `axis`: string containing definition of axis. Must be x, y or z data to the axis.
112112
*
113-
* #### Optional properties
113+
* **Optional properties**
114114
* - `label`: Label to display in tooltips. Falls back to the <code>accessor</code> if not present.
115115
* - `formatter`: function will be called for each data label and allows you to format it according to your needs. Also addresses labels of axis.
116116
*/
@@ -205,7 +205,7 @@ const ScatterChart = forwardRef<HTMLDivElement, ScatterChartProps>((props, ref)
205205
const yMeasure = measures.find(({ axis }) => axis === 'y');
206206
const zMeasure = measures.find(({ axis }) => axis === 'z');
207207

208-
const [yAxisWidth, legendPosition] = useLongestYAxisLabel(dataset?.[0].data, [yMeasure]);
208+
const [yAxisWidth, legendPosition] = useLongestYAxisLabel(dataset?.[0]?.data, [yMeasure]);
209209
const xAxisHeights = useObserveXAxisHeights(chartRef, 1);
210210
const marginChart = useChartMargin(chartConfig.margin, chartConfig.zoomingTool);
211211
const { chartConfig: _0, measures: _1, ...propsWithoutOmitted } = rest;

0 commit comments

Comments
 (0)