## ADDED Requirements ### Requirement: Rectangle tool mode The Toolbox SHALL include a "rectangle" tool button. When activated, the chart enters rectangle drawing mode. Only one tool SHALL be active at a time — activating the rectangle tool deactivates any other active tool. #### Scenario: Activate rectangle tool - **WHEN** user clicks the rectangle tool button in the Toolbox - **THEN** the rectangle tool becomes active, the button appears visually selected, and the chart cursor changes to crosshair #### Scenario: Deactivate rectangle tool - **WHEN** user clicks the already-active rectangle tool button - **THEN** the tool deactivates, the mode returns to "select", and the cursor returns to default #### Scenario: Rectangle tool deactivates other tools - **WHEN** the "line" tool is active and user clicks the rectangle tool button - **THEN** the line tool deactivates and the rectangle tool becomes active ### Requirement: Two-click rectangle drawing When the "rectangle" tool is active, the system SHALL implement a two-click interaction to define a rectangle. The first click sets one corner point (time, price). The second click sets the opposite corner point (time, price). The rectangle is defined by these two arbitrary data-coordinate corners — it is NOT constrained to candle boundaries. #### Scenario: Draw a rectangle - **WHEN** "rectangle" tool is active and user clicks two points on the chart - **THEN** the system saves a rectangle annotation with the two corner coordinates and renders a filled semi-transparent rectangle on the chart #### Scenario: First click registers corner - **WHEN** "rectangle" tool is active and user clicks on the chart - **THEN** the system records the click position as {time, price} for the first corner #### Scenario: Second click completes rectangle - **WHEN** user has set the first corner and clicks a second position - **THEN** the system saves a rectangle annotation via POST /api/annotations with `label_type: "rectangle"` and `geometry: {"startTime", "startPrice", "endTime", "endPrice"}` ### Requirement: Rectangle preview during drawing After the first click, the system SHALL display a preview rectangle that stretches from the first corner to the current cursor position. The preview SHALL have a dashed border and reduced opacity to distinguish it from saved rectangles. #### Scenario: Preview follows cursor - **WHEN** user has clicked the first corner and moves the mouse - **THEN** a semi-transparent preview rectangle renders from the first corner to the cursor position, updating in real-time via crosshair move events #### Scenario: Preview disappears on cancel - **WHEN** user presses Escape during rectangle drawing (after first click) - **THEN** the preview rectangle disappears and the drawing is cancelled without saving ### Requirement: Rectangle rendering via ISeriesPrimitive The system SHALL render saved rectangle annotations using a `RectangleDrawingPrimitive` class that implements `ISeriesPrimitive