@@ -2,14 +2,12 @@ import { ThemingParameters } from '@ui5/webcomponents-react-base/lib/ThemingPara
2
2
import { useConsolidatedRef } from '@ui5/webcomponents-react-base/lib/useConsolidatedRef' ;
3
3
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base/lib/Utils' ;
4
4
import { ChartContainer } from '@ui5/webcomponents-react-charts/lib/components/ChartContainer' ;
5
- import { ChartDataLabel } from '@ui5/webcomponents-react-charts/lib/components/ChartDataLabel' ;
6
5
import { XAxisTicks } from '@ui5/webcomponents-react-charts/lib/components/XAxisTicks' ;
7
6
import { YAxisTicks } from '@ui5/webcomponents-react-charts/lib/components/YAxisTicks' ;
8
7
import { LineChartPlaceholder } from '@ui5/webcomponents-react-charts/lib/LineChartPlaceholder' ;
9
8
import { useLegendItemClick } from '@ui5/webcomponents-react-charts/lib/useLegendItemClick' ;
10
9
import React , { FC , forwardRef , Ref , useCallback , useMemo } from 'react' ;
11
10
import {
12
- Brush ,
13
11
CartesianGrid ,
14
12
Legend ,
15
13
Scatter ,
@@ -18,19 +16,17 @@ import {
18
16
Tooltip ,
19
17
XAxis ,
20
18
YAxis ,
21
- ZAxis ,
22
- Line
19
+ ZAxis
23
20
} from 'recharts' ;
24
21
import { useChartMargin } from '../../hooks/useChartMargin' ;
25
22
import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel' ;
26
- import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights' ;
27
23
import { usePrepareDimensionsAndMeasures } from '../../hooks/usePrepareDimensionsAndMeasures' ;
28
24
import { useTooltipFormatter } from '../../hooks/useTooltipFormatter' ;
29
25
import { IChartBaseProps } from '../../interfaces/IChartBaseProps' ;
30
- import { IChartDimension } from '../../interfaces/IChartDimension' ;
31
26
import { IChartMeasure } from '../../interfaces/IChartMeasure' ;
32
27
import { defaultFormatter } from '../../internal/defaults' ;
33
28
import { tickLineConfig , tooltipContentStyle , tooltipFillOpacity , xAxisPadding } from '../../internal/staticProps' ;
29
+ import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights' ;
34
30
35
31
interface MeasureConfig extends IChartMeasure {
36
32
/**
@@ -43,15 +39,20 @@ interface MeasureConfig extends IChartMeasure {
43
39
* @default 1
44
40
*/
45
41
opacity ?: number ;
42
+ /**
43
+ * Defines axis of measures
44
+ * @default 1
45
+ */
46
+ axis : 'x' | 'y' | 'z' ;
46
47
}
47
48
48
- interface DimensionConfig extends IChartDimension {
49
- interval ?: number ;
49
+ interface ScatterDataObject {
50
+ label ?: string ;
51
+ data : any [ ] ;
50
52
}
51
53
52
54
export interface ScatterChartProps extends IChartBaseProps {
53
- dimension : DimensionConfig ;
54
- dataset ?: Record < string , any > [ ] [ ] ;
55
+ dataset ?: ScatterDataObject [ ] ;
55
56
/**
56
57
* An array of config objects. Each object is defining one line in the chart.
57
58
*
@@ -73,14 +74,8 @@ export interface ScatterChartProps extends IChartBaseProps {
73
74
measures : MeasureConfig [ ] ;
74
75
}
75
76
76
- const dimensionDefaults = {
77
- formatter : defaultFormatter
78
- } ;
79
-
80
77
const measureDefaults = {
81
- formatter : defaultFormatter ,
82
- width : 1 ,
83
- opacity : 1
78
+ formatter : defaultFormatter
84
79
} ;
85
80
86
81
/**
@@ -115,30 +110,10 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
115
110
} ;
116
111
} , [ props . chartConfig ] ) ;
117
112
118
- const { dimensions, measures } = usePrepareDimensionsAndMeasures (
119
- [ ] ,
120
- props . measures ,
121
- dimensionDefaults ,
122
- measureDefaults
123
- ) ;
113
+ const { measures } = usePrepareDimensionsAndMeasures ( [ ] , props . measures , { } , measureDefaults ) ;
124
114
125
115
const tooltipValueFormatter = useTooltipFormatter ( measures ) ;
126
-
127
- const primaryDimension = dimensions [ 0 ] ;
128
- const primaryMeasure = measures [ 0 ] ;
129
-
130
116
const chartRef = useConsolidatedRef < any > ( ref ) ;
131
-
132
- const dataKeys = measures . map ( ( { accessor } ) => accessor ) ;
133
-
134
- const dimension : DimensionConfig = useMemo (
135
- ( ) => ( {
136
- formatter : defaultFormatter ,
137
- ...props . dimension
138
- } ) ,
139
- [ props . dimension ]
140
- ) ;
141
-
142
117
const onItemLegendClick = useLegendItemClick ( onLegendClick ) ;
143
118
144
119
const onDataPointClickInternal = useCallback (
@@ -161,11 +136,18 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
161
136
) ;
162
137
163
138
const isBigDataSet = dataset ?. length > 30 ?? false ;
164
- const primaryDimensionAccessor = primaryDimension ?. accessor ;
165
139
166
- const [ yAxisWidth , legendPosition ] = useLongestYAxisLabel ( dataset [ 0 ] , measures ) ;
140
+ const xMeasure = measures . filter ( ( { axis } ) => axis === 'x' ) ;
141
+ const yMeasure = measures . filter ( ( { axis } ) => axis === 'y' ) ;
142
+ const zMeasure = measures . filter ( ( { axis } ) => axis === 'z' ) ;
143
+
144
+ const [ yAxisWidth , legendPosition ] = useLongestYAxisLabel (
145
+ dataset [ 0 ] . data ,
146
+ measures . filter ( ( { axis } ) => axis === 'y' )
147
+ ) ;
148
+ const xAxisHeights = useObserveXAxisHeights ( chartRef , 1 ) ;
149
+
167
150
const marginChart = useChartMargin ( chartConfig . margin , chartConfig . zoomingTool ) ;
168
- // const xAxisHeights = useObserveXAxisHeights(chartRef, props.dimensions.length);
169
151
170
152
return (
171
153
< ChartContainer
@@ -192,32 +174,40 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
192
174
{ chartConfig . xAxisVisible && (
193
175
< XAxis
194
176
type = { 'number' }
195
- key = { measures [ 0 ] . accessor }
196
- name = { measures [ 0 ] . accessor }
197
- dataKey = { measures [ 0 ] . accessor }
198
- interval = { measures [ 0 ] ?. interval ?? ( isBigDataSet ? 'preserveStart' : 0 ) }
199
- tick = { < XAxisTicks config = { measures [ 0 ] } /> }
177
+ key = { xMeasure [ 0 ] . accessor }
178
+ label = { { position : 'bottom' , value : xMeasure [ 0 ] . label } }
179
+ dataKey = { xMeasure [ 0 ] . accessor }
180
+ interval = { xMeasure [ 0 ] ?. interval ?? ( isBigDataSet ? 'preserveStart' : 0 ) }
181
+ tick = { < XAxisTicks config = { xMeasure [ 0 ] } /> }
200
182
padding = { xAxisPadding }
183
+ // height={xAxisHeights[0]}
201
184
/>
202
185
) }
203
186
< YAxis
187
+ label = { yMeasure [ 0 ] . label ? { position : 'top' , value : yMeasure [ 0 ] . label } : false }
204
188
type = { 'number' }
205
- name = { measures [ 1 ] . accessor }
189
+ name = { yMeasure [ 0 ] . accessor }
206
190
axisLine = { chartConfig . yAxisVisible }
207
191
tickLine = { tickLineConfig }
208
- key = { measures [ 1 ] . accessor }
209
- dataKey = { measures [ 1 ] . accessor }
210
- tickFormatter = { measures [ 1 ] ?. formatter }
192
+ key = { yMeasure [ 0 ] . accessor }
193
+ dataKey = { yMeasure [ 0 ] . accessor }
194
+ tickFormatter = { yMeasure [ 0 ] ?. formatter }
211
195
interval = { 0 }
212
- tick = { < YAxisTicks config = { measures [ 1 ] } /> }
196
+ tick = { < YAxisTicks config = { yMeasure [ 0 ] } /> }
213
197
width = { yAxisWidth }
198
+ padding = { yMeasure [ 0 ] . label ? { top : 10 } : 0 }
199
+ />
200
+ < ZAxis
201
+ name = { zMeasure [ 0 ] . accessor }
202
+ dataKey = { zMeasure [ 0 ] . accessor }
203
+ range = { [ 0 , 5000 ] }
204
+ key = { zMeasure [ 0 ] . accessor }
214
205
/>
215
- < ZAxis name = { dimension . accessor } dataKey = { dimension . accessor } range = { [ 0 , 5000 ] } key = { dimension . accessor } />
216
- { dataset . map ( ( data , index ) => {
206
+ { dataset . map ( ( dataSet , index ) => {
217
207
return (
218
208
< Scatter
219
- data = { data }
220
- name = { dimension . accessor }
209
+ data = { dataSet . data }
210
+ name = { dataSet . label }
221
211
fill = { `var(--sapChart_OrderedColor_${ ( index % 11 ) + 1 } )` }
222
212
isAnimationActive = { noAnimation === false }
223
213
/>
@@ -240,15 +230,6 @@ const ScatterChart: FC<ScatterChartProps> = forwardRef((props: ScatterChartProps
240
230
/>
241
231
) }
242
232
< Tooltip cursor = { tooltipFillOpacity } formatter = { tooltipValueFormatter } contentStyle = { tooltipContentStyle } />
243
- { chartConfig . zoomingTool && (
244
- < Brush
245
- y = { 10 }
246
- dataKey = { primaryDimensionAccessor }
247
- stroke = { ThemingParameters . sapObjectHeader_BorderColor }
248
- travellerWidth = { 10 }
249
- height = { 20 }
250
- />
251
- ) }
252
233
</ ScatterChartLib >
253
234
</ ChartContainer >
254
235
) ;
0 commit comments