@samizdata/mozaic 0.0.0-stage → 0.3.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 +107 -0
- package/dist/annotations/RefLine.svelte.d.ts +27 -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 +107 -0
- package/dist/guides/AxisY.svelte.d.ts +25 -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 +116 -0
- package/dist/interactive/Tooltip.svelte.d.ts +34 -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 +77 -0
- package/dist/marks/Waffle.svelte.d.ts +45 -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,256 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Recipe: a mosaic (Marimekko) chart. One 100% stacked bar per row, with each
|
|
4
|
+
row as tall as its weight (by default the sum of its values), so the area of
|
|
5
|
+
every cell is proportional to its value: votes by district, where the
|
|
6
|
+
height shows how many people voted there. Row labels sit at the right, nudged
|
|
7
|
+
apart where rows are thin. Optional: rows sorted by the share of some series,
|
|
8
|
+
a reference line, and series names written once inside their largest cell.
|
|
9
|
+
Use it as is, or run `mozaic eject MosaicChart` to copy this file into your
|
|
10
|
+
project and change anything.
|
|
11
|
+
-->
|
|
12
|
+
<script lang="ts" generics="T">
|
|
13
|
+
import type { Snippet } from 'svelte';
|
|
14
|
+
import { scaleLinear } from 'd3-scale';
|
|
15
|
+
import { group, sum } from 'd3-array';
|
|
16
|
+
import { Chart, Header, Title, Subtitle, Footer, Source, Notes } from '../frame/index.js';
|
|
17
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
18
|
+
import { Plot, Svg, estimateTextWidth, type PlotContext } from '../core/index.js';
|
|
19
|
+
import { Rects } from '../marks/index.js';
|
|
20
|
+
import { AxisX, Legend } from '../guides/index.js';
|
|
21
|
+
import { RefLine } from '../annotations/index.js';
|
|
22
|
+
import { avoidOverlap } from '../transforms/index.js';
|
|
23
|
+
import { createLocale, type LocaleCode } from '../locale/index.js';
|
|
24
|
+
import { base, contrastRatio, type Breakpoint, type Medium, type Theme } from '../styles/index.js';
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
/** Long format: one datum per row × series. */
|
|
28
|
+
data: T[];
|
|
29
|
+
row: (d: T) => string;
|
|
30
|
+
series: (d: T) => string;
|
|
31
|
+
value: (d: T) => number;
|
|
32
|
+
/** Row height weight; defaults to the sum of the row's values. */
|
|
33
|
+
weight?: (row: string) => number;
|
|
34
|
+
/** Stacking order, left to right. Defaults to first appearance. */
|
|
35
|
+
seriesOrder?: string[];
|
|
36
|
+
/** Sort rows by the combined share of these series, largest first. Defaults to the order given. */
|
|
37
|
+
sortBy?: string[];
|
|
38
|
+
color?: (series: string) => string;
|
|
39
|
+
seriesLabel?: (series: string) => string;
|
|
40
|
+
/** Legend items; defaults to one per series. Pass [] to hide the legend. */
|
|
41
|
+
legend?: { label: string; color: string }[];
|
|
42
|
+
/** Series named once inside their largest cell, when the name fits. */
|
|
43
|
+
labelSeries?: string[];
|
|
44
|
+
/** Vertical reference line at this share (0–1), e.g. 0.5. */
|
|
45
|
+
reference?: number;
|
|
46
|
+
referenceLabel?: string;
|
|
47
|
+
style?: Theme;
|
|
48
|
+
locale?: LocaleCode;
|
|
49
|
+
medium?: Medium;
|
|
50
|
+
width?: number;
|
|
51
|
+
title?: string;
|
|
52
|
+
subtitle?: string;
|
|
53
|
+
notes?: string;
|
|
54
|
+
source?: string;
|
|
55
|
+
alt?: string;
|
|
56
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
57
|
+
embed?: ChartEmbed;
|
|
58
|
+
/** Share format (0–1) for tooltips; defaults to a locale percentage with one decimal. */
|
|
59
|
+
format?: (share: number) => string;
|
|
60
|
+
/** Plot height in px, or a function of the outer width and breakpoint. Defaults to enough room for every row label, and at least 480 px. */
|
|
61
|
+
height?: number | ((size: { width: number; breakpoint: Breakpoint }) => number);
|
|
62
|
+
/** Extra SVG drawn on top of the cells; receives the plot context. */
|
|
63
|
+
annotations?: Snippet<[PlotContext]>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let {
|
|
67
|
+
data,
|
|
68
|
+
row,
|
|
69
|
+
series,
|
|
70
|
+
value,
|
|
71
|
+
weight,
|
|
72
|
+
seriesOrder,
|
|
73
|
+
sortBy,
|
|
74
|
+
color,
|
|
75
|
+
seriesLabel = (s) => s,
|
|
76
|
+
legend,
|
|
77
|
+
labelSeries = [],
|
|
78
|
+
reference,
|
|
79
|
+
referenceLabel,
|
|
80
|
+
style = base,
|
|
81
|
+
locale,
|
|
82
|
+
medium,
|
|
83
|
+
width,
|
|
84
|
+
title,
|
|
85
|
+
subtitle,
|
|
86
|
+
notes,
|
|
87
|
+
source,
|
|
88
|
+
alt,
|
|
89
|
+
embed,
|
|
90
|
+
format,
|
|
91
|
+
height,
|
|
92
|
+
annotations
|
|
93
|
+
}: Props = $props();
|
|
94
|
+
|
|
95
|
+
const theme = $derived(style);
|
|
96
|
+
const loc = $derived(createLocale(locale ?? theme.defaultLocale));
|
|
97
|
+
const fmt = $derived(format ?? ((s: number) => loc.format('.1%')(s)));
|
|
98
|
+
const fontSize = $derived(theme.plot.fontSize);
|
|
99
|
+
const ink = $derived(theme.tokens['--mz-color-text'] ?? '#000');
|
|
100
|
+
const paper = $derived(theme.tokens['--mz-color-bg'] ?? '#fff');
|
|
101
|
+
|
|
102
|
+
const order = $derived(seriesOrder ?? [...new Set(data.map(series))]);
|
|
103
|
+
const colorOf = $derived(
|
|
104
|
+
(s: string) => color?.(s) ?? theme.palettes.categorical[order.indexOf(s) % theme.palettes.categorical.length]
|
|
105
|
+
);
|
|
106
|
+
const textOn = (fill: string) => (contrastRatio(fill, paper) >= contrastRatio(fill, ink) ? paper : ink);
|
|
107
|
+
const legendItems = $derived(legend ?? order.map((s) => ({ label: seriesLabel(s), color: colorOf(s) })));
|
|
108
|
+
|
|
109
|
+
interface Cell {
|
|
110
|
+
row: string;
|
|
111
|
+
series: string;
|
|
112
|
+
share: number;
|
|
113
|
+
/** Share axis, 0–1. */
|
|
114
|
+
x0: number;
|
|
115
|
+
x1: number;
|
|
116
|
+
/** Cumulative weight axis, top to bottom. */
|
|
117
|
+
y0: number;
|
|
118
|
+
y1: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const layout = $derived.by(() => {
|
|
122
|
+
const byRow = group(data, row);
|
|
123
|
+
const rows = [...byRow].map(([name, ds]) => {
|
|
124
|
+
const total = sum(ds, value);
|
|
125
|
+
const share = (s: string) =>
|
|
126
|
+
sum(
|
|
127
|
+
ds.filter((d) => series(d) === s),
|
|
128
|
+
value
|
|
129
|
+
) / (total || 1);
|
|
130
|
+
return { name, total, weight: weight?.(name) ?? total, share };
|
|
131
|
+
});
|
|
132
|
+
if (sortBy) {
|
|
133
|
+
const key = (r: (typeof rows)[number]) => sum(sortBy, r.share);
|
|
134
|
+
rows.sort((a, b) => key(b) - key(a));
|
|
135
|
+
}
|
|
136
|
+
const cells: Cell[] = [];
|
|
137
|
+
const bands: { name: string; y0: number; y1: number }[] = [];
|
|
138
|
+
let y = 0;
|
|
139
|
+
for (const r of rows) {
|
|
140
|
+
let x = 0;
|
|
141
|
+
for (const s of order) {
|
|
142
|
+
const share = r.share(s);
|
|
143
|
+
if (share > 0) cells.push({ row: r.name, series: s, share, x0: x, x1: x + share, y0: y, y1: y + r.weight });
|
|
144
|
+
x += share;
|
|
145
|
+
}
|
|
146
|
+
bands.push({ name: r.name, y0: y, y1: y + r.weight });
|
|
147
|
+
y += r.weight;
|
|
148
|
+
}
|
|
149
|
+
return { cells, bands, total: y };
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const x = scaleLinear().domain([0, 1]);
|
|
153
|
+
const y = $derived(scaleLinear().domain([0, layout.total]));
|
|
154
|
+
const plotHeight = $derived(
|
|
155
|
+
height ??
|
|
156
|
+
(({ width: w }: { width: number }) =>
|
|
157
|
+
Math.max(480, layout.bands.length * (fontSize + 4) * 1.4, Math.min(900, w * 1.1)))
|
|
158
|
+
);
|
|
159
|
+
const right = $derived(Math.max(...layout.bands.map((b) => estimateTextWidth(b.name, fontSize))) + 18);
|
|
160
|
+
|
|
161
|
+
/** Row labels at the centre of each row, nudged apart; a short tick joins a moved label to its row. */
|
|
162
|
+
function rowLabels(plot: PlotContext) {
|
|
163
|
+
const centres = layout.bands.map((b) => ((plot.y(b.y0) ?? 0) + (plot.y(b.y1) ?? 0)) / 2);
|
|
164
|
+
const placed = avoidOverlap(centres, fontSize + 1, [fontSize / 2, plot.height - fontSize / 2]);
|
|
165
|
+
return layout.bands.map((b, i) => ({ name: b.name, at: centres[i], y: placed[i] }));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Each labelled series named in its largest cell that holds the name. */
|
|
169
|
+
function seriesLabels(plot: PlotContext) {
|
|
170
|
+
return labelSeries.flatMap((s) => {
|
|
171
|
+
const text = seriesLabel(s);
|
|
172
|
+
const w = estimateTextWidth(text, fontSize) + 12;
|
|
173
|
+
const fits = layout.cells
|
|
174
|
+
.filter((c) => c.series === s)
|
|
175
|
+
.map((c) => ({
|
|
176
|
+
c,
|
|
177
|
+
x0: plot.x(c.x0) ?? 0,
|
|
178
|
+
x1: plot.x(c.x1) ?? 0,
|
|
179
|
+
y0: plot.y(c.y0) ?? 0,
|
|
180
|
+
y1: plot.y(c.y1) ?? 0
|
|
181
|
+
}))
|
|
182
|
+
.filter((r) => r.x1 - r.x0 >= w && r.y1 - r.y0 >= fontSize + 8)
|
|
183
|
+
.sort((a, b) => (b.x1 - b.x0) * (b.y1 - b.y0) - (a.x1 - a.x0) * (a.y1 - a.y0));
|
|
184
|
+
const best = fits[0];
|
|
185
|
+
return best ? [{ text, x: (best.x0 + best.x1) / 2, y: (best.y0 + best.y1) / 2, fill: textOn(colorOf(s)) }] : [];
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
</script>
|
|
189
|
+
|
|
190
|
+
<Chart {style} {locale} {medium} {width} {alt} {embed}>
|
|
191
|
+
{#if title || subtitle || legendItems.length > 1}
|
|
192
|
+
<Header>
|
|
193
|
+
{#if title}<Title>{title}</Title>{/if}
|
|
194
|
+
{#if subtitle}<Subtitle>{subtitle}</Subtitle>{/if}
|
|
195
|
+
{#if legendItems.length > 1}<Legend items={legendItems} />{/if}
|
|
196
|
+
</Header>
|
|
197
|
+
{/if}
|
|
198
|
+
|
|
199
|
+
<Plot {x} {y} yRange={({ height: h }) => [0, h]} height={plotHeight} padding={{ left: 0, right, top: 0, bottom: 24 }}>
|
|
200
|
+
{#snippet children(plot)}
|
|
201
|
+
<Svg>
|
|
202
|
+
<AxisX ticks={4} format={(v) => loc.format('.0%')(v)} />
|
|
203
|
+
<Rects
|
|
204
|
+
data={layout.cells}
|
|
205
|
+
x={(c) => c.x0}
|
|
206
|
+
x2={(c) => c.x1}
|
|
207
|
+
y={(c) => c.y0}
|
|
208
|
+
y2={(c) => c.y1}
|
|
209
|
+
fill={(c) => colorOf(c.series)}
|
|
210
|
+
stroke={paper}
|
|
211
|
+
title={(c) => `${c.row} · ${seriesLabel(c.series)}: ${fmt(c.share)}`}
|
|
212
|
+
/>
|
|
213
|
+
{#each seriesLabels(plot) as l (l.text)}
|
|
214
|
+
<text class="mz-mosaic-series" x={l.x} y={l.y} dy="0.35em" text-anchor="middle" fill={l.fill}>{l.text}</text>
|
|
215
|
+
{/each}
|
|
216
|
+
{#if reference !== undefined}
|
|
217
|
+
<RefLine x={reference} label={referenceLabel} />
|
|
218
|
+
{/if}
|
|
219
|
+
{#each rowLabels(plot) as l (l.name)}
|
|
220
|
+
<g class="mz-mosaic-row">
|
|
221
|
+
{#if Math.abs(l.y - l.at) > 2}
|
|
222
|
+
<path d="M{plot.width + 1},{l.at} L{plot.width + 5},{l.y}" />
|
|
223
|
+
{/if}
|
|
224
|
+
<text x={plot.width + 7} y={l.y} dy="0.35em">{l.name}</text>
|
|
225
|
+
</g>
|
|
226
|
+
{/each}
|
|
227
|
+
{@render annotations?.(plot)}
|
|
228
|
+
</Svg>
|
|
229
|
+
{/snippet}
|
|
230
|
+
</Plot>
|
|
231
|
+
|
|
232
|
+
{#if notes || source}
|
|
233
|
+
<Footer>
|
|
234
|
+
{#if notes}<Notes>{notes}</Notes>{/if}
|
|
235
|
+
{#if source}<Source>{source}</Source>{/if}
|
|
236
|
+
</Footer>
|
|
237
|
+
{/if}
|
|
238
|
+
</Chart>
|
|
239
|
+
|
|
240
|
+
<style>
|
|
241
|
+
.mz-mosaic-row text,
|
|
242
|
+
.mz-mosaic-series {
|
|
243
|
+
font-family: var(--mz-font-body);
|
|
244
|
+
font-size: var(--mz-size-axis);
|
|
245
|
+
}
|
|
246
|
+
.mz-mosaic-row text {
|
|
247
|
+
fill: var(--mz-color-text);
|
|
248
|
+
}
|
|
249
|
+
.mz-mosaic-row path {
|
|
250
|
+
fill: none;
|
|
251
|
+
stroke: var(--mz-color-axis);
|
|
252
|
+
}
|
|
253
|
+
.mz-mosaic-series {
|
|
254
|
+
font-weight: var(--mz-weight-strong);
|
|
255
|
+
}
|
|
256
|
+
</style>
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Recipe: a scatter plot with optional bubble sizes, colour groups, labels for
|
|
4
|
+
selected points and a nearest-point tooltip. `mozaic eject ScatterChart`
|
|
5
|
+
copies this file into your project.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts" generics="T">
|
|
8
|
+
import type { Snippet } from 'svelte';
|
|
9
|
+
import { scaleLinear, scaleSqrt } from 'd3-scale';
|
|
10
|
+
import { extent, max } 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, type PlotContext } from '../core/index.js';
|
|
14
|
+
import { Points, Voronoi } from '../marks/index.js';
|
|
15
|
+
import { AxisX, AxisY, GridX, GridY, Legend } from '../guides/index.js';
|
|
16
|
+
import { Label } from '../annotations/index.js';
|
|
17
|
+
import { Tooltip } from '../interactive/index.js';
|
|
18
|
+
import { createLocale, type LocaleCode } from '../locale/index.js';
|
|
19
|
+
import { base, type Medium, type Theme } from '../styles/index.js';
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
data: T[];
|
|
23
|
+
x: (d: T) => number;
|
|
24
|
+
y: (d: T) => number;
|
|
25
|
+
/** Name shown in the tooltip and labels. */
|
|
26
|
+
name: (d: T) => string;
|
|
27
|
+
/** Optional size value (bubble chart). */
|
|
28
|
+
size?: (d: T) => number;
|
|
29
|
+
/** Optional colour group. */
|
|
30
|
+
group?: (d: T) => string;
|
|
31
|
+
/** Points to label permanently. */
|
|
32
|
+
labelled?: (d: T) => boolean;
|
|
33
|
+
style?: Theme;
|
|
34
|
+
locale?: LocaleCode;
|
|
35
|
+
medium?: Medium;
|
|
36
|
+
width?: number;
|
|
37
|
+
title?: string;
|
|
38
|
+
subtitle?: string;
|
|
39
|
+
notes?: string;
|
|
40
|
+
source?: string;
|
|
41
|
+
alt?: string;
|
|
42
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
43
|
+
embed?: ChartEmbed;
|
|
44
|
+
xLabel?: string;
|
|
45
|
+
yLabel?: string;
|
|
46
|
+
xFormat?: (n: number) => string;
|
|
47
|
+
yFormat?: (n: number) => string;
|
|
48
|
+
height?: number;
|
|
49
|
+
annotations?: Snippet<[PlotContext]>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let {
|
|
53
|
+
data,
|
|
54
|
+
x: xValue,
|
|
55
|
+
y: yValue,
|
|
56
|
+
name,
|
|
57
|
+
size,
|
|
58
|
+
group,
|
|
59
|
+
labelled,
|
|
60
|
+
style = base,
|
|
61
|
+
locale,
|
|
62
|
+
medium,
|
|
63
|
+
width,
|
|
64
|
+
title,
|
|
65
|
+
subtitle,
|
|
66
|
+
notes,
|
|
67
|
+
source,
|
|
68
|
+
alt,
|
|
69
|
+
embed,
|
|
70
|
+
xLabel,
|
|
71
|
+
yLabel,
|
|
72
|
+
xFormat,
|
|
73
|
+
yFormat,
|
|
74
|
+
height = 360,
|
|
75
|
+
annotations
|
|
76
|
+
}: Props = $props();
|
|
77
|
+
|
|
78
|
+
const theme = $derived(style);
|
|
79
|
+
const loc = $derived(createLocale(locale ?? theme.defaultLocale));
|
|
80
|
+
const x = $derived(
|
|
81
|
+
scaleLinear()
|
|
82
|
+
.domain(extent(data, xValue) as [number, number])
|
|
83
|
+
.nice()
|
|
84
|
+
);
|
|
85
|
+
const y = $derived(
|
|
86
|
+
scaleLinear()
|
|
87
|
+
.domain(extent(data, yValue) as [number, number])
|
|
88
|
+
.nice()
|
|
89
|
+
);
|
|
90
|
+
const r = $derived(
|
|
91
|
+
size
|
|
92
|
+
? scaleSqrt()
|
|
93
|
+
.domain([0, max(data, size) ?? 1])
|
|
94
|
+
.range([0, 18])
|
|
95
|
+
: () => 5
|
|
96
|
+
);
|
|
97
|
+
const groups = $derived(group ? [...new Set(data.map(group))] : []);
|
|
98
|
+
const colour = (d: T) =>
|
|
99
|
+
group
|
|
100
|
+
? theme.palettes.categorical[groups.indexOf(group(d)) % theme.palettes.categorical.length]
|
|
101
|
+
: theme.palettes.categorical[0];
|
|
102
|
+
let hovered = $state<T | null>(null);
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<Chart {style} {locale} {medium} {width} {alt} {embed}>
|
|
106
|
+
<Header>
|
|
107
|
+
{#if title}<Title>{title}</Title>{/if}
|
|
108
|
+
{#if subtitle}<Subtitle>{subtitle}</Subtitle>{/if}
|
|
109
|
+
{#if groups.length > 1}
|
|
110
|
+
<Legend
|
|
111
|
+
shape="circle"
|
|
112
|
+
items={groups.map((g, i) => ({
|
|
113
|
+
label: g,
|
|
114
|
+
color: theme.palettes.categorical[i % theme.palettes.categorical.length]
|
|
115
|
+
}))}
|
|
116
|
+
/>
|
|
117
|
+
{/if}
|
|
118
|
+
</Header>
|
|
119
|
+
|
|
120
|
+
<Plot {x} {y} {height} padding={{ left: 44, right: 16, top: 16, bottom: 36 }}>
|
|
121
|
+
{#snippet children(plot)}
|
|
122
|
+
<Svg>
|
|
123
|
+
<GridX ticks={5} />
|
|
124
|
+
<GridY ticks={5} />
|
|
125
|
+
<AxisX ticks={5} format={xFormat} label={xLabel} />
|
|
126
|
+
<AxisY ticks={5} format={yFormat} label={yLabel} />
|
|
127
|
+
<Points
|
|
128
|
+
{data}
|
|
129
|
+
x={xValue}
|
|
130
|
+
y={yValue}
|
|
131
|
+
r={(d) => (size ? r(size(d)) : 5)}
|
|
132
|
+
fill={colour}
|
|
133
|
+
opacity={(d) => (hovered && hovered !== d ? 0.35 : size ? 0.75 : 0.9)}
|
|
134
|
+
/>
|
|
135
|
+
{#if labelled}
|
|
136
|
+
{#each data.filter(labelled) as d}
|
|
137
|
+
<Label x={xValue(d)} y={yValue(d)} label={name(d)} dx={(size ? r(size(d)) : 5) + 4} />
|
|
138
|
+
{/each}
|
|
139
|
+
{/if}
|
|
140
|
+
{@render annotations?.(plot)}
|
|
141
|
+
<Voronoi
|
|
142
|
+
{data}
|
|
143
|
+
x={xValue}
|
|
144
|
+
y={yValue}
|
|
145
|
+
onpointerenter={(d) => (hovered = d)}
|
|
146
|
+
onpointerleave={() => (hovered = null)}
|
|
147
|
+
/>
|
|
148
|
+
</Svg>
|
|
149
|
+
<Html>
|
|
150
|
+
{#if hovered}
|
|
151
|
+
<Tooltip x={plot.x(xValue(hovered)) ?? 0} y={plot.y(yValue(hovered)) ?? 0}>
|
|
152
|
+
<strong>{name(hovered)}</strong><br />
|
|
153
|
+
{xLabel ?? 'x'}: {(xFormat ?? loc.number)(xValue(hovered))}<br />
|
|
154
|
+
{yLabel ?? 'y'}: {(yFormat ?? loc.number)(yValue(hovered))}
|
|
155
|
+
</Tooltip>
|
|
156
|
+
{/if}
|
|
157
|
+
</Html>
|
|
158
|
+
{/snippet}
|
|
159
|
+
</Plot>
|
|
160
|
+
|
|
161
|
+
{#if notes || source}
|
|
162
|
+
<Footer>
|
|
163
|
+
{#if notes}<Notes>{notes}</Notes>{/if}
|
|
164
|
+
{#if source}<Source>{source}</Source>{/if}
|
|
165
|
+
</Footer>
|
|
166
|
+
{/if}
|
|
167
|
+
</Chart>
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Recipe: 100% stacked bars. One horizontal bar per row, split into the share
|
|
4
|
+
of each series, with the series name and share written inside segments wide
|
|
5
|
+
enough to hold them. Optional: a reference line (e.g. at 50%), brackets above
|
|
6
|
+
the first bar that group neighbouring series ("pro-European", "pro-Russian"),
|
|
7
|
+
and a legend that lists groups of series instead of every series.
|
|
8
|
+
Use it as is, or run `mozaic eject StackedBarChart` to copy this file into
|
|
9
|
+
your project and change anything.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts" generics="T">
|
|
12
|
+
import type { Snippet } from 'svelte';
|
|
13
|
+
import { scaleBand, scaleLinear } from 'd3-scale';
|
|
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 { Rects } from '../marks/index.js';
|
|
18
|
+
import { AxisX, AxisY, Legend } from '../guides/index.js';
|
|
19
|
+
import { RefLine } from '../annotations/index.js';
|
|
20
|
+
import { stack } from '../transforms/index.js';
|
|
21
|
+
import { createLocale, type LocaleCode } from '../locale/index.js';
|
|
22
|
+
import { base, contrastRatio, type Medium, type Theme } from '../styles/index.js';
|
|
23
|
+
|
|
24
|
+
interface Group {
|
|
25
|
+
label: string;
|
|
26
|
+
/** First and last series of the group, in stacking order. */
|
|
27
|
+
from: string;
|
|
28
|
+
to: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface Props {
|
|
32
|
+
/** Long format: one datum per row × series. */
|
|
33
|
+
data: T[];
|
|
34
|
+
row: (d: T) => string;
|
|
35
|
+
series: (d: T) => string;
|
|
36
|
+
value: (d: T) => number;
|
|
37
|
+
/** Stacking order, left to right. Defaults to first appearance. */
|
|
38
|
+
seriesOrder?: string[];
|
|
39
|
+
/** Segment colour per series; defaults to the categorical palette. */
|
|
40
|
+
color?: (series: string) => string;
|
|
41
|
+
/** Name written inside segments and in the default legend; defaults to the series key. */
|
|
42
|
+
seriesLabel?: (series: string) => string;
|
|
43
|
+
/** Legend items; defaults to one per series. Pass [] to hide the legend. */
|
|
44
|
+
legend?: { label: string; color: string }[];
|
|
45
|
+
/** Brackets above the first bar. */
|
|
46
|
+
groups?: Group[];
|
|
47
|
+
/** Vertical reference line at this share (0–1), e.g. 0.5. */
|
|
48
|
+
reference?: number;
|
|
49
|
+
referenceLabel?: string;
|
|
50
|
+
/** Smallest share that gets a label inside its segment (it must also fit). */
|
|
51
|
+
labelMin?: number;
|
|
52
|
+
style?: Theme;
|
|
53
|
+
locale?: LocaleCode;
|
|
54
|
+
medium?: Medium;
|
|
55
|
+
width?: number;
|
|
56
|
+
title?: string;
|
|
57
|
+
subtitle?: string;
|
|
58
|
+
notes?: string;
|
|
59
|
+
source?: string;
|
|
60
|
+
alt?: string;
|
|
61
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
62
|
+
embed?: ChartEmbed;
|
|
63
|
+
/** Share format (0–1); defaults to a locale percentage with one decimal. */
|
|
64
|
+
format?: (share: number) => string;
|
|
65
|
+
rowHeight?: number;
|
|
66
|
+
/** Extra SVG drawn on top of the bars; receives the plot context. */
|
|
67
|
+
annotations?: Snippet<[PlotContext]>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let {
|
|
71
|
+
data,
|
|
72
|
+
row,
|
|
73
|
+
series,
|
|
74
|
+
value,
|
|
75
|
+
seriesOrder,
|
|
76
|
+
color,
|
|
77
|
+
seriesLabel = (s) => s,
|
|
78
|
+
legend,
|
|
79
|
+
groups = [],
|
|
80
|
+
reference,
|
|
81
|
+
referenceLabel,
|
|
82
|
+
labelMin = 0.08,
|
|
83
|
+
style = base,
|
|
84
|
+
locale,
|
|
85
|
+
medium,
|
|
86
|
+
width,
|
|
87
|
+
title,
|
|
88
|
+
subtitle,
|
|
89
|
+
notes,
|
|
90
|
+
source,
|
|
91
|
+
alt,
|
|
92
|
+
embed,
|
|
93
|
+
format,
|
|
94
|
+
rowHeight = 64,
|
|
95
|
+
annotations
|
|
96
|
+
}: Props = $props();
|
|
97
|
+
|
|
98
|
+
const theme = $derived(style);
|
|
99
|
+
const loc = $derived(createLocale(locale ?? theme.defaultLocale));
|
|
100
|
+
const fmt = $derived(format ?? ((s: number) => loc.format('.1%')(s)));
|
|
101
|
+
const fontSize = $derived(theme.plot.fontSize);
|
|
102
|
+
const ink = $derived(theme.tokens['--mz-color-text'] ?? '#000');
|
|
103
|
+
const paper = $derived(theme.tokens['--mz-color-bg'] ?? '#fff');
|
|
104
|
+
|
|
105
|
+
const segments = $derived(stack(data, { key: row, series, value, seriesOrder, offset: 'expand' }));
|
|
106
|
+
const order = $derived(seriesOrder ?? [...new Set(data.map(series))]);
|
|
107
|
+
const colorOf = $derived(
|
|
108
|
+
(s: string) => color?.(s) ?? theme.palettes.categorical[order.indexOf(s) % theme.palettes.categorical.length]
|
|
109
|
+
);
|
|
110
|
+
/** Ink or paper, whichever reads better on the segment. */
|
|
111
|
+
const textOn = (fill: string) => (contrastRatio(fill, paper) >= contrastRatio(fill, ink) ? paper : ink);
|
|
112
|
+
const legendItems = $derived(legend ?? order.map((s) => ({ label: seriesLabel(s), color: colorOf(s) })));
|
|
113
|
+
|
|
114
|
+
const rows = $derived([...new Set(data.map(row))]);
|
|
115
|
+
const single = $derived(rows.length === 1);
|
|
116
|
+
const x = scaleLinear().domain([0, 1]);
|
|
117
|
+
const y = $derived(scaleBand<string>().domain(rows).paddingInner(0.25));
|
|
118
|
+
const left = $derived(single ? 0 : Math.max(...rows.map((r) => estimateTextWidth(r, fontSize))) + 12);
|
|
119
|
+
const bracketSpace = $derived(groups.length ? fontSize + 14 : 0);
|
|
120
|
+
|
|
121
|
+
/** Segment labels: name over value, when both lines fit the segment. */
|
|
122
|
+
function segmentLabel(plot: PlotContext, s: (typeof segments)[number]) {
|
|
123
|
+
const w = (plot.x(s.end) ?? 0) - (plot.x(s.start) ?? 0);
|
|
124
|
+
const name = seriesLabel(s.series);
|
|
125
|
+
const share = fmt(s.end - s.start);
|
|
126
|
+
const needed = Math.max(estimateTextWidth(name, fontSize), estimateTextWidth(share, fontSize)) + 8;
|
|
127
|
+
const tall = plot.y.bandwidth!() >= fontSize * 2.6;
|
|
128
|
+
if (s.end - s.start < labelMin || w < needed || !tall) return null;
|
|
129
|
+
return { x: plot.x((s.start + s.end) / 2) ?? 0, name, share };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Brackets over the first bar, labels kept inside the plot. */
|
|
133
|
+
function brackets(plot: PlotContext) {
|
|
134
|
+
const first = segments.filter((s) => s.key === rows[0]);
|
|
135
|
+
return groups.flatMap((g) => {
|
|
136
|
+
const a = first.find((s) => s.series === g.from);
|
|
137
|
+
const b = first.find((s) => s.series === g.to);
|
|
138
|
+
if (!a || !b) return [];
|
|
139
|
+
const x0 = (plot.x(a.start) ?? 0) + 1;
|
|
140
|
+
const x1 = (plot.x(b.end) ?? 0) - 1;
|
|
141
|
+
const half = estimateTextWidth(g.label, fontSize) / 2;
|
|
142
|
+
const mid = Math.min(plot.width - half, Math.max(half, (x0 + x1) / 2));
|
|
143
|
+
return [{ label: g.label, x0, x1, mid }];
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<Chart {style} {locale} {medium} {width} {alt} {embed}>
|
|
149
|
+
{#if title || subtitle || legendItems.length > 1}
|
|
150
|
+
<Header>
|
|
151
|
+
{#if title}<Title>{title}</Title>{/if}
|
|
152
|
+
{#if subtitle}<Subtitle>{subtitle}</Subtitle>{/if}
|
|
153
|
+
{#if legendItems.length > 1}<Legend items={legendItems} />{/if}
|
|
154
|
+
</Header>
|
|
155
|
+
{/if}
|
|
156
|
+
|
|
157
|
+
<Plot {x} {y} height={rows.length * rowHeight} padding={{ left, right: 4, top: bracketSpace, bottom: 24 }}>
|
|
158
|
+
{#snippet children(plot)}
|
|
159
|
+
<Svg>
|
|
160
|
+
<AxisX ticks={4} format={(v) => loc.format('.0%')(v)} />
|
|
161
|
+
{#if !single}<AxisY />{/if}
|
|
162
|
+
<Rects
|
|
163
|
+
data={segments}
|
|
164
|
+
x={(s) => s.start}
|
|
165
|
+
x2={(s) => s.end}
|
|
166
|
+
y={(s) => s.key as string}
|
|
167
|
+
fill={(s) => colorOf(s.series)}
|
|
168
|
+
stroke={paper}
|
|
169
|
+
title={(s) => `${single ? '' : `${s.key} · `}${seriesLabel(s.series)}: ${fmt(s.end - s.start)}`}
|
|
170
|
+
/>
|
|
171
|
+
{#each segments as s (`${s.key}\u0000${s.series}`)}
|
|
172
|
+
{@const l = segmentLabel(plot, s)}
|
|
173
|
+
{#if l}
|
|
174
|
+
{@const cy = scaled(plot.y, s.key)}
|
|
175
|
+
<text class="mz-stacked-label" x={l.x} y={cy} fill={textOn(colorOf(s.series))} text-anchor="middle">
|
|
176
|
+
<tspan x={l.x} dy="-0.25em">{l.name}</tspan>
|
|
177
|
+
<tspan class="strong" x={l.x} dy="1.2em">{l.share}</tspan>
|
|
178
|
+
</text>
|
|
179
|
+
{/if}
|
|
180
|
+
{/each}
|
|
181
|
+
{#if reference !== undefined}
|
|
182
|
+
<RefLine x={reference} label={referenceLabel} />
|
|
183
|
+
{/if}
|
|
184
|
+
{#each brackets(plot) as b (b.label)}
|
|
185
|
+
<g class="mz-stacked-bracket">
|
|
186
|
+
<path d="M{b.x0},-2 v-5 H{b.x1} v5" />
|
|
187
|
+
<text x={b.mid} y={-11} text-anchor="middle">{b.label}</text>
|
|
188
|
+
</g>
|
|
189
|
+
{/each}
|
|
190
|
+
{@render annotations?.(plot)}
|
|
191
|
+
</Svg>
|
|
192
|
+
{/snippet}
|
|
193
|
+
</Plot>
|
|
194
|
+
|
|
195
|
+
{#if notes || source}
|
|
196
|
+
<Footer>
|
|
197
|
+
{#if notes}<Notes>{notes}</Notes>{/if}
|
|
198
|
+
{#if source}<Source>{source}</Source>{/if}
|
|
199
|
+
</Footer>
|
|
200
|
+
{/if}
|
|
201
|
+
</Chart>
|
|
202
|
+
|
|
203
|
+
<style>
|
|
204
|
+
.mz-stacked-label,
|
|
205
|
+
.mz-stacked-bracket text {
|
|
206
|
+
font-family: var(--mz-font-body);
|
|
207
|
+
font-size: var(--mz-size-axis);
|
|
208
|
+
font-variant-numeric: tabular-nums;
|
|
209
|
+
}
|
|
210
|
+
.mz-stacked-bracket text {
|
|
211
|
+
fill: var(--mz-color-text);
|
|
212
|
+
font-weight: var(--mz-weight-strong);
|
|
213
|
+
}
|
|
214
|
+
.mz-stacked-bracket path {
|
|
215
|
+
fill: none;
|
|
216
|
+
stroke: var(--mz-color-text);
|
|
217
|
+
stroke-width: 1.5;
|
|
218
|
+
}
|
|
219
|
+
.strong {
|
|
220
|
+
font-weight: var(--mz-weight-strong);
|
|
221
|
+
}
|
|
222
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { default as BarChart } from './BarChart.svelte';
|
|
2
|
+
export { default as ColumnChart } from './ColumnChart.svelte';
|
|
3
|
+
export { default as LineChart } from './LineChart.svelte';
|
|
4
|
+
export { default as ScatterChart } from './ScatterChart.svelte';
|
|
5
|
+
export { default as ArrowChart } from './ArrowChart.svelte';
|
|
6
|
+
export { default as BarDotChart } from './BarDotChart.svelte';
|
|
7
|
+
export { default as StackedBarChart } from './StackedBarChart.svelte';
|
|
8
|
+
export { default as MosaicChart } from './MosaicChart.svelte';
|
|
9
|
+
|
|
10
|
+
/** Recipe names accepted by `mozaic eject`. */
|
|
11
|
+
export const recipes = [
|
|
12
|
+
'BarChart',
|
|
13
|
+
'ColumnChart',
|
|
14
|
+
'LineChart',
|
|
15
|
+
'ScatterChart',
|
|
16
|
+
'ArrowChart',
|
|
17
|
+
'BarDotChart',
|
|
18
|
+
'StackedBarChart',
|
|
19
|
+
'MosaicChart'
|
|
20
|
+
] as const;
|