@samizdata/mozaic 0.11.0 → 0.12.1
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 +1 -1
- package/dist/flags/index.d.ts +16 -0
- package/dist/flags/index.js +16 -0
- package/dist/flags/svgs.d.ts +261 -0
- package/dist/flags/svgs.js +265 -0
- package/dist/guides/AxisX.svelte +18 -3
- package/dist/guides/AxisX.svelte.d.ts +4 -0
- package/dist/interactive/Tooltip.svelte +10 -3
- package/dist/locale/index.d.ts +8 -0
- package/dist/locale/index.js +10 -0
- package/dist/marks/Beeswarm.svelte +31 -12
- package/dist/marks/Beeswarm.svelte.d.ts +3 -0
- package/dist/marks/Flag.svelte +65 -0
- package/dist/marks/Flag.svelte.d.ts +27 -0
- package/dist/marks/Flags.svelte +69 -0
- package/dist/marks/Flags.svelte.d.ts +45 -0
- package/dist/marks/index.d.ts +2 -0
- package/dist/marks/index.js +2 -0
- package/dist/recipes/ArrowChart.svelte +4 -1
- package/dist/recipes/ArrowChart.svelte.d.ts +2 -0
- package/dist/recipes/BarChart.svelte +103 -18
- package/dist/recipes/BarChart.svelte.d.ts +20 -2
- package/dist/recipes/BarDotChart.svelte +4 -1
- package/dist/recipes/BarDotChart.svelte.d.ts +2 -0
- package/dist/recipes/ColumnChart.svelte +7 -3
- package/dist/recipes/ColumnChart.svelte.d.ts +2 -0
- package/dist/recipes/LineChart.svelte +8 -2
- package/dist/recipes/LineChart.svelte.d.ts +2 -0
- package/dist/recipes/ScatterChart.svelte +179 -18
- package/dist/recipes/ScatterChart.svelte.d.ts +40 -1
- package/dist/recipes/StripChart.svelte +301 -0
- package/dist/recipes/StripChart.svelte.d.ts +89 -0
- package/dist/recipes/index.d.ts +2 -1
- package/dist/recipes/index.js +3 -1
- package/package.json +174 -170
- package/src/lib/recipes/ArrowChart.svelte +4 -1
- package/src/lib/recipes/BarChart.svelte +103 -18
- package/src/lib/recipes/BarDotChart.svelte +4 -1
- package/src/lib/recipes/ColumnChart.svelte +7 -3
- package/src/lib/recipes/LineChart.svelte +8 -2
- package/src/lib/recipes/ScatterChart.svelte +179 -18
- package/src/lib/recipes/StripChart.svelte +301 -0
- package/src/lib/recipes/index.ts +3 -1
|
@@ -15,6 +15,10 @@ declare function $$render<T>(): {
|
|
|
15
15
|
size?: (d: T) => number;
|
|
16
16
|
/** Optional colour group. */
|
|
17
17
|
group?: (d: T) => string;
|
|
18
|
+
/** The point's flag from `@samizdata/mozaic/flags`, drawn instead of a dot (rows without one keep their dot). */
|
|
19
|
+
flag?: (d: T) => string | null | undefined;
|
|
20
|
+
/** Labels to set in bold, e.g. the story's own country. */
|
|
21
|
+
emphasize?: (d: T) => boolean;
|
|
18
22
|
/** Points to label permanently. */
|
|
19
23
|
labelled?: (d: T) => boolean;
|
|
20
24
|
style?: Theme;
|
|
@@ -33,6 +37,36 @@ declare function $$render<T>(): {
|
|
|
33
37
|
yLabel?: string;
|
|
34
38
|
xFormat?: (n: number) => string;
|
|
35
39
|
yFormat?: (n: number) => string;
|
|
40
|
+
/** Units after the last tick label of each axis and the tooltip values, e.g. "euro a year". */
|
|
41
|
+
xUnit?: string;
|
|
42
|
+
yUnit?: string;
|
|
43
|
+
/** Axis domains; default to the data's extent, rounded. Start at zero to leave room in the corners. */
|
|
44
|
+
xDomain?: [number, number];
|
|
45
|
+
yDomain?: [number, number];
|
|
46
|
+
/** Dashed dividing lines and a label for each quarter (see `Quadrants`). */
|
|
47
|
+
quadrants?: {
|
|
48
|
+
/** Where the vertical and horizontal dividing lines cross, in data units. */
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
/** Labels for the dividing lines, e.g. "EU average". */
|
|
52
|
+
xLabel?: string;
|
|
53
|
+
yLabel?: string;
|
|
54
|
+
/** What each quarter means, written in its outer corner. Newlines split a label; long lines wrap to fit the quarter. */
|
|
55
|
+
topLeft?: string;
|
|
56
|
+
topRight?: string;
|
|
57
|
+
bottomLeft?: string;
|
|
58
|
+
bottomRight?: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* What the low and high ends of each axis mean, e.g. `{ x: ['Poorer', 'Richer'] }`: "← Poorer"
|
|
62
|
+
* and "Richer →" under the x axis, "↑ …" and "↓ …" inside the top and bottom left corners.
|
|
63
|
+
* With `quadrants`, drawn only when the quarter labels don't fit (narrow charts). Leave an end
|
|
64
|
+
* empty (`['', 'Richer']`) for a single arrow; the low end is dropped when both don't fit.
|
|
65
|
+
*/
|
|
66
|
+
directions?: {
|
|
67
|
+
x?: [string, string];
|
|
68
|
+
y?: [string, string];
|
|
69
|
+
};
|
|
36
70
|
height?: number;
|
|
37
71
|
annotations?: Snippet<[PlotContext]>;
|
|
38
72
|
};
|
|
@@ -57,7 +91,12 @@ interface $$IsomorphicComponent {
|
|
|
57
91
|
}
|
|
58
92
|
/**
|
|
59
93
|
* Recipe: a scatter plot with optional bubble sizes, colour groups, labels for
|
|
60
|
-
* selected points and a nearest-point tooltip. `
|
|
94
|
+
* selected points and a nearest-point tooltip. Pass `flag` to draw countries as
|
|
95
|
+
* circular flags, as in ggflags. `quadrants` splits the plot at two reference
|
|
96
|
+
* values (an average, a target) with dashed lines and says in each corner what
|
|
97
|
+
* that quarter means, so readers know where "good" and "bad" are. `directions`
|
|
98
|
+
* puts arrows on the axes ("Richer →"); with quadrants they replace the quarter
|
|
99
|
+
* labels on charts too narrow for them. `mozaic eject ScatterChart`
|
|
61
100
|
* copies this file into your project.
|
|
62
101
|
*/
|
|
63
102
|
declare const ScatterChart: $$IsomorphicComponent;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Recipe: a strip (one-axis dot plot) for comparing many items on one value,
|
|
4
|
+
such as a price across countries. Items sit along the x axis, nudged up and
|
|
5
|
+
down so they do not overlap (a beeswarm), as dots or as circular flags
|
|
6
|
+
(`flag`, as in ggflags). Highlighted items get a label with a leader line
|
|
7
|
+
above the strip; reference values (an average) get a dashed line labelled
|
|
8
|
+
below it. Arrows under the axis (`directions`) say what each end means, and
|
|
9
|
+
very soft gridlines help read values off the axis. Much shorter than a bar chart of the same items, so use it when the
|
|
10
|
+
reader needs the overall spread and a few named items, not every value.
|
|
11
|
+
`mozaic eject StripChart` copies this file into your project.
|
|
12
|
+
-->
|
|
13
|
+
<script lang="ts" generics="T">
|
|
14
|
+
import { scaleLinear } from 'd3-scale';
|
|
15
|
+
import { max, min } from 'd3-array';
|
|
16
|
+
import { Chart, Header, Title, Subtitle, Footer, Source, Notes, type SourceItem } from '../frame/index.js';
|
|
17
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
18
|
+
import { Plot, Svg, Html, estimateTextWidth } from '../core/index.js';
|
|
19
|
+
import { Flag } from '../marks/index.js';
|
|
20
|
+
import { AxisX } from '../guides/index.js';
|
|
21
|
+
import { Tooltip } from '../interactive/index.js';
|
|
22
|
+
import { createLocale, type LocaleCode } from '../locale/index.js';
|
|
23
|
+
import { base, readableColor, type Medium, type Theme } from '../styles/index.js';
|
|
24
|
+
import { dodge } from '../transforms/index.js';
|
|
25
|
+
|
|
26
|
+
interface Reference {
|
|
27
|
+
value: number;
|
|
28
|
+
label: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface Props {
|
|
32
|
+
data: T[];
|
|
33
|
+
value: (d: T) => number;
|
|
34
|
+
/** Name shown in the tooltip and in highlighted labels. */
|
|
35
|
+
label: (d: T) => string;
|
|
36
|
+
/** The item's flag from `@samizdata/mozaic/flags`, drawn instead of a dot. */
|
|
37
|
+
flag?: (d: T) => string | null | undefined;
|
|
38
|
+
/** Items to label above the strip. */
|
|
39
|
+
highlight?: (d: T) => boolean;
|
|
40
|
+
/** Text of a highlighted label; defaults to the name and value. */
|
|
41
|
+
labelText?: (d: T) => string;
|
|
42
|
+
/** Highlighted labels to set in bold, e.g. the story's own country; the rest are regular. */
|
|
43
|
+
emphasize?: (d: T) => boolean;
|
|
44
|
+
/** Dot colour, and the colour of the item's label (darkened to 4.5:1 where needed). */
|
|
45
|
+
color?: (d: T) => string | undefined;
|
|
46
|
+
/** Dashed vertical lines with a label under the strip, e.g. an average. */
|
|
47
|
+
references?: Reference[];
|
|
48
|
+
/** Value axis domain; defaults to zero to the largest value. */
|
|
49
|
+
domain?: [number, number];
|
|
50
|
+
/** Unit after the last axis tick label and the tooltip value, e.g. "c/kWh". */
|
|
51
|
+
unit?: string;
|
|
52
|
+
/** Axis title at the end of the value axis. Leave it out when the subtitle gives the unit. */
|
|
53
|
+
axisLabel?: string;
|
|
54
|
+
/**
|
|
55
|
+
* What the low and high ends of the axis mean, e.g. `["Cheaper", "More expensive"]`,
|
|
56
|
+
* drawn under the axis as "← Cheaper" and "More expensive →". Leave an end empty for a single
|
|
57
|
+
* arrow; the low end is dropped when both do not fit.
|
|
58
|
+
*/
|
|
59
|
+
directions?: [string, string];
|
|
60
|
+
/** Very soft vertical gridlines at the ticks (default true). */
|
|
61
|
+
grid?: boolean;
|
|
62
|
+
/** Dot or flag radius in px; defaults to a size that keeps flags recognisable. */
|
|
63
|
+
r?: number;
|
|
64
|
+
style?: Theme;
|
|
65
|
+
locale?: LocaleCode;
|
|
66
|
+
medium?: Medium;
|
|
67
|
+
width?: number;
|
|
68
|
+
title?: string;
|
|
69
|
+
subtitle?: string;
|
|
70
|
+
notes?: string;
|
|
71
|
+
/** Plain text, or sources with optional links (see `<Source>`). */
|
|
72
|
+
source?: string | SourceItem[];
|
|
73
|
+
alt?: string;
|
|
74
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
75
|
+
embed?: ChartEmbed;
|
|
76
|
+
/** Value format for labels, tooltips and references; defaults to locale numbers. */
|
|
77
|
+
format?: (n: number) => string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let {
|
|
81
|
+
data,
|
|
82
|
+
value,
|
|
83
|
+
label,
|
|
84
|
+
flag,
|
|
85
|
+
highlight,
|
|
86
|
+
labelText,
|
|
87
|
+
emphasize,
|
|
88
|
+
color,
|
|
89
|
+
references = [],
|
|
90
|
+
domain,
|
|
91
|
+
unit,
|
|
92
|
+
axisLabel,
|
|
93
|
+
directions,
|
|
94
|
+
grid = true,
|
|
95
|
+
r: radius,
|
|
96
|
+
style = base,
|
|
97
|
+
locale,
|
|
98
|
+
medium,
|
|
99
|
+
width,
|
|
100
|
+
title,
|
|
101
|
+
subtitle,
|
|
102
|
+
notes,
|
|
103
|
+
source,
|
|
104
|
+
alt,
|
|
105
|
+
embed,
|
|
106
|
+
format
|
|
107
|
+
}: Props = $props();
|
|
108
|
+
|
|
109
|
+
const theme = $derived(style);
|
|
110
|
+
const fmt = $derived(format ?? createLocale(locale ?? theme.defaultLocale).number);
|
|
111
|
+
const fontSize = $derived(theme.plot.fontSize);
|
|
112
|
+
const lineHeight = $derived(Math.round(fontSize * 1.35));
|
|
113
|
+
const r = $derived(radius ?? Math.round(fontSize * 0.7));
|
|
114
|
+
const padding = $derived({ left: 8, right: 8, top: 0, bottom: directions ? 28 + lineHeight + 6 : 28 });
|
|
115
|
+
const ticks = 5;
|
|
116
|
+
const leader = 8;
|
|
117
|
+
const x = $derived(
|
|
118
|
+
scaleLinear()
|
|
119
|
+
.domain(domain ?? [Math.min(0, min(data, value) ?? 0), max(data, value) ?? 1])
|
|
120
|
+
.nice()
|
|
121
|
+
);
|
|
122
|
+
const textOf = (d: T) => labelText?.(d) ?? `${label(d)} ${fmt(value(d))}`;
|
|
123
|
+
const labelled = $derived(highlight ? data.filter(highlight) : []);
|
|
124
|
+
|
|
125
|
+
/** Positions of the items and labels for a plot area `w` px wide. Pure, so the height can be worked out before the plot is drawn. */
|
|
126
|
+
function layout(w: number) {
|
|
127
|
+
const scale = x.copy().range([0, w]);
|
|
128
|
+
const xs = data.map((d) => scale(value(d)));
|
|
129
|
+
const offsets = dodge(xs, r, { padding: 1 });
|
|
130
|
+
const half = Math.max(0, ...offsets.map(Math.abs)) + r;
|
|
131
|
+
// Labels go in rows above the strip, each in the lowest row where it fits.
|
|
132
|
+
const rows: [number, number][][] = [];
|
|
133
|
+
const labels = labelled
|
|
134
|
+
.map((d) => ({ d, text: textOf(d), cx: scale(value(d)) }))
|
|
135
|
+
.sort((a, b) => a.cx - b.cx)
|
|
136
|
+
.map((l) => {
|
|
137
|
+
const wl = estimateTextWidth(l.text, fontSize);
|
|
138
|
+
const left = Math.max(0, Math.min(w - wl, l.cx - wl / 2));
|
|
139
|
+
let row = rows.findIndex((spans) => spans.every(([a, b]) => left > b + 8 || left + wl < a - 8));
|
|
140
|
+
if (row < 0) row = rows.push([]) - 1;
|
|
141
|
+
rows[row].push([left, left + wl]);
|
|
142
|
+
return { ...l, tx: left + wl / 2, row };
|
|
143
|
+
});
|
|
144
|
+
const band = rows.length ? rows.length * lineHeight + leader : 0;
|
|
145
|
+
const centre = band + half;
|
|
146
|
+
const below = references.length ? lineHeight + 4 : 0;
|
|
147
|
+
return { scale, xs, offsets, half, labels, band, centre, height: band + half * 2 + below };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const plotHeight = (size: { width: number }) => layout(size.width - padding.left - padding.right).height;
|
|
151
|
+
const ink = (d: T) => {
|
|
152
|
+
const c = color?.(d);
|
|
153
|
+
return c ? readableColor(c, theme.tokens['--mz-color-bg']) : 'var(--mz-color-text)';
|
|
154
|
+
};
|
|
155
|
+
let hovered = $state<number | null>(null);
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<Chart {style} {locale} {medium} {width} {alt} {embed}>
|
|
159
|
+
{#if title || subtitle}
|
|
160
|
+
<Header>
|
|
161
|
+
{#if title}<Title>{title}</Title>{/if}
|
|
162
|
+
{#if subtitle}<Subtitle>{subtitle}</Subtitle>{/if}
|
|
163
|
+
</Header>
|
|
164
|
+
{/if}
|
|
165
|
+
|
|
166
|
+
<Plot {x} height={plotHeight} {padding}>
|
|
167
|
+
{#snippet children(plot)}
|
|
168
|
+
{@const L = layout(plot.width)}
|
|
169
|
+
<Svg>
|
|
170
|
+
{#if grid}
|
|
171
|
+
{#each x.ticks(ticks) as tick (tick)}
|
|
172
|
+
{@const gx = L.scale(tick)}
|
|
173
|
+
<line class="mz-strip-grid" x1={gx} x2={gx} y1={L.band} y2={plot.height} />
|
|
174
|
+
{/each}
|
|
175
|
+
{/if}
|
|
176
|
+
<AxisX {ticks} label={axisLabel} {unit} />
|
|
177
|
+
{#if directions}
|
|
178
|
+
{@const dy = plot.height + 28 + lineHeight}
|
|
179
|
+
{@const [low, high] = directions}
|
|
180
|
+
{@const both =
|
|
181
|
+
estimateTextWidth(`← ${low}`, fontSize) + estimateTextWidth(`${high} →`, fontSize) + 24 < plot.width}
|
|
182
|
+
{#if low && (both || !high)}
|
|
183
|
+
<text class="mz-strip-direction" x={0} y={dy} font-size={fontSize}>← {low}</text>
|
|
184
|
+
{/if}
|
|
185
|
+
{#if high}
|
|
186
|
+
<text class="mz-strip-direction" x={plot.width} y={dy} text-anchor="end" font-size={fontSize}>{high} →</text
|
|
187
|
+
>
|
|
188
|
+
{/if}
|
|
189
|
+
{/if}
|
|
190
|
+
{#each references as ref (ref.label)}
|
|
191
|
+
{@const rx = L.scale(ref.value)}
|
|
192
|
+
<line
|
|
193
|
+
class="mz-strip-ref"
|
|
194
|
+
x1={rx}
|
|
195
|
+
x2={rx}
|
|
196
|
+
y1={L.band}
|
|
197
|
+
y2={L.centre + L.half}
|
|
198
|
+
stroke="var(--mz-color-muted)"
|
|
199
|
+
stroke-dasharray="3 3"
|
|
200
|
+
/>
|
|
201
|
+
<text
|
|
202
|
+
class="mz-strip-ref-label"
|
|
203
|
+
x={rx}
|
|
204
|
+
y={L.centre + L.half + lineHeight}
|
|
205
|
+
text-anchor="middle"
|
|
206
|
+
font-size={fontSize}>{ref.label}</text
|
|
207
|
+
>
|
|
208
|
+
{/each}
|
|
209
|
+
{#each data as d, i (i)}
|
|
210
|
+
{@const cx = L.xs[i]}
|
|
211
|
+
{@const cy = L.centre + L.offsets[i]}
|
|
212
|
+
{@const svg = flag?.(d)}
|
|
213
|
+
{@const on = highlight?.(d) ?? false}
|
|
214
|
+
{#if svg}
|
|
215
|
+
<Flag
|
|
216
|
+
{svg}
|
|
217
|
+
{cx}
|
|
218
|
+
{cy}
|
|
219
|
+
{r}
|
|
220
|
+
stroke={on ? 'var(--mz-color-text)' : undefined}
|
|
221
|
+
strokeWidth={on ? 1.5 : 1}
|
|
222
|
+
title={label(d)}
|
|
223
|
+
opacity={hovered != null && hovered !== i ? 0.5 : 1}
|
|
224
|
+
onpointerenter={() => (hovered = i)}
|
|
225
|
+
onpointerleave={() => (hovered = null)}
|
|
226
|
+
/>
|
|
227
|
+
{:else}
|
|
228
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
229
|
+
<circle
|
|
230
|
+
{cx}
|
|
231
|
+
{cy}
|
|
232
|
+
{r}
|
|
233
|
+
fill={color?.(d) ?? theme.palettes.categorical[0]}
|
|
234
|
+
stroke="var(--mz-color-bg)"
|
|
235
|
+
opacity={hovered != null && hovered !== i ? 0.5 : 1}
|
|
236
|
+
onpointerenter={() => (hovered = i)}
|
|
237
|
+
onpointerleave={() => (hovered = null)}><title>{label(d)}</title></circle
|
|
238
|
+
>
|
|
239
|
+
{/if}
|
|
240
|
+
{/each}
|
|
241
|
+
{#each L.labels as l (l.text)}
|
|
242
|
+
{@const i = data.indexOf(l.d)}
|
|
243
|
+
{@const ty = L.band - leader - l.row * lineHeight}
|
|
244
|
+
<line
|
|
245
|
+
class="mz-strip-leader"
|
|
246
|
+
x1={l.cx}
|
|
247
|
+
x2={l.cx}
|
|
248
|
+
y1={ty + 3}
|
|
249
|
+
y2={L.centre + L.offsets[i] - r}
|
|
250
|
+
stroke="var(--mz-color-muted)"
|
|
251
|
+
stroke-width="0.75"
|
|
252
|
+
/>
|
|
253
|
+
<text
|
|
254
|
+
class="mz-strip-label"
|
|
255
|
+
x={l.tx}
|
|
256
|
+
y={ty}
|
|
257
|
+
text-anchor="middle"
|
|
258
|
+
font-size={fontSize}
|
|
259
|
+
style:font-weight={emphasize?.(l.d) ? 'var(--mz-weight-strong)' : undefined}
|
|
260
|
+
fill={ink(l.d)}>{l.text}</text
|
|
261
|
+
>
|
|
262
|
+
{/each}
|
|
263
|
+
</Svg>
|
|
264
|
+
<Html>
|
|
265
|
+
{#if hovered != null}
|
|
266
|
+
<Tooltip x={L.xs[hovered]} y={L.centre + L.offsets[hovered]}>
|
|
267
|
+
<strong>{label(data[hovered])}</strong><br />{fmt(value(data[hovered]))}{unit ? ` ${unit}` : ''}
|
|
268
|
+
</Tooltip>
|
|
269
|
+
{/if}
|
|
270
|
+
</Html>
|
|
271
|
+
{/snippet}
|
|
272
|
+
</Plot>
|
|
273
|
+
|
|
274
|
+
{#if notes || source}
|
|
275
|
+
<Footer>
|
|
276
|
+
{#if notes}<Notes>{notes}</Notes>{/if}
|
|
277
|
+
{#if source}<Source sources={source} />{/if}
|
|
278
|
+
</Footer>
|
|
279
|
+
{/if}
|
|
280
|
+
</Chart>
|
|
281
|
+
|
|
282
|
+
<style>
|
|
283
|
+
.mz-strip-grid {
|
|
284
|
+
stroke: var(--mz-color-grid);
|
|
285
|
+
stroke-width: 1;
|
|
286
|
+
opacity: 0.5;
|
|
287
|
+
shape-rendering: crispEdges;
|
|
288
|
+
}
|
|
289
|
+
.mz-strip-direction {
|
|
290
|
+
fill: var(--mz-color-muted);
|
|
291
|
+
font-family: var(--mz-font-body);
|
|
292
|
+
font-style: italic;
|
|
293
|
+
}
|
|
294
|
+
.mz-strip-ref-label {
|
|
295
|
+
fill: var(--mz-color-muted);
|
|
296
|
+
font-family: var(--mz-font-body);
|
|
297
|
+
}
|
|
298
|
+
.mz-strip-label {
|
|
299
|
+
font-family: var(--mz-font-body);
|
|
300
|
+
}
|
|
301
|
+
</style>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type SourceItem } from '../frame/index.js';
|
|
2
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
3
|
+
import { type LocaleCode } from '../locale/index.js';
|
|
4
|
+
import { type Medium, type Theme } from '../styles/index.js';
|
|
5
|
+
declare function $$render<T>(): {
|
|
6
|
+
props: {
|
|
7
|
+
data: T[];
|
|
8
|
+
value: (d: T) => number;
|
|
9
|
+
/** Name shown in the tooltip and in highlighted labels. */
|
|
10
|
+
label: (d: T) => string;
|
|
11
|
+
/** The item's flag from `@samizdata/mozaic/flags`, drawn instead of a dot. */
|
|
12
|
+
flag?: (d: T) => string | null | undefined;
|
|
13
|
+
/** Items to label above the strip. */
|
|
14
|
+
highlight?: (d: T) => boolean;
|
|
15
|
+
/** Text of a highlighted label; defaults to the name and value. */
|
|
16
|
+
labelText?: (d: T) => string;
|
|
17
|
+
/** Highlighted labels to set in bold, e.g. the story's own country; the rest are regular. */
|
|
18
|
+
emphasize?: (d: T) => boolean;
|
|
19
|
+
/** Dot colour, and the colour of the item's label (darkened to 4.5:1 where needed). */
|
|
20
|
+
color?: (d: T) => string | undefined;
|
|
21
|
+
/** Dashed vertical lines with a label under the strip, e.g. an average. */
|
|
22
|
+
references?: {
|
|
23
|
+
value: number;
|
|
24
|
+
label: string;
|
|
25
|
+
}[];
|
|
26
|
+
/** Value axis domain; defaults to zero to the largest value. */
|
|
27
|
+
domain?: [number, number];
|
|
28
|
+
/** Unit after the last axis tick label and the tooltip value, e.g. "c/kWh". */
|
|
29
|
+
unit?: string;
|
|
30
|
+
/** Axis title at the end of the value axis. Leave it out when the subtitle gives the unit. */
|
|
31
|
+
axisLabel?: string;
|
|
32
|
+
/**
|
|
33
|
+
* What the low and high ends of the axis mean, e.g. `["Cheaper", "More expensive"]`,
|
|
34
|
+
* drawn under the axis as "← Cheaper" and "More expensive →". Leave an end empty for a single
|
|
35
|
+
* arrow; the low end is dropped when both do not fit.
|
|
36
|
+
*/
|
|
37
|
+
directions?: [string, string];
|
|
38
|
+
/** Very soft vertical gridlines at the ticks (default true). */
|
|
39
|
+
grid?: boolean;
|
|
40
|
+
/** Dot or flag radius in px; defaults to a size that keeps flags recognisable. */
|
|
41
|
+
r?: number;
|
|
42
|
+
style?: Theme;
|
|
43
|
+
locale?: LocaleCode;
|
|
44
|
+
medium?: Medium;
|
|
45
|
+
width?: number;
|
|
46
|
+
title?: string;
|
|
47
|
+
subtitle?: string;
|
|
48
|
+
notes?: string;
|
|
49
|
+
/** Plain text, or sources with optional links (see `<Source>`). */
|
|
50
|
+
source?: string | SourceItem[];
|
|
51
|
+
alt?: string;
|
|
52
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
53
|
+
embed?: ChartEmbed;
|
|
54
|
+
/** Value format for labels, tooltips and references; defaults to locale numbers. */
|
|
55
|
+
format?: (n: number) => string;
|
|
56
|
+
};
|
|
57
|
+
exports: {};
|
|
58
|
+
bindings: "";
|
|
59
|
+
slots: {};
|
|
60
|
+
events: {};
|
|
61
|
+
};
|
|
62
|
+
declare class __sveltets_Render<T> {
|
|
63
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
64
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
65
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
66
|
+
bindings(): "";
|
|
67
|
+
exports(): {};
|
|
68
|
+
}
|
|
69
|
+
interface $$IsomorphicComponent {
|
|
70
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
71
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
72
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
73
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
74
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Recipe: a strip (one-axis dot plot) for comparing many items on one value,
|
|
78
|
+
* such as a price across countries. Items sit along the x axis, nudged up and
|
|
79
|
+
* down so they do not overlap (a beeswarm), as dots or as circular flags
|
|
80
|
+
* (`flag`, as in ggflags). Highlighted items get a label with a leader line
|
|
81
|
+
* above the strip; reference values (an average) get a dashed line labelled
|
|
82
|
+
* below it. Arrows under the axis (`directions`) say what each end means, and
|
|
83
|
+
* very soft gridlines help read values off the axis. Much shorter than a bar chart of the same items, so use it when the
|
|
84
|
+
* reader needs the overall spread and a few named items, not every value.
|
|
85
|
+
* `mozaic eject StripChart` copies this file into your project.
|
|
86
|
+
*/
|
|
87
|
+
declare const StripChart: $$IsomorphicComponent;
|
|
88
|
+
type StripChart<T> = InstanceType<typeof StripChart<T>>;
|
|
89
|
+
export default StripChart;
|
package/dist/recipes/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ export { default as BarDotChart } from './BarDotChart.svelte';
|
|
|
7
7
|
export { default as StackedBarChart } from './StackedBarChart.svelte';
|
|
8
8
|
export { default as MosaicChart } from './MosaicChart.svelte';
|
|
9
9
|
export { default as PercentileChart } from './PercentileChart.svelte';
|
|
10
|
+
export { default as StripChart } from './StripChart.svelte';
|
|
10
11
|
/** Recipe names accepted by `mozaic eject`. */
|
|
11
|
-
export declare const recipes: readonly ["BarChart", "ColumnChart", "LineChart", "ScatterChart", "ArrowChart", "BarDotChart", "StackedBarChart", "MosaicChart", "PercentileChart"];
|
|
12
|
+
export declare const recipes: readonly ["BarChart", "ColumnChart", "LineChart", "ScatterChart", "ArrowChart", "BarDotChart", "StackedBarChart", "MosaicChart", "PercentileChart", "StripChart"];
|
package/dist/recipes/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { default as BarDotChart } from './BarDotChart.svelte';
|
|
|
7
7
|
export { default as StackedBarChart } from './StackedBarChart.svelte';
|
|
8
8
|
export { default as MosaicChart } from './MosaicChart.svelte';
|
|
9
9
|
export { default as PercentileChart } from './PercentileChart.svelte';
|
|
10
|
+
export { default as StripChart } from './StripChart.svelte';
|
|
10
11
|
/** Recipe names accepted by `mozaic eject`. */
|
|
11
12
|
export const recipes = [
|
|
12
13
|
'BarChart',
|
|
@@ -17,5 +18,6 @@ export const recipes = [
|
|
|
17
18
|
'BarDotChart',
|
|
18
19
|
'StackedBarChart',
|
|
19
20
|
'MosaicChart',
|
|
20
|
-
'PercentileChart'
|
|
21
|
+
'PercentileChart',
|
|
22
|
+
'StripChart'
|
|
21
23
|
];
|