From 5ea63a613e39828574cc93eca6131f676f63671f Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Sat, 14 Feb 2026 06:35:01 +0100 Subject: [PATCH] feat: implement SpanRectanglePrimitive for span annotation rendering - Created SpanRectanglePrimitive.ts implementing ISeriesPrimitive interface - Implemented updateAllViews() with coordinate conversion from data-space to pixel-space - Added semi-transparent rectangle rendering with configurable opacity - Implemented label tag rendering above rectangles showing pattern names - Added hitTest() for click detection within span bounds - Implemented highlight state with thicker borders and increased opacity - Set zOrder to 'bottom' to render rectangles behind candlesticks - Completed Section 4 tasks (4.1-4.6) from span-annotation specification Co-Authored-By: Claude Sonnet 4.5 --- openspec/changes/span-annotation/tasks.md | 12 +- src/components/SpanRectanglePrimitive.ts | 240 ++++++++++++++++++++++ 2 files changed, 246 insertions(+), 6 deletions(-) create mode 100644 src/components/SpanRectanglePrimitive.ts diff --git a/openspec/changes/span-annotation/tasks.md b/openspec/changes/span-annotation/tasks.md index 4292d7d..ef6eca4 100644 --- a/openspec/changes/span-annotation/tasks.md +++ b/openspec/changes/span-annotation/tasks.md @@ -21,12 +21,12 @@ ## 4. SpanRectanglePrimitive (Chart Rendering) -- [ ] 4.1 Create `SpanRectanglePrimitive.ts` implementing `ISeriesPrimitive` with data-space rectangle coordinates (start_time, end_time, max_high, min_low) -- [ ] 4.2 Implement `updateAllViews()` with a pane renderer that converts time/price to pixel coordinates and draws a filled semi-transparent rectangle using `useBitmapCoordinateSpace` -- [ ] 4.3 Implement label tag text rendering above the rectangle (pattern name) -- [ ] 4.4 Implement `hitTest()` to detect clicks within the rectangle bounds -- [ ] 4.5 Add highlight state (thicker border / increased opacity) for selected spans -- [ ] 4.6 Set `zOrder: 'bottom'` so rectangles render behind candlesticks +- [x] 4.1 Create `SpanRectanglePrimitive.ts` implementing `ISeriesPrimitive` with data-space rectangle coordinates (start_time, end_time, max_high, min_low) +- [x] 4.2 Implement `updateAllViews()` with a pane renderer that converts time/price to pixel coordinates and draws a filled semi-transparent rectangle using `useBitmapCoordinateSpace` +- [x] 4.3 Implement label tag text rendering above the rectangle (pattern name) +- [x] 4.4 Implement `hitTest()` to detect clicks within the rectangle bounds +- [x] 4.5 Add highlight state (thicker border / increased opacity) for selected spans +- [x] 4.6 Set `zOrder: 'bottom'` so rectangles render behind candlesticks ## 5. Span Tool State & Integration diff --git a/src/components/SpanRectanglePrimitive.ts b/src/components/SpanRectanglePrimitive.ts new file mode 100644 index 0000000..3714eb5 --- /dev/null +++ b/src/components/SpanRectanglePrimitive.ts @@ -0,0 +1,240 @@ +import { + ISeriesPrimitive, + ISeriesPrimitivePaneView, + SeriesAttachedParameter, + Time, + Logical, +} from 'lightweight-charts'; + +export interface SpanData { + id: number; + start_time: number; + end_time: number; + label: string; + color: string; + max_high: number; + min_low: number; +} + +export interface SpanRectanglePrimitiveOptions { + data: SpanData; + isSelected?: boolean; +} + +class SpanRectanglePaneView implements ISeriesPrimitivePaneView { + private _data: SpanData; + private _isSelected: boolean; + private _series: SeriesAttachedParameter