Drawing Base Class
Abstract base class for all drawing tools. Provides common functionality for handle management, hit testing, and rendering.Constructor
X-axis control for coordinate transformations
Y-axis control for coordinate transformations
Optional array of points to initialize the drawing
TPoint Interface
Properties
Number of handles for the drawing. Set to
0 for variable-handle drawings (e.g., polyline).Array of handle objects representing control points
Index of the currently active handle during creation or editing
Whether the drawing has been fully created
Whether the current handle has been anchored
Abstract Methods
Initialize the drawing. Must set
nHandles to the required number of control points.Render the drawing and return an array of SVG segments (Path, Texts, Circle, Rect, etc.).
Test if a point (x, y) is on or near the drawing for selection.
Methods
Anchor the current handle at the given point. Returns
true if the drawing is completed.Update the current handle position while dragging. Returns the rendered drawing.
Move the entire drawing by dragging. Returns the rendered drawing.
Record handle positions before dragging starts.
Insert a new handle at the given point (for variable-handle drawings). Returns the new handle index.
Delete a handle at the specified index.
Get the index of the handle at position (x, y), or -1 if none found.
Render the drawing without handles.
Render the drawing with visible handles for editing.
Helper Methods
Plot an infinite line through the chart given a base point and slope.
Plot a vertical line at the specified bar index.
Calculate the perpendicular distance from a point to a line.
Drawing.tsx:14-269
LineDrawing
Draws a trend line between two points, optionally extended infinitely.Properties
Whether the line extends infinitely in both directions
Always uses 2 handles (start and end points)
Example Usage
Methods
Returns true if the point is within 4 pixels of the line.Source:
LineDrawing.tsx:12-30Renders the line. If
isExtended is true, the line extends across the entire chart. Otherwise, it only draws between the two handles.Source: LineDrawing.tsx:32-54FibonacciRetraceDrawing
Draws Fibonacci retracement levels between two price points.Fibonacci Levels
Draws horizontal lines at the following retracement levels:- 0% (0.0)
- 23.6% (0.236)
- 38.2% (0.382)
- 50% (0.500)
- 61.8% (0.618)
- 76.3% (0.763)
- 100% (1.0)
- 161.8% (1.618)
- 200% (2.0)
- 261.8% (2.618)
- 300% (3.0)
- 423.7% (4.237)
Properties
Always uses 2 handles (start and end points)
Example Usage
Methods
Returns true if the point is within 4 pixels of any Fibonacci level line and within the horizontal range of the drawing.Source:
FibonacciRetraceDrawing.tsx:26-51Renders horizontal lines at each Fibonacci level with percentage labels. Lines are only drawn if they fit within the chart canvas.Source:
FibonacciRetraceDrawing.tsx:53-83FibonacciRetraceDrawing.tsx:5-88
Available Drawing Tools
The following drawing tools can be created using thecreateDrawing factory function:
createDrawing
Supported Drawing IDs
Creates a
LineDrawing - trend line between two pointsCreates a
FibonacciRetraceDrawing - horizontal Fibonacci retracement levelsCreates a
FibonacciRetraceVerticalDrawing - vertical Fibonacci retracement levelsCreates a
FibonacciTimeZoneDrawing - vertical lines at Fibonacci time intervalsCreates a
GannAnglesDrawing - Gann fan anglesCreates a
ParallelDrawing - parallel trend channelCreates a
PolylineDrawing - multi-point polyline (variable handles)Example
Drawings.ts:11-37
Handle Class
Represents a control point for a drawing tool.Properties
The time and value coordinates of this handle
Constructor
Methods
Returns true if the point is within 8 pixels of the handle center.Source:
Drawing.tsx:301-307Renders the handle as a circle with 5-pixel radius.Source:
Drawing.tsx:309-313Usage Notes
- Handles are rendered when a drawing is selected or being edited
- Users can drag handles to reshape the drawing
- For variable-handle drawings (like polyline), Ctrl+Click can insert/delete handles
Drawing.tsx:271-323
Drawing Interaction
Creating a Drawing
- Call
createDrawing()with the desired drawing ID - User clicks to call
anchorHandle()for each required point - Drawing is completed when all handles are anchored
- For variable-handle drawings, Ctrl+Click completes the drawing
Editing a Drawing
- Click on a drawing to select it (calls
hits()to detect) - Drag handles to reshape using
stretchCurrentHandle() - Drag the drawing body to move it using
dragDrawing() - For polyline: Ctrl+Click to insert/delete handles
Deleting a Drawing
Selected drawings can be deleted through the UI, removing them from the drawings array in ChartView. Source:ChartView.tsx:618-931