Skip to content
weftGitHub

BrushChart

A long series with a strip below it for dragging out the part to look at.

SourcePackage @weft-js/warp

Preview

tsx
import { BrushChart } from '@weft-js/warp'export function Signups() {  return (    <BrushChart title="Signups per day" description="Drag across the lower strip to zoom" data={SIGNUPS_DAILY} x="day" y="signups" name="Signups" domain={[80, 220]} ticks={TICKS} target={GOAL_LINE} annotation="First day over target" />  )}const wobble = (i: number) => Math.sin(i * 12.9898) * 43758.5453 % 1const SIGNUPS_DAILY = Array.from({ length: 120 }, (_, i) => ({ day: `Day ${i + 1}`, signups: Math.round(118 + Math.sin(i / 9) * 26 + i * 0.5 + wobble(i) * 12) }))const TICKS = [100, 160, 220]const GOAL_LINE = { y: 160, label: 'Target 160' }

Installation

npm install @weft-js/warp

Usage

tsx
import { BrushChart } from '@weft-js/warp'<BrushChart title="Signups per day" description="Drag across the lower strip to zoom" data={SIGNUPS_DAILY} x="day" y="signups" name="Signups" domain={[80, 220]} ticks={TICKS} target={GOAL_LINE} annotation="First day over target" />

Accessibility

  • Every chart has a text alternative and a table view of its numbers, so nothing depends on seeing the marks. See Chart for its keyboard support.

API Reference

PropTypeDefaultDescription
titlestring—The heading.
level2 | 3 | 4 | 6 | 5—The title's heading level: one below the heading the chart sits under. Default 3, a chart in a page section.
descriptionunknown—One supporting line under the title.
toolbarunknown—Beside the view toggle: a layout switch, a range picker.
state"error" | "loading" | "empty"—Replaces the plot, in the same frame. With no data the frame shows empty on its own.
loadingstring—Shows that work is under way.
empty{ title: string; detail?: unknown; }—The title and detail shown in place of the plot when there is no data.
error{ title: string; detail?: unknown; }—A message that marks the field invalid and says why.
actionunknown—The next step under an empty or error state: a Retry button.
dataobject[]—The series to draw.
summarystring | ((c: { data: object[]; title: string; }) => string)—One sentence for screen readers and the page; generated from the data when absent.
xstring—The key in each row that names the point on the x axis.
ystring—The key of the value in each row.
namestring—The name it posts under in a form.
domain[number, number]—The fixed y range.
targetReference—A level to watch: { y, label }.
ticksnumber[]—The y values that get a label.
formatFmt—Turns a value into the text shown.
annotationstring—A note on the first value over target.
gapnumber—The space between children, from warp's space scale.

RelatedLine chart