1
1
import { Group as KonvaGroup } from 'konva' ;
2
2
import React from 'react' ;
3
3
import { Circle , Group , Path } from 'react-konva' ;
4
- import { animated , Spring } from 'react-spring/renderprops-konva' ;
4
+ import { animated , Spring } from 'react-spring/renderprops-konva.cjs ' ;
5
5
import { LegendItem } from '../../lib/series/legend' ;
6
6
import { AreaGeometry , getGeometryStyle , PointGeometry } from '../../lib/series/rendering' ;
7
7
import { AreaSeriesStyle , SharedGeometryStyle } from '../../lib/themes/theme' ;
8
- import { GlobalKonvaElementProps } from './globals' ;
8
+ import {
9
+ buildAreaLineProps ,
10
+ buildAreaPointProps ,
11
+ buildAreaProps ,
12
+ } from './utils/rendering_props_utils' ;
9
13
10
14
interface AreaGeometriesDataProps {
11
15
animated ?: boolean ;
@@ -54,45 +58,42 @@ export class AreaGeometries extends React.PureComponent<
54
58
) ;
55
59
}
56
60
private renderPoints = ( areaPoints : PointGeometry [ ] , areaIndex : number ) : JSX . Element [ ] => {
57
- const { radius, stroke , strokeWidth, opacity } = this . props . style . point ;
61
+ const { radius, strokeWidth, opacity } = this . props . style . point ;
58
62
59
- return areaPoints . map ( ( areaPoint , index ) => {
63
+ return areaPoints . map ( ( areaPoint , pointIndex ) => {
60
64
const { x, y, color, transform } = areaPoint ;
61
65
if ( this . props . animated ) {
62
66
return (
63
- < Group key = { `area-point-group-${ areaIndex } -${ index } ` } x = { transform . x } >
67
+ < Group key = { `area-point-group-${ areaIndex } -${ pointIndex } ` } x = { transform . x } >
64
68
< Spring native from = { { y } } to = { { y } } >
65
- { ( props : { y : number } ) => (
66
- < animated . Circle
67
- key = { `area-point-${ areaIndex } -${ index } ` }
68
- x = { x }
69
- y = { y }
70
- radius = { radius }
71
- strokeWidth = { strokeWidth }
72
- strokeEnabled = { strokeWidth !== 0 }
73
- stroke = { color }
74
- fill = { 'white' }
75
- opacity = { opacity }
76
- { ...GlobalKonvaElementProps }
77
- />
78
- ) }
69
+ { ( props : { y : number } ) => {
70
+ const pointProps = buildAreaPointProps ( {
71
+ areaIndex,
72
+ pointIndex,
73
+ x,
74
+ y,
75
+ radius,
76
+ strokeWidth,
77
+ color,
78
+ opacity,
79
+ } ) ;
80
+ return < animated . Circle { ...pointProps } /> ;
81
+ } }
79
82
</ Spring >
80
83
</ Group >
81
84
) ;
82
85
} else {
83
- return (
84
- < Circle
85
- key = { `area-point-${ areaIndex } -${ index } ` }
86
- x = { transform . x + x }
87
- y = { y }
88
- radius = { radius }
89
- strokeWidth = { strokeWidth }
90
- stroke = { stroke }
91
- fill = { color }
92
- opacity = { opacity }
93
- { ...GlobalKonvaElementProps }
94
- />
95
- ) ;
86
+ const pointProps = buildAreaPointProps ( {
87
+ areaIndex,
88
+ pointIndex,
89
+ x : transform . x + x ,
90
+ y,
91
+ radius,
92
+ strokeWidth,
93
+ color,
94
+ opacity,
95
+ } ) ;
96
+ return < Circle { ...pointProps } /> ;
96
97
}
97
98
} ) ;
98
99
}
@@ -108,32 +109,26 @@ export class AreaGeometries extends React.PureComponent<
108
109
return (
109
110
< Group key = { `area-group-${ i } ` } x = { transform . x } >
110
111
< Spring native from = { { area } } to = { { area } } >
111
- { ( props : { area : string } ) => (
112
- < animated . Path
113
- key = { `area-${ i } ` }
114
- data = { props . area }
115
- fill = { color }
116
- lineCap = "round"
117
- lineJoin = "round"
118
- opacity = { opacity }
119
- { ...GlobalKonvaElementProps }
120
- />
121
- ) }
112
+ { ( props : { area : string } ) => {
113
+ const areaProps = buildAreaProps ( {
114
+ index : i ,
115
+ areaPath : props . area ,
116
+ color,
117
+ opacity,
118
+ } ) ;
119
+ return < animated . Path { ...areaProps } /> ;
120
+ } }
122
121
</ Spring >
123
122
</ Group >
124
123
) ;
125
124
} else {
126
- return (
127
- < Path
128
- key = { `area-${ i } ` }
129
- data = { area }
130
- fill = { color }
131
- opacity = { opacity }
132
- lineCap = "round"
133
- lineJoin = "round"
134
- { ...GlobalKonvaElementProps }
135
- />
136
- ) ;
125
+ const areaProps = buildAreaProps ( {
126
+ index : i ,
127
+ areaPath : area ,
128
+ color,
129
+ opacity,
130
+ } ) ;
131
+ return < Path { ...areaProps } /> ;
137
132
}
138
133
} ) ;
139
134
}
@@ -154,31 +149,28 @@ export class AreaGeometries extends React.PureComponent<
154
149
return (
155
150
< Group key = { `area-line-group-${ i } ` } x = { transform . x } >
156
151
< Spring native from = { { line } } to = { { line } } >
157
- { ( props : { line : string } ) => (
158
- < animated . Path
159
- key = { `area-line-${ i } ` }
160
- data = { props . line }
161
- stroke = { color }
162
- strokeWidth = { strokeWidth }
163
- lineCap = "round"
164
- lineJoin = "round"
165
- { ...geometryStyle }
166
- { ...GlobalKonvaElementProps }
167
- />
168
- ) }
152
+ { ( props : { line : string } ) => {
153
+ const lineProps = buildAreaLineProps ( {
154
+ index : i ,
155
+ linePath : props . line ,
156
+ color,
157
+ strokeWidth,
158
+ geometryStyle,
159
+ } ) ;
160
+ return < animated . Path { ...lineProps } /> ;
161
+ } }
169
162
</ Spring >
170
163
</ Group >
171
164
) ;
172
165
} else {
173
- return (
174
- < Path
175
- key = { `area-line-${ i } ` }
176
- data = { line }
177
- fill = { color }
178
- { ...geometryStyle }
179
- { ...GlobalKonvaElementProps }
180
- />
181
- ) ;
166
+ const lineProps = buildAreaLineProps ( {
167
+ index : i ,
168
+ linePath : line ,
169
+ color,
170
+ strokeWidth,
171
+ geometryStyle,
172
+ } ) ;
173
+ return < Path { ...lineProps } /> ;
182
174
}
183
175
} ) ;
184
176
}
0 commit comments