@internetstiftelsen/charts 0.9.2 → 0.10.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.
- package/README.md +136 -2
- package/dist/bar.d.ts +3 -1
- package/dist/bar.js +167 -327
- package/dist/base-chart.d.ts +16 -1
- package/dist/base-chart.js +89 -30
- package/dist/chart-group.d.ts +121 -0
- package/dist/chart-group.js +1097 -0
- package/dist/chart-interface.d.ts +1 -1
- package/dist/donut-chart.js +1 -1
- package/dist/gauge-chart.js +1 -1
- package/dist/legend-state.d.ts +19 -0
- package/dist/legend-state.js +81 -0
- package/dist/legend.d.ts +5 -2
- package/dist/legend.js +35 -29
- package/dist/pie-chart.js +1 -1
- package/dist/scatter.d.ts +16 -0
- package/dist/scatter.js +163 -0
- package/dist/tooltip.d.ts +2 -1
- package/dist/tooltip.js +3 -3
- package/dist/types.d.ts +16 -0
- package/dist/validation.d.ts +4 -0
- package/dist/validation.js +19 -0
- package/dist/xy-chart.d.ts +16 -1
- package/dist/xy-chart.js +317 -102
- package/docs/chart-group.md +213 -0
- package/docs/components.md +308 -0
- package/docs/donut-chart.md +193 -0
- package/docs/gauge-chart.md +175 -0
- package/docs/getting-started.md +311 -0
- package/docs/pie-chart.md +123 -0
- package/docs/theming.md +162 -0
- package/docs/word-cloud-chart.md +98 -0
- package/docs/xy-chart.md +502 -0
- package/package.json +2 -1
package/docs/theming.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Theming
|
|
2
|
+
|
|
3
|
+
Customize the appearance of charts through the theme configuration.
|
|
4
|
+
|
|
5
|
+
Theme overrides are deep-partial. You can override nested fields like
|
|
6
|
+
`theme.axis.fontSize` or `theme.donut.centerContent.mainValue.color` without
|
|
7
|
+
redefining the rest of those nested objects.
|
|
8
|
+
|
|
9
|
+
## Theme Configuration
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
const chart = new XYChart({
|
|
13
|
+
data,
|
|
14
|
+
theme: {
|
|
15
|
+
margins: {
|
|
16
|
+
top: 30,
|
|
17
|
+
right: 30,
|
|
18
|
+
bottom: 40,
|
|
19
|
+
left: 60,
|
|
20
|
+
},
|
|
21
|
+
colorPalette: ['#ff6b6b', '#4ecdc4', '#45b7d1', '#f7b731'],
|
|
22
|
+
grid: {
|
|
23
|
+
color: '#e0e0e0',
|
|
24
|
+
opacity: 0.5,
|
|
25
|
+
},
|
|
26
|
+
axis: {
|
|
27
|
+
fontFamily: 'Inter, sans-serif',
|
|
28
|
+
fontSize: 12,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Built-in theme presets are exported from `@internetstiftelsen/charts/theme`:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import { defaultTheme, newspaperTheme, themes } from '@internetstiftelsen/charts/theme';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Theme Options
|
|
41
|
+
|
|
42
|
+
| Option | Type | Default | Description |
|
|
43
|
+
| --------------------- | ---------- | ---------------------------------------------- | -------------------------------------------- |
|
|
44
|
+
| `margins` | `object` | `{ top: 20, right: 20, bottom: 20, left: 20 }` | Base margins |
|
|
45
|
+
| `colorPalette` | `string[]` | - | Colors for auto-assignment |
|
|
46
|
+
| `grid.color` | `string` | `'#e0e0e0'` | Grid line color |
|
|
47
|
+
| `grid.opacity` | `number` | `0.5` | Grid line opacity |
|
|
48
|
+
| `fontFamily` | `string` | - | Base font family |
|
|
49
|
+
| `axis.fontFamily` | `string` | - | Axis text font |
|
|
50
|
+
| `axis.fontSize` | `number` | - | Axis text size in pixels |
|
|
51
|
+
| `legend.paddingX` | `number` | `0` | Horizontal legend layout padding |
|
|
52
|
+
| `legend.itemSpacingX` | `number` | `20` | Horizontal spacing between legend items |
|
|
53
|
+
| `legend.itemSpacingY` | `number` | `8` | Vertical spacing between wrapped legend rows |
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Color Palette
|
|
58
|
+
|
|
59
|
+
The color palette is used for automatic color assignment. Series without explicit colors get assigned colors from this palette based on their index.
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
theme: {
|
|
63
|
+
colorPalette: [
|
|
64
|
+
'#4ecdc4', // First series
|
|
65
|
+
'#ff6b6b', // Second series
|
|
66
|
+
'#45b7d1', // Third series
|
|
67
|
+
'#f7b731', // Fourth series
|
|
68
|
+
// ... continues cycling
|
|
69
|
+
],
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Manual Color Assignment
|
|
76
|
+
|
|
77
|
+
Override auto-colors by specifying colors directly on series:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
// Lines
|
|
81
|
+
chart.addChild(new Line({ dataKey: 'revenue', stroke: '#00ff00' }));
|
|
82
|
+
chart.addChild(new Line({ dataKey: 'expenses', stroke: '#ff0000' }));
|
|
83
|
+
|
|
84
|
+
// Bars
|
|
85
|
+
chart.addChild(new Bar({ dataKey: 'sales', fill: '#4ecdc4' }));
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For DonutChart, specify colors in the data:
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const data = [
|
|
92
|
+
{ name: 'Desktop', value: 450, color: '#4ecdc4' },
|
|
93
|
+
{ name: 'Mobile', value: 320, color: '#ff6b6b' },
|
|
94
|
+
{ name: 'Tablet', value: 130, color: '#45b7d1' },
|
|
95
|
+
];
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Donut Theme Defaults
|
|
101
|
+
|
|
102
|
+
DonutChart has additional theme defaults:
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
theme: {
|
|
106
|
+
donut: {
|
|
107
|
+
innerRadius: 0.5, // Inner radius ratio (0-1)
|
|
108
|
+
padAngle: 0.02, // Gap between segments
|
|
109
|
+
cornerRadius: 0, // Rounded corners
|
|
110
|
+
centerContent: {
|
|
111
|
+
mainValue: {
|
|
112
|
+
fontSize: 32,
|
|
113
|
+
fontWeight: 'bold',
|
|
114
|
+
color: '#1f2a36',
|
|
115
|
+
},
|
|
116
|
+
title: {
|
|
117
|
+
fontSize: 14,
|
|
118
|
+
fontWeight: 'normal',
|
|
119
|
+
color: '#6b7280',
|
|
120
|
+
},
|
|
121
|
+
subtitle: {
|
|
122
|
+
fontSize: 12,
|
|
123
|
+
fontWeight: 'normal',
|
|
124
|
+
color: '#9ca3af',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Responsive Behavior
|
|
134
|
+
|
|
135
|
+
Theme config controls styling, not sizing. To control size, either pass
|
|
136
|
+
top-level `width` and `height` on the chart config or style the container.
|
|
137
|
+
|
|
138
|
+
For fixed-size charts:
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
const chart = new XYChart({
|
|
142
|
+
data,
|
|
143
|
+
width: 800,
|
|
144
|
+
height: 400,
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
For responsive charts:
|
|
149
|
+
|
|
150
|
+
```css
|
|
151
|
+
.chart-container {
|
|
152
|
+
width: 100%;
|
|
153
|
+
max-width: 1200px;
|
|
154
|
+
height: 600px;
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Charts render with container-driven `100%` height (same model as width). Set an
|
|
159
|
+
explicit container height for predictable visual sizing when you are not using a
|
|
160
|
+
fixed `height`.
|
|
161
|
+
|
|
162
|
+
No manual resize calls needed - charts use ResizeObserver to respond automatically.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# WordCloudChart API
|
|
2
|
+
|
|
3
|
+
`WordCloudChart` renders a word cloud from flat rows with a fixed shape:
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
[
|
|
7
|
+
{ word: 'internet', count: 96 },
|
|
8
|
+
{ word: 'social', count: 82 },
|
|
9
|
+
];
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Constructor
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
new WordCloudChart(config: WordCloudChartConfig)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Config Options
|
|
19
|
+
|
|
20
|
+
| Option | Type | Default | Description |
|
|
21
|
+
| ------------ | ------------------------- | -------- | ------------------------------------------------ |
|
|
22
|
+
| `data` | `DataItem[]` | required | Flat `{ word, count }` rows |
|
|
23
|
+
| `width` | `number` | - | Explicit chart width in pixels |
|
|
24
|
+
| `height` | `number` | - | Explicit chart height in pixels |
|
|
25
|
+
| `theme` | `DeepPartial<ChartTheme>` | - | Theme customization |
|
|
26
|
+
| `responsive` | `ResponsiveConfig` | - | Declarative container-query responsive overrides |
|
|
27
|
+
| `wordCloud` | `WordCloudConfig` | - | Layout and filtering options |
|
|
28
|
+
|
|
29
|
+
### `wordCloud`
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
wordCloud: {
|
|
33
|
+
maxWords?: number; // default: 75
|
|
34
|
+
minWordLength?: number; // default: 1
|
|
35
|
+
minValue?: number; // default: 1
|
|
36
|
+
minFontSize?: number; // default: 3 (% of smaller plot-area dimension)
|
|
37
|
+
maxFontSize?: number; // default: 20 (% of smaller plot-area dimension)
|
|
38
|
+
padding?: number; // default: 1
|
|
39
|
+
rotation?: 'none' | 'right-angle'; // optional preset
|
|
40
|
+
spiral?: 'archimedean' | 'rectangular';
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { WordCloudChart } from '@internetstiftelsen/charts/word-cloud-chart';
|
|
48
|
+
import { Title } from '@internetstiftelsen/charts/title';
|
|
49
|
+
|
|
50
|
+
const data = [
|
|
51
|
+
{ word: 'internet', count: 96 },
|
|
52
|
+
{ word: 'social', count: 82 },
|
|
53
|
+
{ word: 'news', count: 75 },
|
|
54
|
+
{ word: 'streaming', count: 68 },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const chart = new WordCloudChart({
|
|
58
|
+
data,
|
|
59
|
+
wordCloud: {
|
|
60
|
+
minWordLength: 3,
|
|
61
|
+
minValue: 10,
|
|
62
|
+
minFontSize: 3,
|
|
63
|
+
maxFontSize: 20,
|
|
64
|
+
padding: 1,
|
|
65
|
+
spiral: 'archimedean',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
chart.addChild(new Title({ text: 'Most mentioned words' }));
|
|
70
|
+
|
|
71
|
+
chart.render('#word-cloud');
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Data Rules
|
|
75
|
+
|
|
76
|
+
- Grouped datasets are not supported.
|
|
77
|
+
- Word text is normalized with `trim()`.
|
|
78
|
+
- Rows with empty words, non-numeric counts, counts below `minValue`, or words
|
|
79
|
+
shorter than `minWordLength` are skipped.
|
|
80
|
+
- Duplicate surviving words are aggregated after normalization.
|
|
81
|
+
- The chart throws if no valid words remain after filtering.
|
|
82
|
+
|
|
83
|
+
## Supported Components
|
|
84
|
+
|
|
85
|
+
- `Title`
|
|
86
|
+
|
|
87
|
+
`XAxis`, `YAxis`, `Grid`, `Legend`, and `Tooltip` are not used by
|
|
88
|
+
`WordCloudChart`.
|
|
89
|
+
|
|
90
|
+
## Notes
|
|
91
|
+
|
|
92
|
+
- `minFontSize` and `maxFontSize` use percentages of the smaller plot-area
|
|
93
|
+
dimension and define the relative size range passed into `d3-cloud`.
|
|
94
|
+
- The chart uses theme typography and palette colors directly when configuring
|
|
95
|
+
`d3-cloud` and rendering the final SVG.
|
|
96
|
+
- If `rotation` is omitted, the chart uses the native `d3-cloud` rotate
|
|
97
|
+
accessor.
|
|
98
|
+
- `rotation: 'right-angle'` mixes `0` and `90` degree labels.
|