feat: enhance TrendLine plugin and create RectangleDrawingPrimitive

- Add hitTest, setSelected, attached/detached lifecycle methods to TrendLine
- Add preview mode support with dashed lines and reduced opacity
- Draw selection handles on endpoints when selected
- Create RectangleDrawingPrimitive plugin with full ISeriesPrimitive implementation
- Support preview mode, selection, hit testing, and autoscaling for rectangles
- Set z-order to bottom for rectangles to render behind candlesticks

Tasks completed: 1.1-1.4, 2.1-2.7
This commit is contained in:
Marko Djordjevic 2026-02-16 11:51:07 +01:00
parent 28e3f83cf7
commit bec0aeb6ca
14 changed files with 391 additions and 850 deletions

View file

@ -1,19 +1,19 @@
## 1. Enhance TrendLine Plugin
- [ ] 1.1 Add `hitTest(x, y)` method to `TrendLine` class — calculate perpendicular distance from click point to line segment in pixel coordinates, return `PrimitiveHoveredItem` with annotation ID if within 10px tolerance
- [ ] 1.2 Add `setSelected(isSelected)` method and selection state to `TrendLine` — when selected, renderer draws thicker line and circular endpoint handles (radius 6px, white fill, colored stroke)
- [ ] 1.3 Add `attached()/detached()` lifecycle methods to `TrendLine` to store `SeriesAttachedParameter` reference (needed for hitTest coordinate conversion)
- [ ] 1.4 Add preview line support — dashed stroke style and reduced opacity when an `isPreview` option is set
- [x] 1.1 Add `hitTest(x, y)` method to `TrendLine` class — calculate perpendicular distance from click point to line segment in pixel coordinates, return `PrimitiveHoveredItem` with annotation ID if within 10px tolerance
- [x] 1.2 Add `setSelected(isSelected)` method and selection state to `TrendLine` — when selected, renderer draws thicker line and circular endpoint handles (radius 6px, white fill, colored stroke)
- [x] 1.3 Add `attached()/detached()` lifecycle methods to `TrendLine` to store `SeriesAttachedParameter` reference (needed for hitTest coordinate conversion)
- [x] 1.4 Add preview line support — dashed stroke style and reduced opacity when an `isPreview` option is set
## 2. Create RectangleDrawingPrimitive Plugin
- [ ] 2.1 Create `src/plugins/rectangle-drawing.ts` implementing `ISeriesPrimitive<Time>` with renderer, pane view, and data model for two corner points `{time, price}`
- [ ] 2.2 Implement `RectangleDrawingPaneRenderer.draw()` — filled semi-transparent rectangle with border, using `useBitmapCoordinateSpace` for HiDPI scaling
- [ ] 2.3 Implement `hitTest(x, y)` — convert pixel to data coordinates, check if within rectangle time/price bounds
- [ ] 2.4 Add `setSelected(isSelected)` and selection visual feedback (thicker border, increased opacity)
- [ ] 2.5 Add preview mode support — dashed border and reduced opacity for preview rectangles during drawing
- [ ] 2.6 Add `autoscaleInfo()` to include rectangle price range in chart scaling
- [ ] 2.7 Set z-order to "bottom" so rectangles render behind candlesticks
- [x] 2.1 Create `src/plugins/rectangle-drawing.ts` implementing `ISeriesPrimitive<Time>` with renderer, pane view, and data model for two corner points `{time, price}`
- [x] 2.2 Implement `RectangleDrawingPaneRenderer.draw()` — filled semi-transparent rectangle with border, using `useBitmapCoordinateSpace` for HiDPI scaling
- [x] 2.3 Implement `hitTest(x, y)` — convert pixel to data coordinates, check if within rectangle time/price bounds
- [x] 2.4 Add `setSelected(isSelected)` and selection visual feedback (thicker border, increased opacity)
- [x] 2.5 Add preview mode support — dashed border and reduced opacity for preview rectangles during drawing
- [x] 2.6 Add `autoscaleInfo()` to include rectangle price range in chart scaling
- [x] 2.7 Set z-order to "bottom" so rectangles render behind candlesticks
## 3. Wire Up Drawing Interaction in CandleChart