@@ -55,6 +55,32 @@ interface AnnotationsOwnProps {
5555
5656type AnnotationsProps = AnnotationsDispatchProps & AnnotationsStateProps & AnnotationsOwnProps ;
5757
58+ function renderAnnotationLineMarkers (
59+ chartDimensions : Dimensions ,
60+ annotationLines : AnnotationLineProps [ ] ,
61+ id : AnnotationId ,
62+ ) {
63+ return annotationLines . reduce < JSX . Element [ ] > ( ( markers , { marker } : AnnotationLineProps , index : number ) => {
64+ if ( ! marker ) {
65+ return markers ;
66+ }
67+
68+ const { icon, color, position } = marker ;
69+ const style = {
70+ color,
71+ top : chartDimensions . top + position . top ,
72+ left : chartDimensions . left + position . left ,
73+ } ;
74+
75+ markers . push (
76+ < div className = "echAnnotation" style = { { ...style } } key = { `annotation-${ id } -${ index } ` } >
77+ { icon }
78+ </ div > ,
79+ ) ;
80+
81+ return markers ;
82+ } , [ ] ) ;
83+ }
5884const AnnotationsComponent = ( {
5985 tooltipState,
6086 isChartEmpty,
@@ -65,31 +91,6 @@ const AnnotationsComponent = ({
6591 chartId,
6692 onPointerMove,
6793} : AnnotationsProps ) => {
68- const renderAnnotationLineMarkers = useCallback (
69- ( annotationLines : AnnotationLineProps [ ] , id : AnnotationId ) =>
70- annotationLines . reduce < JSX . Element [ ] > ( ( markers , { marker } : AnnotationLineProps , index : number ) => {
71- if ( ! marker ) {
72- return markers ;
73- }
74-
75- const { icon, color, position } = marker ;
76- const style = {
77- color,
78- top : chartDimensions . top + position . top ,
79- left : chartDimensions . left + position . left ,
80- } ;
81-
82- markers . push (
83- < div className = "echAnnotation" style = { { ...style } } key = { `annotation-${ id } -${ index } ` } >
84- { icon }
85- </ div > ,
86- ) ;
87-
88- return markers ;
89- } , [ ] ) ,
90- [ ] , // eslint-disable-line react-hooks/exhaustive-deps
91- ) ;
92-
9394 const renderAnnotationMarkers = useCallback ( ( ) : JSX . Element [ ] => {
9495 const markers : JSX . Element [ ] = [ ] ;
9596
@@ -101,13 +102,13 @@ const AnnotationsComponent = ({
101102
102103 if ( isLineAnnotation ( annotationSpec ) ) {
103104 const annotationLines = dimensions as AnnotationLineProps [ ] ;
104- const lineMarkers = renderAnnotationLineMarkers ( annotationLines , id ) ;
105+ const lineMarkers = renderAnnotationLineMarkers ( chartDimensions , annotationLines , id ) ;
105106 markers . push ( ...lineMarkers ) ;
106107 }
107108 } ) ;
108109
109110 return markers ;
110- } , [ annotationDimensions , annotationSpecs , renderAnnotationLineMarkers ] ) ;
111+ } , [ chartDimensions , annotationDimensions , annotationSpecs ] ) ;
111112
112113 const onScroll = useCallback ( ( ) => {
113114 onPointerMove ( { x : - 1 , y : - 1 } , new Date ( ) . getTime ( ) ) ;
0 commit comments