11import { inject , observer } from 'mobx-react' ;
22import React from 'react' ;
33import { Layer , Rect , Stage } from 'react-konva' ;
4+ import { AnnotationLineStyle } from '../../lib/themes/theme' ;
5+ import { AnnotationId } from '../../lib/utils/ids' ;
6+ import { AnnotationDimensions } from '../../state/annotation_utils' ;
47import { ChartStore , Point } from '../../state/chart_state' ;
58import { BrushExtent } from '../../state/utils' ;
9+ import { Annotation } from './annotation' ;
610import { AreaGeometries } from './area_geometries' ;
711import { Axis } from './axis' ;
812import { BarGeometries } from './bar_geometries' ;
@@ -167,6 +171,33 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
167171 return gridComponents ;
168172 }
169173
174+ renderAnnotations = ( ) => {
175+ const { annotationDimensions, annotationSpecs, chartDimensions, debug } = this . props . chartStore ! ;
176+
177+ const annotationComponents : JSX . Element [ ] = [ ] ;
178+ annotationDimensions . forEach ( ( annotation : AnnotationDimensions , id : AnnotationId ) => {
179+ const spec = annotationSpecs . get ( id ) ;
180+ if ( ! spec ) {
181+ return ;
182+ }
183+
184+ // We merge custom style w/ the default on addAnnotationSpec, so this is guaranteed
185+ // to be complete by the time we get to rendering
186+ const lineStyle = spec . style as AnnotationLineStyle ;
187+
188+ annotationComponents . push (
189+ < Annotation
190+ key = { `annotation-${ id } ` }
191+ chartDimensions = { chartDimensions }
192+ debug = { debug }
193+ lines = { annotation }
194+ lineStyle = { lineStyle }
195+ /> ,
196+ ) ;
197+ } ) ;
198+ return annotationComponents ;
199+ }
200+
170201 renderBrushTool = ( ) => {
171202 const { brushing, brushStart, brushEnd } = this . state ;
172203 const { chartDimensions, chartRotation, chartTransform } = this . props . chartStore ! ;
@@ -242,15 +273,15 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
242273 const clippings = debug
243274 ? { }
244275 : {
245- clipX : 0 ,
246- clipY : 0 ,
247- clipWidth : [ 90 , - 90 ] . includes ( chartRotation )
248- ? chartDimensions . height
249- : chartDimensions . width ,
250- clipHeight : [ 90 , - 90 ] . includes ( chartRotation )
251- ? chartDimensions . width
252- : chartDimensions . height ,
253- } ;
276+ clipX : 0 ,
277+ clipY : 0 ,
278+ clipWidth : [ 90 , - 90 ] . includes ( chartRotation )
279+ ? chartDimensions . height
280+ : chartDimensions . width ,
281+ clipHeight : [ 90 , - 90 ] . includes ( chartRotation )
282+ ? chartDimensions . width
283+ : chartDimensions . height ,
284+ } ;
254285
255286 let brushProps = { } ;
256287 const isBrushEnabled = this . props . chartStore ! . isBrushEnabled ( ) ;
@@ -261,7 +292,7 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
261292 } ;
262293 }
263294
264- const gridClippings = {
295+ const layerClippings = {
265296 clipX : chartDimensions . left ,
266297 clipY : chartDimensions . top ,
267298 clipWidth : chartDimensions . width ,
@@ -297,7 +328,7 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
297328 } }
298329 { ...brushProps }
299330 >
300- < Layer hitGraphEnabled = { false } listening = { false } { ...gridClippings } >
331+ < Layer hitGraphEnabled = { false } listening = { false } { ...layerClippings } >
301332 { this . renderGrids ( ) }
302333 </ Layer >
303334
@@ -325,6 +356,10 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
325356 < Layer hitGraphEnabled = { false } listening = { false } >
326357 { this . renderAxes ( ) }
327358 </ Layer >
359+
360+ < Layer hitGraphEnabled = { false } listening = { false } >
361+ { this . renderAnnotations ( ) }
362+ </ Layer >
328363 </ Stage >
329364 </ div >
330365 ) ;
0 commit comments