chart-factory 0.1.2
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 +162 -0
- package/dist/chart-factory-table.js +1400 -0
- package/dist/chart-factory.css +2368 -0
- package/dist/chart-factory.js +11398 -0
- package/dist/chart-factory.min.js +7 -0
- package/docs/API.md +1815 -0
- package/docs/chart-guide.md +872 -0
- package/docs/color-guide.md +134 -0
- package/docs/conformance-matrix.md +864 -0
- package/docs/theming.md +107 -0
- package/index.d.ts +10453 -0
- package/package.json +83 -0
- package/src/core/base.css +508 -0
- package/src/core/builder-metadata.generated.mjs +406 -0
- package/src/core/d3-base.js +249 -0
- package/src/core/d3-chart-factory.js +18547 -0
- package/src/core/d3-data.js +0 -0
- package/src/core/d3-suggest.js +565 -0
- package/src/core/example-nav.css +62 -0
- package/src/core/example-nav.js +249 -0
- package/src/core/palettes.js +310 -0
- package/src/core/theme-toggle.js +126 -0
- package/src/core/tokens.css +792 -0
- package/src/table/d3-table.js +1570 -0
- package/src/table/table.css +899 -0
- package/src/table/tokens.css +157 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jacob Olsufka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# chart-factory
|
|
2
|
+
|
|
3
|
+
A token-driven, responsive chart library built on [D3 v7](https://d3js.org/). One factory, **79 builders across 12 families** — area, line, slope, bar, scatter, dot, histogram, donut/pie, box plot, calendar heatmap, and sankey charts plus sortable tables — that **fill whatever container you put them in** and re-render crisply on resize.
|
|
4
|
+
|
|
5
|
+
- **Responsive by default** — charts measure their container, render at true pixel size, and adapt density (font size, tick count, dot radius) to the available width. No config needed.
|
|
6
|
+
- **Design tokens** — all styling flows through 300+ CSS custom properties in `tokens.css`; retheme everything by overriding variables.
|
|
7
|
+
- **No build required to consume** — plain ES modules plus a prebuilt browser bundle, TypeScript definitions included.
|
|
8
|
+
- **Date-aware axes** — pass `Date` objects (or ISO strings) as x values and trend charts switch to time scales with adaptive tick formatting automatically.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install chart-factory d3
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`d3` (v7) is a peer dependency — install it alongside. React apps also want
|
|
17
|
+
the adapter: `npm install chart-factory-react`.
|
|
18
|
+
|
|
19
|
+
<details><summary>Other install sources</summary>
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install ../chart-factory # sibling checkout (local development)
|
|
23
|
+
npm install github:jolsufka/chart-factory # straight from git
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
</details>
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### With a bundler (ESM)
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { ChartFactory } from 'chart-factory';
|
|
34
|
+
import 'chart-factory/styles.css'; // everything (tokens + base + table), or import the pieces:
|
|
35
|
+
// import 'chart-factory/core/tokens.css';
|
|
36
|
+
// import 'chart-factory/core/base.css';
|
|
37
|
+
|
|
38
|
+
ChartFactory.Line.createBasic('#chart', {
|
|
39
|
+
data,
|
|
40
|
+
xAccessor: d => d.week,
|
|
41
|
+
yAccessor: d => d.points
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Script tag (no build)
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<link rel="stylesheet" href="node_modules/chart-factory/dist/chart-factory.css">
|
|
49
|
+
<script src="https://d3js.org/d3.v7.min.js"></script>
|
|
50
|
+
<script src="node_modules/chart-factory/dist/chart-factory.js"></script>
|
|
51
|
+
<script>
|
|
52
|
+
ChartFactory.Bar.createBasic('#chart', { data, categoryAccessor: d => d.name, valueAccessor: d => d.value });
|
|
53
|
+
</script>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The dist bundle uses the page's global `d3`, so load d3 first. Plugins that attach to the global (e.g. `d3-hexbin`, used by `Scatter.createHexbin`) keep working.
|
|
57
|
+
|
|
58
|
+
### Responsive behavior
|
|
59
|
+
|
|
60
|
+
Charts fill their container's width; height comes from a per-family aspect ratio (`aspectRatio` config to override, `height: <number>` for a fixed height). The container must be block-level with a real width:
|
|
61
|
+
|
|
62
|
+
```css
|
|
63
|
+
.chart-container { display: block; width: 100%; max-width: 660px; }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Horizontal bar/dot charts and gantt derive height from row count (width-responsive only). Pass `width: <number>` or `responsive: false` to opt out into fixed-size rendering. `size: 'mini' | 'full' | 'wide'` pins the density tier that is otherwise auto-selected from measured width (≤340px → mini, ≤620px → full, else wide). A fourth tier, `size: 'instagram'`, is opt-in only (never auto-selected): poster-scale geometry for 1080px social-feed exports, paired with `<html data-size="instagram">` to scale the text/stroke tokens to match — see docs/API.md.
|
|
67
|
+
|
|
68
|
+
Every chart returns a facade: `chart.setConfig({...})` merges config and re-renders (state survives resizes), `chart.rerender()`, `chart.destroy()`.
|
|
69
|
+
|
|
70
|
+
### Tables
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import { ChartFactory } from 'chart-factory';
|
|
74
|
+
import { D3Table } from 'chart-factory/table';
|
|
75
|
+
import 'chart-factory/table/tokens.css';
|
|
76
|
+
import 'chart-factory/table/table.css';
|
|
77
|
+
|
|
78
|
+
ChartFactory.Table.register(D3Table); // one-time
|
|
79
|
+
ChartFactory.Table.createSortable('my-table', { columns: [...] }).render(data);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
In the browser without a bundler, import `dist/chart-factory-table.js` from a `<script type="module">` (d3 already on the page).
|
|
83
|
+
|
|
84
|
+
### Dark mode
|
|
85
|
+
|
|
86
|
+
Opt in by setting `data-theme="dark"` on the root element:
|
|
87
|
+
|
|
88
|
+
```html
|
|
89
|
+
<html data-theme="dark">
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Every color-bearing token (text, surfaces, chart palettes, table heatmap/bar
|
|
93
|
+
ramps) has a dark value in `core/tokens.css`; spacing and sizing carry over.
|
|
94
|
+
Charts read tokens **live at render time**, so switching themes at runtime
|
|
95
|
+
needs a re-render — SVG attribute colors are baked in at draw:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
document.documentElement.dataset.theme = 'dark'; // or delete it for light
|
|
99
|
+
ChartFactory.rerenderAll(); // re-resolves every live chart and table
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
(`rerenderAll()` tracks all charts and factory-created tables; individual
|
|
103
|
+
handles work too: `chart.rerender()`, `table.rerender()`.)
|
|
104
|
+
|
|
105
|
+
CSS-styled surfaces (containers, tooltip shell, table chrome) restyle
|
|
106
|
+
immediately without a re-render. There is no automatic
|
|
107
|
+
`prefers-color-scheme` switching — wire the attribute (and the re-render
|
|
108
|
+
calls) to your app's theme state; in React/Next.js, `next-themes` with
|
|
109
|
+
`attribute="data-theme"` pairs naturally.
|
|
110
|
+
|
|
111
|
+
### Chart states
|
|
112
|
+
|
|
113
|
+
Dashboards hit three awkward moments; the chart owns all of them:
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
const chart = ChartFactory.Line.createBasic('#c', { state: 'loading' }); // skeleton now
|
|
117
|
+
fetch('/api/rows').then(r => r.json())
|
|
118
|
+
.then(rows => chart.setData(rows)) // real chart (setData ends 'loading')
|
|
119
|
+
.catch(() => chart.setConfig({ state: 'error' }));
|
|
120
|
+
// rows.length === 0 → the built-in empty state renders automatically
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The loading skeleton is family-aware (trend silhouette for line/area,
|
|
124
|
+
breathing columns/rows for bars, quiet dots elsewhere) and takes the chart's
|
|
125
|
+
exact footprint, so the real chart swaps in with zero layout jump.
|
|
126
|
+
`emptyMessage` / `errorMessage` override the state text.
|
|
127
|
+
Live demo (all three states + a fetch simulator):
|
|
128
|
+
[`examples/states-demo.html`](examples/states-demo.html).
|
|
129
|
+
|
|
130
|
+
## Chart catalog
|
|
131
|
+
|
|
132
|
+
| Factory | Variants |
|
|
133
|
+
|---|---|
|
|
134
|
+
| `ChartFactory.Area` | basic, stacked, normalized, smoothed, streamgraph, diverging |
|
|
135
|
+
| `ChartFactory.Line` | basic, multi, yearly, smoothed, combined, YoY, textures, area-gradient, growth-rate, forecast-band, dynamic-band, pulse-anomalies, cumulative-vs-moving, bump |
|
|
136
|
+
| `ChartFactory.Slope` | basic, trend, categorical, highlight, animated, bands, indexed |
|
|
137
|
+
| `ChartFactory.Bar` | basic, inline, label-above, progress, bullet, diverging, stacked, grouped, likert, gantt, range, waterfall, pyramid, vertical, vertical-stacked, vertical-normalized |
|
|
138
|
+
| `ChartFactory.Scatter` | basic, logos, animated, trajectory, comet, beeswarm (×4), heatmap, hexbin, contour, quadrant, diagonal, marginal (×3), KDE |
|
|
139
|
+
| `ChartFactory.Dot` | basic, dumbbell, gradient, comet, confidence, percentile, unit-histogram |
|
|
140
|
+
| `ChartFactory.Histogram` | basic, overlay |
|
|
141
|
+
| `ChartFactory.Donut` | basic (donut; `innerRatio: 0` = pie) |
|
|
142
|
+
| `ChartFactory.BoxPlot` | basic (both orientations, raw or precomputed) |
|
|
143
|
+
| `ChartFactory.Calendar` | heatmap (weekly / monthRows / vertical layouts) |
|
|
144
|
+
| `ChartFactory.Sankey` | basic (d3-sankey optional, built-in fallback) |
|
|
145
|
+
| `ChartFactory.Table` | basic, sortable, with-bars, with-heatmap, combined |
|
|
146
|
+
|
|
147
|
+
Live examples for every variant are in [`examples/`](examples/) — serve the repo root (`npm run serve`) and open `http://localhost:8000/examples/`.
|
|
148
|
+
|
|
149
|
+
## Development
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npm install # installs esbuild
|
|
153
|
+
npm run build # bundles src/ -> dist/ (also runs on npm prepare)
|
|
154
|
+
npm run watch # rebuild on change
|
|
155
|
+
npm run serve # static server for examples/
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Source lives in `src/` as plain ES modules; `dist/` holds the generated browser bundles. All styling values must flow through the design tokens in [`src/core/tokens.css`](src/core/tokens.css) — never hardcode colors, spacing, or font sizes.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
[MIT](LICENSE)
|