@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,45 @@
|
|
|
1
|
+
import { type TreemapCell } from '../transforms/treemap.js';
|
|
2
|
+
declare function $$render<T>(): {
|
|
3
|
+
props: {
|
|
4
|
+
data: T[];
|
|
5
|
+
value: (d: T) => number;
|
|
6
|
+
group?: (d: T) => string;
|
|
7
|
+
fill?: (d: T, group: string | undefined) => string;
|
|
8
|
+
label?: (d: T) => string;
|
|
9
|
+
/** Second label line, e.g. the formatted value. */
|
|
10
|
+
sublabel?: (d: T) => string;
|
|
11
|
+
/** Text colour inside cells; pick one with enough contrast against the fills. */
|
|
12
|
+
labelColor?: string;
|
|
13
|
+
padding?: number;
|
|
14
|
+
title?: (d: T) => string;
|
|
15
|
+
/** Also receives the cell's pixel box, e.g. to place a tooltip at its centre. */
|
|
16
|
+
onpointerenter?: (d: T, event: PointerEvent, cell: TreemapCell<T>) => void;
|
|
17
|
+
onpointerleave?: (d: T, event: PointerEvent, cell: TreemapCell<T>) => void;
|
|
18
|
+
class?: string;
|
|
19
|
+
};
|
|
20
|
+
exports: {};
|
|
21
|
+
bindings: "";
|
|
22
|
+
slots: {};
|
|
23
|
+
events: {};
|
|
24
|
+
};
|
|
25
|
+
declare class __sveltets_Render<T> {
|
|
26
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
27
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
28
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
29
|
+
bindings(): "";
|
|
30
|
+
exports(): {};
|
|
31
|
+
}
|
|
32
|
+
interface $$IsomorphicComponent {
|
|
33
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
34
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
35
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
36
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
37
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A squarified treemap filling the plot area. Labels are drawn only where
|
|
41
|
+
* they fit. Optionally grouped one level deep (`group`).
|
|
42
|
+
*/
|
|
43
|
+
declare const Treemap: $$IsomorphicComponent;
|
|
44
|
+
type Treemap<T> = InstanceType<typeof Treemap<T>>;
|
|
45
|
+
export default Treemap;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Invisible hover cells around each point, so the nearest datum is always easy
|
|
4
|
+
to hit (scatter plots, line charts with many points). Draw it last in `<Svg>`.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts" generics="T">
|
|
7
|
+
import { Delaunay } from 'd3-delaunay';
|
|
8
|
+
import { usePlot } from '../core/context.js';
|
|
9
|
+
import { position } from '../core/scales.js';
|
|
10
|
+
import { access, type Accessor, type Value } from '../core/accessor.js';
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
data: T[];
|
|
14
|
+
x: Accessor<T, Value>;
|
|
15
|
+
y: Accessor<T, Value>;
|
|
16
|
+
onpointerenter?: (d: T, event: PointerEvent) => void;
|
|
17
|
+
onpointerleave?: (d: T, event: PointerEvent) => void;
|
|
18
|
+
onclick?: (d: T, event: MouseEvent) => void;
|
|
19
|
+
/** Show cell outlines (debugging). */
|
|
20
|
+
debug?: boolean;
|
|
21
|
+
class?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let { data, x, y, onpointerenter, onpointerleave, onclick, debug = false, class: className = '' }: Props = $props();
|
|
25
|
+
|
|
26
|
+
const plot = usePlot();
|
|
27
|
+
|
|
28
|
+
const cells = $derived.by(() => {
|
|
29
|
+
const points = data.map((d, i) => position(plot, access(x, d, i), access(y, d, i)));
|
|
30
|
+
const valid = points.map((p, i) => ({ p, i })).filter(({ p }) => Number.isFinite(p[0]) && Number.isFinite(p[1]));
|
|
31
|
+
if (!valid.length || plot.width <= 0 || plot.height <= 0) return [];
|
|
32
|
+
const voronoi = Delaunay.from(valid.map((v) => v.p)).voronoi([0, 0, plot.width, plot.height]);
|
|
33
|
+
return valid.map((v, k) => ({ d: data[v.i], path: voronoi.renderCell(k) }));
|
|
34
|
+
});
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
{#if plot.medium !== 'print'}
|
|
38
|
+
<g class="mz-voronoi {className}" class:mz-debug={debug}>
|
|
39
|
+
{#each cells as cell}
|
|
40
|
+
<!-- svelte-ignore a11y_no_static_element_interactions, a11y_click_events_have_key_events -->
|
|
41
|
+
<path
|
|
42
|
+
d={cell.path}
|
|
43
|
+
onpointerenter={onpointerenter ? (e) => onpointerenter(cell.d, e) : undefined}
|
|
44
|
+
onpointerleave={onpointerleave ? (e) => onpointerleave(cell.d, e) : undefined}
|
|
45
|
+
onclick={onclick ? (e) => onclick(cell.d, e) : undefined}
|
|
46
|
+
/>
|
|
47
|
+
{/each}
|
|
48
|
+
</g>
|
|
49
|
+
{/if}
|
|
50
|
+
|
|
51
|
+
<style>
|
|
52
|
+
.mz-voronoi path {
|
|
53
|
+
fill: transparent;
|
|
54
|
+
stroke: none;
|
|
55
|
+
pointer-events: all;
|
|
56
|
+
}
|
|
57
|
+
.mz-debug path {
|
|
58
|
+
stroke: red;
|
|
59
|
+
stroke-width: 0.5;
|
|
60
|
+
}
|
|
61
|
+
</style>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Accessor, type Value } from '../core/accessor.js';
|
|
2
|
+
declare function $$render<T>(): {
|
|
3
|
+
props: {
|
|
4
|
+
data: T[];
|
|
5
|
+
x: Accessor<T, Value>;
|
|
6
|
+
y: Accessor<T, Value>;
|
|
7
|
+
onpointerenter?: (d: T, event: PointerEvent) => void;
|
|
8
|
+
onpointerleave?: (d: T, event: PointerEvent) => void;
|
|
9
|
+
onclick?: (d: T, event: MouseEvent) => void;
|
|
10
|
+
/** Show cell outlines (debugging). */
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
class?: string;
|
|
13
|
+
};
|
|
14
|
+
exports: {};
|
|
15
|
+
bindings: "";
|
|
16
|
+
slots: {};
|
|
17
|
+
events: {};
|
|
18
|
+
};
|
|
19
|
+
declare class __sveltets_Render<T> {
|
|
20
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
21
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
22
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
23
|
+
bindings(): "";
|
|
24
|
+
exports(): {};
|
|
25
|
+
}
|
|
26
|
+
interface $$IsomorphicComponent {
|
|
27
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
28
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
29
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
30
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
31
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Invisible hover cells around each point, so the nearest datum is always easy
|
|
35
|
+
* to hit (scatter plots, line charts with many points). Draw it last in `<Svg>`.
|
|
36
|
+
*/
|
|
37
|
+
declare const Voronoi: $$IsomorphicComponent;
|
|
38
|
+
type Voronoi<T> = InstanceType<typeof Voronoi<T>>;
|
|
39
|
+
export default Voronoi;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A waffle chart: a grid of squares, one per unit, coloured by category in
|
|
4
|
+
data order. Good for parts of a whole ("37 of 100 people"). With
|
|
5
|
+
`origin="bottom"` the squares fill from the bottom row up, so the first
|
|
6
|
+
category sits at the base and waffles of different totals share a baseline.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts" generics="T">
|
|
9
|
+
import { useChart, usePlot } from '../core/context.js';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
data: T[];
|
|
13
|
+
value: (d: T) => number;
|
|
14
|
+
fill?: (d: T, index: number) => string;
|
|
15
|
+
/** Squares per row. */
|
|
16
|
+
columns?: number;
|
|
17
|
+
/** Total number of squares; defaults to the sum of values. Remaining squares use `emptyFill`. */
|
|
18
|
+
total?: number;
|
|
19
|
+
emptyFill?: string;
|
|
20
|
+
/** Gap between squares in px. */
|
|
21
|
+
gap?: number;
|
|
22
|
+
/** Row the squares start filling from: the top (default) or the bottom of the plot. */
|
|
23
|
+
origin?: 'top' | 'bottom';
|
|
24
|
+
title?: (d: T) => string;
|
|
25
|
+
class?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
data,
|
|
30
|
+
value,
|
|
31
|
+
fill,
|
|
32
|
+
columns = 10,
|
|
33
|
+
total,
|
|
34
|
+
emptyFill = 'var(--mz-color-grid)',
|
|
35
|
+
gap = 2,
|
|
36
|
+
origin = 'top',
|
|
37
|
+
title,
|
|
38
|
+
class: className = ''
|
|
39
|
+
}: Props = $props();
|
|
40
|
+
|
|
41
|
+
const chart = useChart();
|
|
42
|
+
const plot = usePlot();
|
|
43
|
+
|
|
44
|
+
const counts = $derived(data.map((d) => Math.max(0, Math.round(value(d)))));
|
|
45
|
+
const count = $derived(total ?? counts.reduce((a, b) => a + b, 0));
|
|
46
|
+
const rows = $derived(Math.ceil(count / columns));
|
|
47
|
+
const cell = $derived(Math.max(0, Math.min(plot.width / columns, plot.height / Math.max(1, rows))));
|
|
48
|
+
const squares = $derived.by(() => {
|
|
49
|
+
const out: { i: number; d: T | undefined; k: number }[] = [];
|
|
50
|
+
let i = 0;
|
|
51
|
+
counts.forEach((c, k) => {
|
|
52
|
+
for (let n = 0; n < c && i < count; n++) out.push({ i: i++, d: data[k], k });
|
|
53
|
+
});
|
|
54
|
+
while (i < count) out.push({ i: i++, d: undefined, k: -1 });
|
|
55
|
+
return out;
|
|
56
|
+
});
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<g class="mz-waffle {className}">
|
|
60
|
+
{#each squares as sq}
|
|
61
|
+
<rect
|
|
62
|
+
x={(sq.i % columns) * cell + gap / 2}
|
|
63
|
+
y={(origin === 'bottom'
|
|
64
|
+
? plot.height - (Math.floor(sq.i / columns) + 1) * cell
|
|
65
|
+
: Math.floor(sq.i / columns) * cell) +
|
|
66
|
+
gap / 2}
|
|
67
|
+
width={Math.max(0, cell - gap)}
|
|
68
|
+
height={Math.max(0, cell - gap)}
|
|
69
|
+
fill={sq.d === undefined
|
|
70
|
+
? emptyFill
|
|
71
|
+
: fill
|
|
72
|
+
? fill(sq.d, sq.k)
|
|
73
|
+
: chart.theme.palettes.categorical[sq.k % chart.theme.palettes.categorical.length]}
|
|
74
|
+
>{#if title && sq.d !== undefined}<title>{title(sq.d)}</title>{/if}</rect
|
|
75
|
+
>
|
|
76
|
+
{/each}
|
|
77
|
+
</g>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
declare function $$render<T>(): {
|
|
2
|
+
props: {
|
|
3
|
+
data: T[];
|
|
4
|
+
value: (d: T) => number;
|
|
5
|
+
fill?: (d: T, index: number) => string;
|
|
6
|
+
/** Squares per row. */
|
|
7
|
+
columns?: number;
|
|
8
|
+
/** Total number of squares; defaults to the sum of values. Remaining squares use `emptyFill`. */
|
|
9
|
+
total?: number;
|
|
10
|
+
emptyFill?: string;
|
|
11
|
+
/** Gap between squares in px. */
|
|
12
|
+
gap?: number;
|
|
13
|
+
/** Row the squares start filling from: the top (default) or the bottom of the plot. */
|
|
14
|
+
origin?: "top" | "bottom";
|
|
15
|
+
title?: (d: T) => string;
|
|
16
|
+
class?: string;
|
|
17
|
+
};
|
|
18
|
+
exports: {};
|
|
19
|
+
bindings: "";
|
|
20
|
+
slots: {};
|
|
21
|
+
events: {};
|
|
22
|
+
};
|
|
23
|
+
declare class __sveltets_Render<T> {
|
|
24
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
25
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
26
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
27
|
+
bindings(): "";
|
|
28
|
+
exports(): {};
|
|
29
|
+
}
|
|
30
|
+
interface $$IsomorphicComponent {
|
|
31
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
32
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
33
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
34
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
35
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A waffle chart: a grid of squares, one per unit, coloured by category in
|
|
39
|
+
* data order. Good for parts of a whole ("37 of 100 people"). With
|
|
40
|
+
* `origin="bottom"` the squares fill from the bottom row up, so the first
|
|
41
|
+
* category sits at the base and waffles of different totals share a baseline.
|
|
42
|
+
*/
|
|
43
|
+
declare const Waffle: $$IsomorphicComponent;
|
|
44
|
+
type Waffle<T> = InstanceType<typeof Waffle<T>>;
|
|
45
|
+
export default Waffle;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG path for a bar from `base` to `value` along the value axis, `t0`–`t1`
|
|
3
|
+
* across it, with rounded corners only at the data end (square at the baseline).
|
|
4
|
+
*/
|
|
5
|
+
export declare function barPath(orientation: 'horizontal' | 'vertical', base: number, value: number, t0: number, t1: number, radius: number): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG path for a bar from `base` to `value` along the value axis, `t0`–`t1`
|
|
3
|
+
* across it, with rounded corners only at the data end (square at the baseline).
|
|
4
|
+
*/
|
|
5
|
+
export function barPath(orientation, base, value, t0, t1, radius) {
|
|
6
|
+
const length = Math.abs(value - base);
|
|
7
|
+
const r = Math.max(0, Math.min(radius, (t1 - t0) / 2, length));
|
|
8
|
+
const s = value >= base ? 1 : -1;
|
|
9
|
+
if (orientation === 'horizontal') {
|
|
10
|
+
// Grows along x; data end at x = value.
|
|
11
|
+
return `M${base},${t0}H${value - s * r}Q${value},${t0} ${value},${t0 + r}V${t1 - r}Q${value},${t1} ${value - s * r},${t1}H${base}Z`;
|
|
12
|
+
}
|
|
13
|
+
// Grows along y; data end at y = value.
|
|
14
|
+
return `M${t0},${base}V${value + s * r}Q${t0},${value} ${t0 + r},${value}H${t1 - r}Q${t1},${value} ${t1},${value + s * r}V${base}Z`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { default as Bars } from './Bars.svelte';
|
|
2
|
+
export { default as Line } from './Line.svelte';
|
|
3
|
+
export { default as Area } from './Area.svelte';
|
|
4
|
+
export { default as Points } from './Points.svelte';
|
|
5
|
+
export { default as Rects } from './Rects.svelte';
|
|
6
|
+
export { default as Arcs } from './Arcs.svelte';
|
|
7
|
+
export { default as Text } from './Text.svelte';
|
|
8
|
+
export { default as Rules } from './Rules.svelte';
|
|
9
|
+
export { default as GeoPath } from './GeoPath.svelte';
|
|
10
|
+
export { default as Voronoi } from './Voronoi.svelte';
|
|
11
|
+
export { default as LineEndLabels } from './LineEndLabels.svelte';
|
|
12
|
+
export { default as Treemap } from './Treemap.svelte';
|
|
13
|
+
export { default as Waffle } from './Waffle.svelte';
|
|
14
|
+
export { default as Dumbbell } from './Dumbbell.svelte';
|
|
15
|
+
export { default as Arrows } from './Arrows.svelte';
|
|
16
|
+
export { default as Slope } from './Slope.svelte';
|
|
17
|
+
export { default as Beeswarm } from './Beeswarm.svelte';
|
|
18
|
+
export { default as Hemicycle } from './Hemicycle.svelte';
|
|
19
|
+
export { default as Intervals } from './Intervals.svelte';
|
|
20
|
+
export { barPath } from './bar-path.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { default as Bars } from './Bars.svelte';
|
|
2
|
+
export { default as Line } from './Line.svelte';
|
|
3
|
+
export { default as Area } from './Area.svelte';
|
|
4
|
+
export { default as Points } from './Points.svelte';
|
|
5
|
+
export { default as Rects } from './Rects.svelte';
|
|
6
|
+
export { default as Arcs } from './Arcs.svelte';
|
|
7
|
+
export { default as Text } from './Text.svelte';
|
|
8
|
+
export { default as Rules } from './Rules.svelte';
|
|
9
|
+
export { default as GeoPath } from './GeoPath.svelte';
|
|
10
|
+
export { default as Voronoi } from './Voronoi.svelte';
|
|
11
|
+
export { default as LineEndLabels } from './LineEndLabels.svelte';
|
|
12
|
+
export { default as Treemap } from './Treemap.svelte';
|
|
13
|
+
export { default as Waffle } from './Waffle.svelte';
|
|
14
|
+
export { default as Dumbbell } from './Dumbbell.svelte';
|
|
15
|
+
export { default as Arrows } from './Arrows.svelte';
|
|
16
|
+
export { default as Slope } from './Slope.svelte';
|
|
17
|
+
export { default as Beeswarm } from './Beeswarm.svelte';
|
|
18
|
+
export { default as Hemicycle } from './Hemicycle.svelte';
|
|
19
|
+
export { default as Intervals } from './Intervals.svelte';
|
|
20
|
+
export { barPath } from './bar-path.js';
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Recipe: an arrow plot. One row per category, with an arrow from its value at
|
|
4
|
+
one date to its value at a later date, the later value written beside the
|
|
5
|
+
arrowhead and the two dates labelled above the first arrow. Rows with only
|
|
6
|
+
one of the two values get a dot (hollow for the start, filled for the end).
|
|
7
|
+
Use it as is, or run `mozaic eject ArrowChart` to copy this file into your
|
|
8
|
+
project and change anything.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts" generics="T">
|
|
11
|
+
import type { Snippet } from 'svelte';
|
|
12
|
+
import { scaleBand, scaleLinear } from 'd3-scale';
|
|
13
|
+
import { max, min } from 'd3-array';
|
|
14
|
+
import { Chart, Header, Title, Subtitle, Footer, Source, Notes } from '../frame/index.js';
|
|
15
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
16
|
+
import { Plot, Svg, estimateTextWidth, scaled, type PlotContext } from '../core/index.js';
|
|
17
|
+
import { Arrows } from '../marks/index.js';
|
|
18
|
+
import { AxisX, AxisY, GridX } from '../guides/index.js';
|
|
19
|
+
import { createLocale, type LocaleCode } from '../locale/index.js';
|
|
20
|
+
import { base, type Medium, type Theme } from '../styles/index.js';
|
|
21
|
+
|
|
22
|
+
type Maybe = number | null | undefined;
|
|
23
|
+
|
|
24
|
+
interface Props {
|
|
25
|
+
data: T[];
|
|
26
|
+
label: (d: T) => string;
|
|
27
|
+
/** Value at the earlier date (the arrow's tail). Missing values leave a single dot. */
|
|
28
|
+
start: (d: T) => Maybe;
|
|
29
|
+
/** Value at the later date (the arrowhead). */
|
|
30
|
+
end: (d: T) => Maybe;
|
|
31
|
+
/** Names of the two dates, shown above the first complete arrow (e.g. "2013" and "2023"). */
|
|
32
|
+
startLabel?: string;
|
|
33
|
+
endLabel?: string;
|
|
34
|
+
style?: Theme;
|
|
35
|
+
locale?: LocaleCode;
|
|
36
|
+
medium?: Medium;
|
|
37
|
+
width?: number;
|
|
38
|
+
title?: string;
|
|
39
|
+
subtitle?: string;
|
|
40
|
+
notes?: string;
|
|
41
|
+
source?: string;
|
|
42
|
+
alt?: string;
|
|
43
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
44
|
+
embed?: ChartEmbed;
|
|
45
|
+
/** Value label format; defaults to locale numbers. */
|
|
46
|
+
format?: (n: number) => string;
|
|
47
|
+
/** Axis tick format; defaults to `format`. */
|
|
48
|
+
tickFormat?: (n: number) => string;
|
|
49
|
+
/** Arrow colour; defaults to the first categorical colour. Grey out rows to highlight others. */
|
|
50
|
+
color?: (d: T) => string;
|
|
51
|
+
/** Values written beside the arrows: the end value (default), both ends, or none. */
|
|
52
|
+
values?: 'end' | 'both' | 'none';
|
|
53
|
+
/** Row order: as given (default), or by end value, start value or difference, largest first. */
|
|
54
|
+
sort?: 'none' | 'end' | 'start' | 'difference';
|
|
55
|
+
/** x domain; defaults to zero and the largest value, rounded. */
|
|
56
|
+
domain?: [number, number];
|
|
57
|
+
rowHeight?: number;
|
|
58
|
+
/** Extra SVG drawn on top of the arrows (annotations); receives the plot context. */
|
|
59
|
+
annotations?: Snippet<[PlotContext]>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let {
|
|
63
|
+
data,
|
|
64
|
+
label,
|
|
65
|
+
start,
|
|
66
|
+
end,
|
|
67
|
+
startLabel,
|
|
68
|
+
endLabel,
|
|
69
|
+
style = base,
|
|
70
|
+
locale,
|
|
71
|
+
medium,
|
|
72
|
+
width,
|
|
73
|
+
title,
|
|
74
|
+
subtitle,
|
|
75
|
+
notes,
|
|
76
|
+
source,
|
|
77
|
+
alt,
|
|
78
|
+
embed,
|
|
79
|
+
format,
|
|
80
|
+
tickFormat,
|
|
81
|
+
color,
|
|
82
|
+
values = 'end',
|
|
83
|
+
sort = 'none',
|
|
84
|
+
domain,
|
|
85
|
+
rowHeight = 32,
|
|
86
|
+
annotations
|
|
87
|
+
}: Props = $props();
|
|
88
|
+
|
|
89
|
+
const theme = $derived(style);
|
|
90
|
+
const fmt = $derived(format ?? createLocale(locale ?? theme.defaultLocale).number);
|
|
91
|
+
const fontSize = $derived(theme.plot.fontSize);
|
|
92
|
+
const has = (v: Maybe): v is number => v !== null && v !== undefined && Number.isFinite(v);
|
|
93
|
+
const colorOf = $derived((d: T) => color?.(d) ?? theme.palettes.categorical[0]);
|
|
94
|
+
|
|
95
|
+
const rows = $derived.by(() => {
|
|
96
|
+
const key = {
|
|
97
|
+
none: undefined,
|
|
98
|
+
end: (d: T) => end(d) ?? -Infinity,
|
|
99
|
+
start: (d: T) => start(d) ?? -Infinity,
|
|
100
|
+
difference: (d: T) => (has(end(d)) && has(start(d)) ? end(d)! - start(d)! : -Infinity)
|
|
101
|
+
}[sort];
|
|
102
|
+
return key ? data.toSorted((a, b) => key(b) - key(a)) : data;
|
|
103
|
+
});
|
|
104
|
+
const both = $derived(rows.filter((d) => has(start(d)) && has(end(d))));
|
|
105
|
+
const all = $derived(rows.flatMap((d) => [start(d), end(d)]).filter(has));
|
|
106
|
+
const x = $derived(
|
|
107
|
+
scaleLinear()
|
|
108
|
+
.domain(domain ?? [Math.min(0, min(all) ?? 0), Math.max(0, max(all) ?? 1)])
|
|
109
|
+
.nice()
|
|
110
|
+
);
|
|
111
|
+
const y = $derived(scaleBand<string>().domain(rows.map(label)).paddingInner(0.25).paddingOuter(0.1));
|
|
112
|
+
const textWidth = (s: string) => estimateTextWidth(s, fontSize);
|
|
113
|
+
const left = $derived(Math.max(...rows.map((d) => textWidth(label(d))), 0) + 12);
|
|
114
|
+
const right = $derived(Math.max(...all.map((v) => textWidth(fmt(v))), 0) + 12);
|
|
115
|
+
const labelled = $derived(Boolean(startLabel || endLabel) && both.length > 0);
|
|
116
|
+
|
|
117
|
+
/** A value beside one end of an arrow, on the side away from the other end; flipped if it would leave the plot. */
|
|
118
|
+
function valueLabel(plot: PlotContext, at: number, other: number | undefined, text: string) {
|
|
119
|
+
const px = plot.x(at) ?? 0;
|
|
120
|
+
const ox = other === undefined ? px - 1 : (plot.x(other) ?? 0);
|
|
121
|
+
const outward = px >= ox ? 1 : -1;
|
|
122
|
+
const gap = 6 + (other === undefined ? 4 : 0);
|
|
123
|
+
const w = textWidth(text);
|
|
124
|
+
const fits = outward > 0 || px - gap - w >= 0;
|
|
125
|
+
const side = fits ? outward : 1;
|
|
126
|
+
const x0 = side > 0 ? Math.max(px, ox) + gap : px - gap;
|
|
127
|
+
return { x: x0, anchor: side > 0 ? 'start' : 'end', text };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The two date labels above the first arrow: centred on each end, or pushed apart when they would touch. */
|
|
131
|
+
function dateLabels(plot: PlotContext) {
|
|
132
|
+
const d = both[0];
|
|
133
|
+
const sx = plot.x(start(d)!) ?? 0;
|
|
134
|
+
const ex = plot.x(end(d)!) ?? 0;
|
|
135
|
+
const ws = textWidth(startLabel ?? '');
|
|
136
|
+
const we = textWidth(endLabel ?? '');
|
|
137
|
+
const apart = Math.abs(ex - sx) >= (ws + we) / 2 + 8;
|
|
138
|
+
const dir = ex >= sx ? 1 : -1;
|
|
139
|
+
return {
|
|
140
|
+
y: scaled(plot.y, label(d)) - plot.y.bandwidth!() / 2 - 4,
|
|
141
|
+
start: { x: sx, anchor: apart ? 'middle' : dir > 0 ? 'end' : 'start' },
|
|
142
|
+
end: { x: ex, anchor: apart ? 'middle' : dir > 0 ? 'start' : 'end' }
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<Chart {style} {locale} {medium} {width} {alt} {embed}>
|
|
148
|
+
{#if title || subtitle}
|
|
149
|
+
<Header>
|
|
150
|
+
{#if title}<Title>{title}</Title>{/if}
|
|
151
|
+
{#if subtitle}<Subtitle>{subtitle}</Subtitle>{/if}
|
|
152
|
+
</Header>
|
|
153
|
+
{/if}
|
|
154
|
+
|
|
155
|
+
<Plot
|
|
156
|
+
{x}
|
|
157
|
+
{y}
|
|
158
|
+
height={rows.length * rowHeight}
|
|
159
|
+
padding={{ left, right, top: labelled ? fontSize + 6 : 0, bottom: 24 }}
|
|
160
|
+
>
|
|
161
|
+
{#snippet children(plot)}
|
|
162
|
+
<Svg>
|
|
163
|
+
<GridX ticks={4} />
|
|
164
|
+
<AxisX ticks={4} format={tickFormat ?? fmt} />
|
|
165
|
+
<AxisY />
|
|
166
|
+
<Arrows
|
|
167
|
+
data={both}
|
|
168
|
+
y={label}
|
|
169
|
+
x1={(d) => start(d)!}
|
|
170
|
+
x2={(d) => end(d)!}
|
|
171
|
+
stroke={colorOf}
|
|
172
|
+
title={(d) => `${label(d)}: ${fmt(start(d)!)} → ${fmt(end(d)!)}`}
|
|
173
|
+
/>
|
|
174
|
+
{#each rows as d (label(d))}
|
|
175
|
+
{@const s = start(d)}
|
|
176
|
+
{@const e = end(d)}
|
|
177
|
+
{@const cy = scaled(plot.y, label(d))}
|
|
178
|
+
{#if has(s) && !has(e)}
|
|
179
|
+
<circle class="mz-arrow-dot-start" cx={plot.x(s)} {cy} r={4} stroke={colorOf(d)}>
|
|
180
|
+
<title>{label(d)}: {fmt(s)}</title>
|
|
181
|
+
</circle>
|
|
182
|
+
{:else if has(e) && !has(s)}
|
|
183
|
+
<circle class="mz-arrow-dot-end" cx={plot.x(e)} {cy} r={4} fill={colorOf(d)}>
|
|
184
|
+
<title>{label(d)}: {fmt(e)}</title>
|
|
185
|
+
</circle>
|
|
186
|
+
{/if}
|
|
187
|
+
{#if values !== 'none'}
|
|
188
|
+
{#if has(e)}
|
|
189
|
+
{@const v = valueLabel(plot, e, has(s) ? s : undefined, fmt(e))}
|
|
190
|
+
<text class="mz-arrow-value strong" x={v.x} y={cy} dy="0.35em" text-anchor={v.anchor}>{v.text}</text>
|
|
191
|
+
{:else if has(s)}
|
|
192
|
+
{@const v = valueLabel(plot, s, undefined, fmt(s))}
|
|
193
|
+
<text class="mz-arrow-value earlier" x={v.x} y={cy} dy="0.35em" text-anchor={v.anchor}>{v.text}</text>
|
|
194
|
+
{/if}
|
|
195
|
+
{#if values === 'both' && has(s) && has(e)}
|
|
196
|
+
{@const v = valueLabel(plot, s, e, fmt(s))}
|
|
197
|
+
<text class="mz-arrow-value" x={v.x} y={cy} dy="0.35em" text-anchor={v.anchor}>{v.text}</text>
|
|
198
|
+
{/if}
|
|
199
|
+
{/if}
|
|
200
|
+
{/each}
|
|
201
|
+
{#if labelled}
|
|
202
|
+
{@const l = dateLabels(plot)}
|
|
203
|
+
{#if startLabel}
|
|
204
|
+
<text class="mz-arrow-date" x={l.start.x} y={l.y} text-anchor={l.start.anchor}>{startLabel}</text>
|
|
205
|
+
{/if}
|
|
206
|
+
{#if endLabel}
|
|
207
|
+
<text class="mz-arrow-date strong" x={l.end.x} y={l.y} text-anchor={l.end.anchor}>{endLabel}</text>
|
|
208
|
+
{/if}
|
|
209
|
+
{/if}
|
|
210
|
+
{@render annotations?.(plot)}
|
|
211
|
+
</Svg>
|
|
212
|
+
{/snippet}
|
|
213
|
+
</Plot>
|
|
214
|
+
|
|
215
|
+
{#if notes || source}
|
|
216
|
+
<Footer>
|
|
217
|
+
{#if notes}<Notes>{notes}</Notes>{/if}
|
|
218
|
+
{#if source}<Source>{source}</Source>{/if}
|
|
219
|
+
</Footer>
|
|
220
|
+
{/if}
|
|
221
|
+
</Chart>
|
|
222
|
+
|
|
223
|
+
<style>
|
|
224
|
+
.mz-arrow-value,
|
|
225
|
+
.mz-arrow-date {
|
|
226
|
+
font-family: var(--mz-font-body);
|
|
227
|
+
font-size: var(--mz-size-axis);
|
|
228
|
+
fill: var(--mz-color-text);
|
|
229
|
+
font-variant-numeric: tabular-nums;
|
|
230
|
+
}
|
|
231
|
+
/* Date labels, and the value of a row with only the earlier date. */
|
|
232
|
+
.mz-arrow-date,
|
|
233
|
+
.earlier {
|
|
234
|
+
fill: var(--mz-color-muted);
|
|
235
|
+
}
|
|
236
|
+
.strong {
|
|
237
|
+
font-weight: var(--mz-weight-strong);
|
|
238
|
+
}
|
|
239
|
+
.mz-arrow-dot-start {
|
|
240
|
+
fill: var(--mz-color-bg);
|
|
241
|
+
stroke-width: 2;
|
|
242
|
+
}
|
|
243
|
+
.mz-arrow-dot-end {
|
|
244
|
+
stroke: var(--mz-color-bg);
|
|
245
|
+
stroke-width: 1.5;
|
|
246
|
+
}
|
|
247
|
+
</style>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ChartEmbed } from '../embed/index.js';
|
|
3
|
+
import { type PlotContext } from '../core/index.js';
|
|
4
|
+
import { type LocaleCode } from '../locale/index.js';
|
|
5
|
+
import { type Medium, type Theme } from '../styles/index.js';
|
|
6
|
+
declare function $$render<T>(): {
|
|
7
|
+
props: {
|
|
8
|
+
data: T[];
|
|
9
|
+
label: (d: T) => string;
|
|
10
|
+
/** Value at the earlier date (the arrow's tail). Missing values leave a single dot. */
|
|
11
|
+
start: (d: T) => number | null | undefined;
|
|
12
|
+
/** Value at the later date (the arrowhead). */
|
|
13
|
+
end: (d: T) => number | null | undefined;
|
|
14
|
+
/** Names of the two dates, shown above the first complete arrow (e.g. "2013" and "2023"). */
|
|
15
|
+
startLabel?: string;
|
|
16
|
+
endLabel?: string;
|
|
17
|
+
style?: Theme;
|
|
18
|
+
locale?: LocaleCode;
|
|
19
|
+
medium?: Medium;
|
|
20
|
+
width?: number;
|
|
21
|
+
title?: string;
|
|
22
|
+
subtitle?: string;
|
|
23
|
+
notes?: string;
|
|
24
|
+
source?: string;
|
|
25
|
+
alt?: string;
|
|
26
|
+
/** The chart's embed page, for the embed code under the chart (see `<Chart embed>`). */
|
|
27
|
+
embed?: ChartEmbed;
|
|
28
|
+
/** Value label format; defaults to locale numbers. */
|
|
29
|
+
format?: (n: number) => string;
|
|
30
|
+
/** Axis tick format; defaults to `format`. */
|
|
31
|
+
tickFormat?: (n: number) => string;
|
|
32
|
+
/** Arrow colour; defaults to the first categorical colour. Grey out rows to highlight others. */
|
|
33
|
+
color?: (d: T) => string;
|
|
34
|
+
/** Values written beside the arrows: the end value (default), both ends, or none. */
|
|
35
|
+
values?: "end" | "both" | "none";
|
|
36
|
+
/** Row order: as given (default), or by end value, start value or difference, largest first. */
|
|
37
|
+
sort?: "none" | "end" | "start" | "difference";
|
|
38
|
+
/** x domain; defaults to zero and the largest value, rounded. */
|
|
39
|
+
domain?: [number, number];
|
|
40
|
+
rowHeight?: number;
|
|
41
|
+
/** Extra SVG drawn on top of the arrows (annotations); receives the plot context. */
|
|
42
|
+
annotations?: Snippet<[PlotContext]>;
|
|
43
|
+
};
|
|
44
|
+
exports: {};
|
|
45
|
+
bindings: "";
|
|
46
|
+
slots: {};
|
|
47
|
+
events: {};
|
|
48
|
+
};
|
|
49
|
+
declare class __sveltets_Render<T> {
|
|
50
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
51
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
52
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
53
|
+
bindings(): "";
|
|
54
|
+
exports(): {};
|
|
55
|
+
}
|
|
56
|
+
interface $$IsomorphicComponent {
|
|
57
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
58
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
59
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
60
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
61
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Recipe: an arrow plot. One row per category, with an arrow from its value at
|
|
65
|
+
* one date to its value at a later date, the later value written beside the
|
|
66
|
+
* arrowhead and the two dates labelled above the first arrow. Rows with only
|
|
67
|
+
* one of the two values get a dot (hollow for the start, filled for the end).
|
|
68
|
+
* Use it as is, or run `mozaic eject ArrowChart` to copy this file into your
|
|
69
|
+
* project and change anything.
|
|
70
|
+
*/
|
|
71
|
+
declare const ArrowChart: $$IsomorphicComponent;
|
|
72
|
+
type ArrowChart<T> = InstanceType<typeof ArrowChart<T>>;
|
|
73
|
+
export default ArrowChart;
|