-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: annotation markers render when parent size is computed
- Loading branch information
Showing
2 changed files
with
29 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,32 @@ interface AnnotationsOwnProps { | |
|
||
type AnnotationsProps = AnnotationsDispatchProps & AnnotationsStateProps & AnnotationsOwnProps; | ||
|
||
function renderAnnotationLineMarkers( | ||
chartDimensions: Dimensions, | ||
annotationLines: AnnotationLineProps[], | ||
id: AnnotationId, | ||
) { | ||
return annotationLines.reduce<JSX.Element[]>((markers, { marker }: AnnotationLineProps, index: number) => { | ||
if (!marker) { | ||
return markers; | ||
} | ||
|
||
const { icon, color, position } = marker; | ||
const style = { | ||
color, | ||
top: chartDimensions.top + position.top, | ||
left: chartDimensions.left + position.left, | ||
}; | ||
|
||
markers.push( | ||
<div className="echAnnotation" style={{ ...style }} key={`annotation-${id}-${index}`}> | ||
{icon} | ||
</div>, | ||
); | ||
|
||
return markers; | ||
}, []); | ||
} | ||
const AnnotationsComponent = ({ | ||
tooltipState, | ||
isChartEmpty, | ||
|
@@ -65,31 +91,6 @@ const AnnotationsComponent = ({ | |
chartId, | ||
onPointerMove, | ||
}: AnnotationsProps) => { | ||
const renderAnnotationLineMarkers = useCallback( | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
markov00
Author
Member
|
||
(annotationLines: AnnotationLineProps[], id: AnnotationId) => | ||
annotationLines.reduce<JSX.Element[]>((markers, { marker }: AnnotationLineProps, index: number) => { | ||
if (!marker) { | ||
return markers; | ||
} | ||
|
||
const { icon, color, position } = marker; | ||
const style = { | ||
color, | ||
top: chartDimensions.top + position.top, | ||
left: chartDimensions.left + position.left, | ||
}; | ||
|
||
markers.push( | ||
<div className="echAnnotation" style={{ ...style }} key={`annotation-${id}-${index}`}> | ||
{icon} | ||
</div>, | ||
); | ||
|
||
return markers; | ||
}, []), | ||
[], // eslint-disable-line react-hooks/exhaustive-deps | ||
); | ||
|
||
const renderAnnotationMarkers = useCallback((): JSX.Element[] => { | ||
const markers: JSX.Element[] = []; | ||
|
||
|
@@ -101,13 +102,13 @@ const AnnotationsComponent = ({ | |
|
||
if (isLineAnnotation(annotationSpec)) { | ||
const annotationLines = dimensions as AnnotationLineProps[]; | ||
const lineMarkers = renderAnnotationLineMarkers(annotationLines, id); | ||
const lineMarkers = renderAnnotationLineMarkers(chartDimensions, annotationLines, id); | ||
markers.push(...lineMarkers); | ||
} | ||
}); | ||
|
||
return markers; | ||
}, [annotationDimensions, annotationSpecs, renderAnnotationLineMarkers]); | ||
}, [chartDimensions, annotationDimensions, annotationSpecs]); | ||
|
||
const onScroll = useCallback(() => { | ||
onPointerMove({ x: -1, y: -1 }, new Date().getTime()); | ||
|
Was the
useCallback
the main culprit here?