@internetstiftelsen/charts 0.12.0 → 0.13.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 +10 -1
- package/dist/base-chart.d.ts +12 -1
- package/dist/base-chart.js +58 -18
- package/dist/chart-group.d.ts +15 -2
- package/dist/chart-group.js +181 -45
- package/dist/chart-interface.d.ts +3 -3
- package/dist/grouped-data.d.ts +1 -0
- package/dist/grouped-data.js +80 -40
- package/dist/grouped-tabular.js +12 -3
- package/dist/layout-manager.js +4 -4
- package/dist/text.d.ts +40 -0
- package/dist/text.js +217 -0
- package/dist/theme.js +56 -0
- package/dist/title.d.ts +6 -12
- package/dist/title.js +29 -82
- package/dist/types.d.ts +34 -1
- package/docs/chart-group.md +24 -5
- package/docs/components.md +99 -15
- package/docs/donut-chart.md +2 -1
- package/docs/gauge-chart.md +2 -1
- package/docs/getting-started.md +1 -1
- package/docs/pie-chart.md +2 -1
- package/docs/theming.md +35 -0
- package/docs/word-cloud-chart.md +1 -0
- package/package.json +1 -1
package/docs/components.md
CHANGED
|
@@ -224,34 +224,116 @@ charts from one shared legend.
|
|
|
224
224
|
|
|
225
225
|
---
|
|
226
226
|
|
|
227
|
-
##
|
|
227
|
+
## Text
|
|
228
228
|
|
|
229
|
-
Renders
|
|
229
|
+
Renders layout-aware text above or below the chart. Use it for titles,
|
|
230
|
+
subtitles, captions, source notes, and other short chart copy.
|
|
230
231
|
|
|
231
232
|
```typescript
|
|
232
|
-
new
|
|
233
|
-
display?: boolean,
|
|
234
|
-
text: string,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
align?: 'left' | 'center' | 'right',
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
new Text({
|
|
234
|
+
display?: boolean, // Render text and reserve layout space (default: true)
|
|
235
|
+
text: string, // Text content (required)
|
|
236
|
+
position?: 'top' | 'bottom', // Layout position (default: 'top')
|
|
237
|
+
variant?: string, // Theme variant (default: 'caption')
|
|
238
|
+
align?: 'left' | 'center' | 'right', // Alignment (default: 'center')
|
|
239
|
+
fontSize?: number, // Override variant font size
|
|
240
|
+
fontWeight?: string, // Override variant font weight
|
|
241
|
+
fontFamily?: string, // Override variant font family
|
|
242
|
+
color?: string, // Override variant text color
|
|
243
|
+
lineHeight?: number, // Override variant line height
|
|
244
|
+
marginTop?: number, // Override variant top spacing
|
|
245
|
+
marginBottom?: number, // Override variant bottom spacing
|
|
240
246
|
})
|
|
241
247
|
```
|
|
242
248
|
|
|
243
249
|
### Example
|
|
244
250
|
|
|
245
251
|
```javascript
|
|
252
|
+
import { Text } from '@internetstiftelsen/charts/text';
|
|
253
|
+
|
|
254
|
+
chart
|
|
255
|
+
.addChild(
|
|
256
|
+
new Text({
|
|
257
|
+
text: 'Monthly Revenue',
|
|
258
|
+
variant: 'title',
|
|
259
|
+
align: 'left',
|
|
260
|
+
}),
|
|
261
|
+
)
|
|
262
|
+
.addChild(
|
|
263
|
+
new Text({
|
|
264
|
+
text: 'Revenue by month, SEK',
|
|
265
|
+
variant: 'subtitle',
|
|
266
|
+
align: 'left',
|
|
267
|
+
}),
|
|
268
|
+
)
|
|
269
|
+
.addChild(
|
|
270
|
+
new Text({
|
|
271
|
+
text: 'Source: Internal reporting',
|
|
272
|
+
position: 'bottom',
|
|
273
|
+
variant: 'caption',
|
|
274
|
+
align: 'left',
|
|
275
|
+
}),
|
|
276
|
+
);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Text variants come from `theme.text.variants`. Built-in variants are `title`,
|
|
280
|
+
`subtitle`, and `caption`. Component config overrides the selected variant.
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
const chart = new XYChart({
|
|
284
|
+
data,
|
|
285
|
+
theme: {
|
|
286
|
+
text: {
|
|
287
|
+
variants: {
|
|
288
|
+
source: {
|
|
289
|
+
fontSize: 10,
|
|
290
|
+
color: '#64748b',
|
|
291
|
+
marginTop: 6,
|
|
292
|
+
marginBottom: 0,
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
|
|
246
299
|
chart.addChild(
|
|
247
|
-
new
|
|
248
|
-
text: '
|
|
249
|
-
|
|
250
|
-
|
|
300
|
+
new Text({
|
|
301
|
+
text: 'Source: Internetstiftelsen',
|
|
302
|
+
position: 'bottom',
|
|
303
|
+
variant: 'source',
|
|
251
304
|
}),
|
|
252
305
|
);
|
|
253
306
|
```
|
|
254
307
|
|
|
308
|
+
## Title
|
|
309
|
+
|
|
310
|
+
`Title` remains available as a compatibility shortcut for top title text:
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
new Title({
|
|
314
|
+
display?: boolean,
|
|
315
|
+
text: string,
|
|
316
|
+
fontSize?: number,
|
|
317
|
+
fontWeight?: string,
|
|
318
|
+
fontFamily?: string,
|
|
319
|
+
align?: 'left' | 'center' | 'right',
|
|
320
|
+
color?: string,
|
|
321
|
+
lineHeight?: number,
|
|
322
|
+
marginTop?: number,
|
|
323
|
+
marginBottom?: number,
|
|
324
|
+
})
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
It maps to the same rendering and layout behavior as:
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
new Text({
|
|
331
|
+
text: 'Monthly Revenue',
|
|
332
|
+
position: 'top',
|
|
333
|
+
variant: 'title',
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
255
337
|
---
|
|
256
338
|
|
|
257
339
|
## Export Hooks
|
|
@@ -346,12 +428,14 @@ Components are rendered in the order they're added. A typical order:
|
|
|
346
428
|
|
|
347
429
|
```javascript
|
|
348
430
|
chart
|
|
349
|
-
.addChild(new
|
|
431
|
+
.addChild(new Text({ text: 'Chart Title', variant: 'title' }))
|
|
432
|
+
.addChild(new Text({ text: 'Subtitle', variant: 'subtitle' }))
|
|
350
433
|
.addChild(new Grid({ value: true }))
|
|
351
434
|
.addChild(new XAxis({ dataKey: 'date' }))
|
|
352
435
|
.addChild(new YAxis())
|
|
353
436
|
.addChild(new Tooltip())
|
|
354
437
|
.addChild(new Legend({ position: 'bottom' }))
|
|
438
|
+
.addChild(new Text({ text: 'Source note', position: 'bottom' }))
|
|
355
439
|
.addChild(new Line({ dataKey: 'value1' }))
|
|
356
440
|
.addChild(new Line({ dataKey: 'value2' }));
|
|
357
441
|
```
|
package/docs/donut-chart.md
CHANGED
|
@@ -176,7 +176,8 @@ new DonutCenterContent({
|
|
|
176
176
|
DonutChart supports the following components via `addChild()`:
|
|
177
177
|
|
|
178
178
|
- `DonutCenterContent` - Center text content
|
|
179
|
-
- `
|
|
179
|
+
- `Text` - Chart text, captions, and source notes
|
|
180
|
+
- `Title` - Shortcut for top title text
|
|
180
181
|
- `Legend` - Interactive legend (click to toggle segments)
|
|
181
182
|
- `Tooltip` - Hover tooltips with segment info
|
|
182
183
|
|
package/docs/gauge-chart.md
CHANGED
|
@@ -170,6 +170,7 @@ const chart = new GaugeChart({
|
|
|
170
170
|
|
|
171
171
|
GaugeChart supports the following components via `addChild()`:
|
|
172
172
|
|
|
173
|
-
- `
|
|
173
|
+
- `Text` - Chart text, captions, and source notes
|
|
174
|
+
- `Title` - Shortcut for top title text
|
|
174
175
|
- `Tooltip` - Hover tooltip (value, target)
|
|
175
176
|
- `Legend` - Segment legend with visibility toggles
|
package/docs/getting-started.md
CHANGED
|
@@ -366,5 +366,5 @@ directly when laying out and rendering the cloud.
|
|
|
366
366
|
- [DonutChart API](./donut-chart.md) - Donut/pie charts
|
|
367
367
|
- [PieChart API](./pie-chart.md) - Pie charts
|
|
368
368
|
- [GaugeChart API](./gauge-chart.md) - Gauge charts
|
|
369
|
-
- [Components](./components.md) - Axes, Grid, Tooltip, Legend, Title
|
|
369
|
+
- [Components](./components.md) - Axes, Grid, Tooltip, Legend, Text, Title
|
|
370
370
|
- [Theming](./theming.md) - Customize colors and styles
|
package/docs/pie-chart.md
CHANGED
|
@@ -108,7 +108,8 @@ fit inside its slice is hidden. In `auto` mode, labels that are too tight (based
|
|
|
108
108
|
|
|
109
109
|
PieChart supports the following components via `addChild()`:
|
|
110
110
|
|
|
111
|
-
- `
|
|
111
|
+
- `Text` - Chart text, captions, and source notes
|
|
112
|
+
- `Title` - Shortcut for top title text
|
|
112
113
|
- `Legend` - Interactive legend (click to toggle slices)
|
|
113
114
|
- `Tooltip` - Hover/focus tooltips with slice info
|
|
114
115
|
|
package/docs/theming.md
CHANGED
|
@@ -111,6 +111,41 @@ const data = [
|
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
|
|
114
|
+
## Text Variants
|
|
115
|
+
|
|
116
|
+
`Text` uses `theme.text.variants` for reusable typography and spacing. Built-in
|
|
117
|
+
variants are `title`, `subtitle`, and `caption`; add custom keys when a chart
|
|
118
|
+
needs another text style.
|
|
119
|
+
|
|
120
|
+
```javascript
|
|
121
|
+
theme: {
|
|
122
|
+
text: {
|
|
123
|
+
variants: {
|
|
124
|
+
title: {
|
|
125
|
+
fontSize: 18,
|
|
126
|
+
fontWeight: 'bold',
|
|
127
|
+
color: '#1f2a36',
|
|
128
|
+
lineHeight: 1.2,
|
|
129
|
+
marginTop: 10,
|
|
130
|
+
marginBottom: 15,
|
|
131
|
+
},
|
|
132
|
+
source: {
|
|
133
|
+
fontSize: 10,
|
|
134
|
+
color: '#64748b',
|
|
135
|
+
lineHeight: 1.3,
|
|
136
|
+
marginTop: 6,
|
|
137
|
+
marginBottom: 0,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Component config overrides the chosen variant, so a one-off chart can adjust
|
|
145
|
+
`fontSize`, `color`, or spacing without changing the theme.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
114
149
|
## Donut Theme Defaults
|
|
115
150
|
|
|
116
151
|
DonutChart has additional theme defaults:
|
package/docs/word-cloud-chart.md
CHANGED
package/package.json
CHANGED