@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,137 @@
|
|
|
1
|
+
# BPC DSL — Language Specification
|
|
2
|
+
|
|
3
|
+
The Blueprint Chart format (`.bpc`) is a declarative text DSL for describing a chart and its scenes. It is parsed by a PEG grammar (Peggy) into an AST and converted at runtime into `ChartData` + `ChartOptions`.
|
|
4
|
+
|
|
5
|
+
The canonical grammar lives in [`packages/lib/src/dsl/grammar.peggy`](https://github.com/blueprint-chart/blueprint-chart/blob/main/packages/lib/src/dsl/grammar.peggy). This page is the human-readable specification.
|
|
6
|
+
|
|
7
|
+
::: tip Stability
|
|
8
|
+
The DSL is **round-trip safe**: `parse(source)` → `serialize(ast)` → `parse(...)` produces an equivalent AST. Backward-compatible grammar changes ship as minor releases; breaking changes will require a major bump.
|
|
9
|
+
:::
|
|
10
|
+
|
|
11
|
+
## A minimal example
|
|
12
|
+
|
|
13
|
+
```bpc
|
|
14
|
+
chart line {
|
|
15
|
+
title = "Bitcoin surged past $90,000 in 2024"
|
|
16
|
+
description = "USD, year-end closing price"
|
|
17
|
+
source = "CoinGecko"
|
|
18
|
+
sourceUrl = "https://www.coingecko.com"
|
|
19
|
+
colors = "#f7931a"
|
|
20
|
+
lineSymbols = true
|
|
21
|
+
lineSymbolShowOn = "all"
|
|
22
|
+
lineSymbolShape = "diamond"
|
|
23
|
+
verticalNumberFormat = ",.0f"
|
|
24
|
+
tooltips = true
|
|
25
|
+
|
|
26
|
+
annotation "2021" {
|
|
27
|
+
text = "All-time high cycle"
|
|
28
|
+
dy = -12
|
|
29
|
+
showArrow = true
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
data {
|
|
33
|
+
"2016" = 963
|
|
34
|
+
"2017" = 13880
|
|
35
|
+
"2018" = 3742
|
|
36
|
+
"2019" = 7194
|
|
37
|
+
"2020" = 28949
|
|
38
|
+
"2021" = 46306
|
|
39
|
+
"2022" = 16547
|
|
40
|
+
"2023" = 42258
|
|
41
|
+
"2024" = 93429
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
::: info From `packages/lib/src/samples/bitcoin-price.bpc`
|
|
47
|
+
A single-series line chart with a brand color, custom symbol shape, vertical-axis number format, and one point annotation — every feature appears in the same ~30-line block.
|
|
48
|
+
:::
|
|
49
|
+
|
|
50
|
+
## Top-level structure
|
|
51
|
+
|
|
52
|
+
A BPC document is exactly one `chart` block:
|
|
53
|
+
|
|
54
|
+
```bpc
|
|
55
|
+
chart <chartType> {
|
|
56
|
+
<properties>
|
|
57
|
+
<data block>
|
|
58
|
+
<series>
|
|
59
|
+
<colorize / highlight / areafill / annotation / range / note>
|
|
60
|
+
<scenes>
|
|
61
|
+
<transforms>
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Where `<chartType>` is one of the registered chart-type identifiers (`line`, `bar-vertical`, `bar-horizontal`, `bar-grouped`, `bar-stacked`, `bar-multi`, `bar-split`, `column-stacked`, `area`, `area-stacked`, `line-multi`, `pie`, `donut`). The authoritative list is exported as `ChartType` from [`@blueprint-chart/lib`](/reference/api/).
|
|
66
|
+
|
|
67
|
+
## Lexical grammar
|
|
68
|
+
|
|
69
|
+
### Identifiers
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
Identifier ← [a-zA-Z_#] [a-zA-Z0-9_#-]*
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Used for chart-type names, property keys, and transform names.
|
|
76
|
+
|
|
77
|
+
### Strings
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
String ← '"' StringChar* '"'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Strings are double-quoted. Supported escapes: `\\`, `\"`, `\n`, `\t`, `\r`.
|
|
84
|
+
|
|
85
|
+
### Numbers
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
Number ← '-'? Digit+ ('.' Digit+)?
|
|
89
|
+
Percent ← Number '%'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
A trailing `%` marks the value as a percentage; the parser preserves `isPercentage: true` on the AST node so downstream code can distinguish `25` from `25%`.
|
|
93
|
+
|
|
94
|
+
### Comments
|
|
95
|
+
|
|
96
|
+
Line comments start with `//` and run to end-of-line. There are no block comments.
|
|
97
|
+
|
|
98
|
+
## Working with the AST
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { parse, serialize, compactSerialize } from '@blueprint-chart/lib'
|
|
102
|
+
|
|
103
|
+
const ast = parse(source) // BPC text → AST
|
|
104
|
+
const text = serialize(ast) // AST → BPC text (pretty)
|
|
105
|
+
const tight = compactSerialize(ast) // AST → BPC text (compact)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Round-trip identity is guaranteed for any value the grammar accepts — `parse(serialize(parse(x)))` is structurally equal to `parse(x)`. This invariant is enforced by the test suite.
|
|
109
|
+
|
|
110
|
+
## Stability and versioning
|
|
111
|
+
|
|
112
|
+
- `parse` errors throw `SyntaxError` with a 1-indexed `location` (line / column) for tooling.
|
|
113
|
+
- Unknown property keys are preserved on the AST; renderers may ignore them.
|
|
114
|
+
- Unknown top-level statements are a parse error — by design.
|
|
115
|
+
- The grammar version tracks the lib's `MAJOR.MINOR`; patch releases never change the language.
|
|
116
|
+
|
|
117
|
+
## See it in action
|
|
118
|
+
|
|
119
|
+
Every snippet across these DSL pages is taken verbatim from a runnable sample in `packages/lib/src/samples/`. The corresponding chart-type pages document the option surface and render live previews:
|
|
120
|
+
|
|
121
|
+
| Feature shown | Sample file | Chart-type page |
|
|
122
|
+
| --- | --- | --- |
|
|
123
|
+
| Minimal example, point annotation | `bitcoin-price.bpc` | [Line chart](/charts/line) |
|
|
124
|
+
| Multi-series data, `_series` row | `medal-count.bpc` | [Bar multi](/charts/bar-multi) |
|
|
125
|
+
| `colorize` single category | `letter-frequency.bpc` | [Bar vertical](/charts/bar-vertical) |
|
|
126
|
+
| Curved-leader annotation | `temperature-anomaly.bpc` | [Line chart](/charts/line) |
|
|
127
|
+
| Scene-by-scene `highlight` tour | `co2-emissions-story.bpc` | [Bar horizontal](/charts/bar-horizontal) |
|
|
128
|
+
| Scenes overriding chart `type` | `farm-compass.bpc` | [Area stacked](/charts/area-stacked) |
|
|
129
|
+
| `transform sort` | `coffee-production.bpc` | [Bar vertical](/charts/bar-vertical) |
|
|
130
|
+
|
|
131
|
+
## Next steps
|
|
132
|
+
|
|
133
|
+
The rest of the DSL specification is split across three chapter pages:
|
|
134
|
+
|
|
135
|
+
- [Properties & data](/reference/dsl/properties) — value-bearing constructs.
|
|
136
|
+
- [Color directives & annotations](/reference/dsl/annotations) — `colorize`, `highlight`, `areafill`, and the three annotation kinds.
|
|
137
|
+
- [Scenes & transforms](/reference/dsl/scenes-and-transforms) — story-level constructs and data-pipeline operations.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# DSL — Properties & data
|
|
2
|
+
|
|
3
|
+
Value-bearing constructs in a `.bpc` document: key/value properties on the chart, the `data` block carrying values, and `series` overrides for per-series visual control. See [DSL overview](/reference/dsl/) for the top-level chart-block structure.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
Properties are simple key/value pairs:
|
|
8
|
+
|
|
9
|
+
```bpc
|
|
10
|
+
title = "Chrome dominates the desktop browser market"
|
|
11
|
+
displayAsPercentage = true
|
|
12
|
+
tooltips = true
|
|
13
|
+
lineSymbolShape = "diamond"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
| Value kind | Example | Notes |
|
|
17
|
+
| --- | --- | --- |
|
|
18
|
+
| String | `"Chrome"` | Double-quoted. |
|
|
19
|
+
| Number | `42`, `3.14`, `-1.2` | Optional minus, optional decimal part. |
|
|
20
|
+
| Percentage | `35%` | Number suffixed with `%`. |
|
|
21
|
+
| Identifier | `true`, `false`, `right` | Used for enum-valued properties. |
|
|
22
|
+
|
|
23
|
+
Property keys may be identifiers (`title`) or strings (`"data-attribute"`).
|
|
24
|
+
|
|
25
|
+
The full set of recognized property keys per chart type is defined by `ChartTypeOptions` in `@blueprint-chart/lib` and listed in the [API reference](/reference/api/).
|
|
26
|
+
|
|
27
|
+
## Data block
|
|
28
|
+
|
|
29
|
+
The `data` block carries the chart's primary values.
|
|
30
|
+
|
|
31
|
+
```bpc
|
|
32
|
+
data {
|
|
33
|
+
"2022" = 16547
|
|
34
|
+
"2023" = 42258
|
|
35
|
+
"2024" = 93429
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
For multi-series data, comma-separated values map positionally to series. A leading `_series = "A","B",…` row labels each column:
|
|
40
|
+
|
|
41
|
+
```bpc
|
|
42
|
+
data {
|
|
43
|
+
_series = "Gold","Silver","Bronze"
|
|
44
|
+
"USA" = 40,44,42
|
|
45
|
+
"China" = 38,32,18
|
|
46
|
+
"Japan" = 27,14,17
|
|
47
|
+
"Great Britain" = 22,21,22
|
|
48
|
+
"Australia" = 17,7,22
|
|
49
|
+
"France" = 16,20,23
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
::: info From `packages/lib/src/samples/medal-count.bpc`
|
|
54
|
+
A `bar-multi` chart driven by three positional columns. The `_series` row supplies legend labels; each subsequent row's comma-separated values map to those columns in order.
|
|
55
|
+
:::
|
|
56
|
+
|
|
57
|
+
A **tabular** form is also accepted — keys and values separated by a literal tab character — for pasting CSV-like input:
|
|
58
|
+
|
|
59
|
+
```bpc
|
|
60
|
+
data {
|
|
61
|
+
"Jan" 16547
|
|
62
|
+
"Feb" 17203
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Series
|
|
67
|
+
|
|
68
|
+
`series` blocks define per-series overrides — name, color, interpolation, visibility, etc.
|
|
69
|
+
|
|
70
|
+
```bpc
|
|
71
|
+
series "Renewables" {
|
|
72
|
+
color = "#2ca02c"
|
|
73
|
+
interpolation = "monotone"
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
::: tip
|
|
78
|
+
None of the bundled `packages/lib/src/samples/*.bpc` files currently exercise top-level `series` overrides — the samples lean on `_series` legends inside `data` plus `colors`, `colorPalette`, and `colorize` directives. The example above is illustrative; the grammar is exercised by parser tests.
|
|
79
|
+
:::
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# DSL — Scenes & transforms
|
|
2
|
+
|
|
3
|
+
Story-level constructs: **scenes** compose multiple visualisation states into a stepable narrative, and **transforms** describe data-pipeline operations applied before rendering. Scenes can override almost any chart member — including chart `type` and `data` — and add their own annotation-visibility verbs.
|
|
4
|
+
|
|
5
|
+
## Scenes
|
|
6
|
+
|
|
7
|
+
A **scene** is a named visualisation state — the same chart with different data, styling, or annotations. Multiple scenes compose into a **story** that users can step through.
|
|
8
|
+
|
|
9
|
+
A simple "highlight tour" — each scene swaps the title and emphasises one bar:
|
|
10
|
+
|
|
11
|
+
```bpc
|
|
12
|
+
scene "China spotlight" {
|
|
13
|
+
title = "China emits more than the US and India combined"
|
|
14
|
+
|
|
15
|
+
highlight "China"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
scene "India rising" {
|
|
19
|
+
title = "India surpassed the EU in 2023"
|
|
20
|
+
|
|
21
|
+
highlight "India"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
scene "Japan declining" {
|
|
25
|
+
title = "Japan's emissions fell 20% from their peak"
|
|
26
|
+
|
|
27
|
+
highlight "Japan"
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
::: info From `packages/lib/src/samples/co2-emissions-story.bpc`
|
|
32
|
+
Three scenes on a `bar-horizontal` chart. Each scene inherits the chart's data and styling, and only overrides what changes — `title` plus a `highlight` target.
|
|
33
|
+
:::
|
|
34
|
+
|
|
35
|
+
Scenes can also override the chart's **type** and **data** wholesale, switching from one visualisation to another mid-story:
|
|
36
|
+
|
|
37
|
+
```bpc
|
|
38
|
+
scene "Bulgarian farms grew" {
|
|
39
|
+
title = "Average farm size in Bulgaria quadrupled"
|
|
40
|
+
description = "Average farm size in hectares"
|
|
41
|
+
type = line
|
|
42
|
+
|
|
43
|
+
data {
|
|
44
|
+
"2005" = 5
|
|
45
|
+
"2007" = 6
|
|
46
|
+
"2010" = 12
|
|
47
|
+
"2013" = 18
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
scene "Cash crops replaced vegetables" {
|
|
52
|
+
title = "Cash crops replaced vegetables in Bulgaria"
|
|
53
|
+
description = "Production of Bulgarian farms, million euros"
|
|
54
|
+
type = area-stacked
|
|
55
|
+
|
|
56
|
+
data {
|
|
57
|
+
_series = "Vegetables","Cash crops","Other production"
|
|
58
|
+
"2000" = 464,615,1854
|
|
59
|
+
"2008" = 541,2045,1563
|
|
60
|
+
"2015" = 144,2986,785
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
highlight "Cash crops"
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
::: info From `packages/lib/src/samples/farm-compass.bpc`
|
|
68
|
+
A "story" can transition between chart types — here from a stacked area to a single-series line, then to a different stacked area — by setting `type` and supplying fresh `data` inside the scene.
|
|
69
|
+
:::
|
|
70
|
+
|
|
71
|
+
Scenes accept the same member set as the top-level chart, **plus** annotation-visibility verbs:
|
|
72
|
+
|
|
73
|
+
| Verb | Effect |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `hide_annotation "<id>"` | Hide a point annotation set on the chart. |
|
|
76
|
+
| `hide_range "<id>"` | Hide a range annotation. |
|
|
77
|
+
| `hide_note "<id>"` | Hide a free / note annotation. |
|
|
78
|
+
| `show_annotation "<id>"` / `show_range "<id>"` / `show_note "<id>"` | Re-show one previously hidden by an earlier scene. |
|
|
79
|
+
|
|
80
|
+
`step` is accepted as an alias for `scene`.
|
|
81
|
+
|
|
82
|
+
## Transforms
|
|
83
|
+
|
|
84
|
+
Transforms describe data-pipeline operations applied before rendering.
|
|
85
|
+
|
|
86
|
+
```bpc
|
|
87
|
+
transform sort {
|
|
88
|
+
column = "value"
|
|
89
|
+
direction = descending
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
::: info From `packages/lib/src/samples/coffee-production.bpc`
|
|
94
|
+
A `sort` transform reorders the data by the `value` column in descending order. The chart's `sort = descending` property is equivalent for simple cases; the `transform` form composes with other pipeline steps.
|
|
95
|
+
:::
|
|
96
|
+
|
|
97
|
+
Transforms compose — each `transform <name> { … }` block is applied in source order. The grammar accepts any identifier in the `<name>` slot; the set of registered transform types is part of `@blueprint-chart/lib`'s public surface; see the API reference.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Reference
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Reference
|
|
6
|
+
|
|
7
|
+
Blueprint Chart's reference material covers the same model from two angles:
|
|
8
|
+
|
|
9
|
+
- **[BPC DSL](/reference/dsl/)** — the `.bpc` text format. Source-level grammar, properties, annotations, scenes, transforms.
|
|
10
|
+
- **[API](/reference/api/)** — the TypeScript surface of `@blueprint-chart/lib`. Every exported symbol — types, enums, helpers, rendering primitives, the chart-type registry, and the DSL parse/serialize bridge.
|
|
11
|
+
|
|
12
|
+
The two views are bridged by `parse` / `serialize` (`.bpc` text ⇆ AST) and by the `ChartType` enum (the list of valid chart-type identifiers is exported from the lib).
|
|
13
|
+
|
|
14
|
+
## When to read which
|
|
15
|
+
|
|
16
|
+
- Authoring `.bpc` files (by hand or in the editor): start with the [DSL overview](/reference/dsl/).
|
|
17
|
+
- Embedding Blueprint Chart in a TS/JS project, consuming the AST, or building custom renderers: start with the [API reference](/reference/api/).
|
|
18
|
+
- Both: read in either order — they share examples (the `bitcoin-price` sample appears in both).
|