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
This commit is contained in:
parent
17eb2ca745
commit
551e8423b2
1 changed files with 9 additions and 7 deletions
|
|
@ -157,13 +157,15 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
|
||||||
(a) => a.label_type === 'break_up' || a.label_type === 'break_down'
|
(a) => a.label_type === 'break_up' || a.label_type === 'break_down'
|
||||||
);
|
);
|
||||||
|
|
||||||
const markers = markerAnnotations.map((annotation) => ({
|
const markers = markerAnnotations
|
||||||
time: annotation.timestamp as Time,
|
.map((annotation) => ({
|
||||||
position: annotation.label_type === 'break_up' ? ('belowBar' as const) : ('aboveBar' as const),
|
time: annotation.timestamp as Time,
|
||||||
color: annotation.label_type === 'break_up' ? '#22c55e' : '#ef4444',
|
position: annotation.label_type === 'break_up' ? ('belowBar' as const) : ('aboveBar' as const),
|
||||||
shape: annotation.label_type === 'break_up' ? ('arrowUp' as const) : ('arrowDown' as const),
|
color: annotation.label_type === 'break_up' ? '#22c55e' : '#ef4444',
|
||||||
text: annotation.label_type === 'break_up' ? 'Break Up' : 'Break Down',
|
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);
|
seriesRef.current.setMarkers(markers);
|
||||||
}, [annotations]);
|
}, [annotations]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue