Skip to content

Core (imperative) API

insomni-plot/core is the imperative layer the grammar is built on: raw scales, axis builders, mark builders, legends, formatters, palettes, the data viewport, and the data navigator. Reach for it when you want to hand-wire a render without the Chart builder — or when you need a single primitive (a scale, a formatter, a color palette) in isolation.

import { linearScale, bandScale, bottomAxis, leftAxis, pointMark } from "insomni-plot/core";

Everything below is re-exported from insomni-plot/core. Many type exports accompany the functions; the tables list the runtime values.

ExportBuilds
linearScaleContinuous linear scale.
logScaleLog scale.
sqrtScaleSquare-root scale.
timeScaleTime (Date) scale.
bandScaleCategorical band scale.
groupedBandScaleNested band scale (for grouped / dodged layouts).
timeTicks / timeTickFormatTime-axis tick generation and formatting.
const x = linearScale([0, 100], [0, 640]);
const y = bandScale(["a", "b", "c"], [0, 480]);

bottomAxis, leftAxis, topAxis, rightAxis build axes against a scale and emit into a layer. truncateToWidth clips labels to a pixel budget. Tick configuration uses TickSpec / TickIntervalSpec (shared with the grammar’s AxisSpec.ticks).

The drawing primitives that geoms compose:

ExportMark
pointMarkScatter / glyph points.
lineMarkPolyline.
barMark / categoricalBarMarkBars.
groupedBarMark / stackedBarMarkMulti-series bars.
areaMark / stackedAreaMarkFilled areas.
stackStack layout (StackOffset / StackOrder).
resamplePointsCurve resampling for smoothing.
defineCurve / cardinalCurveCustom line curves.
DASHED_PATTERN / DOTTED_PATTERNDash pattern constants.

Annotation marks: ruleMark, bandMark, valueLabelMark.

legend builds a legend; pointSwatch, lineSwatch, barSwatch, areaSwatch build individual swatch specs. colorBar renders a continuous color-bar legend.

Tick / label formatters: siNumber, currency, fixed, percent — each takes (value, options?) and returns a string. See the axis tick-formatting example.

colorScale builds a color scale; categoricalPalette / continuousPalette construct palettes. Named palettes are re-exported here too — categorical (category10, tableau10, set1/set2/set3, dark2, paired, pastel, accent) and continuous / diverging (viridis, magma, inferno, plasma, cividis, coolwarm, spectral, rdbu, brbg, piyg, prgn, puor, blues, greens, reds, oranges, purples, greys).

The viewport models a pan/zoomable visible window over data:

  • createDataViewport(options)DataViewport — a continuous/band/time viewport with panBy, zoomAt, visible-domain queries, and pan bounds.
  • linkViewports(options) — keep multiple viewports in sync.
  • bindDataViewport(options) — wire pointer events on a canvas to a viewport.

This is what the grammar’s panZoom: true mount option drives internally; MountedPlot.viewport exposes the live instance.

createDataNavigator(options)DataNavigator — an overview / minimap-style navigator with a draggable indicator window over the full data extent.

createRangePresets(options) builds a controller for quick range buttons (e.g. “1D / 1W / 1M / YTD”). linearPreset, logPreset, and timePreset build individual presets. The grammar wraps this in MountedPlot.attachRangePresets(...).

Pure helpers for stat geoms and custom analysis: bin, binBy, binBreaks, binWithBreaks, boxStats, confidenceBand, groupBy, jitter, kde, linearFit, loessFit, polyFit, quantile, rollingWindow, histogramMeasureValue.

import { linearFit, kde } from "insomni-plot/core";
const fit = linearFit(xs, ys); // RegressionFit | null — slope at fit?.summary.slope
const density = kde(values, { bandwidth: "silverman" });

heatmapLayer(data, spec) produces a GPU heatmap layer (HeatmapProducer) for dense density / matrix rendering, separate from the grammar’s tile geom.