Skip to content

Commit 5cce9e0

Browse files
committed
Scatter chart: improved documentation
1 parent 6df856b commit 5cce9e0

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

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

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,77 @@ import { defaultFormatter } from '../../internal/defaults';
2828
import { tickLineConfig, tooltipContentStyle, tooltipFillOpacity, xAxisPadding } from '../../internal/staticProps';
2929
import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights';
3030

31-
interface MeasureConfig extends IChartMeasure {
32-
opacity?: number;
31+
interface MeasureConfig extends Omit<IChartMeasure, 'color' | 'hideDataLabel' | 'DataLabel'> {
3332
/**
3433
* Defines axis of measures
3534
*/
3635
axis: 'x' | 'y' | 'z';
3736
}
3837

3938
interface ScatterDataObject {
39+
/**
40+
* Defines label of the dataset
41+
*/
4042
label?: string;
43+
/**
44+
* Contains the data of the chart
45+
*/
4146
data?: any[];
47+
/**
48+
* Any valid CSS Color or CSS Variable. Defaults to the `sapChart_Ordinal` colors
49+
*/
4250
color?: CSSProperties['color'];
51+
/**
52+
* Defines opacity of the displayed dataset
53+
* @default 1
54+
*/
55+
opacity?: number;
4356
}
4457

4558
export interface ScatterChartProps extends IChartBaseProps {
59+
/**
60+
* An array of dataset objects. Each object defines a dataset which is displayed.
61+
*
62+
* <h4>Optional properties</h4>
63+
* - `label`: string containing the label of the dataset which is also displayed in the legend.
64+
* - `data`: array of objects which contains the data.
65+
* - `color`: any valid CSS color or CSS variable. Defaults to the `sapChart_Ordinal` colors.
66+
* - ´opacity´: number contains value of opacity of dataset
67+
*
68+
* Example of dataset:
69+
* <code>
70+
* [
71+
* {
72+
* label: 'America',
73+
* opacity: 0.7,
74+
* data: [
75+
* {
76+
* users: 120,
77+
* sessions: 200,
78+
* volume: 302
79+
* },
80+
* {
81+
* users: 20,
82+
* sessions: 230,
83+
* volume: 392
84+
* }
85+
* ]
86+
* }
87+
* ]
88+
* </code>
89+
*/
4690
dataset?: ScatterDataObject[];
4791
/**
48-
* An array of config objects. Each object is defining one line in the chart.
92+
* An array of config objects. Each object is defining one axis in the chart.
4993
*
5094
* <h4>Required properties</h4>
51-
* - `accessor`: string containing the path to the dataset key this line should display. Supports object structures by using <code>'parent.child'</code>.
52-
* Can also be a getter.
95+
* - `accessor`: string containing the path to the dataset key this line should display. Supports object structures by using <code>'parent.child'</code>.
96+
* Can also be a getter.
97+
* - `axis`: string containing definition of axis. Must be x, y or z data to the axis.
5398
*
99+
* <h4>Optional properties</h4>
100+
* - `label`: Label to display in tooltips. Falls back to the <code>accessor</code> if not present.
101+
* - `formatter`: function will be called for each data label and allows you to format it according to your needs. Also addresses labels of axis.
54102
*/
55103
measures?: MeasureConfig[];
56104
}
@@ -151,6 +199,7 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
151199
<XAxis
152200
type={'number'}
153201
key={xMeasure?.accessor}
202+
name={xMeasure?.label}
154203
dataKey={xMeasure?.accessor}
155204
xAxisId={0}
156205
interval={xMeasure?.interval ?? (isBigDataSet ? 'preserveStart' : 0)}
@@ -163,7 +212,7 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
163212
<YAxis
164213
label={yMeasure?.label ? { value: yMeasure?.label, angle: -90, position: 'insideLeft' } : false}
165214
type={'number'}
166-
name={yMeasure?.accessor}
215+
name={yMeasure?.label}
167216
axisLine={chartConfig.yAxisVisible}
168217
tickLine={tickLineConfig}
169218
key={yMeasure?.accessor}
@@ -174,10 +223,11 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
174223
width={yMeasure?.label ? yAxisWidth + 10 : yAxisWidth}
175224
margin={yMeasure?.label ? { left: 200 } : 0}
176225
/>
177-
<ZAxis name={zMeasure?.accessor} dataKey={zMeasure?.accessor} range={[0, 5000]} key={zMeasure?.accessor} />
226+
<ZAxis name={zMeasure?.label} dataKey={zMeasure?.accessor} range={[0, 5000]} key={zMeasure?.accessor} />
178227
{dataset?.map((dataSet, index) => {
179228
return (
180229
<Scatter
230+
opacity={dataSet.opacity}
181231
data={dataSet?.data}
182232
name={dataSet?.label}
183233
fill={dataSet?.color ?? `var(--sapChart_OrderedColor_${(index % 11) + 1})`}

packages/charts/src/resources/DemoProps.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const secondaryDimensionDataSet = [
174174

175175
export const scatterComplexDataSet = [
176176
{
177-
label: 'Volume',
177+
label: 'Americas',
178178
data: [
179179
{
180180
users: 120,
@@ -239,7 +239,8 @@ export const scatterComplexDataSet = [
239239
]
240240
},
241241
{
242-
label: 'Volume',
242+
label: 'APJ',
243+
opacity: 0.6,
243244
data: [
244245
{
245246
users: 100,
@@ -307,7 +308,7 @@ export const scatterComplexDataSet = [
307308

308309
export const scatterColorDataSet = [
309310
{
310-
label: 'Volume',
311+
label: 'Americas',
311312
color: 'red',
312313
data: [
313314
{

0 commit comments

Comments
 (0)