@samizdata/mozaic 0.0.0-stage → 0.2.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/LICENSE +674 -0
- package/README.md +44 -2
- package/dist/annotations/Arrow.svelte +50 -0
- package/dist/annotations/Arrow.svelte.d.ts +18 -0
- package/dist/annotations/Callout.svelte +87 -0
- package/dist/annotations/Callout.svelte.d.ts +22 -0
- package/dist/annotations/Label.svelte +55 -0
- package/dist/annotations/Label.svelte.d.ts +19 -0
- package/dist/annotations/RefBand.svelte +46 -0
- package/dist/annotations/RefBand.svelte.d.ts +18 -0
- package/dist/annotations/RefLine.svelte +72 -0
- package/dist/annotations/RefLine.svelte.d.ts +19 -0
- package/dist/annotations/callout-geometry.d.ts +23 -0
- package/dist/annotations/callout-geometry.js +45 -0
- package/dist/annotations/index.d.ts +6 -0
- package/dist/annotations/index.js +6 -0
- package/dist/core/Canvas.svelte +55 -0
- package/dist/core/Canvas.svelte.d.ts +19 -0
- package/dist/core/Facets.svelte +80 -0
- package/dist/core/Facets.svelte.d.ts +49 -0
- package/dist/core/Html.svelte +38 -0
- package/dist/core/Html.svelte.d.ts +13 -0
- package/dist/core/Plot.svelte +202 -0
- package/dist/core/Plot.svelte.d.ts +60 -0
- package/dist/core/Svg.svelte +58 -0
- package/dist/core/Svg.svelte.d.ts +17 -0
- package/dist/core/accessor.d.ts +5 -0
- package/dist/core/accessor.js +3 -0
- package/dist/core/context.d.ts +25 -0
- package/dist/core/context.js +69 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.js +9 -0
- package/dist/core/scales.d.ts +16 -0
- package/dist/core/scales.js +32 -0
- package/dist/core/types.d.ts +78 -0
- package/dist/core/types.js +1 -0
- package/dist/core/units.d.ts +6 -0
- package/dist/core/units.js +10 -0
- package/dist/embed/Embed.svelte +50 -0
- package/dist/embed/Embed.svelte.d.ts +14 -0
- package/dist/embed/code.d.ts +18 -0
- package/dist/embed/code.js +9 -0
- package/dist/embed/host.d.ts +6 -0
- package/dist/embed/host.js +20 -0
- package/dist/embed/index.d.ts +6 -0
- package/dist/embed/index.js +5 -0
- package/dist/embed/manifest.d.ts +16 -0
- package/dist/embed/manifest.js +1 -0
- package/dist/embed/params.svelte.d.ts +10 -0
- package/dist/embed/params.svelte.js +27 -0
- package/dist/embed/resize.d.ts +13 -0
- package/dist/embed/resize.js +28 -0
- package/dist/export/download.d.ts +13 -0
- package/dist/export/download.js +52 -0
- package/dist/export/figure-to-svg.d.ts +21 -0
- package/dist/export/figure-to-svg.js +187 -0
- package/dist/export/fonts.d.ts +26 -0
- package/dist/export/fonts.js +112 -0
- package/dist/export/index.d.ts +2 -0
- package/dist/export/index.js +2 -0
- package/dist/frame/Byline.svelte +26 -0
- package/dist/frame/Byline.svelte.d.ts +8 -0
- package/dist/frame/Chart.svelte +144 -0
- package/dist/frame/Chart.svelte.d.ts +37 -0
- package/dist/frame/ChartTools.svelte +259 -0
- package/dist/frame/ChartTools.svelte.d.ts +17 -0
- package/dist/frame/DataDownload.svelte +34 -0
- package/dist/frame/DataDownload.svelte.d.ts +34 -0
- package/dist/frame/DataTable.svelte +49 -0
- package/dist/frame/DataTable.svelte.d.ts +34 -0
- package/dist/frame/Footer.svelte +39 -0
- package/dist/frame/Footer.svelte.d.ts +10 -0
- package/dist/frame/Header.svelte +21 -0
- package/dist/frame/Header.svelte.d.ts +9 -0
- package/dist/frame/Logo.svelte +57 -0
- package/dist/frame/Logo.svelte.d.ts +8 -0
- package/dist/frame/Notes.svelte +29 -0
- package/dist/frame/Notes.svelte.d.ts +9 -0
- package/dist/frame/Source.svelte +29 -0
- package/dist/frame/Source.svelte.d.ts +9 -0
- package/dist/frame/Subtitle.svelte +22 -0
- package/dist/frame/Subtitle.svelte.d.ts +9 -0
- package/dist/frame/Title.svelte +31 -0
- package/dist/frame/Title.svelte.d.ts +9 -0
- package/dist/frame/index.d.ts +12 -0
- package/dist/frame/index.js +12 -0
- package/dist/guides/AxisX.svelte +101 -0
- package/dist/guides/AxisX.svelte.d.ts +22 -0
- package/dist/guides/AxisY.svelte +84 -0
- package/dist/guides/AxisY.svelte.d.ts +21 -0
- package/dist/guides/ColorRamp.svelte +93 -0
- package/dist/guides/ColorRamp.svelte.d.ts +25 -0
- package/dist/guides/GridX.svelte +35 -0
- package/dist/guides/GridX.svelte.d.ts +9 -0
- package/dist/guides/GridY.svelte +35 -0
- package/dist/guides/GridY.svelte.d.ts +9 -0
- package/dist/guides/Key.svelte +48 -0
- package/dist/guides/Key.svelte.d.ts +14 -0
- package/dist/guides/Legend.svelte +112 -0
- package/dist/guides/Legend.svelte.d.ts +26 -0
- package/dist/guides/SizeLegend.svelte +62 -0
- package/dist/guides/SizeLegend.svelte.d.ts +15 -0
- package/dist/guides/index.d.ts +9 -0
- package/dist/guides/index.js +9 -0
- package/dist/guides/ticks.d.ts +6 -0
- package/dist/guides/ticks.js +15 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -0
- package/dist/interactive/ButtonGroup.svelte +98 -0
- package/dist/interactive/ButtonGroup.svelte.d.ts +42 -0
- package/dist/interactive/PointerArea.svelte +49 -0
- package/dist/interactive/PointerArea.svelte.d.ts +18 -0
- package/dist/interactive/Scroller.svelte +147 -0
- package/dist/interactive/Scroller.svelte.d.ts +54 -0
- package/dist/interactive/Tooltip.svelte +66 -0
- package/dist/interactive/Tooltip.svelte.d.ts +19 -0
- package/dist/interactive/index.d.ts +4 -0
- package/dist/interactive/index.js +4 -0
- package/dist/interactive/tooltip-position.d.ts +12 -0
- package/dist/interactive/tooltip-position.js +16 -0
- package/dist/locale/definitions.d.ts +145 -0
- package/dist/locale/definitions.js +138 -0
- package/dist/locale/index.d.ts +23 -0
- package/dist/locale/index.js +34 -0
- package/dist/marks/Arcs.svelte +93 -0
- package/dist/marks/Arcs.svelte.d.ts +47 -0
- package/dist/marks/Area.svelte +44 -0
- package/dist/marks/Area.svelte.d.ts +43 -0
- package/dist/marks/Arrows.svelte +93 -0
- package/dist/marks/Arrows.svelte.d.ts +50 -0
- package/dist/marks/Bars.svelte +111 -0
- package/dist/marks/Bars.svelte.d.ts +61 -0
- package/dist/marks/Beeswarm.svelte +84 -0
- package/dist/marks/Beeswarm.svelte.d.ts +42 -0
- package/dist/marks/Dumbbell.svelte +71 -0
- package/dist/marks/Dumbbell.svelte.d.ts +42 -0
- package/dist/marks/GeoPath.svelte +56 -0
- package/dist/marks/GeoPath.svelte.d.ts +42 -0
- package/dist/marks/Hemicycle.svelte +182 -0
- package/dist/marks/Hemicycle.svelte.d.ts +78 -0
- package/dist/marks/Intervals.svelte +128 -0
- package/dist/marks/Intervals.svelte.d.ts +60 -0
- package/dist/marks/Line.svelte +64 -0
- package/dist/marks/Line.svelte.d.ts +43 -0
- package/dist/marks/LineEndLabels.svelte +70 -0
- package/dist/marks/LineEndLabels.svelte.d.ts +41 -0
- package/dist/marks/Points.svelte +70 -0
- package/dist/marks/Points.svelte.d.ts +46 -0
- package/dist/marks/Rects.svelte +92 -0
- package/dist/marks/Rects.svelte.d.ts +47 -0
- package/dist/marks/Rules.svelte +46 -0
- package/dist/marks/Rules.svelte.d.ts +15 -0
- package/dist/marks/Slope.svelte +112 -0
- package/dist/marks/Slope.svelte.d.ts +41 -0
- package/dist/marks/Text.svelte +75 -0
- package/dist/marks/Text.svelte.d.ts +47 -0
- package/dist/marks/Treemap.svelte +89 -0
- package/dist/marks/Treemap.svelte.d.ts +45 -0
- package/dist/marks/Voronoi.svelte +61 -0
- package/dist/marks/Voronoi.svelte.d.ts +39 -0
- package/dist/marks/Waffle.svelte +69 -0
- package/dist/marks/Waffle.svelte.d.ts +41 -0
- package/dist/marks/bar-path.d.ts +5 -0
- package/dist/marks/bar-path.js +15 -0
- package/dist/marks/index.d.ts +20 -0
- package/dist/marks/index.js +20 -0
- package/dist/recipes/ArrowChart.svelte +247 -0
- package/dist/recipes/ArrowChart.svelte.d.ts +73 -0
- package/dist/recipes/BarChart.svelte +122 -0
- package/dist/recipes/BarChart.svelte.d.ts +58 -0
- package/dist/recipes/BarDotChart.svelte +204 -0
- package/dist/recipes/BarDotChart.svelte.d.ts +75 -0
- package/dist/recipes/ColumnChart.svelte +119 -0
- package/dist/recipes/ColumnChart.svelte.d.ts +56 -0
- package/dist/recipes/LineChart.svelte +159 -0
- package/dist/recipes/LineChart.svelte.d.ts +61 -0
- package/dist/recipes/MosaicChart.svelte +256 -0
- package/dist/recipes/MosaicChart.svelte.d.ts +83 -0
- package/dist/recipes/ScatterChart.svelte +167 -0
- package/dist/recipes/ScatterChart.svelte.d.ts +63 -0
- package/dist/recipes/StackedBarChart.svelte +222 -0
- package/dist/recipes/StackedBarChart.svelte.d.ts +83 -0
- package/dist/recipes/index.d.ts +10 -0
- package/dist/recipes/index.js +19 -0
- package/dist/styles/base.d.ts +5 -0
- package/dist/styles/base.js +102 -0
- package/dist/styles/check.d.ts +8 -0
- package/dist/styles/check.js +32 -0
- package/dist/styles/color.d.ts +11 -0
- package/dist/styles/color.js +29 -0
- package/dist/styles/index.d.ts +9 -0
- package/dist/styles/index.js +17 -0
- package/dist/styles/types.d.ts +90 -0
- package/dist/styles/types.js +1 -0
- package/dist/table/Sparkline.svelte +59 -0
- package/dist/table/Sparkline.svelte.d.ts +16 -0
- package/dist/table/Table.svelte +287 -0
- package/dist/table/Table.svelte.d.ts +44 -0
- package/dist/table/csv.d.ts +3 -0
- package/dist/table/csv.js +12 -0
- package/dist/table/index.d.ts +4 -0
- package/dist/table/index.js +3 -0
- package/dist/table/types.d.ts +26 -0
- package/dist/table/types.js +1 -0
- package/dist/transforms/bin.d.ts +15 -0
- package/dist/transforms/bin.js +18 -0
- package/dist/transforms/dodge.d.ts +10 -0
- package/dist/transforms/dodge.js +35 -0
- package/dist/transforms/group.d.ts +14 -0
- package/dist/transforms/group.js +14 -0
- package/dist/transforms/hemicycle.d.ts +30 -0
- package/dist/transforms/hemicycle.js +51 -0
- package/dist/transforms/index.d.ts +8 -0
- package/dist/transforms/index.js +8 -0
- package/dist/transforms/labels.d.ts +6 -0
- package/dist/transforms/labels.js +20 -0
- package/dist/transforms/smooth.d.ts +61 -0
- package/dist/transforms/smooth.js +105 -0
- package/dist/transforms/stack.d.ts +25 -0
- package/dist/transforms/stack.js +61 -0
- package/dist/transforms/treemap.d.ts +21 -0
- package/dist/transforms/treemap.js +31 -0
- package/package.json +152 -3
- package/src/lib/recipes/ArrowChart.svelte +247 -0
- package/src/lib/recipes/BarChart.svelte +122 -0
- package/src/lib/recipes/BarDotChart.svelte +204 -0
- package/src/lib/recipes/ColumnChart.svelte +119 -0
- package/src/lib/recipes/LineChart.svelte +159 -0
- package/src/lib/recipes/MosaicChart.svelte +256 -0
- package/src/lib/recipes/ScatterChart.svelte +167 -0
- package/src/lib/recipes/StackedBarChart.svelte +222 -0
- package/src/lib/recipes/index.ts +20 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Recipe: horizontal bars for the latest value of each category, a dot for an
|
|
4
|
+
earlier value, and the latest value with its change written at the right
|
|
5
|
+
("29.2% −3.2"). Good for two survey waves where the latest one matters most.
|
|
6
|
+
Rows missing a value show only the bar or the dot. Use it as is, or run
|
|
7
|
+
`mozaic eject BarDotChart` to copy this file into your project and change
|
|
8
|
+
anything.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts" generics="T">
|
|
11
|
+
import type { Snippet } from 'svelte';
|
|
12
|
+
import { scaleBand, scaleLinear } from 'd3-scale';
|
|
13
|
+
import { max, min } from 'd3-array';
|
|
14
|
+
import { Chart, Header, Title, Subtitle, Footer, Source, Notes } from '../frame/index.js';
|
|
15
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
16
|
+
import { Plot, Svg, estimateTextWidth, scaled, type PlotContext } from '../core/index.js';
|
|
17
|
+
import { Bars, Points } from '../marks/index.js';
|
|
18
|
+
import { AxisX, AxisY, GridX, Legend } from '../guides/index.js';
|
|
19
|
+
import { createLocale, type LocaleCode } from '../locale/index.js';
|
|
20
|
+
import { base, type Medium, type Theme } from '../styles/index.js';
|
|
21
|
+
|
|
22
|
+
type Maybe = number | null | undefined;
|
|
23
|
+
|
|
24
|
+
interface Props {
|
|
25
|
+
data: T[];
|
|
26
|
+
label: (d: T) => string;
|
|
27
|
+
/** Latest value, drawn as a bar. */
|
|
28
|
+
value: (d: T) => Maybe;
|
|
29
|
+
/** Earlier value, drawn as a dot. */
|
|
30
|
+
previous: (d: T) => Maybe;
|
|
31
|
+
/** Legend names for the bars and the dots (e.g. the two fieldwork dates). */
|
|
32
|
+
valueLabel?: string;
|
|
33
|
+
previousLabel?: string;
|
|
34
|
+
style?: Theme;
|
|
35
|
+
locale?: LocaleCode;
|
|
36
|
+
medium?: Medium;
|
|
37
|
+
width?: number;
|
|
38
|
+
title?: string;
|
|
39
|
+
subtitle?: string;
|
|
40
|
+
notes?: string;
|
|
41
|
+
source?: string;
|
|
42
|
+
alt?: string;
|
|
43
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
44
|
+
embed?: ChartEmbed;
|
|
45
|
+
/** Value label format; defaults to locale numbers. */
|
|
46
|
+
format?: (n: number) => string;
|
|
47
|
+
/** Change label format; defaults to one decimal with a sign. */
|
|
48
|
+
formatChange?: (n: number) => string;
|
|
49
|
+
/** Axis tick format; defaults to `format`. */
|
|
50
|
+
tickFormat?: (n: number) => string;
|
|
51
|
+
/** Bar colour; defaults to a mid step of the sequential palette. Use the context grey for "don't know" rows. */
|
|
52
|
+
color?: (d: T) => string;
|
|
53
|
+
/** Dot colour; defaults to the darkest sequential step. */
|
|
54
|
+
dotColor?: string;
|
|
55
|
+
/** Sort by the latest value, largest first, or keep data order (default). */
|
|
56
|
+
sort?: boolean;
|
|
57
|
+
/** x domain; defaults to zero and the largest value, rounded. */
|
|
58
|
+
domain?: [number, number];
|
|
59
|
+
rowHeight?: number;
|
|
60
|
+
/** Extra SVG drawn on top (annotations); receives the plot context. */
|
|
61
|
+
annotations?: Snippet<[PlotContext]>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let {
|
|
65
|
+
data,
|
|
66
|
+
label,
|
|
67
|
+
value,
|
|
68
|
+
previous,
|
|
69
|
+
valueLabel,
|
|
70
|
+
previousLabel,
|
|
71
|
+
style = base,
|
|
72
|
+
locale,
|
|
73
|
+
medium,
|
|
74
|
+
width,
|
|
75
|
+
title,
|
|
76
|
+
subtitle,
|
|
77
|
+
notes,
|
|
78
|
+
source,
|
|
79
|
+
alt,
|
|
80
|
+
embed,
|
|
81
|
+
format,
|
|
82
|
+
formatChange,
|
|
83
|
+
tickFormat,
|
|
84
|
+
color,
|
|
85
|
+
dotColor,
|
|
86
|
+
sort = false,
|
|
87
|
+
domain,
|
|
88
|
+
rowHeight = 32,
|
|
89
|
+
annotations
|
|
90
|
+
}: Props = $props();
|
|
91
|
+
|
|
92
|
+
const theme = $derived(style);
|
|
93
|
+
const numbers = $derived(createLocale(locale ?? theme.defaultLocale));
|
|
94
|
+
const fmt = $derived(format ?? numbers.number);
|
|
95
|
+
const signed = $derived(
|
|
96
|
+
formatChange ?? ((n: number) => (Math.abs(n) < 0.05 ? numbers.format('.1f')(0) : numbers.format('+.1f')(n)))
|
|
97
|
+
);
|
|
98
|
+
const fontSize = $derived(theme.plot.fontSize);
|
|
99
|
+
const has = (v: Maybe): v is number => v !== null && v !== undefined && Number.isFinite(v);
|
|
100
|
+
const sequential = $derived(theme.palettes.sequential);
|
|
101
|
+
const barColor = $derived((d: T) => color?.(d) ?? sequential[Math.floor(sequential.length / 2)]);
|
|
102
|
+
const dot = $derived(dotColor ?? sequential[sequential.length - 1]);
|
|
103
|
+
|
|
104
|
+
const rows = $derived(sort ? data.toSorted((a, b) => (value(b) ?? -Infinity) - (value(a) ?? -Infinity)) : data);
|
|
105
|
+
const all = $derived(rows.flatMap((d) => [value(d), previous(d)]).filter(has));
|
|
106
|
+
const x = $derived(
|
|
107
|
+
scaleLinear()
|
|
108
|
+
.domain(domain ?? [Math.min(0, min(all) ?? 0), Math.max(0, max(all) ?? 1)])
|
|
109
|
+
.nice()
|
|
110
|
+
);
|
|
111
|
+
const y = $derived(scaleBand<string>().domain(rows.map(label)).padding(0.3));
|
|
112
|
+
const text = (d: T) => {
|
|
113
|
+
const v = value(d);
|
|
114
|
+
const p = previous(d);
|
|
115
|
+
return { value: has(v) ? fmt(v) : '–', change: has(v) && has(p) ? signed(v - p) : '' };
|
|
116
|
+
};
|
|
117
|
+
const left = $derived(Math.max(...rows.map((d) => estimateTextWidth(label(d), fontSize)), 0) + 12);
|
|
118
|
+
const right = $derived(
|
|
119
|
+
Math.max(
|
|
120
|
+
...rows.map((d) => {
|
|
121
|
+
const t = text(d);
|
|
122
|
+
return estimateTextWidth(`${t.value} ${t.change}`, fontSize);
|
|
123
|
+
}),
|
|
124
|
+
0
|
|
125
|
+
) + 12
|
|
126
|
+
);
|
|
127
|
+
</script>
|
|
128
|
+
|
|
129
|
+
<Chart {style} {locale} {medium} {width} {alt} {embed}>
|
|
130
|
+
<Header>
|
|
131
|
+
{#if title}<Title>{title}</Title>{/if}
|
|
132
|
+
{#if subtitle}<Subtitle>{subtitle}</Subtitle>{/if}
|
|
133
|
+
{#if valueLabel || previousLabel}
|
|
134
|
+
<div class="mz-bar-dot-legend">
|
|
135
|
+
{#if valueLabel}<Legend
|
|
136
|
+
items={[{ label: valueLabel, color: sequential[Math.floor(sequential.length / 2)] }]}
|
|
137
|
+
/>{/if}
|
|
138
|
+
{#if previousLabel}<Legend shape="circle" items={[{ label: previousLabel, color: dot }]} />{/if}
|
|
139
|
+
</div>
|
|
140
|
+
{/if}
|
|
141
|
+
</Header>
|
|
142
|
+
|
|
143
|
+
<Plot {x} {y} height={rows.length * rowHeight} padding={{ left, right, top: 4, bottom: 24 }}>
|
|
144
|
+
{#snippet children(plot)}
|
|
145
|
+
<Svg>
|
|
146
|
+
<GridX ticks={4} />
|
|
147
|
+
<AxisX ticks={4} format={tickFormat ?? fmt} />
|
|
148
|
+
<AxisY />
|
|
149
|
+
<Bars
|
|
150
|
+
data={rows.filter((d) => has(value(d)))}
|
|
151
|
+
y={label}
|
|
152
|
+
x={(d) => value(d)!}
|
|
153
|
+
fill={barColor}
|
|
154
|
+
title={(d) => `${label(d)}: ${fmt(value(d)!)}`}
|
|
155
|
+
/>
|
|
156
|
+
<Points
|
|
157
|
+
data={rows.filter((d) => has(previous(d)))}
|
|
158
|
+
y={label}
|
|
159
|
+
x={(d) => previous(d)!}
|
|
160
|
+
r={4}
|
|
161
|
+
fill={dot}
|
|
162
|
+
stroke={theme.tokens['--mz-color-bg']}
|
|
163
|
+
strokeWidth={1.5}
|
|
164
|
+
title={(d) => `${label(d)}${previousLabel ? `, ${previousLabel}` : ''}: ${fmt(previous(d)!)}`}
|
|
165
|
+
/>
|
|
166
|
+
{#each rows as d (label(d))}
|
|
167
|
+
{@const t = text(d)}
|
|
168
|
+
<text class="mz-bar-dot-value" x={plot.width + 8} y={scaled(plot.y, label(d))} dy="0.35em">
|
|
169
|
+
<tspan class="strong">{t.value}</tspan>
|
|
170
|
+
{#if t.change}<tspan class="change" dx="6">{t.change}</tspan>{/if}
|
|
171
|
+
</text>
|
|
172
|
+
{/each}
|
|
173
|
+
{@render annotations?.(plot)}
|
|
174
|
+
</Svg>
|
|
175
|
+
{/snippet}
|
|
176
|
+
</Plot>
|
|
177
|
+
|
|
178
|
+
{#if notes || source}
|
|
179
|
+
<Footer>
|
|
180
|
+
{#if notes}<Notes>{notes}</Notes>{/if}
|
|
181
|
+
{#if source}<Source>{source}</Source>{/if}
|
|
182
|
+
</Footer>
|
|
183
|
+
{/if}
|
|
184
|
+
</Chart>
|
|
185
|
+
|
|
186
|
+
<style>
|
|
187
|
+
.mz-bar-dot-legend {
|
|
188
|
+
display: flex;
|
|
189
|
+
flex-wrap: wrap;
|
|
190
|
+
gap: 0 1rem;
|
|
191
|
+
}
|
|
192
|
+
.mz-bar-dot-value {
|
|
193
|
+
font-family: var(--mz-font-body);
|
|
194
|
+
font-size: var(--mz-size-axis);
|
|
195
|
+
fill: var(--mz-color-text);
|
|
196
|
+
font-variant-numeric: tabular-nums;
|
|
197
|
+
}
|
|
198
|
+
.strong {
|
|
199
|
+
font-weight: var(--mz-weight-strong);
|
|
200
|
+
}
|
|
201
|
+
.change {
|
|
202
|
+
fill: var(--mz-color-muted);
|
|
203
|
+
}
|
|
204
|
+
</style>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
3
|
+
import { type PlotContext } from '../core/index.js';
|
|
4
|
+
import { type LocaleCode } from '../locale/index.js';
|
|
5
|
+
import { type Medium, type Theme } from '../styles/index.js';
|
|
6
|
+
declare function $$render<T>(): {
|
|
7
|
+
props: {
|
|
8
|
+
data: T[];
|
|
9
|
+
label: (d: T) => string;
|
|
10
|
+
/** Latest value, drawn as a bar. */
|
|
11
|
+
value: (d: T) => number | null | undefined;
|
|
12
|
+
/** Earlier value, drawn as a dot. */
|
|
13
|
+
previous: (d: T) => number | null | undefined;
|
|
14
|
+
/** Legend names for the bars and the dots (e.g. the two fieldwork dates). */
|
|
15
|
+
valueLabel?: string;
|
|
16
|
+
previousLabel?: string;
|
|
17
|
+
style?: Theme;
|
|
18
|
+
locale?: LocaleCode;
|
|
19
|
+
medium?: Medium;
|
|
20
|
+
width?: number;
|
|
21
|
+
title?: string;
|
|
22
|
+
subtitle?: string;
|
|
23
|
+
notes?: string;
|
|
24
|
+
source?: string;
|
|
25
|
+
alt?: string;
|
|
26
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
27
|
+
embed?: ChartEmbed;
|
|
28
|
+
/** Value label format; defaults to locale numbers. */
|
|
29
|
+
format?: (n: number) => string;
|
|
30
|
+
/** Change label format; defaults to one decimal with a sign. */
|
|
31
|
+
formatChange?: (n: number) => string;
|
|
32
|
+
/** Axis tick format; defaults to `format`. */
|
|
33
|
+
tickFormat?: (n: number) => string;
|
|
34
|
+
/** Bar colour; defaults to a mid step of the sequential palette. Use the context grey for "don't know" rows. */
|
|
35
|
+
color?: (d: T) => string;
|
|
36
|
+
/** Dot colour; defaults to the darkest sequential step. */
|
|
37
|
+
dotColor?: string;
|
|
38
|
+
/** Sort by the latest value, largest first, or keep data order (default). */
|
|
39
|
+
sort?: boolean;
|
|
40
|
+
/** x domain; defaults to zero and the largest value, rounded. */
|
|
41
|
+
domain?: [number, number];
|
|
42
|
+
rowHeight?: number;
|
|
43
|
+
/** Extra SVG drawn on top (annotations); receives the plot context. */
|
|
44
|
+
annotations?: Snippet<[PlotContext]>;
|
|
45
|
+
};
|
|
46
|
+
exports: {};
|
|
47
|
+
bindings: "";
|
|
48
|
+
slots: {};
|
|
49
|
+
events: {};
|
|
50
|
+
};
|
|
51
|
+
declare class __sveltets_Render<T> {
|
|
52
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
53
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
54
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
55
|
+
bindings(): "";
|
|
56
|
+
exports(): {};
|
|
57
|
+
}
|
|
58
|
+
interface $$IsomorphicComponent {
|
|
59
|
+
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']>> & {
|
|
60
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
61
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
62
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
63
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Recipe: horizontal bars for the latest value of each category, a dot for an
|
|
67
|
+
* earlier value, and the latest value with its change written at the right
|
|
68
|
+
* ("29.2% −3.2"). Good for two survey waves where the latest one matters most.
|
|
69
|
+
* Rows missing a value show only the bar or the dot. Use it as is, or run
|
|
70
|
+
* `mozaic eject BarDotChart` to copy this file into your project and change
|
|
71
|
+
* anything.
|
|
72
|
+
*/
|
|
73
|
+
declare const BarDotChart: $$IsomorphicComponent;
|
|
74
|
+
type BarDotChart<T> = InstanceType<typeof BarDotChart<T>>;
|
|
75
|
+
export default BarDotChart;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Recipe: a vertical column chart (one series), e.g. a value per year, with
|
|
4
|
+
gridlines, hover tooltip and the full frame. `mozaic eject ColumnChart`
|
|
5
|
+
copies this file into your project.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts" generics="T">
|
|
8
|
+
import type { Snippet } from 'svelte';
|
|
9
|
+
import { scaleBand, scaleLinear } from 'd3-scale';
|
|
10
|
+
import { max, min } from 'd3-array';
|
|
11
|
+
import { Chart, Header, Title, Subtitle, Footer, Source, Notes } from '../frame/index.js';
|
|
12
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
13
|
+
import { Plot, Svg, Html, scaled, type PlotContext } from '../core/index.js';
|
|
14
|
+
import { Bars, Rules } from '../marks/index.js';
|
|
15
|
+
import { AxisX, AxisY, GridY } from '../guides/index.js';
|
|
16
|
+
import { Tooltip } from '../interactive/index.js';
|
|
17
|
+
import { createLocale, type LocaleCode } from '../locale/index.js';
|
|
18
|
+
import { base, type Medium, type Theme } from '../styles/index.js';
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
data: T[];
|
|
22
|
+
/** Category on the x axis (e.g. the year). */
|
|
23
|
+
label: (d: T) => string;
|
|
24
|
+
value: (d: T) => number;
|
|
25
|
+
style?: Theme;
|
|
26
|
+
locale?: LocaleCode;
|
|
27
|
+
medium?: Medium;
|
|
28
|
+
width?: number;
|
|
29
|
+
title?: string;
|
|
30
|
+
subtitle?: string;
|
|
31
|
+
notes?: string;
|
|
32
|
+
source?: string;
|
|
33
|
+
alt?: string;
|
|
34
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
35
|
+
embed?: ChartEmbed;
|
|
36
|
+
format?: (n: number) => string;
|
|
37
|
+
color?: (d: T) => string;
|
|
38
|
+
height?: number;
|
|
39
|
+
/** Show every nth x label (useful for long series). */
|
|
40
|
+
labelEvery?: number;
|
|
41
|
+
annotations?: Snippet<[PlotContext]>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let {
|
|
45
|
+
data,
|
|
46
|
+
label,
|
|
47
|
+
value,
|
|
48
|
+
style = base,
|
|
49
|
+
locale,
|
|
50
|
+
medium,
|
|
51
|
+
width,
|
|
52
|
+
title,
|
|
53
|
+
subtitle,
|
|
54
|
+
notes,
|
|
55
|
+
source,
|
|
56
|
+
alt,
|
|
57
|
+
embed,
|
|
58
|
+
format,
|
|
59
|
+
color,
|
|
60
|
+
height = 280,
|
|
61
|
+
labelEvery,
|
|
62
|
+
annotations
|
|
63
|
+
}: Props = $props();
|
|
64
|
+
|
|
65
|
+
const theme = $derived(style);
|
|
66
|
+
const fmt = $derived(format ?? createLocale(locale ?? theme.defaultLocale).number);
|
|
67
|
+
const x = $derived(scaleBand<string>().domain(data.map(label)).paddingInner(0.2).paddingOuter(0.1));
|
|
68
|
+
const y = $derived(
|
|
69
|
+
scaleLinear()
|
|
70
|
+
.domain([Math.min(0, min(data, value) ?? 0), Math.max(0, max(data, value) ?? 1)])
|
|
71
|
+
.nice()
|
|
72
|
+
);
|
|
73
|
+
let hovered = $state<T | null>(null);
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<Chart {style} {locale} {medium} {width} {alt} {embed}>
|
|
77
|
+
{#if title || subtitle}
|
|
78
|
+
<Header>
|
|
79
|
+
{#if title}<Title>{title}</Title>{/if}
|
|
80
|
+
{#if subtitle}<Subtitle>{subtitle}</Subtitle>{/if}
|
|
81
|
+
</Header>
|
|
82
|
+
{/if}
|
|
83
|
+
|
|
84
|
+
<Plot {x} {y} {height} padding={{ left: 40, right: 8, top: 8, bottom: 28 }}>
|
|
85
|
+
{#snippet children(plot)}
|
|
86
|
+
{@const every = labelEvery ?? Math.max(1, Math.ceil((data.length * 36) / Math.max(1, plot.width)))}
|
|
87
|
+
<Svg>
|
|
88
|
+
<GridY ticks={5} />
|
|
89
|
+
<AxisY ticks={5} format={fmt} />
|
|
90
|
+
<AxisX tickValues={data.map(label).filter((_, i) => i % every === 0)} />
|
|
91
|
+
<Bars
|
|
92
|
+
{data}
|
|
93
|
+
x={label}
|
|
94
|
+
y={value}
|
|
95
|
+
fill={color}
|
|
96
|
+
opacity={(d) => (hovered && hovered !== d ? 0.5 : 1)}
|
|
97
|
+
onpointerenter={(d) => (hovered = d)}
|
|
98
|
+
onpointerleave={() => (hovered = null)}
|
|
99
|
+
/>
|
|
100
|
+
<Rules y={[0]} />
|
|
101
|
+
{@render annotations?.(plot)}
|
|
102
|
+
</Svg>
|
|
103
|
+
<Html>
|
|
104
|
+
{#if hovered}
|
|
105
|
+
<Tooltip x={scaled(plot.x, label(hovered))} y={plot.y(value(hovered)) ?? 0}>
|
|
106
|
+
<strong>{label(hovered)}</strong><br />{fmt(value(hovered))}
|
|
107
|
+
</Tooltip>
|
|
108
|
+
{/if}
|
|
109
|
+
</Html>
|
|
110
|
+
{/snippet}
|
|
111
|
+
</Plot>
|
|
112
|
+
|
|
113
|
+
{#if notes || source}
|
|
114
|
+
<Footer>
|
|
115
|
+
{#if notes}<Notes>{notes}</Notes>{/if}
|
|
116
|
+
{#if source}<Source>{source}</Source>{/if}
|
|
117
|
+
</Footer>
|
|
118
|
+
{/if}
|
|
119
|
+
</Chart>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
3
|
+
import { type PlotContext } from '../core/index.js';
|
|
4
|
+
import { type LocaleCode } from '../locale/index.js';
|
|
5
|
+
import { type Medium, type Theme } from '../styles/index.js';
|
|
6
|
+
declare function $$render<T>(): {
|
|
7
|
+
props: {
|
|
8
|
+
data: T[];
|
|
9
|
+
/** Category on the x axis (e.g. the year). */
|
|
10
|
+
label: (d: T) => string;
|
|
11
|
+
value: (d: T) => number;
|
|
12
|
+
style?: Theme;
|
|
13
|
+
locale?: LocaleCode;
|
|
14
|
+
medium?: Medium;
|
|
15
|
+
width?: number;
|
|
16
|
+
title?: string;
|
|
17
|
+
subtitle?: string;
|
|
18
|
+
notes?: string;
|
|
19
|
+
source?: string;
|
|
20
|
+
alt?: string;
|
|
21
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
22
|
+
embed?: ChartEmbed;
|
|
23
|
+
format?: (n: number) => string;
|
|
24
|
+
color?: (d: T) => string;
|
|
25
|
+
height?: number;
|
|
26
|
+
/** Show every nth x label (useful for long series). */
|
|
27
|
+
labelEvery?: number;
|
|
28
|
+
annotations?: Snippet<[PlotContext]>;
|
|
29
|
+
};
|
|
30
|
+
exports: {};
|
|
31
|
+
bindings: "";
|
|
32
|
+
slots: {};
|
|
33
|
+
events: {};
|
|
34
|
+
};
|
|
35
|
+
declare class __sveltets_Render<T> {
|
|
36
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
37
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
38
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
39
|
+
bindings(): "";
|
|
40
|
+
exports(): {};
|
|
41
|
+
}
|
|
42
|
+
interface $$IsomorphicComponent {
|
|
43
|
+
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']>> & {
|
|
44
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
45
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
46
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
47
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Recipe: a vertical column chart (one series), e.g. a value per year, with
|
|
51
|
+
* gridlines, hover tooltip and the full frame. `mozaic eject ColumnChart`
|
|
52
|
+
* copies this file into your project.
|
|
53
|
+
*/
|
|
54
|
+
declare const ColumnChart: $$IsomorphicComponent;
|
|
55
|
+
type ColumnChart<T> = InstanceType<typeof ColumnChart<T>>;
|
|
56
|
+
export default ColumnChart;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Recipe: a multi-series line chart with a legend, direct end labels and a
|
|
4
|
+
crosshair tooltip. Series colours follow the series order in the theme's
|
|
5
|
+
categorical palette. `mozaic eject LineChart` copies this file into your
|
|
6
|
+
project.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts" generics="S, P">
|
|
9
|
+
import type { Snippet } from 'svelte';
|
|
10
|
+
import { scaleLinear, scaleTime } from 'd3-scale';
|
|
11
|
+
import { bisector, extent, max, min } from 'd3-array';
|
|
12
|
+
import { curveMonotoneX } from 'd3-shape';
|
|
13
|
+
import { Chart, Header, Title, Subtitle, Footer, Source, Notes } from '../frame/index.js';
|
|
14
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
15
|
+
import { Plot, Svg, Html, type PlotContext } from '../core/index.js';
|
|
16
|
+
import { Line, LineEndLabels } from '../marks/index.js';
|
|
17
|
+
import { AxisX, AxisY, GridY, Legend } from '../guides/index.js';
|
|
18
|
+
import { PointerArea, Tooltip } from '../interactive/index.js';
|
|
19
|
+
import { createLocale, type LocaleCode } from '../locale/index.js';
|
|
20
|
+
import { base, type Medium, type Theme } from '../styles/index.js';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
series: S[];
|
|
24
|
+
/** Points of one series, sorted by x. */
|
|
25
|
+
points: (s: S) => P[];
|
|
26
|
+
name: (s: S) => string;
|
|
27
|
+
x: (p: P) => Date;
|
|
28
|
+
y: (p: P) => number;
|
|
29
|
+
style?: Theme;
|
|
30
|
+
locale?: LocaleCode;
|
|
31
|
+
medium?: Medium;
|
|
32
|
+
width?: number;
|
|
33
|
+
title?: string;
|
|
34
|
+
subtitle?: string;
|
|
35
|
+
notes?: string;
|
|
36
|
+
source?: string;
|
|
37
|
+
alt?: string;
|
|
38
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
39
|
+
embed?: ChartEmbed;
|
|
40
|
+
format?: (n: number) => string;
|
|
41
|
+
/** Tooltip date format (d3-time-format specifier). */
|
|
42
|
+
dateFormat?: string;
|
|
43
|
+
color?: (s: S, index: number) => string;
|
|
44
|
+
/** Start the y axis at zero. */
|
|
45
|
+
zero?: boolean;
|
|
46
|
+
height?: number;
|
|
47
|
+
annotations?: Snippet<[PlotContext]>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let {
|
|
51
|
+
series,
|
|
52
|
+
points,
|
|
53
|
+
name,
|
|
54
|
+
x: xValue,
|
|
55
|
+
y: yValue,
|
|
56
|
+
style = base,
|
|
57
|
+
locale,
|
|
58
|
+
medium,
|
|
59
|
+
width,
|
|
60
|
+
title,
|
|
61
|
+
subtitle,
|
|
62
|
+
notes,
|
|
63
|
+
source,
|
|
64
|
+
alt,
|
|
65
|
+
embed,
|
|
66
|
+
format,
|
|
67
|
+
dateFormat = '%B %Y',
|
|
68
|
+
color,
|
|
69
|
+
zero = false,
|
|
70
|
+
height,
|
|
71
|
+
annotations
|
|
72
|
+
}: Props = $props();
|
|
73
|
+
|
|
74
|
+
const theme = $derived(style);
|
|
75
|
+
const loc = $derived(createLocale(locale ?? theme.defaultLocale));
|
|
76
|
+
const fmt = $derived(format ?? loc.number);
|
|
77
|
+
const colour = (s: S, i: number) =>
|
|
78
|
+
color?.(s, i) ?? theme.palettes.categorical[i % theme.palettes.categorical.length];
|
|
79
|
+
|
|
80
|
+
const all = $derived(series.flatMap(points));
|
|
81
|
+
const x = $derived(scaleTime().domain(extent(all, xValue) as [Date, Date]));
|
|
82
|
+
const y = $derived(
|
|
83
|
+
scaleLinear()
|
|
84
|
+
.domain([zero ? Math.min(0, min(all, yValue) ?? 0) : (min(all, yValue) ?? 0), max(all, yValue) ?? 1])
|
|
85
|
+
.nice()
|
|
86
|
+
);
|
|
87
|
+
const ends = $derived(series.map((s, i) => ({ s, i, p: points(s)[points(s).length - 1] })).filter((e) => e.p));
|
|
88
|
+
const dates = $derived(points(series[0] ?? ([] as unknown as S)) ?? []);
|
|
89
|
+
const nearest = $derived(bisector<P, Date>(xValue).center);
|
|
90
|
+
let hover = $state<P | null>(null);
|
|
91
|
+
const valueAt = (s: S, date: Date) => points(s).find((p) => +xValue(p) === +date);
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<Chart {style} {locale} {medium} {width} {alt} {embed}>
|
|
95
|
+
<Header>
|
|
96
|
+
{#if title}<Title>{title}</Title>{/if}
|
|
97
|
+
{#if subtitle}<Subtitle>{subtitle}</Subtitle>{/if}
|
|
98
|
+
{#if series.length > 1}
|
|
99
|
+
<Legend shape="line" items={series.map((s, i) => ({ label: name(s), color: colour(s, i) }))} />
|
|
100
|
+
{/if}
|
|
101
|
+
</Header>
|
|
102
|
+
|
|
103
|
+
<Plot
|
|
104
|
+
{x}
|
|
105
|
+
{y}
|
|
106
|
+
height={height ?? (({ breakpoint }) => (breakpoint === 's' ? 260 : 340))}
|
|
107
|
+
padding={({ breakpoint }) => ({ left: breakpoint === 's' ? 0 : 40, right: 80, top: 16, bottom: 28 })}
|
|
108
|
+
>
|
|
109
|
+
{#snippet children(plot)}
|
|
110
|
+
<Svg>
|
|
111
|
+
<GridY ticks={5} />
|
|
112
|
+
<AxisY ticks={5} format={fmt} inside={plot.breakpoint === 's'} />
|
|
113
|
+
<AxisX ticks={plot.breakpoint === 's' ? 4 : 7} />
|
|
114
|
+
{#if hover}
|
|
115
|
+
<line x1={plot.x(xValue(hover))} x2={plot.x(xValue(hover))} y2={plot.height} stroke="var(--mz-color-axis)" />
|
|
116
|
+
{/if}
|
|
117
|
+
{#each series as s, i}
|
|
118
|
+
<Line data={points(s)} x={xValue} y={yValue} stroke={colour(s, i)} curve={curveMonotoneX} />
|
|
119
|
+
{/each}
|
|
120
|
+
<LineEndLabels
|
|
121
|
+
data={ends}
|
|
122
|
+
x={(e) => xValue(e.p)}
|
|
123
|
+
y={(e) => yValue(e.p)}
|
|
124
|
+
text={(e) => name(e.s)}
|
|
125
|
+
color={(e) => colour(e.s, e.i)}
|
|
126
|
+
/>
|
|
127
|
+
{@render annotations?.(plot)}
|
|
128
|
+
<PointerArea
|
|
129
|
+
onmove={({ x: px }) => {
|
|
130
|
+
const date = plot.x.invert?.(px);
|
|
131
|
+
hover = date ? (dates[nearest(dates, date)] ?? null) : null;
|
|
132
|
+
}}
|
|
133
|
+
onleave={() => (hover = null)}
|
|
134
|
+
/>
|
|
135
|
+
</Svg>
|
|
136
|
+
<Html>
|
|
137
|
+
{#if hover}
|
|
138
|
+
{@const date = xValue(hover)}
|
|
139
|
+
<Tooltip x={plot.x(date) ?? 0} y={plot.height / 2}>
|
|
140
|
+
<strong>{loc.timeFormat(dateFormat)(date)}</strong>
|
|
141
|
+
{#each series as s, i}
|
|
142
|
+
{@const p = valueAt(s, date)}
|
|
143
|
+
{#if p}
|
|
144
|
+
<div><span style:color={colour(s, i)}>●</span> {name(s)}: <strong>{fmt(yValue(p))}</strong></div>
|
|
145
|
+
{/if}
|
|
146
|
+
{/each}
|
|
147
|
+
</Tooltip>
|
|
148
|
+
{/if}
|
|
149
|
+
</Html>
|
|
150
|
+
{/snippet}
|
|
151
|
+
</Plot>
|
|
152
|
+
|
|
153
|
+
{#if notes || source}
|
|
154
|
+
<Footer>
|
|
155
|
+
{#if notes}<Notes>{notes}</Notes>{/if}
|
|
156
|
+
{#if source}<Source>{source}</Source>{/if}
|
|
157
|
+
</Footer>
|
|
158
|
+
{/if}
|
|
159
|
+
</Chart>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
3
|
+
import { type PlotContext } from '../core/index.js';
|
|
4
|
+
import { type LocaleCode } from '../locale/index.js';
|
|
5
|
+
import { type Medium, type Theme } from '../styles/index.js';
|
|
6
|
+
declare function $$render<S, P>(): {
|
|
7
|
+
props: {
|
|
8
|
+
series: S[];
|
|
9
|
+
/** Points of one series, sorted by x. */
|
|
10
|
+
points: (s: S) => P[];
|
|
11
|
+
name: (s: S) => string;
|
|
12
|
+
x: (p: P) => Date;
|
|
13
|
+
y: (p: P) => number;
|
|
14
|
+
style?: Theme;
|
|
15
|
+
locale?: LocaleCode;
|
|
16
|
+
medium?: Medium;
|
|
17
|
+
width?: number;
|
|
18
|
+
title?: string;
|
|
19
|
+
subtitle?: string;
|
|
20
|
+
notes?: string;
|
|
21
|
+
source?: string;
|
|
22
|
+
alt?: string;
|
|
23
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
24
|
+
embed?: ChartEmbed;
|
|
25
|
+
format?: (n: number) => string;
|
|
26
|
+
/** Tooltip date format (d3-time-format specifier). */
|
|
27
|
+
dateFormat?: string;
|
|
28
|
+
color?: (s: S, index: number) => string;
|
|
29
|
+
/** Start the y axis at zero. */
|
|
30
|
+
zero?: boolean;
|
|
31
|
+
height?: number;
|
|
32
|
+
annotations?: Snippet<[PlotContext]>;
|
|
33
|
+
};
|
|
34
|
+
exports: {};
|
|
35
|
+
bindings: "";
|
|
36
|
+
slots: {};
|
|
37
|
+
events: {};
|
|
38
|
+
};
|
|
39
|
+
declare class __sveltets_Render<S, P> {
|
|
40
|
+
props(): ReturnType<typeof $$render<S, P>>['props'];
|
|
41
|
+
events(): ReturnType<typeof $$render<S, P>>['events'];
|
|
42
|
+
slots(): ReturnType<typeof $$render<S, P>>['slots'];
|
|
43
|
+
bindings(): "";
|
|
44
|
+
exports(): {};
|
|
45
|
+
}
|
|
46
|
+
interface $$IsomorphicComponent {
|
|
47
|
+
new <S, P>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<S, P>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<S, P>['props']>, ReturnType<__sveltets_Render<S, P>['events']>, ReturnType<__sveltets_Render<S, P>['slots']>> & {
|
|
48
|
+
$$bindings?: ReturnType<__sveltets_Render<S, P>['bindings']>;
|
|
49
|
+
} & ReturnType<__sveltets_Render<S, P>['exports']>;
|
|
50
|
+
<S, P>(internal: unknown, props: ReturnType<__sveltets_Render<S, P>['props']> & {}): ReturnType<__sveltets_Render<S, P>['exports']>;
|
|
51
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Recipe: a multi-series line chart with a legend, direct end labels and a
|
|
55
|
+
* crosshair tooltip. Series colours follow the series order in the theme's
|
|
56
|
+
* categorical palette. `mozaic eject LineChart` copies this file into your
|
|
57
|
+
* project.
|
|
58
|
+
*/
|
|
59
|
+
declare const LineChart: $$IsomorphicComponent;
|
|
60
|
+
type LineChart<S, P> = InstanceType<typeof LineChart<S, P>>;
|
|
61
|
+
export default LineChart;
|