@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.
Files changed (232) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +44 -2
  3. package/dist/annotations/Arrow.svelte +50 -0
  4. package/dist/annotations/Arrow.svelte.d.ts +18 -0
  5. package/dist/annotations/Callout.svelte +87 -0
  6. package/dist/annotations/Callout.svelte.d.ts +22 -0
  7. package/dist/annotations/Label.svelte +55 -0
  8. package/dist/annotations/Label.svelte.d.ts +19 -0
  9. package/dist/annotations/RefBand.svelte +46 -0
  10. package/dist/annotations/RefBand.svelte.d.ts +18 -0
  11. package/dist/annotations/RefLine.svelte +72 -0
  12. package/dist/annotations/RefLine.svelte.d.ts +19 -0
  13. package/dist/annotations/callout-geometry.d.ts +23 -0
  14. package/dist/annotations/callout-geometry.js +45 -0
  15. package/dist/annotations/index.d.ts +6 -0
  16. package/dist/annotations/index.js +6 -0
  17. package/dist/core/Canvas.svelte +55 -0
  18. package/dist/core/Canvas.svelte.d.ts +19 -0
  19. package/dist/core/Facets.svelte +80 -0
  20. package/dist/core/Facets.svelte.d.ts +49 -0
  21. package/dist/core/Html.svelte +38 -0
  22. package/dist/core/Html.svelte.d.ts +13 -0
  23. package/dist/core/Plot.svelte +202 -0
  24. package/dist/core/Plot.svelte.d.ts +60 -0
  25. package/dist/core/Svg.svelte +58 -0
  26. package/dist/core/Svg.svelte.d.ts +17 -0
  27. package/dist/core/accessor.d.ts +5 -0
  28. package/dist/core/accessor.js +3 -0
  29. package/dist/core/context.d.ts +25 -0
  30. package/dist/core/context.js +69 -0
  31. package/dist/core/index.d.ts +10 -0
  32. package/dist/core/index.js +9 -0
  33. package/dist/core/scales.d.ts +16 -0
  34. package/dist/core/scales.js +32 -0
  35. package/dist/core/types.d.ts +78 -0
  36. package/dist/core/types.js +1 -0
  37. package/dist/core/units.d.ts +6 -0
  38. package/dist/core/units.js +10 -0
  39. package/dist/embed/Embed.svelte +50 -0
  40. package/dist/embed/Embed.svelte.d.ts +14 -0
  41. package/dist/embed/code.d.ts +18 -0
  42. package/dist/embed/code.js +9 -0
  43. package/dist/embed/host.d.ts +6 -0
  44. package/dist/embed/host.js +20 -0
  45. package/dist/embed/index.d.ts +6 -0
  46. package/dist/embed/index.js +5 -0
  47. package/dist/embed/manifest.d.ts +16 -0
  48. package/dist/embed/manifest.js +1 -0
  49. package/dist/embed/params.svelte.d.ts +10 -0
  50. package/dist/embed/params.svelte.js +27 -0
  51. package/dist/embed/resize.d.ts +13 -0
  52. package/dist/embed/resize.js +28 -0
  53. package/dist/export/download.d.ts +13 -0
  54. package/dist/export/download.js +52 -0
  55. package/dist/export/figure-to-svg.d.ts +21 -0
  56. package/dist/export/figure-to-svg.js +187 -0
  57. package/dist/export/fonts.d.ts +26 -0
  58. package/dist/export/fonts.js +112 -0
  59. package/dist/export/index.d.ts +2 -0
  60. package/dist/export/index.js +2 -0
  61. package/dist/frame/Byline.svelte +26 -0
  62. package/dist/frame/Byline.svelte.d.ts +8 -0
  63. package/dist/frame/Chart.svelte +144 -0
  64. package/dist/frame/Chart.svelte.d.ts +37 -0
  65. package/dist/frame/ChartTools.svelte +259 -0
  66. package/dist/frame/ChartTools.svelte.d.ts +17 -0
  67. package/dist/frame/DataDownload.svelte +34 -0
  68. package/dist/frame/DataDownload.svelte.d.ts +34 -0
  69. package/dist/frame/DataTable.svelte +49 -0
  70. package/dist/frame/DataTable.svelte.d.ts +34 -0
  71. package/dist/frame/Footer.svelte +39 -0
  72. package/dist/frame/Footer.svelte.d.ts +10 -0
  73. package/dist/frame/Header.svelte +21 -0
  74. package/dist/frame/Header.svelte.d.ts +9 -0
  75. package/dist/frame/Logo.svelte +57 -0
  76. package/dist/frame/Logo.svelte.d.ts +8 -0
  77. package/dist/frame/Notes.svelte +29 -0
  78. package/dist/frame/Notes.svelte.d.ts +9 -0
  79. package/dist/frame/Source.svelte +29 -0
  80. package/dist/frame/Source.svelte.d.ts +9 -0
  81. package/dist/frame/Subtitle.svelte +22 -0
  82. package/dist/frame/Subtitle.svelte.d.ts +9 -0
  83. package/dist/frame/Title.svelte +31 -0
  84. package/dist/frame/Title.svelte.d.ts +9 -0
  85. package/dist/frame/index.d.ts +12 -0
  86. package/dist/frame/index.js +12 -0
  87. package/dist/guides/AxisX.svelte +101 -0
  88. package/dist/guides/AxisX.svelte.d.ts +22 -0
  89. package/dist/guides/AxisY.svelte +84 -0
  90. package/dist/guides/AxisY.svelte.d.ts +21 -0
  91. package/dist/guides/ColorRamp.svelte +93 -0
  92. package/dist/guides/ColorRamp.svelte.d.ts +25 -0
  93. package/dist/guides/GridX.svelte +35 -0
  94. package/dist/guides/GridX.svelte.d.ts +9 -0
  95. package/dist/guides/GridY.svelte +35 -0
  96. package/dist/guides/GridY.svelte.d.ts +9 -0
  97. package/dist/guides/Key.svelte +48 -0
  98. package/dist/guides/Key.svelte.d.ts +14 -0
  99. package/dist/guides/Legend.svelte +112 -0
  100. package/dist/guides/Legend.svelte.d.ts +26 -0
  101. package/dist/guides/SizeLegend.svelte +62 -0
  102. package/dist/guides/SizeLegend.svelte.d.ts +15 -0
  103. package/dist/guides/index.d.ts +9 -0
  104. package/dist/guides/index.js +9 -0
  105. package/dist/guides/ticks.d.ts +6 -0
  106. package/dist/guides/ticks.js +15 -0
  107. package/dist/index.d.ts +13 -0
  108. package/dist/index.js +14 -0
  109. package/dist/interactive/ButtonGroup.svelte +98 -0
  110. package/dist/interactive/ButtonGroup.svelte.d.ts +42 -0
  111. package/dist/interactive/PointerArea.svelte +49 -0
  112. package/dist/interactive/PointerArea.svelte.d.ts +18 -0
  113. package/dist/interactive/Scroller.svelte +147 -0
  114. package/dist/interactive/Scroller.svelte.d.ts +54 -0
  115. package/dist/interactive/Tooltip.svelte +66 -0
  116. package/dist/interactive/Tooltip.svelte.d.ts +19 -0
  117. package/dist/interactive/index.d.ts +4 -0
  118. package/dist/interactive/index.js +4 -0
  119. package/dist/interactive/tooltip-position.d.ts +12 -0
  120. package/dist/interactive/tooltip-position.js +16 -0
  121. package/dist/locale/definitions.d.ts +145 -0
  122. package/dist/locale/definitions.js +138 -0
  123. package/dist/locale/index.d.ts +23 -0
  124. package/dist/locale/index.js +34 -0
  125. package/dist/marks/Arcs.svelte +93 -0
  126. package/dist/marks/Arcs.svelte.d.ts +47 -0
  127. package/dist/marks/Area.svelte +44 -0
  128. package/dist/marks/Area.svelte.d.ts +43 -0
  129. package/dist/marks/Arrows.svelte +93 -0
  130. package/dist/marks/Arrows.svelte.d.ts +50 -0
  131. package/dist/marks/Bars.svelte +111 -0
  132. package/dist/marks/Bars.svelte.d.ts +61 -0
  133. package/dist/marks/Beeswarm.svelte +84 -0
  134. package/dist/marks/Beeswarm.svelte.d.ts +42 -0
  135. package/dist/marks/Dumbbell.svelte +71 -0
  136. package/dist/marks/Dumbbell.svelte.d.ts +42 -0
  137. package/dist/marks/GeoPath.svelte +56 -0
  138. package/dist/marks/GeoPath.svelte.d.ts +42 -0
  139. package/dist/marks/Hemicycle.svelte +182 -0
  140. package/dist/marks/Hemicycle.svelte.d.ts +78 -0
  141. package/dist/marks/Intervals.svelte +128 -0
  142. package/dist/marks/Intervals.svelte.d.ts +60 -0
  143. package/dist/marks/Line.svelte +64 -0
  144. package/dist/marks/Line.svelte.d.ts +43 -0
  145. package/dist/marks/LineEndLabels.svelte +70 -0
  146. package/dist/marks/LineEndLabels.svelte.d.ts +41 -0
  147. package/dist/marks/Points.svelte +70 -0
  148. package/dist/marks/Points.svelte.d.ts +46 -0
  149. package/dist/marks/Rects.svelte +92 -0
  150. package/dist/marks/Rects.svelte.d.ts +47 -0
  151. package/dist/marks/Rules.svelte +46 -0
  152. package/dist/marks/Rules.svelte.d.ts +15 -0
  153. package/dist/marks/Slope.svelte +112 -0
  154. package/dist/marks/Slope.svelte.d.ts +41 -0
  155. package/dist/marks/Text.svelte +75 -0
  156. package/dist/marks/Text.svelte.d.ts +47 -0
  157. package/dist/marks/Treemap.svelte +89 -0
  158. package/dist/marks/Treemap.svelte.d.ts +45 -0
  159. package/dist/marks/Voronoi.svelte +61 -0
  160. package/dist/marks/Voronoi.svelte.d.ts +39 -0
  161. package/dist/marks/Waffle.svelte +69 -0
  162. package/dist/marks/Waffle.svelte.d.ts +41 -0
  163. package/dist/marks/bar-path.d.ts +5 -0
  164. package/dist/marks/bar-path.js +15 -0
  165. package/dist/marks/index.d.ts +20 -0
  166. package/dist/marks/index.js +20 -0
  167. package/dist/recipes/ArrowChart.svelte +247 -0
  168. package/dist/recipes/ArrowChart.svelte.d.ts +73 -0
  169. package/dist/recipes/BarChart.svelte +122 -0
  170. package/dist/recipes/BarChart.svelte.d.ts +58 -0
  171. package/dist/recipes/BarDotChart.svelte +204 -0
  172. package/dist/recipes/BarDotChart.svelte.d.ts +75 -0
  173. package/dist/recipes/ColumnChart.svelte +119 -0
  174. package/dist/recipes/ColumnChart.svelte.d.ts +56 -0
  175. package/dist/recipes/LineChart.svelte +159 -0
  176. package/dist/recipes/LineChart.svelte.d.ts +61 -0
  177. package/dist/recipes/MosaicChart.svelte +256 -0
  178. package/dist/recipes/MosaicChart.svelte.d.ts +83 -0
  179. package/dist/recipes/ScatterChart.svelte +167 -0
  180. package/dist/recipes/ScatterChart.svelte.d.ts +63 -0
  181. package/dist/recipes/StackedBarChart.svelte +222 -0
  182. package/dist/recipes/StackedBarChart.svelte.d.ts +83 -0
  183. package/dist/recipes/index.d.ts +10 -0
  184. package/dist/recipes/index.js +19 -0
  185. package/dist/styles/base.d.ts +5 -0
  186. package/dist/styles/base.js +102 -0
  187. package/dist/styles/check.d.ts +8 -0
  188. package/dist/styles/check.js +32 -0
  189. package/dist/styles/color.d.ts +11 -0
  190. package/dist/styles/color.js +29 -0
  191. package/dist/styles/index.d.ts +9 -0
  192. package/dist/styles/index.js +17 -0
  193. package/dist/styles/types.d.ts +90 -0
  194. package/dist/styles/types.js +1 -0
  195. package/dist/table/Sparkline.svelte +59 -0
  196. package/dist/table/Sparkline.svelte.d.ts +16 -0
  197. package/dist/table/Table.svelte +287 -0
  198. package/dist/table/Table.svelte.d.ts +44 -0
  199. package/dist/table/csv.d.ts +3 -0
  200. package/dist/table/csv.js +12 -0
  201. package/dist/table/index.d.ts +4 -0
  202. package/dist/table/index.js +3 -0
  203. package/dist/table/types.d.ts +26 -0
  204. package/dist/table/types.js +1 -0
  205. package/dist/transforms/bin.d.ts +15 -0
  206. package/dist/transforms/bin.js +18 -0
  207. package/dist/transforms/dodge.d.ts +10 -0
  208. package/dist/transforms/dodge.js +35 -0
  209. package/dist/transforms/group.d.ts +14 -0
  210. package/dist/transforms/group.js +14 -0
  211. package/dist/transforms/hemicycle.d.ts +30 -0
  212. package/dist/transforms/hemicycle.js +51 -0
  213. package/dist/transforms/index.d.ts +8 -0
  214. package/dist/transforms/index.js +8 -0
  215. package/dist/transforms/labels.d.ts +6 -0
  216. package/dist/transforms/labels.js +20 -0
  217. package/dist/transforms/smooth.d.ts +61 -0
  218. package/dist/transforms/smooth.js +105 -0
  219. package/dist/transforms/stack.d.ts +25 -0
  220. package/dist/transforms/stack.js +61 -0
  221. package/dist/transforms/treemap.d.ts +21 -0
  222. package/dist/transforms/treemap.js +31 -0
  223. package/package.json +152 -3
  224. package/src/lib/recipes/ArrowChart.svelte +247 -0
  225. package/src/lib/recipes/BarChart.svelte +122 -0
  226. package/src/lib/recipes/BarDotChart.svelte +204 -0
  227. package/src/lib/recipes/ColumnChart.svelte +119 -0
  228. package/src/lib/recipes/LineChart.svelte +159 -0
  229. package/src/lib/recipes/MosaicChart.svelte +256 -0
  230. package/src/lib/recipes/ScatterChart.svelte +167 -0
  231. package/src/lib/recipes/StackedBarChart.svelte +222 -0
  232. package/src/lib/recipes/index.ts +20 -0
@@ -0,0 +1,98 @@
1
+ <!--
2
+ @component
3
+ A segmented control for switching between views (e.g. "Total" / "Per capita").
4
+ Accessible as a radio group: arrow keys move between options. Hidden in print.
5
+
6
+ ```svelte
7
+ <ButtonGroup label="Measure" options={[{ value: 'total', label: 'Total' }, { value: 'share', label: 'Share' }]} bind:value={measure} />
8
+ ```
9
+ -->
10
+ <script lang="ts" generics="V extends string">
11
+ import { useChart } from '../core/context.js';
12
+
13
+ interface Props {
14
+ options: { value: V; label: string }[];
15
+ value: V;
16
+ /** Accessible name for the group. */
17
+ label: string;
18
+ onchange?: (value: V) => void;
19
+ class?: string;
20
+ }
21
+
22
+ let { options, value = $bindable(), label, onchange, class: className = '' }: Props = $props();
23
+
24
+ const chart = useChart();
25
+ let buttons: HTMLButtonElement[] = $state([]);
26
+
27
+ function select(next: V, focus = false) {
28
+ value = next;
29
+ onchange?.(next);
30
+ if (focus) buttons[options.findIndex((o) => o.value === next)]?.focus();
31
+ }
32
+
33
+ function onkeydown(event: KeyboardEvent, index: number) {
34
+ const step =
35
+ event.key === 'ArrowRight' || event.key === 'ArrowDown'
36
+ ? 1
37
+ : event.key === 'ArrowLeft' || event.key === 'ArrowUp'
38
+ ? -1
39
+ : 0;
40
+ if (!step) return;
41
+ event.preventDefault();
42
+ select(options[(index + step + options.length) % options.length].value, true);
43
+ }
44
+ </script>
45
+
46
+ {#if chart.medium !== 'print'}
47
+ <div class="mz-button-group {className}" role="radiogroup" aria-label={label}>
48
+ {#each options as option, i (option.value)}
49
+ <button
50
+ bind:this={buttons[i]}
51
+ type="button"
52
+ role="radio"
53
+ aria-checked={option.value === value}
54
+ tabindex={option.value === value ? 0 : -1}
55
+ onclick={() => select(option.value)}
56
+ onkeydown={(e) => onkeydown(e, i)}
57
+ >
58
+ {option.label}
59
+ </button>
60
+ {/each}
61
+ </div>
62
+ {/if}
63
+
64
+ <style>
65
+ .mz-button-group {
66
+ display: inline-flex;
67
+ /* Don't stretch inside flex columns such as <Header>. */
68
+ align-self: flex-start;
69
+ flex-wrap: wrap;
70
+ gap: 2px;
71
+ padding: 2px;
72
+ border-radius: var(--mz-radius);
73
+ background: var(--mz-color-grid);
74
+ font-family: var(--mz-font-label);
75
+ }
76
+ button {
77
+ padding: 0.3rem 0.75rem;
78
+ border: 0;
79
+ border-radius: var(--mz-radius);
80
+ background: transparent;
81
+ color: var(--mz-color-muted);
82
+ font: inherit;
83
+ font-size: var(--mz-size-small);
84
+ font-weight: var(--mz-weight-label);
85
+ text-transform: var(--mz-control-transform);
86
+ letter-spacing: var(--mz-control-tracking);
87
+ cursor: pointer;
88
+ }
89
+ /* The selected option is a filled control in the house accent. */
90
+ button[aria-checked='true'] {
91
+ background: var(--mz-color-accent);
92
+ color: #ffffff;
93
+ }
94
+ button:focus-visible {
95
+ outline: 2px solid var(--mz-color-accent);
96
+ outline-offset: 3px;
97
+ }
98
+ </style>
@@ -0,0 +1,42 @@
1
+ declare function $$render<V extends string>(): {
2
+ props: {
3
+ options: {
4
+ value: V;
5
+ label: string;
6
+ }[];
7
+ value: V;
8
+ /** Accessible name for the group. */
9
+ label: string;
10
+ onchange?: (value: V) => void;
11
+ class?: string;
12
+ };
13
+ exports: {};
14
+ bindings: "value";
15
+ slots: {};
16
+ events: {};
17
+ };
18
+ declare class __sveltets_Render<V extends string> {
19
+ props(): ReturnType<typeof $$render<V>>['props'];
20
+ events(): ReturnType<typeof $$render<V>>['events'];
21
+ slots(): ReturnType<typeof $$render<V>>['slots'];
22
+ bindings(): "value";
23
+ exports(): {};
24
+ }
25
+ interface $$IsomorphicComponent {
26
+ new <V extends string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V>['props']>, ReturnType<__sveltets_Render<V>['events']>, ReturnType<__sveltets_Render<V>['slots']>> & {
27
+ $$bindings?: ReturnType<__sveltets_Render<V>['bindings']>;
28
+ } & ReturnType<__sveltets_Render<V>['exports']>;
29
+ <V extends string>(internal: unknown, props: ReturnType<__sveltets_Render<V>['props']> & {}): ReturnType<__sveltets_Render<V>['exports']>;
30
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
31
+ }
32
+ /**
33
+ * A segmented control for switching between views (e.g. "Total" / "Per capita").
34
+ * Accessible as a radio group: arrow keys move between options. Hidden in print.
35
+ *
36
+ * ```svelte
37
+ * <ButtonGroup label="Measure" options={[{ value: 'total', label: 'Total' }, { value: 'share', label: 'Share' }]} bind:value={measure} />
38
+ * ```
39
+ */
40
+ declare const ButtonGroup: $$IsomorphicComponent;
41
+ type ButtonGroup<V extends string> = InstanceType<typeof ButtonGroup<V>>;
42
+ export default ButtonGroup;
@@ -0,0 +1,49 @@
1
+ <!--
2
+ @component
3
+ An invisible rectangle over the plot area (inside `<Svg>`) that reports the
4
+ pointer position in plot pixels. Invert it with your scales to find the
5
+ nearest datum. Works with mouse, pen and touch.
6
+ -->
7
+ <script lang="ts">
8
+ import { usePlot } from '../core/context.js';
9
+
10
+ export type PointerPosition = { x: number; y: number; event: PointerEvent };
11
+
12
+ interface Props {
13
+ onmove?: (position: PointerPosition) => void;
14
+ onleave?: (event: PointerEvent) => void;
15
+ class?: string;
16
+ }
17
+
18
+ let { onmove, onleave, class: className = '' }: Props = $props();
19
+
20
+ const plot = usePlot();
21
+
22
+ function report(event: PointerEvent) {
23
+ const rect = (event.currentTarget as SVGRectElement).getBoundingClientRect();
24
+ // The SVG may be scaled (before it is measured), so convert screen px to plot px.
25
+ const sx = rect.width ? plot.width / rect.width : 1;
26
+ const sy = rect.height ? plot.height / rect.height : 1;
27
+ onmove?.({ x: (event.clientX - rect.left) * sx, y: (event.clientY - rect.top) * sy, event });
28
+ }
29
+ </script>
30
+
31
+ {#if plot.medium !== 'print'}
32
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
33
+ <rect
34
+ class="mz-pointer-area {className}"
35
+ width={plot.width}
36
+ height={plot.height}
37
+ fill="transparent"
38
+ onpointermove={report}
39
+ onpointerdown={report}
40
+ onpointerleave={(e) => onleave?.(e)}
41
+ />
42
+ {/if}
43
+
44
+ <style>
45
+ .mz-pointer-area {
46
+ pointer-events: all;
47
+ touch-action: pan-y;
48
+ }
49
+ </style>
@@ -0,0 +1,18 @@
1
+ export type PointerPosition = {
2
+ x: number;
3
+ y: number;
4
+ event: PointerEvent;
5
+ };
6
+ interface Props {
7
+ onmove?: (position: PointerPosition) => void;
8
+ onleave?: (event: PointerEvent) => void;
9
+ class?: string;
10
+ }
11
+ /**
12
+ * An invisible rectangle over the plot area (inside `<Svg>`) that reports the
13
+ * pointer position in plot pixels. Invert it with your scales to find the
14
+ * nearest datum. Works with mouse, pen and touch.
15
+ */
16
+ declare const PointerArea: import("svelte").Component<Props, {}, "">;
17
+ type PointerArea = ReturnType<typeof PointerArea>;
18
+ export default PointerArea;
@@ -0,0 +1,147 @@
1
+ <!--
2
+ @component
3
+ Scrollytelling: a sticky graphic with text steps scrolling over it. The
4
+ graphic snippet receives the active step index and the progress (0–1)
5
+ through that step, so the chart can change state as the reader scrolls.
6
+
7
+ Scroll stories need the page itself to scroll: publish them as a full page
8
+ (or a full-page embed), not inside an auto-height iframe.
9
+
10
+ ```svelte
11
+ <Scroller steps={texts}>
12
+ {#snippet graphic({ index, progress })}<MyChart state={index} />{/snippet}
13
+ {#snippet step(text)}<p>{text}</p>{/snippet}
14
+ </Scroller>
15
+ ```
16
+ -->
17
+ <script lang="ts" generics="S">
18
+ import type { Snippet } from 'svelte';
19
+
20
+ interface Props {
21
+ steps: S[];
22
+ graphic: Snippet<[{ index: number; progress: number }]>;
23
+ step: Snippet<[S, number]>;
24
+ /** Active step index (bindable). */
25
+ index?: number;
26
+ /** Progress through the active step, 0–1 (bindable). */
27
+ progress?: number;
28
+ /** Viewport position of the trigger line, 0 = top, 1 = bottom. */
29
+ offset?: number;
30
+ class?: string;
31
+ }
32
+
33
+ let {
34
+ steps,
35
+ graphic,
36
+ step,
37
+ index = $bindable(0),
38
+ progress = $bindable(0),
39
+ offset = 0.6,
40
+ class: className = ''
41
+ }: Props = $props();
42
+
43
+ let stepEls: HTMLElement[] = $state([]);
44
+
45
+ $effect(() => {
46
+ const observer = new IntersectionObserver(
47
+ (entries) => {
48
+ for (const entry of entries)
49
+ if (entry.isIntersecting) index = Number((entry.target as HTMLElement).dataset.index);
50
+ },
51
+ // A one-pixel-high root at the trigger line.
52
+ { rootMargin: `-${offset * 100}% 0px -${(1 - offset) * 100}% 0px` }
53
+ );
54
+ for (const el of stepEls) if (el) observer.observe(el);
55
+ return () => observer.disconnect();
56
+ });
57
+
58
+ $effect(() => {
59
+ const update = () => {
60
+ const el = stepEls[index];
61
+ if (!el) return;
62
+ const rect = el.getBoundingClientRect();
63
+ const line = window.innerHeight * offset;
64
+ progress = Math.max(0, Math.min(1, (line - rect.top) / Math.max(1, rect.height)));
65
+ };
66
+ update();
67
+ window.addEventListener('scroll', update, { passive: true });
68
+ window.addEventListener('resize', update);
69
+ return () => {
70
+ window.removeEventListener('scroll', update);
71
+ window.removeEventListener('resize', update);
72
+ };
73
+ });
74
+ </script>
75
+
76
+ <div class="mz-scroller {className}">
77
+ <div class="mz-scroller-graphic">
78
+ {@render graphic({ index, progress })}
79
+ </div>
80
+ <div class="mz-scroller-steps">
81
+ {#each steps as s, i}
82
+ <section class="mz-scroller-step" class:active={i === index} data-index={i} bind:this={stepEls[i]}>
83
+ <div class="mz-scroller-card">{@render step(s, i)}</div>
84
+ </section>
85
+ {/each}
86
+ </div>
87
+ </div>
88
+
89
+ <style>
90
+ .mz-scroller {
91
+ position: relative;
92
+ }
93
+ .mz-scroller-graphic {
94
+ position: sticky;
95
+ top: 0;
96
+ height: 100vh;
97
+ display: flex;
98
+ align-items: center;
99
+ justify-content: center;
100
+ }
101
+ .mz-scroller-steps {
102
+ position: relative;
103
+ margin-top: -100vh;
104
+ pointer-events: none;
105
+ }
106
+ .mz-scroller-step {
107
+ min-height: 90vh;
108
+ display: flex;
109
+ align-items: center;
110
+ justify-content: center;
111
+ padding: 0 16px;
112
+ }
113
+ .mz-scroller-step:first-child {
114
+ margin-top: 50vh;
115
+ }
116
+ .mz-scroller-step:last-child {
117
+ margin-bottom: 40vh;
118
+ }
119
+ .mz-scroller-card {
120
+ max-width: 28rem;
121
+ padding: 1rem 1.25rem;
122
+ background: color-mix(in srgb, var(--mz-color-bg, #fff) 94%, transparent);
123
+ border: 1px solid var(--mz-color-border, #e4e4e4);
124
+ border-radius: var(--mz-radius-floating, 6px);
125
+ box-shadow: var(--mz-shadow-floating, 0 2px 10px rgb(0 0 0 / 0.08));
126
+ opacity: 0.45;
127
+ transition: opacity 200ms;
128
+ pointer-events: auto;
129
+ }
130
+ .active .mz-scroller-card {
131
+ opacity: 1;
132
+ }
133
+ @media (prefers-reduced-motion: reduce) {
134
+ .mz-scroller-card {
135
+ transition: none;
136
+ }
137
+ }
138
+ @media print {
139
+ .mz-scroller-graphic {
140
+ position: static;
141
+ height: auto;
142
+ }
143
+ .mz-scroller-steps {
144
+ margin-top: 0;
145
+ }
146
+ }
147
+ </style>
@@ -0,0 +1,54 @@
1
+ import type { Snippet } from 'svelte';
2
+ declare function $$render<S>(): {
3
+ props: {
4
+ steps: S[];
5
+ graphic: Snippet<[{
6
+ index: number;
7
+ progress: number;
8
+ }]>;
9
+ step: Snippet<[S, number]>;
10
+ /** Active step index (bindable). */
11
+ index?: number;
12
+ /** Progress through the active step, 0–1 (bindable). */
13
+ progress?: number;
14
+ /** Viewport position of the trigger line, 0 = top, 1 = bottom. */
15
+ offset?: number;
16
+ class?: string;
17
+ };
18
+ exports: {};
19
+ bindings: "index" | "progress";
20
+ slots: {};
21
+ events: {};
22
+ };
23
+ declare class __sveltets_Render<S> {
24
+ props(): ReturnType<typeof $$render<S>>['props'];
25
+ events(): ReturnType<typeof $$render<S>>['events'];
26
+ slots(): ReturnType<typeof $$render<S>>['slots'];
27
+ bindings(): "index" | "progress";
28
+ exports(): {};
29
+ }
30
+ interface $$IsomorphicComponent {
31
+ new <S>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<S>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<S>['props']>, ReturnType<__sveltets_Render<S>['events']>, ReturnType<__sveltets_Render<S>['slots']>> & {
32
+ $$bindings?: ReturnType<__sveltets_Render<S>['bindings']>;
33
+ } & ReturnType<__sveltets_Render<S>['exports']>;
34
+ <S>(internal: unknown, props: ReturnType<__sveltets_Render<S>['props']> & {}): ReturnType<__sveltets_Render<S>['exports']>;
35
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
36
+ }
37
+ /**
38
+ * Scrollytelling: a sticky graphic with text steps scrolling over it. The
39
+ * graphic snippet receives the active step index and the progress (0–1)
40
+ * through that step, so the chart can change state as the reader scrolls.
41
+ *
42
+ * Scroll stories need the page itself to scroll: publish them as a full page
43
+ * (or a full-page embed), not inside an auto-height iframe.
44
+ *
45
+ * ```svelte
46
+ * <Scroller steps={texts}>
47
+ * {#snippet graphic({ index, progress })}<MyChart state={index} />{/snippet}
48
+ * {#snippet step(text)}<p>{text}</p>{/snippet}
49
+ * </Scroller>
50
+ * ```
51
+ */
52
+ declare const Scroller: $$IsomorphicComponent;
53
+ type Scroller<S> = InstanceType<typeof Scroller<S>>;
54
+ export default Scroller;
@@ -0,0 +1,66 @@
1
+ <!--
2
+ @component
3
+ A tooltip card at a pixel position in the plot area (inside `<Html>`).
4
+ Flips to the left of the point in the right part of the plot, and changes side or
5
+ slides over when needed to stay inside the chart.
6
+ -->
7
+ <script lang="ts">
8
+ import type { Snippet } from 'svelte';
9
+ import { usePlot } from '../core/context.js';
10
+ import { tooltipLeft } from './tooltip-position.js';
11
+
12
+ interface Props {
13
+ /** Plot-area pixel position. */
14
+ x: number;
15
+ y: number;
16
+ visible?: boolean;
17
+ /** Distance from the point, px. */
18
+ offset?: number;
19
+ class?: string;
20
+ children?: Snippet;
21
+ }
22
+
23
+ let { x, y, visible = true, offset = 12, class: className = '', children }: Props = $props();
24
+
25
+ const plot = usePlot();
26
+ const flip = $derived(x > plot.width * 0.6);
27
+ const top = $derived(Math.max(0, Math.min(plot.height, y)));
28
+ // Once measured, the tooltip is placed so it stays inside the chart (see tooltipLeft).
29
+ let tooltipWidth = $state(0);
30
+ const left = $derived(tooltipWidth ? tooltipLeft(x, tooltipWidth, plot, offset) : null);
31
+ </script>
32
+
33
+ {#if visible && plot.medium !== 'print'}
34
+ <div
35
+ class="mz-tooltip {className}"
36
+ role="status"
37
+ style:left="{left ?? x}px"
38
+ style:top="{top}px"
39
+ style:transform={left !== null
40
+ ? 'translate(0, -50%)'
41
+ : flip
42
+ ? `translate(calc(-100% - ${offset}px), -50%)`
43
+ : `translate(${offset}px, -50%)`}
44
+ bind:offsetWidth={tooltipWidth}
45
+ >
46
+ {@render children?.()}
47
+ </div>
48
+ {/if}
49
+
50
+ <style>
51
+ .mz-tooltip {
52
+ position: absolute;
53
+ z-index: 1;
54
+ min-width: 6rem;
55
+ max-width: 16rem;
56
+ padding: 0.5rem 0.625rem;
57
+ background: var(--mz-color-tooltip-bg);
58
+ border: 1px solid var(--mz-color-border);
59
+ border-radius: var(--mz-radius-floating);
60
+ box-shadow: var(--mz-shadow-floating);
61
+ font-size: var(--mz-size-small);
62
+ line-height: 1.35;
63
+ color: var(--mz-color-text);
64
+ pointer-events: none;
65
+ }
66
+ </style>
@@ -0,0 +1,19 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ /** Plot-area pixel position. */
4
+ x: number;
5
+ y: number;
6
+ visible?: boolean;
7
+ /** Distance from the point, px. */
8
+ offset?: number;
9
+ class?: string;
10
+ children?: Snippet;
11
+ }
12
+ /**
13
+ * A tooltip card at a pixel position in the plot area (inside `<Html>`).
14
+ * Flips to the left of the point in the right part of the plot, and changes side or
15
+ * slides over when needed to stay inside the chart.
16
+ */
17
+ declare const Tooltip: import("svelte").Component<Props, {}, "">;
18
+ type Tooltip = ReturnType<typeof Tooltip>;
19
+ export default Tooltip;
@@ -0,0 +1,4 @@
1
+ export { default as PointerArea, type PointerPosition } from './PointerArea.svelte';
2
+ export { default as Tooltip } from './Tooltip.svelte';
3
+ export { default as ButtonGroup } from './ButtonGroup.svelte';
4
+ export { default as Scroller } from './Scroller.svelte';
@@ -0,0 +1,4 @@
1
+ export { default as PointerArea } from './PointerArea.svelte';
2
+ export { default as Tooltip } from './Tooltip.svelte';
3
+ export { default as ButtonGroup } from './ButtonGroup.svelte';
4
+ export { default as Scroller } from './Scroller.svelte';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Left edge of a tooltip, in plot-area pixels, for a point at `x`: beside the point, on the
3
+ * right unless the point is in the right part of the plot (or there is no room there), and
4
+ * always inside the chart (the plot area plus its padding).
5
+ */
6
+ export declare function tooltipLeft(x: number, tooltipWidth: number, plot: {
7
+ width: number;
8
+ padding: {
9
+ left: number;
10
+ right: number;
11
+ };
12
+ }, offset?: number): number;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Left edge of a tooltip, in plot-area pixels, for a point at `x`: beside the point, on the
3
+ * right unless the point is in the right part of the plot (or there is no room there), and
4
+ * always inside the chart (the plot area plus its padding).
5
+ */
6
+ export function tooltipLeft(x, tooltipWidth, plot, offset = 12) {
7
+ const min = 0 - plot.padding.left;
8
+ const max = plot.width + plot.padding.right - tooltipWidth;
9
+ const right = x + offset;
10
+ const left = x - offset - tooltipWidth;
11
+ const preferLeft = x > plot.width * 0.6;
12
+ const fitsRight = right <= max;
13
+ const fitsLeft = left >= min;
14
+ const chosen = preferLeft ? (fitsLeft || !fitsRight ? left : right) : fitsRight || !fitsLeft ? right : left;
15
+ return Math.max(min, Math.min(max, chosen));
16
+ }
@@ -0,0 +1,145 @@
1
+ import type { FormatLocaleDefinition } from 'd3-format';
2
+ import type { TimeLocaleDefinition } from 'd3-time-format';
3
+ export interface LocaleStrings {
4
+ source: string;
5
+ sources: string;
6
+ note: string;
7
+ notes: string;
8
+ graphic: string;
9
+ showData: string;
10
+ downloadData: string;
11
+ /** The control under a chart that shows its embed code, the code's label, and its copy button. */
12
+ embed: string;
13
+ embedCode: string;
14
+ copy: string;
15
+ copied: string;
16
+ /** The control under a chart that saves it as an image ("Download" PNG · SVG). */
17
+ downloadImage: string;
18
+ noData: string;
19
+ search: string;
20
+ showAll: (n: number) => string;
21
+ showFewer: string;
22
+ }
23
+ export interface LocaleDefinition {
24
+ /** BCP 47 language tag for the `lang` attribute. */
25
+ lang: string;
26
+ number: FormatLocaleDefinition;
27
+ time: TimeLocaleDefinition;
28
+ strings: LocaleStrings;
29
+ }
30
+ export declare const definitions: {
31
+ en: {
32
+ lang: string;
33
+ number: {
34
+ decimal: string;
35
+ thousands: string;
36
+ grouping: number[];
37
+ currency: [string, string];
38
+ minus: string;
39
+ };
40
+ time: {
41
+ dateTime: string;
42
+ date: string;
43
+ time: string;
44
+ periods: [string, string];
45
+ days: [string, string, string, string, string, string, string];
46
+ shortDays: [string, string, string, string, string, string, string];
47
+ months: [string, string, string, string, string, string, string, string, string, string, string, string];
48
+ shortMonths: [string, string, string, string, string, string, string, string, string, string, string, string];
49
+ };
50
+ strings: {
51
+ source: string;
52
+ sources: string;
53
+ note: string;
54
+ notes: string;
55
+ graphic: string;
56
+ showData: string;
57
+ downloadData: string;
58
+ embed: string;
59
+ embedCode: string;
60
+ copy: string;
61
+ copied: string;
62
+ downloadImage: string;
63
+ noData: string;
64
+ search: string;
65
+ showAll: (n: number) => string;
66
+ showFewer: string;
67
+ };
68
+ };
69
+ ro: {
70
+ lang: string;
71
+ number: {
72
+ decimal: string;
73
+ thousands: string;
74
+ grouping: number[];
75
+ currency: [string, string];
76
+ minus: string;
77
+ };
78
+ time: {
79
+ dateTime: string;
80
+ date: string;
81
+ time: string;
82
+ periods: [string, string];
83
+ days: [string, string, string, string, string, string, string];
84
+ shortDays: [string, string, string, string, string, string, string];
85
+ months: [string, string, string, string, string, string, string, string, string, string, string, string];
86
+ shortMonths: [string, string, string, string, string, string, string, string, string, string, string, string];
87
+ };
88
+ strings: {
89
+ source: string;
90
+ sources: string;
91
+ note: string;
92
+ notes: string;
93
+ graphic: string;
94
+ showData: string;
95
+ downloadData: string;
96
+ embed: string;
97
+ embedCode: string;
98
+ copy: string;
99
+ copied: string;
100
+ downloadImage: string;
101
+ noData: string;
102
+ search: string;
103
+ showAll: (n: number) => string;
104
+ showFewer: string;
105
+ };
106
+ };
107
+ ru: {
108
+ lang: string;
109
+ number: {
110
+ decimal: string;
111
+ thousands: string;
112
+ grouping: number[];
113
+ currency: [string, string];
114
+ minus: string;
115
+ };
116
+ time: {
117
+ dateTime: string;
118
+ date: string;
119
+ time: string;
120
+ periods: [string, string];
121
+ days: [string, string, string, string, string, string, string];
122
+ shortDays: [string, string, string, string, string, string, string];
123
+ months: [string, string, string, string, string, string, string, string, string, string, string, string];
124
+ shortMonths: [string, string, string, string, string, string, string, string, string, string, string, string];
125
+ };
126
+ strings: {
127
+ source: string;
128
+ sources: string;
129
+ note: string;
130
+ notes: string;
131
+ graphic: string;
132
+ showData: string;
133
+ downloadData: string;
134
+ embed: string;
135
+ embedCode: string;
136
+ copy: string;
137
+ copied: string;
138
+ downloadImage: string;
139
+ noData: string;
140
+ search: string;
141
+ showAll: (n: number) => string;
142
+ showFewer: string;
143
+ };
144
+ };
145
+ };