@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,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;
|