@reincharts/interactive

Drawing tools, brush and zoom controls.

npm install @reincharts/interactive

Everything here is also re-exported by the umbrella package reincharts.

Components

NameDescription
BrushDrag a rectangle to zoom into / report a range.
DrawingsRenders and edits the drawings of a controller.
DrawingStyleToolbarFloating style editor shown above the selected drawing(s): color, width, dash, fill, lock, clone, delete.
DrawingToolbarDrawing tools toolbar with group flyouts, magnet, keep drawing, lock / hide / remove all.
ZoomButtonsZoom out / zoom in / scroll / reset buttons at the bottom of the chart.

Hooks

NameDescription
useDrawingsCreates a drawing controller for <Drawings>, <DrawingToolbar> and <DrawingStyleToolbar>.
useDrawingStateSubscribes a component to a controller's state.

Functions

NameDescription
arrowHeadFilled arrow head at to, pointing away from from.
constrainAngleConstrains p relative to origin to the nearest multiple of 45° (shift key).
createDrawingControllerFramework agnostic drawing store: drawings, selection, active tool, undo / redo, clipboard, serialization and events.
createEditorFramework agnostic editing logic of <Drawings>: rendering, hit testing, creation, dragging, keyboard shortcuts and alerts.
createGeometryConverts a drawing to pixels for the given pane.
defineToolDefines a drawing tool.
distDistance between two points in pixels.
distToSegmentDistance from p to segment ab.
drawingIdGenerates a unique drawing id.
extendSegmentExtends segment a→b far beyond a box of size w×h (the canvas clip trims it).
fillOfTranslucent version of the drawing color for fills.
fillPolygonFills a closed polygon through points with a color.
handleDraws one edit handle.
inPolygonEven-odd point in polygon test.
inRectWhether (x, y) lies inside the rectangle spanned by a and b.
labelA filled label box.
linearRegressionLeast squares fit y = intercept + slope * x.
lineCrossPrice of the line through the first two points at a logical x (respecting style.extend).
multiLabelMulti-line label box (measure / position stats).
nearPolylineTrue when (x, y) is near any segment of the polyline.
nearSegmentWhether (x, y) is within the hit tolerance of segment a–b.
polylineTraces a polyline through points into the current path.
rectOfNormalized rect spanned by two points.
regressionLinear regression of the source values between the two points (logical x).
renderOrderDrawings sorted for rendering (by z, then creation order).
segmentStrokes a straight line between two points (uses the current stroke style).
strokeOfApplies the drawing's color / width / dash.
textPlain text (no box).
textBoxLayout of a multi-line text box whose top-left is at.

Constants

NameDescription
annotationToolsDrawing tools of one toolbar group: textTool, callout, priceLabel, priceLine.
arrowThe Arrow drawing tool (type: "arrow").
brushThe Brush drawing tool (type: "brush").
builtinToolsEvery built-in tool, in toolbar order.
calloutThe Callout drawing tool (type: "callout").
crossLineThe Cross Line drawing tool (type: "crossLine").
dateAndPriceRangeThe Date and Price Range drawing tool (type: "dateAndPriceRange").
dateRangeThe Date Range drawing tool (type: "dateRange").
DRAWING_COLORSDefault color swatches.
ellipseThe Ellipse drawing tool (type: "ellipse").
extendedLineThe Extended Line drawing tool (type: "extendedLine").
FIB_LEVELSDefault fibonacci levels and colors.
fibExtensionThe Trend-Based Fib Extension drawing tool (type: "fibExtension").
fibRetracementThe Fib Retracement drawing tool (type: "fibRetracement").
fibToolsDrawing tools of one toolbar group: fibRetracement, fibExtension, gannFan.
freehandToolsFreehand tools: brush and highlighter.
GANN_LEVELSDefault gann fan ratios (time/price).
gannFanThe Gann Fan drawing tool (type: "gannFan").
highlighterThick, translucent freehand strokes for marking up a chart.
horizontalLineToolThe Horizontal Line drawing tool (type: "horizontalLine").
horizontalRayThe Horizontal Ray drawing tool (type: "horizontalRay").
iconsBuilt-in 28×28 line icons (tool and toolbar icons), drawn with currentColor.
infoLineThe Info Line drawing tool (type: "infoLine").
lineToolsDrawing tools of one toolbar group: trendLine, ray, infoLine, extendedLine, arrow, horizontalLineTool, horizontalRay, verticalLineTool, crossLine, parallelChannel, regressionChannel, pitchfork.
longPositionThe Long position drawing tool (type: "longPosition").
measureToolsDrawing tools of one toolbar group: longPosition, shortPosition, priceRange, dateRange, dateAndPriceRange.
parallelChannelThe Parallel Channel drawing tool (type: "parallelChannel").
pathThe Path drawing tool (type: "path").
pitchforkThe Pitchfork drawing tool (type: "pitchfork").
priceLabelThe Price Label drawing tool (type: "priceLabel").
priceLineDraggable horizontal price line with a label and a close button (orders, alerts).
priceRangeThe Price Range drawing tool (type: "priceRange").
rayThe Ray drawing tool (type: "ray").
rectangleThe Rectangle drawing tool (type: "rectangle").
regressionChannelThe Regression Trend drawing tool (type: "regressionChannel").
shapeToolsDrawing tools of one toolbar group: rectangle, ellipse, triangle, path.
shortPositionThe Short position drawing tool (type: "shortPosition").
textToolThe Text drawing tool (type: "text").
TOLERANCEHit tolerance in pixels.
toolGroupsToolbar groups (toolbar order).
trendLineThe Trend Line drawing tool (type: "trendLine").
triangleThe Triangle drawing tool (type: "triangle").
verticalLineToolThe Vertical Line drawing tool (type: "verticalLine").

Types

NameDescription
BrushPropsProps of the Brush component.
BrushRangeRange selected with <Brush>.
CrossEventFired when new data crosses a line drawing (price alerts).
CursorModePointer mode of the chart when no drawing tool is active.
DrawingOne drawing on the chart.
DrawingControllerThe drawing controller returned by useDrawings() / createDrawingController().
DrawingControllerEvents
DrawingControllerOptions
DrawingControllerStateSnapshot of the controller state (immutable, safe for React).
DrawingEditor
DrawingLevelA fibonacci / gann level.
DrawingPointA drawing anchor: data x value (timestamp / number) and raw price.
DrawingsJSONSerialized drawings (toJSON / load).
DrawingsPropsProps of the Drawings component.
DrawingStyleVisual style of a drawing.
DrawingStyleToolbarPropsProps of the DrawingStyleToolbar component.
DrawingToolbarPropsProps of the DrawingToolbar component.
DrawStateRender state of a drawing.
EditorOptionsOptions of the drawing editor (props of <Drawings>).
GeometryThe drawing converted to pixels plus helpers, handed to tool draw / hitTest / handles.
GeometryContext
HitPartResult of a hit test: false = miss, "body" (or true) = the drawing, a number = handle index, "remove" = a close button.
IconName
MagnetModeMagnet mode used while placing points.
NewDrawingInput of add: a drawing without id (the pane defaults to "main").
PtA point in pane plot pixels.
StyleControlControls of the floating style toolbar.
ToolDefinitionA drawing tool.
UseDrawingsOptionsOptions of useDrawings (the controller options).
ZoomButtonsPropsProps of the ZoomButtons component.

On this page