@@ -4,18 +4,18 @@ import { Circle, Group, Path } from 'react-konva';
44import { animated , Spring } from 'react-spring/renderprops-konva.cjs' ;
55import { LegendItem } from '../../lib/series/legend' ;
66import { AreaGeometry , getGeometryStyle , PointGeometry } from '../../lib/series/rendering' ;
7- import { AreaSeriesStyle , SharedGeometryStyle } from '../../lib/themes/theme' ;
7+ import { SharedGeometryStyle } from '../../lib/themes/theme' ;
88import {
9- buildAreaLineProps ,
10- buildAreaPointProps ,
11- buildAreaProps ,
9+ buildAreaRenderProps ,
1210 buildPointStyleProps ,
11+ buildPointRenderProps ,
12+ PointStyleProps ,
13+ buildLineRenderProps ,
1314} from './utils/rendering_props_utils' ;
1415
1516interface AreaGeometriesDataProps {
1617 animated ?: boolean ;
1718 areas : AreaGeometry [ ] ;
18- style : AreaSeriesStyle ;
1919 sharedStyle : SharedGeometryStyle ;
2020 highlightedLegendItem : LegendItem | null ;
2121}
@@ -35,171 +35,113 @@ export class AreaGeometries extends React.PureComponent<AreaGeometriesDataProps,
3535 } ;
3636 }
3737 render ( ) {
38- const { point, area, line } = this . props . style ;
39-
4038 return (
4139 < Group ref = { this . barSeriesRef } key = { 'bar_series' } >
42- { this . renderAreaGeoms ( area . visible ) }
43- { this . renderAreaLines ( line . visible ) }
44- { this . renderAreaPoints ( point . visible ) }
40+ { this . renderAreaGeoms ( ) }
41+ { this . renderAreaLines ( ) }
42+ { this . renderAreaPoints ( ) }
4543 </ Group >
4644 ) ;
4745 }
48- private renderAreaPoints = ( themeIsVisible : boolean ) : JSX . Element [ ] => {
46+ private renderAreaPoints = ( ) : JSX . Element [ ] => {
4947 const { areas } = this . props ;
5048 return areas . reduce (
5149 ( acc , glyph , i ) => {
52- const { points, seriesPointStyle } = glyph ;
50+ const { points, seriesPointStyle, color } = glyph ;
5351
54- const isVisible = seriesPointStyle ? seriesPointStyle . visible : themeIsVisible ;
55- if ( ! isVisible ) {
52+ if ( ! seriesPointStyle . visible ) {
5653 return acc ;
5754 }
5855
59- const { radius, strokeWidth, opacity } = this . props . style . point ;
60- const pointStyleProps = buildPointStyleProps ( {
61- radius,
62- strokeWidth,
63- opacity,
64- seriesPointStyle,
65- } ) ;
56+ const pointStyleProps = buildPointStyleProps ( color , seriesPointStyle ) ;
6657
6758 return [ ...acc , ...this . renderPoints ( points , i , pointStyleProps ) ] ;
6859 } ,
6960 [ ] as JSX . Element [ ] ,
7061 ) ;
7162 } ;
72- private renderPoints = ( areaPoints : PointGeometry [ ] , areaIndex : number , pointStyleProps : any ) : JSX . Element [ ] => {
63+ private renderPoints = (
64+ areaPoints : PointGeometry [ ] ,
65+ areaIndex : number ,
66+ pointStyleProps : PointStyleProps ,
67+ ) : JSX . Element [ ] => {
7368 const areaPointElements : JSX . Element [ ] = [ ] ;
69+
7470 areaPoints . forEach ( ( areaPoint , pointIndex ) => {
75- const { x, y, color, transform } = areaPoint ;
71+ const { x, y, transform } = areaPoint ;
72+ const key = `area-point-${ areaIndex } -${ pointIndex } ` ;
7673
7774 if ( this . props . animated ) {
7875 areaPointElements . push (
7976 < Group key = { `area-point-group-${ areaIndex } -${ pointIndex } ` } x = { transform . x } >
8077 < Spring native from = { { y } } to = { { y } } >
8178 { ( ) => {
82- const pointProps = buildAreaPointProps ( {
83- areaIndex,
84- pointIndex,
85- x,
86- y,
87- color,
88- pointStyleProps,
89- } ) ;
90- return < animated . Circle { ...pointProps } /> ;
79+ const pointProps = buildPointRenderProps ( x , y , pointStyleProps ) ;
80+ return < animated . Circle { ...pointProps } key = { key } /> ;
9181 } }
9282 </ Spring >
9383 </ Group > ,
9484 ) ;
9585 } else {
96- const pointProps = buildAreaPointProps ( {
97- areaIndex,
98- pointIndex,
99- x : transform . x + x ,
100- y,
101- color,
102- pointStyleProps,
103- } ) ;
104- areaPointElements . push ( < Circle { ...pointProps } /> ) ;
86+ const pointProps = buildPointRenderProps ( transform . x + x , y , pointStyleProps ) ;
87+ areaPointElements . push ( < Circle { ...pointProps } key = { key } /> ) ;
10588 }
10689 } ) ;
10790 return areaPointElements ;
10891 } ;
10992
110- private renderAreaGeoms = ( themeIsVisible : boolean ) : JSX . Element [ ] => {
111- const { areas } = this . props ;
112- const { opacity } = this . props . style . area ;
93+ private renderAreaGeoms = ( ) : JSX . Element [ ] => {
94+ const { areas, sharedStyle } = this . props ;
11395 const areasToRender : JSX . Element [ ] = [ ] ;
11496
11597 areas . forEach ( ( glyph , i ) => {
116- const { area, color, transform, seriesAreaStyle } = glyph ;
117- const isVisible = seriesAreaStyle ? seriesAreaStyle . visible : themeIsVisible ;
118- if ( ! isVisible ) {
98+ const { area, color, transform, geometryId, seriesAreaStyle } = glyph ;
99+ if ( ! seriesAreaStyle . visible ) {
119100 return ;
120101 }
121-
102+ const customOpacity = seriesAreaStyle ? seriesAreaStyle . opacity : undefined ;
103+ const geometryStyle = getGeometryStyle ( geometryId , this . props . highlightedLegendItem , sharedStyle , customOpacity ) ;
104+ const key = `area-${ i } ` ;
122105 if ( this . props . animated ) {
123106 areasToRender . push (
124107 < Group key = { `area-group-${ i } ` } x = { transform . x } >
125108 < Spring native from = { { area } } to = { { area } } >
126109 { ( props : { area : string } ) => {
127- const areaProps = buildAreaProps ( {
128- index : i ,
129- areaPath : props . area ,
130- xTransform : 0 ,
131- color,
132- opacity,
133- seriesAreaStyle,
134- } ) ;
135- return < animated . Path { ...areaProps } /> ;
110+ const areaProps = buildAreaRenderProps ( 0 , props . area , color , seriesAreaStyle , geometryStyle ) ;
111+ return < animated . Path { ...areaProps } key = { key } /> ;
136112 } }
137113 </ Spring >
138114 </ Group > ,
139115 ) ;
140116 } else {
141- const areaProps = buildAreaProps ( {
142- index : i ,
143- areaPath : area ,
144- xTransform : transform . x ,
145- color,
146- opacity,
147- seriesAreaStyle,
148- } ) ;
149- areasToRender . push ( < Path { ...areaProps } /> ) ;
117+ const areaProps = buildAreaRenderProps ( transform . x , area , color , seriesAreaStyle , geometryStyle ) ;
118+ areasToRender . push ( < Path { ...areaProps } key = { key } /> ) ;
150119 }
151120 } ) ;
152121 return areasToRender ;
153122 } ;
154- private renderAreaLines = ( themeIsVisible : boolean ) : JSX . Element [ ] => {
123+ private renderAreaLines = ( ) : JSX . Element [ ] => {
155124 const { areas, sharedStyle } = this . props ;
156- const { strokeWidth } = this . props . style . line ;
157125 const linesToRender : JSX . Element [ ] = [ ] ;
158126 areas . forEach ( ( glyph , areaIndex ) => {
159127 const { lines, color, geometryId, transform, seriesAreaLineStyle } = glyph ;
160- const isVisible = seriesAreaLineStyle ? seriesAreaLineStyle . visible : themeIsVisible ;
161- if ( ! isVisible ) {
128+ if ( ! seriesAreaLineStyle . visible ) {
162129 return ;
163130 }
164131
165- const customOpacity = seriesAreaLineStyle ? seriesAreaLineStyle . opacity : undefined ;
166-
167- const geometryStyle = getGeometryStyle ( geometryId , this . props . highlightedLegendItem , sharedStyle , customOpacity ) ;
132+ const geometryStyle = getGeometryStyle (
133+ geometryId ,
134+ this . props . highlightedLegendItem ,
135+ sharedStyle ,
136+ seriesAreaLineStyle . opacity ,
137+ ) ;
168138
169139 lines . forEach ( ( linePath , lineIndex ) => {
170- const lineProps = buildAreaLineProps ( {
171- areaIndex,
172- lineIndex,
173- xTransform : transform . x ,
174- linePath,
175- color,
176- strokeWidth,
177- geometryStyle,
178- seriesAreaLineStyle,
179- } ) ;
180- linesToRender . push ( < Path { ...lineProps } /> ) ;
140+ const key = `area-${ areaIndex } -line-${ lineIndex } ` ;
141+ const lineProps = buildLineRenderProps ( transform . x , linePath , color , seriesAreaLineStyle , geometryStyle ) ;
142+ linesToRender . push ( < Path { ...lineProps } key = { key } /> ) ;
181143 } ) ;
182144 } ) ;
183145 return linesToRender ;
184- // if (this.props.animated) {
185- // return (
186- // <Group key={`area-line-group-${i}`} x={transform.x}>
187- // <Spring native from={{ line }} to={{ line }}>
188- // {(props: { line: string }) => {
189- // const lineProps = buildAreaLineProps({
190- // index: i,
191- // linePath: props.line,
192- // color,
193- // strokeWidth,
194- // geometryStyle,
195- // });
196- // return <animated.Path {...lineProps} />;
197- // }}
198- // </Spring>
199- // </Group>
200- // );
201- // } else {
202-
203- // }
204146 } ;
205147}
0 commit comments