@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,46 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Reference lines across the whole plot: vertical at each `x` value, horizontal
|
|
4
|
+
at each `y` value. Typically the zero line.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { usePlot } from '../core/context.js';
|
|
8
|
+
import { scaled } from '../core/scales.js';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
x?: unknown[];
|
|
12
|
+
y?: unknown[];
|
|
13
|
+
stroke?: string;
|
|
14
|
+
strokeWidth?: number;
|
|
15
|
+
dash?: string;
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
x = [],
|
|
21
|
+
y = [],
|
|
22
|
+
stroke = 'var(--mz-color-text)',
|
|
23
|
+
strokeWidth = 1,
|
|
24
|
+
dash,
|
|
25
|
+
class: className = ''
|
|
26
|
+
}: Props = $props();
|
|
27
|
+
|
|
28
|
+
const plot = usePlot();
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<g class="mz-rules {className}" style:stroke stroke-width={strokeWidth} stroke-dasharray={dash}>
|
|
32
|
+
{#each x as value}
|
|
33
|
+
{@const px = scaled(plot.x, value)}
|
|
34
|
+
<line x1={px} x2={px} y2={plot.height} />
|
|
35
|
+
{/each}
|
|
36
|
+
{#each y as value}
|
|
37
|
+
{@const py = scaled(plot.y, value)}
|
|
38
|
+
<line y1={py} y2={py} x2={plot.width} />
|
|
39
|
+
{/each}
|
|
40
|
+
</g>
|
|
41
|
+
|
|
42
|
+
<style>
|
|
43
|
+
.mz-rules line {
|
|
44
|
+
shape-rendering: crispEdges;
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
x?: unknown[];
|
|
3
|
+
y?: unknown[];
|
|
4
|
+
stroke?: string;
|
|
5
|
+
strokeWidth?: number;
|
|
6
|
+
dash?: string;
|
|
7
|
+
class?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reference lines across the whole plot: vertical at each `x` value, horizontal
|
|
11
|
+
* at each `y` value. Typically the zero line.
|
|
12
|
+
*/
|
|
13
|
+
declare const Rules: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type Rules = ReturnType<typeof Rules>;
|
|
15
|
+
export default Rules;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A slope chart: each item is a line from its start value (left edge of the
|
|
4
|
+
plot) to its end value (right edge), with labels on both sides nudged apart.
|
|
5
|
+
Needs a continuous y scale; leave padding left and right for the labels.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts" generics="T">
|
|
8
|
+
import { useChart, usePlot } from '../core/context.js';
|
|
9
|
+
import { avoidOverlap } from '../transforms/labels.js';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
data: T[];
|
|
13
|
+
start: (d: T) => number;
|
|
14
|
+
end: (d: T) => number;
|
|
15
|
+
label: (d: T) => string;
|
|
16
|
+
color?: (d: T, index: number) => string;
|
|
17
|
+
format?: (n: number) => string;
|
|
18
|
+
/** Column headings, e.g. ['2015', '2025']. */
|
|
19
|
+
headings?: [string, string];
|
|
20
|
+
/** Minimum vertical distance between labels, px. */
|
|
21
|
+
minGap?: number;
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
data,
|
|
27
|
+
start,
|
|
28
|
+
end,
|
|
29
|
+
label,
|
|
30
|
+
color,
|
|
31
|
+
format = String,
|
|
32
|
+
headings,
|
|
33
|
+
minGap = 14,
|
|
34
|
+
class: className = ''
|
|
35
|
+
}: Props = $props();
|
|
36
|
+
|
|
37
|
+
const chart = useChart();
|
|
38
|
+
const plot = usePlot();
|
|
39
|
+
|
|
40
|
+
const left = $derived(
|
|
41
|
+
avoidOverlap(
|
|
42
|
+
data.map((d) => plot.y(start(d)) ?? 0),
|
|
43
|
+
minGap,
|
|
44
|
+
[0, plot.height]
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
const right = $derived(
|
|
48
|
+
avoidOverlap(
|
|
49
|
+
data.map((d) => plot.y(end(d)) ?? 0),
|
|
50
|
+
minGap,
|
|
51
|
+
[0, plot.height]
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
const colour = (d: T, i: number) =>
|
|
55
|
+
color?.(d, i) ?? chart.theme.palettes.categorical[i % chart.theme.palettes.categorical.length];
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<g class="mz-slope {className}">
|
|
59
|
+
{#if headings}
|
|
60
|
+
<text class="mz-slope-heading" x={0} y={-10} text-anchor="middle">{headings[0]}</text>
|
|
61
|
+
<text class="mz-slope-heading" x={plot.width} y={-10} text-anchor="middle">{headings[1]}</text>
|
|
62
|
+
{/if}
|
|
63
|
+
<line class="mz-slope-axis" x1={0} x2={0} y2={plot.height} />
|
|
64
|
+
<line class="mz-slope-axis" x1={plot.width} x2={plot.width} y2={plot.height} />
|
|
65
|
+
{#each data as d, i}
|
|
66
|
+
<line
|
|
67
|
+
x1={0}
|
|
68
|
+
x2={plot.width}
|
|
69
|
+
y1={plot.y(start(d))}
|
|
70
|
+
y2={plot.y(end(d))}
|
|
71
|
+
stroke={colour(d, i)}
|
|
72
|
+
stroke-width={chart.theme.plot.lineWidth}
|
|
73
|
+
stroke-linecap="round"
|
|
74
|
+
/>
|
|
75
|
+
<circle cx={0} cy={plot.y(start(d))} r={4} fill={colour(d, i)} />
|
|
76
|
+
<circle cx={plot.width} cy={plot.y(end(d))} r={4} fill={colour(d, i)} />
|
|
77
|
+
<text x={-10} y={left[i]} dy="0.32em" text-anchor="end"
|
|
78
|
+
>{label(d)} <tspan class="mz-slope-value">{format(start(d))}</tspan></text
|
|
79
|
+
>
|
|
80
|
+
<text x={plot.width + 10} y={right[i]} dy="0.32em"
|
|
81
|
+
><tspan class="mz-slope-value">{format(end(d))}</tspan> {label(d)}</text
|
|
82
|
+
>
|
|
83
|
+
{/each}
|
|
84
|
+
</g>
|
|
85
|
+
|
|
86
|
+
<style>
|
|
87
|
+
text {
|
|
88
|
+
fill: var(--mz-color-text);
|
|
89
|
+
font-size: var(--mz-size-axis);
|
|
90
|
+
paint-order: stroke;
|
|
91
|
+
stroke: var(--mz-color-bg);
|
|
92
|
+
stroke-width: 3px;
|
|
93
|
+
stroke-linejoin: round;
|
|
94
|
+
}
|
|
95
|
+
.mz-slope-value {
|
|
96
|
+
font-weight: var(--mz-weight-strong);
|
|
97
|
+
}
|
|
98
|
+
.mz-slope-heading {
|
|
99
|
+
font-family: var(--mz-font-label);
|
|
100
|
+
font-weight: var(--mz-weight-label);
|
|
101
|
+
text-transform: var(--mz-label-transform);
|
|
102
|
+
letter-spacing: var(--mz-label-tracking);
|
|
103
|
+
fill: var(--mz-color-muted);
|
|
104
|
+
}
|
|
105
|
+
.mz-slope-axis {
|
|
106
|
+
stroke: var(--mz-color-grid);
|
|
107
|
+
}
|
|
108
|
+
circle {
|
|
109
|
+
stroke: var(--mz-color-bg);
|
|
110
|
+
stroke-width: 1.5;
|
|
111
|
+
}
|
|
112
|
+
</style>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
declare function $$render<T>(): {
|
|
2
|
+
props: {
|
|
3
|
+
data: T[];
|
|
4
|
+
start: (d: T) => number;
|
|
5
|
+
end: (d: T) => number;
|
|
6
|
+
label: (d: T) => string;
|
|
7
|
+
color?: (d: T, index: number) => string;
|
|
8
|
+
format?: (n: number) => string;
|
|
9
|
+
/** Column headings, e.g. ['2015', '2025']. */
|
|
10
|
+
headings?: [string, string];
|
|
11
|
+
/** Minimum vertical distance between labels, px. */
|
|
12
|
+
minGap?: number;
|
|
13
|
+
class?: string;
|
|
14
|
+
};
|
|
15
|
+
exports: {};
|
|
16
|
+
bindings: "";
|
|
17
|
+
slots: {};
|
|
18
|
+
events: {};
|
|
19
|
+
};
|
|
20
|
+
declare class __sveltets_Render<T> {
|
|
21
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
22
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
23
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
24
|
+
bindings(): "";
|
|
25
|
+
exports(): {};
|
|
26
|
+
}
|
|
27
|
+
interface $$IsomorphicComponent {
|
|
28
|
+
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']>> & {
|
|
29
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
30
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
31
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
32
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A slope chart: each item is a line from its start value (left edge of the
|
|
36
|
+
* plot) to its end value (right edge), with labels on both sides nudged apart.
|
|
37
|
+
* Needs a continuous y scale; leave padding left and right for the labels.
|
|
38
|
+
*/
|
|
39
|
+
declare const Slope: $$IsomorphicComponent;
|
|
40
|
+
type Slope<T> = InstanceType<typeof Slope<T>>;
|
|
41
|
+
export default Slope;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Text at data positions. Without `data`, draws a single label at `x`/`y`. With a projection on
|
|
4
|
+
`<Plot>`, `x`/`y` are longitude/latitude.
|
|
5
|
+
Newlines in the text become separate lines. `halo` adds an outline in the
|
|
6
|
+
background colour so text stays legible over marks.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts" generics="T">
|
|
9
|
+
import { usePlot } from '../core/context.js';
|
|
10
|
+
import { access, type Accessor, type Value } from '../core/accessor.js';
|
|
11
|
+
import { position } from '../core/scales.js';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
data?: T[];
|
|
15
|
+
x: Accessor<T, Value>;
|
|
16
|
+
y: Accessor<T, Value>;
|
|
17
|
+
text: Accessor<T, string>;
|
|
18
|
+
dx?: number;
|
|
19
|
+
dy?: number;
|
|
20
|
+
anchor?: 'start' | 'middle' | 'end';
|
|
21
|
+
/** Vertical alignment of the first line relative to y. */
|
|
22
|
+
baseline?: 'top' | 'middle' | 'bottom';
|
|
23
|
+
fill?: Accessor<T, string>;
|
|
24
|
+
fontSize?: number | string;
|
|
25
|
+
fontWeight?: number | string;
|
|
26
|
+
halo?: boolean;
|
|
27
|
+
lineHeight?: number;
|
|
28
|
+
class?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
data = [undefined as T],
|
|
33
|
+
x,
|
|
34
|
+
y,
|
|
35
|
+
text,
|
|
36
|
+
dx = 0,
|
|
37
|
+
dy = 0,
|
|
38
|
+
anchor = 'start',
|
|
39
|
+
baseline = 'middle',
|
|
40
|
+
fill,
|
|
41
|
+
fontSize,
|
|
42
|
+
fontWeight,
|
|
43
|
+
halo = false,
|
|
44
|
+
lineHeight = 1.2,
|
|
45
|
+
class: className = ''
|
|
46
|
+
}: Props = $props();
|
|
47
|
+
|
|
48
|
+
const plot = usePlot();
|
|
49
|
+
const shift = $derived(baseline === 'top' ? '0.71em' : baseline === 'middle' ? '0.32em' : '0');
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<g class="mz-text {className}" class:mz-halo={halo} font-size={fontSize} font-weight={fontWeight}>
|
|
53
|
+
{#each data as d, i}
|
|
54
|
+
{@const lines = String(access(text, d, i)).split('\n')}
|
|
55
|
+
{@const [px, py] = position(plot, access(x, d, i), access(y, d, i))}
|
|
56
|
+
<text x={px + dx} y={py + dy} text-anchor={anchor} style:fill={fill ? access(fill, d, i) : undefined}>
|
|
57
|
+
{#each lines as line, l}
|
|
58
|
+
<tspan x={px + dx} dy={l === 0 ? shift : `${lineHeight}em`}>{line}</tspan>
|
|
59
|
+
{/each}
|
|
60
|
+
</text>
|
|
61
|
+
{/each}
|
|
62
|
+
</g>
|
|
63
|
+
|
|
64
|
+
<style>
|
|
65
|
+
.mz-text text {
|
|
66
|
+
fill: var(--mz-color-text);
|
|
67
|
+
font-size: var(--mz-size-axis);
|
|
68
|
+
}
|
|
69
|
+
.mz-halo text {
|
|
70
|
+
paint-order: stroke;
|
|
71
|
+
stroke: var(--mz-color-bg);
|
|
72
|
+
stroke-width: 3px;
|
|
73
|
+
stroke-linejoin: round;
|
|
74
|
+
}
|
|
75
|
+
</style>
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
text: Accessor<T, string>;
|
|
8
|
+
dx?: number;
|
|
9
|
+
dy?: number;
|
|
10
|
+
anchor?: "start" | "middle" | "end";
|
|
11
|
+
/** Vertical alignment of the first line relative to y. */
|
|
12
|
+
baseline?: "top" | "middle" | "bottom";
|
|
13
|
+
fill?: Accessor<T, string>;
|
|
14
|
+
fontSize?: number | string;
|
|
15
|
+
fontWeight?: number | string;
|
|
16
|
+
halo?: boolean;
|
|
17
|
+
lineHeight?: number;
|
|
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
|
+
* Text at data positions. Without `data`, draws a single label at `x`/`y`. With a projection on
|
|
41
|
+
* `<Plot>`, `x`/`y` are longitude/latitude.
|
|
42
|
+
* Newlines in the text become separate lines. `halo` adds an outline in the
|
|
43
|
+
* background colour so text stays legible over marks.
|
|
44
|
+
*/
|
|
45
|
+
declare const Text: $$IsomorphicComponent;
|
|
46
|
+
type Text<T> = InstanceType<typeof Text<T>>;
|
|
47
|
+
export default Text;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A squarified treemap filling the plot area. Labels are drawn only where
|
|
4
|
+
they fit. Optionally grouped one level deep (`group`).
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts" generics="T">
|
|
7
|
+
import { useChart, usePlot } from '../core/context.js';
|
|
8
|
+
import { estimateTextWidth } from '../core/scales.js';
|
|
9
|
+
import { treemapLayout, type TreemapCell } from '../transforms/treemap.js';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
data: T[];
|
|
13
|
+
value: (d: T) => number;
|
|
14
|
+
group?: (d: T) => string;
|
|
15
|
+
fill?: (d: T, group: string | undefined) => string;
|
|
16
|
+
label?: (d: T) => string;
|
|
17
|
+
/** Second label line, e.g. the formatted value. */
|
|
18
|
+
sublabel?: (d: T) => string;
|
|
19
|
+
/** Text colour inside cells; pick one with enough contrast against the fills. */
|
|
20
|
+
labelColor?: string;
|
|
21
|
+
padding?: number;
|
|
22
|
+
title?: (d: T) => string;
|
|
23
|
+
/** Also receives the cell's pixel box, e.g. to place a tooltip at its centre. */
|
|
24
|
+
onpointerenter?: (d: T, event: PointerEvent, cell: TreemapCell<T>) => void;
|
|
25
|
+
onpointerleave?: (d: T, event: PointerEvent, cell: TreemapCell<T>) => void;
|
|
26
|
+
class?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let {
|
|
30
|
+
data,
|
|
31
|
+
value,
|
|
32
|
+
group,
|
|
33
|
+
fill,
|
|
34
|
+
label,
|
|
35
|
+
sublabel,
|
|
36
|
+
labelColor = '#ffffff',
|
|
37
|
+
padding = 1,
|
|
38
|
+
title,
|
|
39
|
+
onpointerenter,
|
|
40
|
+
onpointerleave,
|
|
41
|
+
class: className = ''
|
|
42
|
+
}: Props = $props();
|
|
43
|
+
|
|
44
|
+
const chart = useChart();
|
|
45
|
+
const plot = usePlot();
|
|
46
|
+
|
|
47
|
+
const cells = $derived(treemapLayout(data, { value, group, width: plot.width, height: plot.height, padding }));
|
|
48
|
+
const groupNames = $derived([...new Set(cells.map((c) => c.group))]);
|
|
49
|
+
const size = $derived(chart.theme.plot.fontSize);
|
|
50
|
+
|
|
51
|
+
function colour(cell: TreemapCell<T>): string {
|
|
52
|
+
if (fill) return fill(cell.datum, cell.group);
|
|
53
|
+
const palette = chart.theme.palettes.categorical;
|
|
54
|
+
return palette[Math.max(0, groupNames.indexOf(cell.group)) % palette.length];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function fits(cell: TreemapCell<T>, text: string, lines: number): boolean {
|
|
58
|
+
return cell.x1 - cell.x0 >= estimateTextWidth(text, size) + 8 && cell.y1 - cell.y0 >= size * 1.3 * lines + 6;
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<g class="mz-treemap {className}">
|
|
63
|
+
{#each cells as cell}
|
|
64
|
+
{@const main = label?.(cell.datum) ?? ''}
|
|
65
|
+
{@const sub = sublabel?.(cell.datum) ?? ''}
|
|
66
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
67
|
+
<g
|
|
68
|
+
transform="translate({cell.x0},{cell.y0})"
|
|
69
|
+
onpointerenter={onpointerenter ? (e) => onpointerenter(cell.datum, e, cell) : undefined}
|
|
70
|
+
onpointerleave={onpointerleave ? (e) => onpointerleave(cell.datum, e, cell) : undefined}
|
|
71
|
+
>
|
|
72
|
+
<rect width={cell.x1 - cell.x0} height={cell.y1 - cell.y0} fill={colour(cell)}
|
|
73
|
+
>{#if title}<title>{title(cell.datum)}</title>{/if}</rect
|
|
74
|
+
>
|
|
75
|
+
{#if main && fits(cell, main, sub ? 2 : 1)}
|
|
76
|
+
<text x={4} y={4} dy="0.9em" style:fill={labelColor} font-size={size}>
|
|
77
|
+
<tspan x={4} style:font-weight="var(--mz-weight-strong)">{main}</tspan>
|
|
78
|
+
{#if sub && fits(cell, sub, 2)}<tspan x={4} dy="1.25em">{sub}</tspan>{/if}
|
|
79
|
+
</text>
|
|
80
|
+
{/if}
|
|
81
|
+
</g>
|
|
82
|
+
{/each}
|
|
83
|
+
</g>
|
|
84
|
+
|
|
85
|
+
<style>
|
|
86
|
+
text {
|
|
87
|
+
pointer-events: none;
|
|
88
|
+
}
|
|
89
|
+
</style>
|
|
@@ -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,69 @@
|
|
|
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").
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts" generics="T">
|
|
7
|
+
import { useChart, usePlot } from '../core/context.js';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
data: T[];
|
|
11
|
+
value: (d: T) => number;
|
|
12
|
+
fill?: (d: T, index: number) => string;
|
|
13
|
+
/** Squares per row. */
|
|
14
|
+
columns?: number;
|
|
15
|
+
/** Total number of squares; defaults to the sum of values. Remaining squares use `emptyFill`. */
|
|
16
|
+
total?: number;
|
|
17
|
+
emptyFill?: string;
|
|
18
|
+
/** Gap between squares in px. */
|
|
19
|
+
gap?: number;
|
|
20
|
+
title?: (d: T) => string;
|
|
21
|
+
class?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let {
|
|
25
|
+
data,
|
|
26
|
+
value,
|
|
27
|
+
fill,
|
|
28
|
+
columns = 10,
|
|
29
|
+
total,
|
|
30
|
+
emptyFill = 'var(--mz-color-grid)',
|
|
31
|
+
gap = 2,
|
|
32
|
+
title,
|
|
33
|
+
class: className = ''
|
|
34
|
+
}: Props = $props();
|
|
35
|
+
|
|
36
|
+
const chart = useChart();
|
|
37
|
+
const plot = usePlot();
|
|
38
|
+
|
|
39
|
+
const counts = $derived(data.map((d) => Math.max(0, Math.round(value(d)))));
|
|
40
|
+
const count = $derived(total ?? counts.reduce((a, b) => a + b, 0));
|
|
41
|
+
const rows = $derived(Math.ceil(count / columns));
|
|
42
|
+
const cell = $derived(Math.max(0, Math.min(plot.width / columns, plot.height / Math.max(1, rows))));
|
|
43
|
+
const squares = $derived.by(() => {
|
|
44
|
+
const out: { i: number; d: T | undefined; k: number }[] = [];
|
|
45
|
+
let i = 0;
|
|
46
|
+
counts.forEach((c, k) => {
|
|
47
|
+
for (let n = 0; n < c && i < count; n++) out.push({ i: i++, d: data[k], k });
|
|
48
|
+
});
|
|
49
|
+
while (i < count) out.push({ i: i++, d: undefined, k: -1 });
|
|
50
|
+
return out;
|
|
51
|
+
});
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<g class="mz-waffle {className}">
|
|
55
|
+
{#each squares as sq}
|
|
56
|
+
<rect
|
|
57
|
+
x={(sq.i % columns) * cell + gap / 2}
|
|
58
|
+
y={Math.floor(sq.i / columns) * cell + gap / 2}
|
|
59
|
+
width={Math.max(0, cell - gap)}
|
|
60
|
+
height={Math.max(0, cell - gap)}
|
|
61
|
+
fill={sq.d === undefined
|
|
62
|
+
? emptyFill
|
|
63
|
+
: fill
|
|
64
|
+
? fill(sq.d, sq.k)
|
|
65
|
+
: chart.theme.palettes.categorical[sq.k % chart.theme.palettes.categorical.length]}
|
|
66
|
+
>{#if title && sq.d !== undefined}<title>{title(sq.d)}</title>{/if}</rect
|
|
67
|
+
>
|
|
68
|
+
{/each}
|
|
69
|
+
</g>
|