Skip to content

Documentation / @ripl/charts

@ripl/charts

Pre-built, animated chart components for Ripl — a unified API for 2D graphics rendering in the browser.

Installation

bash
npm install @ripl/charts

Chart Types

CategoryCharts
CartesianBar, Line, Area, Scatter, Trend (multi-series bar/line), Stock, Realtime
RadialPie/Donut, Radar, Polar Area, Polar Scatter, Radial Bar, Gauge, Sunburst
RelationalSankey, Chord, Force-Directed, Arc Diagram
DistributionHeatmap, Treemap, Packed Circle, Funnel
SchedulingGantt

Usage

typescript
import {
    BarChart,
} from '@ripl/charts';

const chart = new BarChart('#chart', {
    data: [
        { label: 'A',
            value: 10 },
        { label: 'B',
            value: 25 },
        { label: 'C',
            value: 15 },
    ],
    keyBy: 'label',
    series: [
        { valueBy: item => item.value },
    ],
});

Features

  • Animated transitions — Smooth entry, update, and exit animations out of the box
  • Interactive — Tooltips, crosshairs, hover effects, and click events
  • Configurable — Axes, legends, grids, colors, padding, and more
  • Canvas & SVG — Renders to either context via Ripl's unified API
  • Tree-shakable — Import only the chart types you need

Documentation

Full documentation, options reference, and interactive demos are available at ripl.run.

License

MIT

Classes

ClassDescription
ArcDiagramChartArc diagram: a cartesian axis whose points are nodes, connected by semicircular arcs whose thickness encodes the link value. Nodes are laid out in order along the axis (horizontal by default, or vertical), optionally sized by their connection count. On entry the arcs draw out of each node and cascade along the axis — a ripple that fades each node in as its arcs reach it — and updates animate arcs reshaping and nodes resizing. Supports labels, tooltips, and typed node/link interaction events.
AreaChartArea chart rendering filled regions beneath series lines.
BarChartBar chart supporting vertical/horizontal orientation and grouped/stacked modes.
BoxPlotChartBox-plot chart: summarises a numeric field per category with the shared boxplotStats transform and draws a box (Q1–Q3) with a median line, whiskers to the 1.5×IQR fences, and outlier points. Boxes fade/grow in on entry and animate out on exit.
CartesianChartBase class providing shared cartesian component lifecycle and layout.
ChartAbstract base class for all chart types, providing the scene, renderer, animation, colour management, title/legend layout, and the render/update lifecycle that every concrete chart builds on. Consumers never instantiate this directly — each chart exposes a createXChart factory (e.g. createBarChart) and this class supplies the shared behaviour behind it.
ChartLayoutTracks the remaining free space within a chart and allows components to reserve bands from any edge. The order of reservation determines stacking: bands reserved first sit furthest from the plot area.
ChordChartChord diagram visualizing inter-relationships in a square matrix.
ColorLegendA continuous-colour legend: a gradient bar (approximated by solid segments so it works identically on Canvas and SVG) annotated with formatted value labels drawn from a ColorScale. Renders into a reserved region like the other chart components; formatting is supplied explicitly, keeping the scale and the formatter decoupled.
ForceDirectedChartForce-directed network chart laying out nodes and links with a settling physics simulation.
FunnelChartFunnel chart rendering horizontally centered bars of decreasing width.
GanttChartGantt chart rendering time-based task bars on a categorical y-axis and time x-axis.
GaugeChartGauge chart displaying a single value on a 270-degree arc.
HeatmapChartHeatmap chart rendering a grid of colored cells on two categorical axes.
HistogramChartHistogram chart: bins a numeric field with the shared bin transform and draws each bin as a bar on a continuous value axis against a frequency axis. Supports animated entry/update/exit, tooltips, grid, and a chart title.
LineChartLine chart rendering one or more series as polylines with optional markers.
PackedCircleChartPacked circle chart rendering each datum as a circle whose area encodes its value, arranged in a tight, non-overlapping cluster. Great for showing many parts of a whole without the rigid grid of a treemap. Supports labels on sufficiently large circles, tooltips, and animated transitions.
PieChartPie chart rendering proportional arc segments with optional inner radius (donut).
PolarAreaChartPolar area chart rendering equal-angle segments whose radius encodes value.
PolarScatterChartPolar scatter chart plotting points by angle and radius on a circular grid.
RadarChartRadar (spider) chart plotting multi-axis data as filled polygonal areas.
RadialBarChartRadial bar chart rendering each category as a concentric ring whose arc length encodes its value.
RealtimeChartRealtime streaming chart rendering continuously updating line/area series.
RibbonA chord diagram ribbon connecting two arc segments with quadratic Bézier curves through the center.
SankeyChartSankey diagram visualizing directional flow between nodes.
SankeyLinkPathA curved Sankey link shape rendered as a cubic Bézier curve between source and target points.
ScatterChartScatter chart (bubble chart) plotting data points as circles on two continuous axes.
StockChartCandlestick (stock) chart rendering OHLC data with optional volume bars.
SunburstChartSunburst chart rendering hierarchical data as concentric arc rings.
TreemapChartAbstract base class for all chart types, providing the scene, renderer, animation, colour management, title/legend layout, and the render/update lifecycle that every concrete chart builds on. Consumers never instantiate this directly — each chart exposes a createXChart factory (e.g. createBarChart) and this class supplies the shared behaviour behind it.
TrendChartTrend chart combining bar and line series on shared categorical/value axes.

Interfaces

InterfaceDescription
ArcDiagramChartEventMapEvents emitted by an ArcDiagramChart that consumers can subscribe to via chart.on(...).
ArcDiagramChartOptionsOptions for configuring an ArcDiagramChart.
ArcDiagramLinkA link between two nodes.
ArcDiagramLinkEventPayload emitted for arc diagram link interaction events.
ArcDiagramNodeA node in an arc diagram.
ArcDiagramNodeEventPayload emitted for arc diagram node interaction events.
AreaChartEventMapEvents emitted by an AreaChart that consumers can subscribe to via chart.on(...).
AreaChartMarkerEventPayload emitted for area marker interaction events.
AreaChartOptionsOptions for configuring an AreaChart.
AreaChartSeriesOptionsConfiguration for an individual area chart series.
BarChartBarEventPayload emitted for bar interaction events.
BarChartEventMapEvents emitted by a BarChart that consumers can subscribe to via chart.on(...).
BarChartOptionsOptions for configuring a BarChart.
BarChartSeriesOptionsConfiguration for an individual bar chart series.
BaseChartOptionsBase options shared by all chart types.
BaseTrendChartSeriesOptionsBase configuration shared by all trend chart series types.
BinA histogram bin covering the half-open interval [x0, x1) (the last bin includes x1).
BinOptionsOptions for bin.
BoxPlotBoxEventPayload emitted for box interaction events.
BoxPlotChartEventMapEvents emitted by a BoxPlotChart that consumers can subscribe to via chart.on(...).
BoxPlotChartOptionsOptions for configuring a BoxPlotChart.
BoxplotStatsFive-number summary plus IQR and outliers, as used by a box plot.
CartesianChartOptionsOptions shared by all cartesian charts.
CartesianSetupDeclares which optional cartesian components a chart wants constructed.
ChartAnimationOptionsFully resolved chart animation options.
ChartAreaA rectangular region expressed as a top-left origin plus dimensions.
ChartAxisItemOptionsOptions for a single axis (x or y).
ChartAxisOptionsCombined x and y axis configuration.
ChartCrosshairOptionsFully resolved chart crosshair options.
ChartDataLabelsOptionsFully resolved data label options.
ChartGridOptionsFully resolved chart grid options.
ChartLegendOptionsFully resolved chart legend options.
ChartPaddingPadding with explicit top, right, bottom, and left values.
ChartSegmentLabelsOptionsFully resolved segment-label options for radial charts.
ChartTitleOptionsFully resolved chart title options.
ChartTooltipOptionsFully resolved chart tooltip options.
ChartYAxisItemOptionsY-axis specific options extending the base axis item with a left/right position.
ChordChartArcEventPayload emitted for chord outer-arc interaction events.
ChordChartEventMapEvents emitted by a ChordChart that consumers can subscribe to via chart.on(...).
ChordChartOptionsOptions for configuring a ChordChart.
ChordChartRibbonEventPayload emitted for chord ribbon interaction events.
ColorLegendComponentOptionsOptions for constructing a ColorLegend.
ColorLegendOptionsVisual options for a ColorLegend.
DataLabelSpecDescribes a single data label to render.
ForceDirectedChartEventMapEvents emitted by a ForceDirectedChart that consumers can subscribe to via chart.on(...).
ForceDirectedChartOptionsOptions for configuring a ForceDirectedChart.
ForceDirectedLinkEventPayload emitted for force-directed link interaction events.
ForceDirectedNodeEventPayload emitted for force-directed node interaction events.
ForceNetworkLinkA link between two nodes.
ForceNetworkNodeA node in a force-directed network.
FunnelChartEventMapEvents emitted by a FunnelChart that consumers can subscribe to via chart.on(...).
FunnelChartOptionsOptions for configuring a FunnelChart.
FunnelChartSegmentEventPayload emitted for funnel segment interaction events.
GanttChartEventMapEvents emitted by a GanttChart that consumers can subscribe to via chart.on(...).
GanttChartOptionsOptions for configuring a GanttChart.
GanttChartTaskEventPayload emitted for gantt task interaction events.
GaugeChartEventMapEvents emitted by a GaugeChart that consumers can subscribe to via chart.on(...).
GaugeChartOptionsOptions for configuring a GaugeChart.
GaugeChartValueEventPayload emitted for gauge value interaction events.
HeatmapChartCellEventPayload emitted for heatmap cell interaction events.
HeatmapChartEventMapEvents emitted by a HeatmapChart that consumers can subscribe to via chart.on(...).
HeatmapChartOptionsOptions for configuring a HeatmapChart.
HistogramBinEventPayload emitted for histogram bin interaction events.
HistogramChartEventMapEvents emitted by a HistogramChart that consumers can subscribe to via chart.on(...).
HistogramChartOptionsOptions for configuring a HistogramChart.
HoverHighlightOptionsOptions describing how an element should respond to hover.
HoverTooltipMinimal tooltip surface required by the hover helper (decouples it from the Tooltip class).
InteractionPointThe pointer position passed to interaction callbacks.
KdeOptionsOptions for kde.
LinearRegressionA fitted simple linear regression.
LineChartEventMapEvents emitted by a LineChart that consumers can subscribe to via chart.on(...).
LineChartMarkerEventPayload emitted for line marker interaction events.
LineChartOptionsOptions for configuring a LineChart.
LineChartSeriesOptionsConfiguration for an individual line chart series.
PackedCircleChartCellEventPayload emitted for packed circle interaction events.
PackedCircleChartEventMapEvents emitted by a PackedCircleChart that consumers can subscribe to via chart.on(...).
PackedCircleChartOptionsOptions for configuring a PackedCircleChart.
PaddingResolved padding with explicit top, right, bottom, and left values.
PieChartEventMapEvents emitted by a PieChart that consumers can subscribe to via chart.on(...).
PieChartOptionsOptions for configuring a PieChart.
PieChartSegmentEventPayload emitted for pie segment interaction events.
PolarAreaChartEventMapEvents emitted by a PolarAreaChart that consumers can subscribe to via chart.on(...).
PolarAreaChartOptionsOptions for configuring a PolarAreaChart.
PolarAreaChartSegmentEventPayload emitted for polar-area segment interaction events.
PolarScatterChartEventMapEvents emitted by a PolarScatterChart that consumers can subscribe to via chart.on(...).
PolarScatterChartOptionsOptions for configuring a PolarScatterChart.
PolarScatterMarkerEventPayload emitted for polar scatter marker interaction events.
PolarScatterSeriesOptionsConfiguration for an individual polar scatter series.
RadarChartEventMapEvents emitted by a RadarChart that consumers can subscribe to via chart.on(...).
RadarChartOptionsOptions for configuring a RadarChart.
RadarChartPointEventPayload emitted for radar point interaction events.
RadarChartSeriesOptionsConfiguration for an individual radar chart series.
RadialBarChartBarEventPayload emitted for radial bar interaction events.
RadialBarChartEventMapEvents emitted by a RadialBarChart that consumers can subscribe to via chart.on(...).
RadialBarChartOptionsOptions for configuring a RadialBarChart.
RadialLabelAnchorA resolved anchor for a radial label, plus alignment.
RadialLabelInputInput geometry for placing a label around a radial (arc-based) segment.
RadialLabelPlacementResolved inside and outside placements for a radial segment label.
RealtimeChartOptionsOptions for configuring a RealtimeChart.
RealtimeChartSeriesOptionsConfiguration for an individual realtime chart series.
ResolvedAnimationA fully resolved animation ready to be applied to a transition.
RibbonStateState interface for a ribbon shape connecting two arc segments via quadratic curves.
SankeyChartEventMapEvents emitted by a SankeyChart that consumers can subscribe to via chart.on(...).
SankeyChartLinkEventPayload emitted for Sankey link interaction events.
SankeyChartNodeEventPayload emitted for Sankey node interaction events.
SankeyChartOptionsOptions for configuring a SankeyChart.
SankeyLinkA directional flow between two nodes in a Sankey diagram.
SankeyLinkStateState interface for a Sankey link, defining source and target endpoint coordinates.
SankeyNodeA node in a Sankey diagram, with an optional typed datum carried through to node events.
ScatterChartEventMapEvents emitted by a ScatterChart that consumers can subscribe to via chart.on(...).
ScatterChartMarkerEventPayload emitted for scatter marker interaction events.
ScatterChartOptionsOptions for configuring a ScatterChart.
ScatterChartSeriesOptionsConfiguration for an individual scatter chart series.
SegmentLabelLayoutFully resolved layout for a segment label: placement, content, styling, and leader-line points.
SegmentLabelSpecDescribes a single segment label to render.
StockChartCandleEventPayload emitted for stock candlestick interaction events.
StockChartEventMapEvents emitted by a StockChart that consumers can subscribe to via chart.on(...).
StockChartOptionsOptions for configuring a StockChart.
SunburstChartEventMapEvents emitted by a SunburstChart that consumers can subscribe to via chart.on(...).
SunburstChartOptionsOptions for configuring a SunburstChart.
SunburstChartSegmentEventPayload emitted for sunburst segment interaction events.
SunburstNodeA node in a sunburst hierarchy with optional nested children and an optional typed datum.
TreemapChartCellEventPayload emitted for treemap cell interaction events.
TreemapChartEventMapEvents emitted by a TreemapChart that consumers can subscribe to via chart.on(...).
TreemapChartOptionsOptions for configuring a TreemapChart.
TrendChartAreaSeriesOptionsSeries options for area-type series within a trend chart.
TrendChartBarSeriesOptionsSeries options for bar-type series within a trend chart.
TrendChartEventMapEvents emitted by a TrendChart that consumers can subscribe to via chart.on(...).
TrendChartLineSeriesOptionsSeries options for line-type series within a trend chart.
TrendChartOptionsOptions for configuring a TrendChart.
TrendChartValueEventPayload emitted for trend bar/marker interaction events.

Type Aliases

Type AliasDescription
AccessorA value accessor expressed as a property key, a constant, or a function.
ArcDiagramOrientationHow the node axis is oriented.
AxisFormatTypeBuilt-in axis label format types.
BarChartModeWhether multiple series are drawn side by side (grouped) or accumulated into one column (stacked).
BarChartOrientationWhether bars are laid out vertically (default) or horizontally.
BorderRadiusInputBorder radius expressed as a uniform number or a per-corner tuple.
CartesianTargetRe-exported for convenience to subclasses that accept a render target.
ChartAnimationInputAnimation input accepting a boolean toggle or partial options object.
ChartAxisInputAxis input accepting a boolean toggle or a full axis options object.
ChartCrosshairInputCrosshair input accepting a boolean toggle or partial options object.
ChartDataLabelsInputData label input: a boolean toggle, a LabelAnchor string selecting where labels sit, or a partial options object.
ChartGridInputGrid input accepting a boolean toggle or partial options object.
ChartLegendInputLegend input accepting a boolean, position string, or partial options object.
ChartOptionsAlias for a chart's options type, used by factory helpers for readability and future augmentation.
ChartSegmentLabelsInputSegment-label input: a boolean toggle, a SegmentLabelPosition string (which also enables labels), or a partial options object.
ChartSideAn edge of the layout from which a band can be reserved.
ChartTitleInputTitle input accepting a plain string or partial options object.
ChartTooltipInputTooltip input accepting a boolean toggle or partial options object.
ColorLegendOrientationOrientation of the colour legend bar.
CrosshairAxisWhich axis the crosshair tracks.
EaseNameNamed easing function identifiers.
LabelAnchorWhere a data label is anchored relative to its marker/bar.
LegendPositionPosition of the chart legend relative to the chart area.
LineStyleHow a series line is stroked: a preset, or a custom canvas dash array.
NumericAccessorA strongly-typed numeric accessor: a numeric-valued property key of TData, or a function returning a number. Using this (instead of a bare keyof TData) makes the compiler reject a key that points at a non-numeric field. Fields that also accept a fixed constant (e.g. a scatter sizeBy) widen this with `
NumericKeyThe keys of TData whose values are number. Resolves to never for unknown/loose data.
PaddingInputPadding expressed as a uniform number or a [top, right, bottom, left] tuple.
SegmentLabelPositionWhere a radial segment label sits: inside the segment, or outside with a leader line.
SeriesTypeSupported series visualization types within a trend chart.
TitlePositionPosition of the chart title relative to the chart area.
TrendChartSeriesOptionsDiscriminated union of all trend chart series option types.
ValueFormatInputA value formatter accepted anywhere a chart renders a raw value as text (tooltips, data labels, pie segment labels). Either a built-in format type or a custom callback.

Variables

VariableDescription
ANIMATION_REFERENCEReference durations (in ms, at the default animation speed) for each transition kind.
DEFAULT_NUMBER_PRECISIONDefault maximum number of decimal places applied when rendering numeric values as text.
SEGMENT_LABEL_FONTShared segment-label style constants. Every chart routes its segment labels through these so the appearance is identical across chart types and across the Canvas and SVG contexts. The cross-context inconsistency this fixes came from labels that omitted font, leaving each backend to fall back to its own default — always set an explicit font.
SEGMENT_LABEL_INSIDE_FILLFill for labels drawn inside a segment (on top of the filled shape).
SEGMENT_LABEL_OUTSIDE_FILLFill for labels drawn outside a segment (on the chart background).

Functions

FunctionDescription
applyHoverHighlightWires consistent hover behaviour (highlight transition + optional tooltip) onto an element. Safe to call repeatedly on the same persistent element across renders — prior listeners are disposed first so handlers never accumulate.
binBins numeric values into a histogram. Without explicit thresholds, a "nice" uniform bin width is derived from the target bin count (Sturges' rule by default). Values outside the domain are dropped.
boxplotStatsComputes the box-plot five-number summary, splitting values beyond 1.5×IQR out as outliers.
computeStackOffsetComputes the stacked baseline offset for a series at a given data item. Positive and negative values stack independently so diverging stacks render correctly. Series earlier in the array sit closer to the baseline.
createArcDiagramChartFactory function that creates a new ArcDiagramChart instance.
createAreaChartFactory function that creates a new AreaChart instance.
createBarChartFactory function that creates a new BarChart instance.
createBoxPlotChartFactory function that creates a new BoxPlotChart.
createChordChartFactory function that creates a new ChordChart instance.
createColorLegendFactory function that creates a new ColorLegend.
createDataLabelCreates a data label Text element (at opacity 0) positioned by its anchor.
createForceDirectedChartFactory function that creates a new ForceDirectedChart instance.
createFunnelChartFactory function that creates a new FunnelChart instance.
createGanttChartFactory function that creates a new GanttChart instance.
createGaugeChartFactory function that creates a new GaugeChart instance.
createHeatmapChartFactory function that creates a new HeatmapChart instance.
createHistogramChartFactory function that creates a new HistogramChart.
createLineChartFactory function that creates a new LineChart instance.
createPackedCircleChartFactory function that creates a new PackedCircleChart instance.
createPieChartFactory function that creates a new PieChart instance.
createPolarAreaChartFactory function that creates a new PolarAreaChart instance.
createPolarScatterChartFactory function that creates a new PolarScatterChart instance.
createRadarChartFactory function that creates a new RadarChart instance.
createRadialBarChartFactory function that creates a new RadialBarChart instance.
createRealtimeChartFactory function that creates a new RealtimeChart instance.
createRibbonFactory function that creates a new Ribbon instance.
createSankeyChartFactory function that creates a new SankeyChart instance.
createSankeyLinkFactory function that creates a new SankeyLinkPath instance.
createScatterChartFactory function that creates a new ScatterChart instance.
createSegmentLabelCreates a segment label Text with all style properties set explicitly (never inheriting the context default), guaranteeing identical rendering across chart types and Canvas/SVG contexts.
createStockChartFactory function that creates a new StockChart instance.
createSunburstChartFactory function that creates a new SunburstChart instance.
createTreemapChartFactory function that creates a new TreemapChart instance.
createTrendChartFactory function that creates a new TrendChart instance.
deviationThe population standard deviation of the values.
elementIsRibbonType guard that checks whether a value is a Ribbon instance.
elementIsSankeyLinkType guard that checks whether a value is a SankeyLinkPath instance.
exitElementTransitions an element to a terminal state (defaulting to fully transparent) and then destroys it, giving every chart a consistent exit animation. When animation is disabled the element is destroyed immediately.
formatNumberFormats a numeric value as a localized string, capping the precision at precision decimal places (default DEFAULT_NUMBER_PRECISION). Integers render without decimals; fractional values are rounded to at most precision places with trailing zeros stripped. Non-numeric values fall back to String(value). This is the shared entry point every chart uses so labels, axes, tooltips, and tick marks share one consistent precision cap.
kdeReturns a Gaussian kernel density estimator f(x) for the values. The bandwidth defaults to Silverman's rule; pass one explicitly for tighter or smoother density curves.
linearRegressionFits a simple least-squares linear regression to [x, y] points and reports its R².
meanThe arithmetic mean of the values (NaN when empty).
normalizeAnimationNormalizes animation input into fully resolved ChartAnimationOptions.
normalizeAxisNormalizes axis input into a full ChartAxisOptions object with both x and y.
normalizeAxisItemNormalizes a single axis item input into fully resolved options.
normalizeCrosshairNormalizes crosshair input into fully resolved ChartCrosshairOptions.
normalizeDataLabelsNormalizes a data label input into fully resolved ChartDataLabelsOptions.
normalizeGridNormalizes grid input into fully resolved ChartGridOptions.
normalizeLegendNormalizes legend input into fully resolved ChartLegendOptions.
normalizePaddingNormalizes a padding input into a Padding object, or returns undefined if no input.
normalizeSegmentLabelsNormalizes a segment-label input into fully resolved ChartSegmentLabelsOptions.
normalizeTitleNormalizes a title input into fully resolved ChartTitleOptions.
normalizeTooltipNormalizes tooltip input into fully resolved ChartTooltipOptions.
normalizeYAxisItemNormalizes a Y-axis item input into fully resolved options with position.
quantileThe p-quantile (0–1) of the values via linear interpolation between order statistics.
resolveAccessorNormalises an Accessor into a function. Property keys read the field, functions are passed through, and any other value is treated as a constant.
resolveAnimationResolves chart animation options for a given reference duration, scaling by the configured speed and collapsing to 0/disabled when animation is turned off.
resolveDataLabelLayoutResolves the anchored position and text alignment for a data label.
resolveEaseResolves an ease name or function to an Ease function, defaulting to easeOutCubic.
resolveFormatLabelResolves an axis format type or custom formatter into a label formatting function.
resolveLineDashResolves a LineStyle into a lineDash array ([] for a solid line).
resolveRadialLabelComputes both the inside (centroid) and outside (leader-line) label placements for a radial segment. Shared by the pie and polar-area charts so their inside/outside label behaviour — and the elbow leader line — stay identical. The outside textAlign flips by hemisphere so text reads away from the centre.
resolveSegmentLabelLayoutResolves a segment's label into a ready-to-render layout (inside centroid or outside leader line), honouring visibility, an optional minimum-angle clutter guard, and position/font/colour options. Shared by the pie and polar-area charts so their label behaviour is identical.
resolveValueFormatResolves a value formatter into a function, always returning a usable formatter (falling back to String when no custom format is supplied). Convenience wrapper over resolveFormatLabel for the value-as-text sites that always need to print something.
rollupGroups values by a key and reduces each group, returning a Map of key → reduced value.
staggerComputes a per-element stagger delay so that a collection of entering elements animate in sequence rather than all at once. Returns 0 when there is nothing to stagger.