@blueprint-chart/docs 0.3.0 → 0.4.0

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.
@@ -126,6 +126,13 @@
126
126
  "blurb": "> 50+ curated categorical palettes, plus the helpers to resolve, audit, and adjust them for the background you render against.",
127
127
  "mdPath": "guide/palettes.md"
128
128
  },
129
+ {
130
+ "slug": "rendering",
131
+ "group": "guide",
132
+ "title": "rendering",
133
+ "blurb": "The `render()` function is the primary programmatic entry point for `@blueprint-chart/lib`. It accepts a BPC source string and returns a **chart handle** — an object with methods to produce SVG, PNG, ",
134
+ "mdPath": "guide/rendering.md"
135
+ },
129
136
  {
130
137
  "slug": "scenes",
131
138
  "group": "guide",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueprint-chart/docs",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Public documentation for Blueprint Chart — handbook, guide, BPC DSL spec, and lib API reference.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -49,8 +49,8 @@
49
49
  "vitepress": "^1.5.0",
50
50
  "vitest": "^3.2.4",
51
51
  "vue": "^3.5",
52
- "@blueprint-chart/lib": "0.3.0",
53
- "@blueprint-chart/ui": "0.3.0"
52
+ "@blueprint-chart/lib": "0.4.0",
53
+ "@blueprint-chart/ui": "0.4.0"
54
54
  },
55
55
  "scripts": {
56
56
  "dev": "vitepress dev src --host 0.0.0.0 --port 4445",
@@ -0,0 +1,56 @@
1
+ # Rendering in code
2
+
3
+ The `render()` function is the primary programmatic entry point for `@blueprint-chart/lib`. It accepts a BPC source string and returns a **chart handle** — an object with methods to produce SVG, PNG, or a live DOM mount.
4
+
5
+ ## Node — write SVG and PNG to disk
6
+
7
+ ```ts
8
+ import { render } from '@blueprint-chart/lib'
9
+ import { writeFile } from 'node:fs/promises'
10
+
11
+ const chart = await render(bpc)
12
+ await writeFile('chart.svg', await chart.toSvg())
13
+ await writeFile('chart.png', await chart.toPng({ width: 1200 }))
14
+ ```
15
+
16
+ PNG export and headless SVG in Node require optional native deps (`jsdom`, `@napi-rs/canvas`, `@resvg/resvg-js`). These are installed automatically as `optionalDependencies`. If a binary failed to install, the Node methods throw `MissingNodeRenderDepsError` naming what to reinstall.
17
+
18
+ ## Browser — mount and step scenes
19
+
20
+ ```ts
21
+ const { mount, scene } = await render(bpc)
22
+ mount('#chart') // element or selector
23
+ scene(2) // advance to scene index 2
24
+ ```
25
+
26
+ `mount` accepts an `HTMLElement` or a CSS selector string and returns the handle for chaining. `scene(n)` steps to scene index `n` and is also chainable.
27
+
28
+ ## Options
29
+
30
+ Pass a second argument to `render()` to control the output:
31
+
32
+ | Option | Default | Description |
33
+ | --- | --- | --- |
34
+ | `theme` | system | `'light'` or `'dark'` |
35
+ | `scene` | `0` | Initial scene index |
36
+ | `width` | `640` | Output width in px (headless only) |
37
+ | `height` | `400` | Output height in px (headless only) |
38
+ | `frame` | `true` | `false` renders frameless (no title/source/etc.) |
39
+
40
+ ```ts
41
+ const chart = await render(bpc, { theme: 'dark', width: 1200, height: 630 })
42
+ ```
43
+
44
+ ## The handle
45
+
46
+ `render()` resolves to a `ChartHandle`. Its methods are **bound** — destructure freely — and `mount`/`scene` are **chainable**.
47
+
48
+ | Method | Browser | Node | Returns |
49
+ | --- | --- | --- | --- |
50
+ | `toSvg(opts?)` | ✅ | ✅ | `Promise<string>` |
51
+ | `toHtml(opts?)` | ✅ | ✅ | `Promise<string>` |
52
+ | `toPng(opts?)` | ❌ throws `PngBrowserUnsupportedError` | ✅ | `Promise<Uint8Array>` |
53
+ | `mount(target)` | ✅ | no-op (warns) | `ChartHandle` |
54
+ | `scene(n)` | ✅ | ✅ | `ChartHandle` |
55
+
56
+ See the [API reference](/reference/api/) for the full surface of `@blueprint-chart/lib`, including low-level rendering primitives and the chart-type registry.
@@ -27,6 +27,18 @@ Truncating the y-axis on a bar or area chart visually exaggerates differences. T
27
27
  - Remove grid lines entirely when value labels are shown directly on data
28
28
  - Grid lines are reference aids, not primary content — they should never compete with data
29
29
 
30
+ ## Bar charts default to no value axis
31
+
32
+ Bar charts label each bar directly, so the value axis is redundant. Every bar
33
+ variant — vertical, horizontal, grouped, stacked, split — defaults to **no
34
+ value-axis line, no value ticks/numbers, and no value gridlines**. Only the zero
35
+ baseline and the category names remain.
36
+
37
+ When a segment is too small to hold its label legibly, the label is suppressed
38
+ and the value falls back to the tooltip. To restore a value axis, set
39
+ `showVerticalAxis` / `showHorizontalAxis`, `verticalGridStyle` /
40
+ `horizontalGridStyle`, or turn `valueLabels` off explicitly.
41
+
30
42
  ## Tick marks
31
43
 
32
44
  - Subtle or no ticks are preferred in modern chart design
@@ -63,6 +75,8 @@ A trend that looks alarming at 3:1 can look flat at 3:4. When showing rate of ch
63
75
 
64
76
  Blueprint Chart's `AxisOptions` exposes scale type (linear / log), tick count, tick format, and baseline behavior. D3 scales drive the tick layout, and a shared number formatter is used by the axis, tooltip, and direct labels so the same value is rendered identically wherever it appears.
65
77
 
78
+ Bar charts ship with the value axis suppressed by default — direct value labels replace it. The category axis always remains. See [Bar charts default to no value axis](#bar-charts-default-to-no-value-axis) above for the complete rule.
79
+
66
80
  See the [API reference](/reference/api/) for the public options that toggle grid lines, tick density, and baseline zero.
67
81
 
68
82
  ## Worked example: number format on the axis
@@ -71,9 +71,6 @@ chart bar-vertical {
71
71
  description = "Million 60-kg bags, 2023/24 crop year"
72
72
  source = "International Coffee Organization"
73
73
  colorPalette = "Harvey"
74
- valueLabels = true
75
- verticalGridStyle = "none"
76
- horizontalGridStyle = "none"
77
74
 
78
75
  data {
79
76
  "Brazil" = 66.4
@@ -96,7 +93,7 @@ chart bar-vertical {
96
93
  ```
97
94
 
98
95
  ::: info From `packages/lib/src/samples/coffee-production.bpc`
99
- Five bars stay in muted neutrals; the `colorize "Brazil"` block lifts the one bar the title is about. `valueLabels = true` removes the need for a y-axis altogether — direct labels carry the precise numbers, and gridlines drop out entirely. Restraint, purposefulness, and "start with grey" applied in a single chart.
96
+ Five bars stay in muted neutrals; the `colorize "Brazil"` block lifts the one bar the title is about. Direct labels carry the precise numbers by default, removing the need for a y-axis altogether, and gridlines drop out entirely. Restraint, purposefulness, and "start with grey" applied in a single chart.
100
97
  :::
101
98
 
102
99
  ## How Blueprint Chart applies these principles
@@ -36,8 +36,10 @@ Place labels directly on or adjacent to data elements instead of using a separat
36
36
 
37
37
  ## Value labels
38
38
 
39
- - Show value labels when precision matters to the reader
40
- - On bar charts: inside the bar (if wide enough) or at the end
39
+ For bar charts, value labels are **on by default** — they replace the value axis entirely, so each bar carries its number directly. The renderer uses an "auto: label if it fits" rule: when a bar or stack segment is too narrow to hold its label legibly, the label is suppressed and the value falls back to the tooltip instead. See [Axes & Grid Lines](/handbook/axes) for the no-value-axis default.
40
+
41
+ For other chart types:
42
+
41
43
  - On line charts: at key data points only, not every point
42
44
  - On pie / donut charts: outside for small slices, inside for large ones
43
45
  - Position labels to avoid overlap; use tooltips as a fallback for dense data
@@ -65,9 +67,6 @@ chart bar-vertical {
65
67
  title = "E is the most frequent letter in English"
66
68
  description = "How often each letter appears in typical English text"
67
69
  sort = descending
68
- valueLabels = true
69
- verticalLabelPosition = off
70
- verticalGridStyle = none
71
70
 
72
71
  data {
73
72
  "E" = 12.70
@@ -80,7 +79,7 @@ chart bar-vertical {
80
79
  ```
81
80
 
82
81
  ::: info From `packages/lib/src/samples/letter-frequency.bpc`
83
- `valueLabels = true` puts the precise number at the end of every bar, so the y-axis label position can be set to `off` and the gridlines removed entirely. Direct labelling replaces both the legend and the axis labels — a clean application of the data-ink rule.
82
+ Value labels appear at the end of every bar by default, so the y-axis label position can be set to `off` and the gridlines removed entirely. Direct labelling replaces both the legend and the axis labels — a clean application of the data-ink rule.
84
83
  :::
85
84
 
86
85
  ## Worked example: legend at the top, direct value labels at the bar end
@@ -91,9 +90,6 @@ chart bar-multi {
91
90
  description = "2024 Paris Summer Games — top six nations"
92
91
  colors = "#eeca3b, #c0c0c0, #cd7f32"
93
92
  legendPosition = "top"
94
- valueLabels = true
95
- verticalGridStyle = none
96
- verticalLabelPosition = off
97
93
  sort = descending
98
94
 
99
95
  data {
@@ -106,7 +102,7 @@ chart bar-multi {
106
102
  ```
107
103
 
108
104
  ::: info From `packages/lib/src/samples/medal-count.bpc`
109
- A multi-series bar chart needs a legend to map the three hues to Gold / Silver / Bronze — placed at the top so the eye reaches it before scanning the bars. Inside each bar, `valueLabels = true` prints the exact count, eliminating the need to read against a vertical scale.
105
+ A multi-series bar chart needs a legend to map the three hues to Gold / Silver / Bronze — placed at the top so the eye reaches it before scanning the bars. Inside each bar, value labels print the exact count by default, eliminating the need to read against a vertical scale.
110
106
  :::
111
107
 
112
108
  ## See also
@@ -68,7 +68,6 @@ chart bar-vertical {
68
68
  source = "Lewand, Cryptological Mathematics"
69
69
  note = "Based on analysis of 40,000 words from English prose"
70
70
  valueLabels = true
71
- verticalLabelPosition = off
72
71
  verticalGridStyle = none
73
72
 
74
73
  data {
@@ -6,6 +6,59 @@ Public surface of [`@blueprint-chart/lib`](https://www.npmjs.com/package/@bluepr
6
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
7
  :::
8
8
 
9
+ ## Rendering a chart
10
+
11
+ The fastest path: one function returns a chart **handle**.
12
+
13
+ ```ts
14
+ import { render } from '@blueprint-chart/lib'
15
+
16
+ const chart = await render(bpcSource, { theme: 'dark' })
17
+ ```
18
+
19
+ ### Node — write SVG and PNG to disk
20
+
21
+ ```ts
22
+ import { render } from '@blueprint-chart/lib'
23
+ import { writeFile } from 'node:fs/promises'
24
+
25
+ const chart = await render(bpc)
26
+ await writeFile('chart.svg', await chart.toSvg())
27
+ await writeFile('chart.png', await chart.toPng({ width: 1200 }))
28
+ ```
29
+
30
+ ### Browser — mount and step scenes
31
+
32
+ ```ts
33
+ const { mount, scene } = await render(bpc)
34
+ mount('#chart') // element or selector
35
+ scene(2) // advance to scene index 2
36
+ ```
37
+
38
+ ### The handle
39
+
40
+ `render(source, options?)` resolves to a `ChartHandle`. Its methods are **bound** — destructure them freely (`const { toSvg } = await render(bpc)`) — and `mount`/`scene` are **chainable** (`(await render(bpc)).scene(1).toSvg()`).
41
+
42
+ | Method | Browser | Node | Returns |
43
+ | --- | --- | --- | --- |
44
+ | `toSvg(opts?)` | ✅ | ✅ | `Promise<string>` |
45
+ | `toHtml(opts?)` | ✅ | ✅ | `Promise<string>` |
46
+ | `toPng(opts?)` | ❌ throws `PngBrowserUnsupportedError` | ✅ | `Promise<Uint8Array>` |
47
+ | `mount(target)` | ✅ | no-op (warns) | `ChartHandle` |
48
+ | `scene(n)` | ✅ | ✅ | `ChartHandle` |
49
+
50
+ `toHtml()` returns the `.bc-frame` outerHTML (the complete framed chart markup). When `frame: false` was passed to `render()`, it falls back to the bare chart SVG.
51
+
52
+ `RenderApiOptions`: `theme?`, `scene?` (initial scene), `width?`/`height?` (default `640×400`, used for headless output only), `frame?` (default `true`; `false` renders frameless). `OutputOptions` on `toSvg`/`toPng`: `width?`, `height?`.
53
+
54
+ ### Node dependencies
55
+
56
+ PNG export and headless SVG in Node require optional native deps (`jsdom`, `@napi-rs/canvas`, `@resvg/resvg-js`), installed automatically as `optionalDependencies`. If a binary failed to install, the Node methods throw `MissingNodeRenderDepsError` naming what to reinstall. Browser bundles never include these.
57
+
58
+ > SVG produced headlessly carries inline data colors and renders fonts via bundled DejaVu during PNG rasterization. It does not inline the full `charts.scss` theme; opening the bare `.svg` outside an app with that stylesheet may lack some structural styling.
59
+
60
+ ## Low-level surface
61
+
9
62
  ## Entrypoints
10
63
 
11
64
  | Entrypoint | Purpose |