From 551e8423b28c659819b03684ed858c751b2b1fba Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Thu, 12 Feb 2026 11:54:41 +0100 Subject: [PATCH] fix: sort markers by timestamp before setting on chart - Add sorting to annotation markers in ascending order by time - Fixes 'data must be asc ordered by time' error for markers - Ensures both candle data and markers are properly sorted --- src/components/CandleChart.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/CandleChart.tsx b/src/components/CandleChart.tsx index 8f12c8e..c5689c9 100644 --- a/src/components/CandleChart.tsx +++ b/src/components/CandleChart.tsx @@ -157,13 +157,15 @@ const CandleChart = forwardRef( (a) => a.label_type === 'break_up' || a.label_type === 'break_down' ); - const markers = markerAnnotations.map((annotation) => ({ - time: annotation.timestamp as Time, - position: annotation.label_type === 'break_up' ? ('belowBar' as const) : ('aboveBar' as const), - color: annotation.label_type === 'break_up' ? '#22c55e' : '#ef4444', - shape: annotation.label_type === 'break_up' ? ('arrowUp' as const) : ('arrowDown' as const), - text: annotation.label_type === 'break_up' ? 'Break Up' : 'Break Down', - })); + const markers = markerAnnotations + .map((annotation) => ({ + time: annotation.timestamp as Time, + position: annotation.label_type === 'break_up' ? ('belowBar' as const) : ('aboveBar' as const), + color: annotation.label_type === 'break_up' ? '#22c55e' : '#ef4444', + shape: annotation.label_type === 'break_up' ? ('arrowUp' as const) : ('arrowDown' as const), + text: annotation.label_type === 'break_up' ? 'Break Up' : 'Break Down', + })) + .sort((a, b) => (a.time as number) - (b.time as number)); seriesRef.current.setMarkers(markers); }, [annotations]);