@blueprint-chart/docs 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/api.d.ts +13 -0
- package/dist/api.js +29 -0
- package/dist/manifest.json +242 -0
- package/package.json +63 -0
- package/src/charts/area-stacked.md +64 -0
- package/src/charts/area.md +65 -0
- package/src/charts/bar-grouped.md +60 -0
- package/src/charts/bar-horizontal.md +71 -0
- package/src/charts/bar-multi.md +64 -0
- package/src/charts/bar-split.md +61 -0
- package/src/charts/bar-stacked.md +62 -0
- package/src/charts/bar-vertical.md +71 -0
- package/src/charts/column-stacked.md +57 -0
- package/src/charts/donut.md +66 -0
- package/src/charts/index.md +36 -0
- package/src/charts/line-multi.md +64 -0
- package/src/charts/line.md +65 -0
- package/src/charts/pie.md +63 -0
- package/src/guide/accessibility.md +196 -0
- package/src/guide/data-transforms.md +191 -0
- package/src/guide/dsl-editor.md +218 -0
- package/src/guide/embed.md +208 -0
- package/src/guide/getting-started.md +159 -0
- package/src/guide/palettes.md +207 -0
- package/src/guide/scenes.md +223 -0
- package/src/handbook/accessibility.md +109 -0
- package/src/handbook/annotations.md +143 -0
- package/src/handbook/anti-patterns.md +85 -0
- package/src/handbook/axes.md +116 -0
- package/src/handbook/choosing.md +120 -0
- package/src/handbook/color.md +141 -0
- package/src/handbook/design-principles.md +111 -0
- package/src/handbook/frame-elements.md +98 -0
- package/src/handbook/index.md +91 -0
- package/src/handbook/labels.md +117 -0
- package/src/handbook/tooltips.md +98 -0
- package/src/handbook/typography.md +93 -0
- package/src/reference/api/index.md +245 -0
- package/src/reference/dsl/annotations.md +135 -0
- package/src/reference/dsl/index.md +137 -0
- package/src/reference/dsl/properties.md +79 -0
- package/src/reference/dsl/scenes-and-transforms.md +97 -0
- package/src/reference/index.md +18 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Tooltips & Interaction
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Tooltips & Interaction
|
|
6
|
+
|
|
7
|
+
> Tooltips progressively disclose detail, they never replace critical information. Interaction must be consistent, accessible, and keyboard-reachable. Crosshairs and hover states support — not replace — clear visual hierarchy.
|
|
8
|
+
|
|
9
|
+
## Tooltip content
|
|
10
|
+
|
|
11
|
+
- Include **both value AND category context**: *"3.4% unemployed"* not just *"3.4%"*
|
|
12
|
+
- Keep content brief and self-sufficient (microcopy)
|
|
13
|
+
- Repeat units and formatting seen elsewhere in the chart
|
|
14
|
+
- Do not rely on tooltips for critical information — essential data must always be visible
|
|
15
|
+
|
|
16
|
+
::: warning
|
|
17
|
+
Tooltips are hidden by default. If information is essential to the chart's headline, it must be in the frame or on the data, not behind a hover.
|
|
18
|
+
:::
|
|
19
|
+
|
|
20
|
+
## Tooltip interaction
|
|
21
|
+
|
|
22
|
+
- Support both **mouse hover and keyboard navigation** for accessibility
|
|
23
|
+
- Tooltips are primarily a desktop pattern; on touch devices, use tap-triggered popups or always-visible labels
|
|
24
|
+
- Apply tooltips **consistently** across all interactive elements — erratic deployment means users will not discover them
|
|
25
|
+
- Tooltips must be user-initiated, not auto-appearing
|
|
26
|
+
|
|
27
|
+
## Tooltip positioning
|
|
28
|
+
|
|
29
|
+
- Never obscure the data point the user is examining
|
|
30
|
+
- Use arrow indicators when multiple elements are nearby
|
|
31
|
+
- Keep the tooltip within the viewport
|
|
32
|
+
|
|
33
|
+
## Crosshair patterns
|
|
34
|
+
|
|
35
|
+
- **Vertical crosshair** (tracking x-position) is standard for time-series line charts
|
|
36
|
+
- Helps align reading across multiple series at the same x-value
|
|
37
|
+
- Often combined with a tooltip showing all series values at that position
|
|
38
|
+
- **Horizontal crosshair** is useful for value comparison on scatter plots
|
|
39
|
+
- Crosshair lines should be subtle (dashed, light grey by default)
|
|
40
|
+
- Hide crosshairs when the cursor leaves the chart area
|
|
41
|
+
|
|
42
|
+
## Hover states
|
|
43
|
+
|
|
44
|
+
- Use color saturation or opacity changes to indicate the active element
|
|
45
|
+
- De-emphasize non-hovered elements (reduce opacity to 0.2-0.3) to create focus
|
|
46
|
+
- Maintain the visual hierarchy: the hovered element should become the most prominent
|
|
47
|
+
|
|
48
|
+
## Interaction design checklist
|
|
49
|
+
|
|
50
|
+
- Is there a visible affordance that the chart is interactive?
|
|
51
|
+
- Is the same interaction reachable by keyboard?
|
|
52
|
+
- Do tooltips reappear consistently, or are they flaky at chart edges?
|
|
53
|
+
- Does the tooltip echo the chart's number format and units?
|
|
54
|
+
- Does the hovered element stay inside the viewport when tooltips grow?
|
|
55
|
+
|
|
56
|
+
## How Blueprint Chart applies interaction
|
|
57
|
+
|
|
58
|
+
Blueprint Chart's interaction layer is declarative. Crosshair direction and style enums configure axis-aligned crosshairs; tooltips are produced from the same scale and accessor layer used to render the chart, so the numbers always match. Tooltip positioning respects the viewport and flips sides automatically when the cursor approaches the chart edge.
|
|
59
|
+
|
|
60
|
+
See the [API reference](/reference/api/) for the tooltip options exposed to consumers.
|
|
61
|
+
|
|
62
|
+
## Worked example: tooltips plus a dashed vertical crosshair
|
|
63
|
+
|
|
64
|
+
```bpc
|
|
65
|
+
chart line-multi {
|
|
66
|
+
title = "Detroit's unemployment hit 16% during the Great Recession"
|
|
67
|
+
description = "Percent of labour force, 2000–2014"
|
|
68
|
+
source = "Bureau of Labor Statistics"
|
|
69
|
+
legend = false
|
|
70
|
+
tooltips = true
|
|
71
|
+
crosshair = true
|
|
72
|
+
crosshairStyle = "dashed"
|
|
73
|
+
|
|
74
|
+
annotation "2009" {
|
|
75
|
+
text = "Great Recession peak"
|
|
76
|
+
dy = -10
|
|
77
|
+
showArrow = true
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
data {
|
|
81
|
+
_series = "New York","Los Angeles","Chicago","Detroit"
|
|
82
|
+
"2000" = 5.0,5.6,4.5,3.8
|
|
83
|
+
"2009" = 9.5,12.4,11.2,16.2
|
|
84
|
+
"2014" = 6.5,8.0,7.1,8.2
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
::: info From `packages/lib/src/samples/unemployment-rates.bpc`
|
|
90
|
+
The annotation carries the headline (`"Great Recession peak"`) so the chart stands on its own. `tooltips = true` plus `crosshair = true` then layer progressive disclosure on top: hover anywhere on the x-axis and a dashed vertical line aligns the cursor with all four series at once, while the tooltip shows the four percentages for that year. The essential story is never trapped behind a hover.
|
|
91
|
+
:::
|
|
92
|
+
|
|
93
|
+
## See also
|
|
94
|
+
|
|
95
|
+
- [Accessibility](/handbook/accessibility)
|
|
96
|
+
- [Labels & Legends](/handbook/labels)
|
|
97
|
+
- [Annotations](/handbook/annotations)
|
|
98
|
+
- [Design Principles](/handbook/design-principles)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Typography
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Typography
|
|
6
|
+
|
|
7
|
+
> Type in charts must be small, sharp, and legible at a glance. Use sans-serifs with unambiguous character shapes, size ruthlessly, never rotate, prefer sentence case, and left-align.
|
|
8
|
+
|
|
9
|
+
## Font selection
|
|
10
|
+
|
|
11
|
+
- Use **sans-serif fonts** for charts: Roboto, Lato, Open Sans, Source Sans Pro, Noto Sans
|
|
12
|
+
- Choose fonts where capital I, lowercase l, and number 1 are visibly different (Source Sans Pro, Verdana pass this test)
|
|
13
|
+
- For maximum accessibility: **Atkinson Hyperlegible** (Braille Institute / Google Fonts)
|
|
14
|
+
- Use **lining figures** (same height) for numbers in charts
|
|
15
|
+
- Use **tabular figures** (equal width) for aligned columns and data tables
|
|
16
|
+
- Maximum **two font families** in a single visualization
|
|
17
|
+
|
|
18
|
+
## Sizing
|
|
19
|
+
|
|
20
|
+
- Minimum **12-14px** for chart text on web
|
|
21
|
+
- Minimum **36pt** for presentations
|
|
22
|
+
- Title should be the largest, boldest text with highest contrast
|
|
23
|
+
- Axis labels and data labels at medium size
|
|
24
|
+
- Source and credit lines at smallest size, lowest contrast
|
|
25
|
+
|
|
26
|
+
## Readability rules
|
|
27
|
+
|
|
28
|
+
::: warning
|
|
29
|
+
**Never rotate text.** If axis labels don't fit, rephrase them, abbreviate, or switch to horizontal bars.
|
|
30
|
+
:::
|
|
31
|
+
|
|
32
|
+
- Use **sentence case** (not ALL CAPS) for readability
|
|
33
|
+
- **Left-align** multi-line text
|
|
34
|
+
- Use **bold** sparingly for emphasis; avoid italics (harder to read)
|
|
35
|
+
- Add text outlines (stroke in background color) when labels overlay chart elements
|
|
36
|
+
|
|
37
|
+
## Hierarchy
|
|
38
|
+
|
|
39
|
+
A chart typically has three to four type levels:
|
|
40
|
+
|
|
41
|
+
1. **Title** — largest, boldest, highest contrast (states the insight)
|
|
42
|
+
2. **Description / subtitle** — medium size, regular weight (context, time period, units)
|
|
43
|
+
3. **Axis and data labels** — medium, consistent throughout
|
|
44
|
+
4. **Source, note, credit** — smallest, lowest contrast
|
|
45
|
+
|
|
46
|
+
Anything beyond four levels starts competing for attention. Collapse hierarchy aggressively.
|
|
47
|
+
|
|
48
|
+
## How Blueprint Chart applies typography
|
|
49
|
+
|
|
50
|
+
The renderer defaults to a sans-serif with tabular figures for axis ticks and data labels; source lines are the smallest, greyest type in the frame. Type sizes and weights are exposed as CSS custom properties so a single theme change propagates everywhere — including the editor's stories and the component library.
|
|
51
|
+
|
|
52
|
+
```css
|
|
53
|
+
.bc-chart {
|
|
54
|
+
--bc-font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
55
|
+
--bc-font-size-title: 1.25rem;
|
|
56
|
+
--bc-font-size-description: 0.9375rem;
|
|
57
|
+
--bc-font-size-axis: 0.8125rem;
|
|
58
|
+
--bc-font-size-source: 0.75rem;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Worked example: a short title doing the work
|
|
63
|
+
|
|
64
|
+
```bpc
|
|
65
|
+
chart bar-vertical {
|
|
66
|
+
title = "E is the most frequent letter in English"
|
|
67
|
+
description = "How often each letter appears in typical English text"
|
|
68
|
+
source = "Lewand, Cryptological Mathematics"
|
|
69
|
+
note = "Based on analysis of 40,000 words from English prose"
|
|
70
|
+
valueLabels = true
|
|
71
|
+
verticalLabelPosition = off
|
|
72
|
+
verticalGridStyle = none
|
|
73
|
+
|
|
74
|
+
data {
|
|
75
|
+
"E" = 12.70
|
|
76
|
+
"T" = 9.06
|
|
77
|
+
"A" = 8.17
|
|
78
|
+
"O" = 7.51
|
|
79
|
+
"I" = 6.97
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
::: info From `packages/lib/src/samples/letter-frequency.bpc`
|
|
85
|
+
Title under 50 characters, description under 70, single-letter axis labels — no rotation needed. The chart frame stays typographically neutral so the value labels (`12.70`, `9.06`…) sit at the same medium size as the axis ticks. Type hierarchy is collapsed to the minimum.
|
|
86
|
+
:::
|
|
87
|
+
|
|
88
|
+
## See also
|
|
89
|
+
|
|
90
|
+
- [Frame Elements](/handbook/frame-elements)
|
|
91
|
+
- [Labels & Legends](/handbook/labels)
|
|
92
|
+
- [Accessibility](/handbook/accessibility)
|
|
93
|
+
- [Design Principles](/handbook/design-principles)
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
Public surface of [`@blueprint-chart/lib`](https://www.npmjs.com/package/@blueprint-chart/lib). Every symbol on this page is exported from the package root.
|
|
4
|
+
|
|
5
|
+
::: info Source of truth
|
|
6
|
+
This page mirrors [`packages/lib/src/index.ts`](https://github.com/blueprint-chart/blueprint-chart/blob/main/packages/lib/src/index.ts). It will be progressively replaced by automatically-generated TypeDoc output; for now, treat the source file as canonical when a symbol is missing here.
|
|
7
|
+
:::
|
|
8
|
+
|
|
9
|
+
## Entrypoints
|
|
10
|
+
|
|
11
|
+
| Entrypoint | Purpose |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `@blueprint-chart/lib` | The ESM API — types, parsing, rendering primitives, registry. |
|
|
14
|
+
| `@blueprint-chart/lib/dist/lib/lib.iife.js` | Standalone IIFE runtime that auto-renders `<script type="application/blueprint-chart">` tags. Exposed globally as `BlueprintChart`. |
|
|
15
|
+
| `@blueprint-chart/lib/charts.scss` | Base SCSS for chart styling — import once at the app level. |
|
|
16
|
+
|
|
17
|
+
## Enums
|
|
18
|
+
|
|
19
|
+
Authoritative list of enum exports (from `./enums`):
|
|
20
|
+
|
|
21
|
+
`ChartType` · `AxisDirection` · `ScaleType` · `GridStyle` · `LabelPosition` · `LabelRotation` · `TickPosition` · `FrameSizing` · `CompassDirection` · `AnnotationLineStyle` · `StrokeStyle` · `AnnotationKind` · `AnnotationAction` · `RangeAnchor` · `Orientation` · `SymbolShape` · `SymbolShowOn` · `SymbolStyle` · `SortDirection` · `SortMode` · `LegendPosition` · `Anchor` · `ValueLabelPosition` · `CrosshairDirection` · `CrosshairStyle` · `StackMode` · `LineStyle` · `ChartOptionType` · `DirectLabelMode` · `Interpolation` · `DslNodeType`
|
|
22
|
+
|
|
23
|
+
## Types
|
|
24
|
+
|
|
25
|
+
### Chart data and options
|
|
26
|
+
|
|
27
|
+
`ChartData` · `ChartOptions` · `ChartRenderer` · `ChartOptionDef` · `ChartTypeOptions` · `ChartTypeOptionKey` · `Margin`
|
|
28
|
+
|
|
29
|
+
### Visual configuration
|
|
30
|
+
|
|
31
|
+
`ColorizeConfig` · `HighlightConfig` · `AxisOptions` · `FrameOptions` · `AreaFillConfig` · `LineSymbolConfig` · `SeriesOverride`
|
|
32
|
+
|
|
33
|
+
### Annotations
|
|
34
|
+
|
|
35
|
+
`AnnotationConfig` · `PointAnnotationConfig` · `RangeAnnotationConfig` · `FreeAnnotationConfig` · `AnnotationLineConfig`
|
|
36
|
+
|
|
37
|
+
## Rendering primitives
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import {
|
|
41
|
+
createFrame,
|
|
42
|
+
createCanvas,
|
|
43
|
+
renderVerticalAxis,
|
|
44
|
+
renderHorizontalAxis,
|
|
45
|
+
renderLegend,
|
|
46
|
+
} from '@blueprint-chart/lib'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Symbol | Purpose |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `createFrame(options)` | Set up the chart's outer frame (title, description, source, axis labels, note). Returns `FrameElements`. |
|
|
52
|
+
| `createCanvas(options)` | Set up the inner drawing surface. Returns `CanvasElements`. |
|
|
53
|
+
| `renderVerticalAxis(...)` / `renderHorizontalAxis(...)` | Draw axes with grid lines, ticks, and labels. |
|
|
54
|
+
| `renderLegend(...)` | Draw a chart legend (position + interactivity). |
|
|
55
|
+
|
|
56
|
+
## Chart-type registry
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import {
|
|
60
|
+
registerChart,
|
|
61
|
+
getChart,
|
|
62
|
+
getChartOptions,
|
|
63
|
+
listCharts,
|
|
64
|
+
} from '@blueprint-chart/lib'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Charts register themselves with the registry at import time. `getChart(type)` returns the renderer; `listCharts()` enumerates every registered type.
|
|
68
|
+
|
|
69
|
+
## Helpers
|
|
70
|
+
|
|
71
|
+
### Data and option helpers
|
|
72
|
+
|
|
73
|
+
`parseData` · `buildChartOptions` · `getChartTypeDefaults` · `resolveChartTypeOptions` · `resolveBarGapPadding` · `DEFAULT_BAR_GAP`
|
|
74
|
+
|
|
75
|
+
### Palettes
|
|
76
|
+
|
|
77
|
+
`resolvePalette` · `listPalettes` · type `PaletteEntry`
|
|
78
|
+
|
|
79
|
+
### Series
|
|
80
|
+
|
|
81
|
+
`resolveSeriesColor` · `resolveSeriesInterpolation` · `isSeriesHidden`
|
|
82
|
+
|
|
83
|
+
### Color and accessibility
|
|
84
|
+
|
|
85
|
+
`resolveBackgroundColor` · `adjustColorsForBackground` · `wcagContrastRatio` · `wcagLevel`
|
|
86
|
+
|
|
87
|
+
`getCvdFilterId` · `createCvdSvgFilter` · `simulateCvdColor` · `checkCvdColors` · types `CvdType` · `CvdIssue`
|
|
88
|
+
|
|
89
|
+
### Motion
|
|
90
|
+
|
|
91
|
+
`getTransitionDuration` · `snapshotForFadeOut` · `commitFadeOut` · `fadeIn` · `getCachedChart`
|
|
92
|
+
|
|
93
|
+
## DSL
|
|
94
|
+
|
|
95
|
+
### Parsing and serialization
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { parse, serialize, compactSerialize } from '@blueprint-chart/lib'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
| Symbol | Behaviour |
|
|
102
|
+
| --- | --- |
|
|
103
|
+
| `parse(source)` | BPC text → AST. Throws on syntax errors. |
|
|
104
|
+
| `serialize(ast)` | AST → BPC text (formatted). |
|
|
105
|
+
| `compactSerialize(ast)` | AST → BPC text (whitespace-minimized). |
|
|
106
|
+
|
|
107
|
+
### Parse, modify, serialize
|
|
108
|
+
|
|
109
|
+
A typical pipeline reads a BPC source, mutates the AST in-place, then writes it back. Bundled samples make convenient inputs:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { parse, serialize, samples } from '@blueprint-chart/lib'
|
|
113
|
+
|
|
114
|
+
// Pull the Bitcoin price sample shipped with the lib.
|
|
115
|
+
const bitcoin = samples.find(s => s.id === 'bitcoin-price')!
|
|
116
|
+
|
|
117
|
+
// Parse the verbatim BPC source into an AST.
|
|
118
|
+
const ast = parse(bitcoin.dsl)
|
|
119
|
+
|
|
120
|
+
// Mutate: retitle the chart and bump the latest data point.
|
|
121
|
+
const title = ast.properties.find(p => p.key === 'title')
|
|
122
|
+
if (title) {
|
|
123
|
+
title.value = 'Bitcoin closed 2024 at a record high'
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const latest = ast.data?.entries.find(e => e.key === '2024')
|
|
127
|
+
if (latest) {
|
|
128
|
+
latest.value = 95000
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Serialize back to BPC text — round-trip safe.
|
|
132
|
+
const updated = serialize(ast)
|
|
133
|
+
console.log(updated)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The `parse → mutate → serialize` cycle is **round-trip safe**: re-parsing the output yields a structurally equal AST. Use `compactSerialize(ast)` instead of `serialize(ast)` when emitting BPC for embedding in HTML attributes or one-line URLs.
|
|
137
|
+
|
|
138
|
+
### Converters
|
|
139
|
+
|
|
140
|
+
`propertyMap` · `extractChartTypeOptions` · `dataEntriesToString` · `extractSceneOverrides` · `convertColorizes` · `convertHighlights` · `convertAreaFills` · `convertAnnotations` · `convertSeriesOverrides`
|
|
141
|
+
|
|
142
|
+
### AST node types
|
|
143
|
+
|
|
144
|
+
`ChartNode` · `DataNode` · `PropertyNode` · `SeriesNode` · `SceneNode` · `StepNode` · `TransformNode` · `ColorizeNode` · `HighlightNode` · `AreaFillNode` · `AnnotationNode` · `PointAnnotationNode` · `RangeAnnotationNode` · `FreeAnnotationNode` · `AnnotationVisibilityNode`
|
|
145
|
+
|
|
146
|
+
See [the DSL spec](/reference/dsl/) for the corresponding source-level grammar.
|
|
147
|
+
|
|
148
|
+
## Samples
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { samples, type ChartSample } from '@blueprint-chart/lib'
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`samples` is a curated set of BPC sources used by the editor's sample gallery. Each entry includes title, description, and source — the underlying `.bpc` files live in [`packages/lib/src/samples/`](https://github.com/blueprint-chart/blueprint-chart/tree/main/packages/lib/src/samples).
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { samples, parse } from '@blueprint-chart/lib'
|
|
158
|
+
|
|
159
|
+
// Discover everything bundled and filter by chart type.
|
|
160
|
+
const lineSamples = samples.filter(s => s.chartType === 'line')
|
|
161
|
+
|
|
162
|
+
// Each sample carries its raw BPC source on `.dsl`.
|
|
163
|
+
const ast = parse(lineSamples[0].dsl)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Each `ChartSample` exposes:
|
|
167
|
+
|
|
168
|
+
| Field | Type | Description |
|
|
169
|
+
| --- | --- | --- |
|
|
170
|
+
| `id` | `string` | Stable identifier matching the source filename (e.g. `bitcoin-price`). |
|
|
171
|
+
| `title` | `string` | The chart's `title` property, extracted at build time. |
|
|
172
|
+
| `description` | `string` | The chart's `description` property. |
|
|
173
|
+
| `chartType` | `string` | The DSL chart type (`line`, `bar-vertical`, `area-stacked`, …). |
|
|
174
|
+
| `tsvData` | `string` | Data block flattened to tab-separated values for paste-in flows. |
|
|
175
|
+
| `serializedData` | `string` | Data block re-emitted as BPC `data { … }` lines. |
|
|
176
|
+
| `dsl` | `string` | The verbatim `.bpc` source. |
|
|
177
|
+
|
|
178
|
+
## Runtime entrypoint
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
// Available only from the IIFE bundle (auto-initialized) or:
|
|
182
|
+
import { initBlueprint, createSceneController, createStepController } from '@blueprint-chart/lib/dist/runtime'
|
|
183
|
+
import type { SceneDefinition, SceneController, StepDefinition, StepController } from '@blueprint-chart/lib/dist/runtime'
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
| Symbol | Purpose |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| `initBlueprint()` | Find every `<script type="application/blueprint-chart">` on the page and replace it with a rendered chart iframe. |
|
|
189
|
+
| `createSceneController(...)` | Imperative API for stepping through a chart's scenes programmatically. |
|
|
190
|
+
| `createStepController(...)` | Lower-level step-based controller (aliased scene API). |
|
|
191
|
+
|
|
192
|
+
### End-to-end example
|
|
193
|
+
|
|
194
|
+
Drop a BPC source into the page inside a typed `<script>` tag, then call `initBlueprint()` once. Each script tag is replaced with a sandboxed iframe that renders the chart and posts back its measured height:
|
|
195
|
+
|
|
196
|
+
```html
|
|
197
|
+
<script type="application/blueprint-chart">
|
|
198
|
+
chart line {
|
|
199
|
+
title = "Bitcoin surged past $90,000 in 2024"
|
|
200
|
+
description = "USD, year-end closing price"
|
|
201
|
+
source = "CoinGecko"
|
|
202
|
+
colors = "#f7931a"
|
|
203
|
+
lineSymbols = true
|
|
204
|
+
lineSymbolShape = "diamond"
|
|
205
|
+
verticalNumberFormat = ",.0f"
|
|
206
|
+
|
|
207
|
+
annotation "2021" {
|
|
208
|
+
text = "All-time high cycle"
|
|
209
|
+
dy = -12
|
|
210
|
+
showArrow = true
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
data {
|
|
214
|
+
"2016" = 963
|
|
215
|
+
"2017" = 13880
|
|
216
|
+
"2018" = 3742
|
|
217
|
+
"2019" = 7194
|
|
218
|
+
"2020" = 28949
|
|
219
|
+
"2021" = 46306
|
|
220
|
+
"2022" = 16547
|
|
221
|
+
"2023" = 42258
|
|
222
|
+
"2024" = 93429
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
</script>
|
|
226
|
+
|
|
227
|
+
<script type="module">
|
|
228
|
+
import { initBlueprint } from '@blueprint-chart/lib/dist/runtime'
|
|
229
|
+
initBlueprint()
|
|
230
|
+
</script>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
::: info BPC source from `packages/lib/src/samples/bitcoin-price.bpc`
|
|
234
|
+
The IIFE bundle (`@blueprint-chart/lib/dist/lib/lib.iife.js`) calls `initBlueprint()` for you on `DOMContentLoaded`. Import the module form when you want to control timing or re-initialize after DOM updates.
|
|
235
|
+
:::
|
|
236
|
+
|
|
237
|
+
## Versioning
|
|
238
|
+
|
|
239
|
+
The lib follows semver:
|
|
240
|
+
|
|
241
|
+
- **Patch** — bug fixes, internal refactors, doc updates.
|
|
242
|
+
- **Minor** — additive API surface, backward-compatible grammar growth.
|
|
243
|
+
- **Major** — breaking changes (rare). The DSL grammar version tracks `MAJOR.MINOR` of the lib.
|
|
244
|
+
|
|
245
|
+
See [`RELEASING.md`](https://github.com/blueprint-chart/blueprint-chart/blob/main/RELEASING.md) for the release process.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# DSL — Color directives & annotations
|
|
2
|
+
|
|
3
|
+
Two families of named blocks that target specific data values to draw the eye: **color directives** (`colorize`, `highlight`, `areafill`) recolor or emphasize parts of the chart, and **annotations** (`annotation`, `range`, `note`) attach text and shapes to data points, ranges, or absolute positions. Both share the same "named block with a body" shape, and `highlight` is the verb scenes use to switch emphasis — see [Scenes & transforms](/reference/dsl/scenes-and-transforms).
|
|
4
|
+
|
|
5
|
+
## Color directives
|
|
6
|
+
|
|
7
|
+
| Directive | Purpose |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| `colorize "<target>" { … }` | Apply a color rule to a target (axis label, value label, etc.). |
|
|
10
|
+
| `highlight "<target>" { … }` or `highlight "<target>"` | Emphasize a data point or series. The short form has no body. |
|
|
11
|
+
| `areafill "<from>" "<to>" { … }` | Fill the area between two series with a color (line / area charts). |
|
|
12
|
+
|
|
13
|
+
### `colorize`
|
|
14
|
+
|
|
15
|
+
```bpc
|
|
16
|
+
chart bar-vertical {
|
|
17
|
+
title = "E is the most frequent letter in English"
|
|
18
|
+
colorPalette = "London"
|
|
19
|
+
sort = descending
|
|
20
|
+
|
|
21
|
+
colorize "E" {
|
|
22
|
+
color = "#e15759"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
data {
|
|
26
|
+
"E" = 12.70
|
|
27
|
+
"T" = 9.06
|
|
28
|
+
"A" = 8.17
|
|
29
|
+
"O" = 7.51
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
::: info From `packages/lib/src/samples/letter-frequency.bpc`
|
|
35
|
+
`colorize` paints a single category (`"E"`) in a contrasting color over the base palette, drawing the eye to the chart's lede.
|
|
36
|
+
:::
|
|
37
|
+
|
|
38
|
+
### `highlight`
|
|
39
|
+
|
|
40
|
+
The short form `highlight "<name>"` (no body) is the common case — useful inside `scene` blocks for emphasising one series at a time:
|
|
41
|
+
|
|
42
|
+
```bpc
|
|
43
|
+
scene "China spotlight" {
|
|
44
|
+
title = "China emits more than the US and India combined"
|
|
45
|
+
|
|
46
|
+
highlight "China"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
scene "India rising" {
|
|
50
|
+
title = "India surpassed the EU in 2023"
|
|
51
|
+
|
|
52
|
+
highlight "India"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
scene "Japan declining" {
|
|
56
|
+
title = "Japan's emissions fell 20% from their peak"
|
|
57
|
+
|
|
58
|
+
highlight "Japan"
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
::: info From `packages/lib/src/samples/co2-emissions-story.bpc`
|
|
63
|
+
Three scenes share the same data and successively highlight one country each — the canonical "guided tour" pattern.
|
|
64
|
+
:::
|
|
65
|
+
|
|
66
|
+
### `areafill`
|
|
67
|
+
|
|
68
|
+
```bpc
|
|
69
|
+
areafill "Lower bound" "Upper bound" {
|
|
70
|
+
color = "#94a3b8"
|
|
71
|
+
opacity = 0.2
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
::: tip
|
|
76
|
+
No bundled sample currently uses `areafill`. The grammar is documented and parser-tested; the example above is illustrative.
|
|
77
|
+
:::
|
|
78
|
+
|
|
79
|
+
## Annotations
|
|
80
|
+
|
|
81
|
+
Three kinds of annotation, sharing a body of properties (`text`, `dx`, `dy`, `showArrow`, …):
|
|
82
|
+
|
|
83
|
+
### Point annotation — anchored to a data key
|
|
84
|
+
|
|
85
|
+
```bpc
|
|
86
|
+
annotation "2021" {
|
|
87
|
+
text = "All-time high cycle"
|
|
88
|
+
dy = -12
|
|
89
|
+
showArrow = true
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
::: info From `packages/lib/src/samples/bitcoin-price.bpc`
|
|
94
|
+
A minimal point annotation: the key matches a data label, `dy` nudges the text up, and an arrow draws back to the point.
|
|
95
|
+
:::
|
|
96
|
+
|
|
97
|
+
A richer point annotation with a connector line and curved leader:
|
|
98
|
+
|
|
99
|
+
```bpc
|
|
100
|
+
annotation "2015" {
|
|
101
|
+
id = "2o3cx"
|
|
102
|
+
text = "2015 Paris Agreement to limit global warming to 1.5°C "
|
|
103
|
+
maxWidth = 224
|
|
104
|
+
showLine = true
|
|
105
|
+
lineStyle = curve-right
|
|
106
|
+
showArrow = true
|
|
107
|
+
showCircle = true
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
::: info From `packages/lib/src/samples/temperature-anomaly.bpc`
|
|
112
|
+
Demonstrates `showLine` + `lineStyle = curve-right` for a labelled callout that arcs from the data point to the text block, plus `maxWidth` for wrapping.
|
|
113
|
+
:::
|
|
114
|
+
|
|
115
|
+
### Range and free annotations
|
|
116
|
+
|
|
117
|
+
```bpc
|
|
118
|
+
range { # range: spans a domain/value window
|
|
119
|
+
fromX = "2020"
|
|
120
|
+
toX = "2022"
|
|
121
|
+
text = "Pandemic rally"
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
note { # free: absolutely positioned
|
|
125
|
+
text = "Methodology footnote"
|
|
126
|
+
x = "10%"
|
|
127
|
+
y = "90%"
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
::: tip
|
|
132
|
+
The bundled samples do not currently exercise `range` or `note` annotations — these are illustrative. The grammar is parser-tested and the AST node types (`RangeAnnotationNode`, `FreeAnnotationNode`) are exported.
|
|
133
|
+
:::
|
|
134
|
+
|
|
135
|
+
The full property surface for each annotation kind is documented in the `AnnotationConfig` / `PointAnnotationConfig` / `RangeAnnotationConfig` / `FreeAnnotationConfig` types exported by `@blueprint-chart/lib`.
|