Skip to content

Gap Chart API

Show the distance between two numbers and let the bar carry the punch - see the Gap Chart demo.

Import

ts
import "@michi-vz/wc/gap-chart";
// <michi-vz-gap-chart> is now defined
ts
import { mountGapChart } from "@michi-vz/core";

const chart = mountGapChart(el, props);

Props

PropTypeDefaultDescription
dataSet*GapDataItem[]-Array of rows, one horizontal value1->value2 gap bar per item
titlestring-Optional chart title rendered above the plot
colorMode"label" | "shape""label"Whether marks are colored per row label ("label", default) or per role/shape via shapeColorsMapping ("shape")
shapeColorsMappingShapeMapping-When colorMode is "shape", the colors for the value1, value2, and gap parts
shapesLabelsMappingShapeMapping-Optional display labels for the value1/value2/gap roles (e.g. legend captions)
filterFilter-Top-N / sort filter applied to the data before rendering
timelineboolean | TimelinePeriodConfig-Opt-in "play through years": snapshots one period at a time over the distinct per-row `date` values, with a headless controller (`chart.timeline()`) plus an optional built-in play button + scrubber. Off by default; requires rows with `date`. The user's `filter` still applies within each period.
shapeValue1"circle" | "square" | "triangle""circle"Marker shape for the value1 endpoint: "circle" (default), "square", or "triangle"
shapeValue2"circle" | "square" | "triangle""circle"Marker shape for the value2 endpoint: "circle" (default), "square", or "triangle"
xAxisDataType"date_annual" | "date_monthly" | "number""number"How x values are parsed and formatted: yearly dates, monthly dates, or plain numbers
xAxisDomain[number, number]-Fix the value-axis range as [min, max] instead of the derived zero-baseline domain (e.g. zoom a life-expectancy story into its 35-90 band)
interactiveRowLabelsbooleanfalseMake the row labels interactive: hovering or focusing a label draws a leader line to its row's marks, highlights the row, and shows its tooltip; clicking pins the tooltip. Labels become keyboard-focusable. Default false.
xAxisFormat(d: number | string) => string-Formats an x tick value into its display label
yAxisFormat(d: number | string) => string-Formats a y tick value into its display label
ticksnumber5Approximate number of axis ticks to generate
tickValuesArray<number | Date>-Explicit tick values, overriding the generated ones
enableExplicitTickValuesboolean-When false, ignore `tickValues` for tick placement and GapChart's mark-scale domain, letting the chart use its data-derived domain and generated ticks.
tickHtmlWidthnumber100Width in px of the HTML y-axis label box, which ellipsizes longer labels (default 100)
squareRadiusnumber2Corner radius in px for square markers (default 2)
showZeroLineForXAxisbooleanfalseDraw a solid vertical line at x=0 on the value axis (diverging charts). Default false.
maxBarHeightnumber-Cap each row's thickness (px). When few rows would otherwise balloon the bandwidth (a scaleBand stretched over the full plot height), the band range shrinks to yield exactly this thickness and is centred in the plot (symmetric whitespace), so a 1-2 row chart reads tidily instead of a single row floating mid-plot. No-op for dense charts whose natural bandwidth is already below the cap. Mirrors ComparableBarChart's `maxBarHeight`.
showLegendboolean-Whether to render a legend
legendAlign"left" | "center" | "right"-Horizontal alignment of the legend: "left", "center", or "right"
tooltipFormatter(d: GapDataItem) => string-Returns custom tooltip HTML for a hovered datum (sanitized before it is inserted)
isLoadingboolean-Show the loading overlay and skip the no-data check (legacy michi-vz parity).
isNodataboolean | ((dataSet: GapDataItem[] | null | undefined) => boolean)-No-data override: boolean, or a predicate on the data; default = empty data.
noDataLabelstring-Text for the vanilla default no-data overlay (ignored when suppressed).
suppressDefaultOverlayboolean-A framework wrapper sets this to render its OWN loading/no-data node instead.
onHighlightItem(item: GapDataItem | null) => void-Called when the hovered/highlighted label(s) change
Common props - shared by every chart (14)
PropTypeDefaultDescription
widthnumber1000Chart width in pixels
heightnumber500Chart height in pixels
marginMargin{ top: 50, right: 150, bottom: 100, left: 150 }Inner margins (top/right/bottom/left, in px); default 8 (36 top with a title)
colorsstring[]-Categorical palette for rings without an explicit colour or colorsMapping entry
colorsMappingRecord<string, string>-Explicit label -> colour map; takes precedence over the palette and per-item colours
highlightItemsstring[]-Labels to emphasise (active styling); others keep their base opacity
disabledItemsstring[]-Labels to hide entirely (ring + track removed; remaining rings keep their radii order)
renderer"svg" | "canvas" | "webgpu""svg"Render as inline SVG (default) or to a canvas / WebGPU layer; getContext() is identical either way
localestring-BCP-47 locale used for number formatting
skipColorMappingDispatchbooleanfalseExternal-CSS mode: unmapped labels resolve to transparent and onColorMappingGenerated is not emitted, so arc colours come from your CSS via the data-label-safe contract
enableTransitionsbooleantrueAnimate opacity/arc changes with CSS transitions (SVG renderer; default true)
onColorMappingGenerated(mapping: Record<string, string>) => void-Called with the resolved label -> colour map after the chart assigns colours
onChartDataProcessed(context: ChartContext) => void-Called with the renderer-agnostic ChartContext whenever the data is (re)processed
onDataWarning(warnings: DataWarning[]) => void-Called with any non-fatal data warnings (out-of-range values, duplicate labels, ...)

Events

The web component dispatches these bubbling CustomEvents (the engine exposes the same via the on* callbacks in the table above):

EventDetailFires when
michi-vz:highlightstring[]hover highlight changes
michi-vz:colormappingRecord<string, string>a color mapping is generated
michi-vz:dataprocessedChartContextdata is (re)processed
michi-vz:datawarningDataWarning[]input warnings are detected

getContext()

mountGapChart(el, props).getContext() returns a renderer-agnostic GapChartContext (structured stats + a deterministic natural-language summary + an a11y table). See LLM context.

Source

Props are typed as GapChartProps in @michi-vz/core.