tuidroid 0.0.0-stage → 0.1.1
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 +181 -2
- package/dist/arrange/Mover.svelte +42 -0
- package/dist/arrange/Mover.svelte.d.ts +29 -0
- package/dist/arrange/PutAway.svelte +48 -0
- package/dist/arrange/PutAway.svelte.d.ts +30 -0
- package/dist/arrange/arrangement.svelte.d.ts +27 -0
- package/dist/arrange/arrangement.svelte.js +44 -0
- package/dist/arrange/order.d.ts +7 -0
- package/dist/arrange/order.js +20 -0
- package/dist/calendar/Calendar.svelte +328 -0
- package/dist/calendar/Calendar.svelte.d.ts +28 -0
- package/dist/calendar/MonthPicker.svelte +41 -0
- package/dist/calendar/MonthPicker.svelte.d.ts +10 -0
- package/dist/calendar/YearPicker.svelte +61 -0
- package/dist/calendar/YearPicker.svelte.d.ts +11 -0
- package/dist/calendar/dates.d.ts +23 -0
- package/dist/calendar/dates.js +54 -0
- package/dist/charts/BarChart.svelte +98 -0
- package/dist/charts/BarChart.svelte.d.ts +28 -0
- package/dist/charts/ChartFrame.svelte +133 -0
- package/dist/charts/ChartFrame.svelte.d.ts +21 -0
- package/dist/charts/ColumnChart.svelte +79 -0
- package/dist/charts/ColumnChart.svelte.d.ts +20 -0
- package/dist/charts/HeatGrid.svelte +110 -0
- package/dist/charts/HeatGrid.svelte.d.ts +22 -0
- package/dist/charts/LineChart.svelte +132 -0
- package/dist/charts/LineChart.svelte.d.ts +29 -0
- package/dist/charts/StripChart.svelte +80 -0
- package/dist/charts/StripChart.svelte.d.ts +27 -0
- package/dist/charts/scale.d.ts +17 -0
- package/dist/charts/scale.js +35 -0
- package/dist/controls/AccentStepper.svelte +24 -0
- package/dist/controls/AccentStepper.svelte.d.ts +8 -0
- package/dist/controls/Button.svelte +264 -0
- package/dist/controls/Button.svelte.d.ts +26 -0
- package/dist/controls/Cycle.svelte +27 -0
- package/dist/controls/Cycle.svelte.d.ts +31 -0
- package/dist/controls/NumberStepper.svelte +28 -0
- package/dist/controls/NumberStepper.svelte.d.ts +12 -0
- package/dist/controls/OptionStepper.svelte +42 -0
- package/dist/controls/OptionStepper.svelte.d.ts +34 -0
- package/dist/controls/Segmented.svelte +72 -0
- package/dist/controls/Segmented.svelte.d.ts +35 -0
- package/dist/controls/SettingRow.svelte +59 -0
- package/dist/controls/SettingRow.svelte.d.ts +11 -0
- package/dist/controls/Stepper.svelte +151 -0
- package/dist/controls/Stepper.svelte.d.ts +17 -0
- package/dist/controls/TextInput.svelte +176 -0
- package/dist/controls/TextInput.svelte.d.ts +12 -0
- package/dist/controls/Toggle.svelte +22 -0
- package/dist/controls/Toggle.svelte.d.ts +9 -0
- package/dist/data/BarRows.svelte +75 -0
- package/dist/data/BarRows.svelte.d.ts +15 -0
- package/dist/data/CellBar.svelte +55 -0
- package/dist/data/CellBar.svelte.d.ts +13 -0
- package/dist/data/Delta.svelte +28 -0
- package/dist/data/Delta.svelte.d.ts +11 -0
- package/dist/data/Hatch.svelte +9 -0
- package/dist/data/Hatch.svelte.d.ts +8 -0
- package/dist/data/KeyValues.svelte +56 -0
- package/dist/data/KeyValues.svelte.d.ts +14 -0
- package/dist/data/Legend.svelte +64 -0
- package/dist/data/Legend.svelte.d.ts +15 -0
- package/dist/data/Meter.svelte +46 -0
- package/dist/data/Meter.svelte.d.ts +9 -0
- package/dist/data/StackedBar.svelte +64 -0
- package/dist/data/StackedBar.svelte.d.ts +14 -0
- package/dist/data/Swatch.svelte +56 -0
- package/dist/data/Swatch.svelte.d.ts +11 -0
- package/dist/data/Table.svelte +86 -0
- package/dist/data/Table.svelte.d.ts +16 -0
- package/dist/data/Value.svelte +32 -0
- package/dist/data/Value.svelte.d.ts +12 -0
- package/dist/data/cells.d.ts +27 -0
- package/dist/data/cells.js +41 -0
- package/dist/data/fit.d.ts +10 -0
- package/dist/data/fit.js +35 -0
- package/dist/gestures/drag.d.ts +28 -0
- package/dist/gestures/drag.js +110 -0
- package/dist/gestures/hold.d.ts +7 -0
- package/dist/gestures/hold.js +59 -0
- package/dist/gestures/pick.d.ts +5 -0
- package/dist/gestures/pick.js +60 -0
- package/dist/haptics.d.ts +5 -0
- package/dist/haptics.js +16 -0
- package/dist/icons/Icon.svelte +52 -0
- package/dist/icons/Icon.svelte.d.ts +17 -0
- package/dist/icons/material.d.ts +68 -0
- package/dist/icons/material.js +69 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +91 -0
- package/dist/layout/Alert.svelte +46 -0
- package/dist/layout/Alert.svelte.d.ts +12 -0
- package/dist/layout/Block.svelte +166 -0
- package/dist/layout/Block.svelte.d.ts +22 -0
- package/dist/layout/Panes.svelte +41 -0
- package/dist/layout/Panes.svelte.d.ts +9 -0
- package/dist/layout/Rows.svelte +37 -0
- package/dist/layout/Rows.svelte.d.ts +8 -0
- package/dist/layout/Split.svelte +18 -0
- package/dist/layout/Split.svelte.d.ts +4 -0
- package/dist/layout/Stage.svelte +59 -0
- package/dist/layout/Stage.svelte.d.ts +10 -0
- package/dist/layout/Unfold.svelte +25 -0
- package/dist/layout/Unfold.svelte.d.ts +9 -0
- package/dist/lists/ListItem.svelte +75 -0
- package/dist/lists/ListItem.svelte.d.ts +13 -0
- package/dist/lists/SwipeRow.svelte +158 -0
- package/dist/lists/SwipeRow.svelte.d.ts +21 -0
- package/dist/lists/UndoRow.svelte +37 -0
- package/dist/lists/UndoRow.svelte.d.ts +10 -0
- package/dist/motion/FlipCard.svelte +197 -0
- package/dist/motion/FlipCard.svelte.d.ts +34 -0
- package/dist/motion/Hero.svelte +59 -0
- package/dist/motion/Hero.svelte.d.ts +9 -0
- package/dist/motion/ShuffleText.svelte +42 -0
- package/dist/motion/ShuffleText.svelte.d.ts +13 -0
- package/dist/motion/TypeText.svelte +68 -0
- package/dist/motion/TypeText.svelte.d.ts +11 -0
- package/dist/motion/shuffle.d.ts +24 -0
- package/dist/motion/shuffle.js +58 -0
- package/dist/motion/still.d.ts +2 -0
- package/dist/motion/still.js +7 -0
- package/dist/motion/sweep.d.ts +14 -0
- package/dist/motion/sweep.js +59 -0
- package/dist/motion/typing.d.ts +9 -0
- package/dist/motion/typing.js +19 -0
- package/dist/motion/unfold.d.ts +4 -0
- package/dist/motion/unfold.js +13 -0
- package/dist/nav/Hang.svelte +194 -0
- package/dist/nav/Hang.svelte.d.ts +15 -0
- package/dist/nav/Pager.svelte +89 -0
- package/dist/nav/Pager.svelte.d.ts +43 -0
- package/dist/nav/Pane.svelte +93 -0
- package/dist/nav/Pane.svelte.d.ts +15 -0
- package/dist/nav/Shell.svelte +40 -0
- package/dist/nav/Shell.svelte.d.ts +34 -0
- package/dist/nav/TabBar.svelte +139 -0
- package/dist/nav/TabBar.svelte.d.ts +15 -0
- package/dist/styles/base.css +87 -0
- package/dist/styles/tokens.css +253 -0
- package/dist/text/Fields.svelte +28 -0
- package/dist/text/Fields.svelte.d.ts +8 -0
- package/dist/text/fields.d.ts +6 -0
- package/dist/text/fields.js +16 -0
- package/dist/theme/FlavourButton.svelte +55 -0
- package/dist/theme/FlavourButton.svelte.d.ts +13 -0
- package/dist/theme/Theme.svelte +48 -0
- package/dist/theme/Theme.svelte.d.ts +15 -0
- package/dist/theme/palette.d.ts +23 -0
- package/dist/theme/palette.js +55 -0
- package/dist/theme/reveal.d.ts +10 -0
- package/dist/theme/reveal.js +92 -0
- package/dist/theme/theme.d.ts +15 -0
- package/dist/theme/theme.js +21 -0
- package/package.json +72 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
/** The chart's box and the grid it is drawn on, in px. */
|
|
3
|
+
export interface ChartSize {
|
|
4
|
+
width: number
|
|
5
|
+
height: number
|
|
6
|
+
ch: number // a character's width
|
|
7
|
+
em: number // the font's size
|
|
8
|
+
}
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import type { Snippet } from 'svelte'
|
|
13
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
14
|
+
import { charWidth } from '../data/fit'
|
|
15
|
+
import { pick, type OnPick } from '../gestures/pick'
|
|
16
|
+
|
|
17
|
+
// The ground every chart is drawn on: an SVG as wide as it is given and `height` high,
|
|
18
|
+
// in px on the text's grid, its labels in the app's font. bind:size to lay the marks out
|
|
19
|
+
// in it. A tap or a sideways drag on it goes to `onpick`; up and down still scroll. The
|
|
20
|
+
// line under it (`below`) reads out what is picked, or says what the chart shows. The
|
|
21
|
+
// marks are the chart's `children`, drawn with the classes here: .axis (labels), .rule
|
|
22
|
+
// and .base (lines), .empty, .mark, .dim.
|
|
23
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
24
|
+
height?: string // a CSS length
|
|
25
|
+
label: string // what the chart shows, for a screen reader
|
|
26
|
+
size?: ChartSize
|
|
27
|
+
onpick?: OnPick
|
|
28
|
+
children: Snippet
|
|
29
|
+
below?: Snippet
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let {
|
|
33
|
+
height = '6.5em',
|
|
34
|
+
label,
|
|
35
|
+
size = $bindable({ width: 0, height: 0, ch: 8, em: 16 }),
|
|
36
|
+
onpick,
|
|
37
|
+
children,
|
|
38
|
+
below,
|
|
39
|
+
class: className,
|
|
40
|
+
...rest
|
|
41
|
+
}: Props = $props()
|
|
42
|
+
|
|
43
|
+
function measure(node: HTMLElement) {
|
|
44
|
+
const update = () => {
|
|
45
|
+
const style = getComputedStyle(node)
|
|
46
|
+
size = { width: node.clientWidth, height: node.clientHeight, ch: charWidth(node), em: parseFloat(style.fontSize) || 16 }
|
|
47
|
+
}
|
|
48
|
+
update()
|
|
49
|
+
const observer = new ResizeObserver(update)
|
|
50
|
+
observer.observe(node)
|
|
51
|
+
void document.fonts?.ready.then(update)
|
|
52
|
+
return () => observer.disconnect()
|
|
53
|
+
}
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<div {...rest} class={['tui-chart', className]}>
|
|
57
|
+
<div class="ground" style:height {@attach measure}>
|
|
58
|
+
{#if size.width && size.height}
|
|
59
|
+
<svg
|
|
60
|
+
width={size.width}
|
|
61
|
+
height={size.height}
|
|
62
|
+
viewBox="0 0 {size.width} {size.height}"
|
|
63
|
+
role="img"
|
|
64
|
+
aria-label={label}
|
|
65
|
+
{@attach onpick && pick(onpick)}>{@render children()}</svg
|
|
66
|
+
>
|
|
67
|
+
{/if}
|
|
68
|
+
</div>
|
|
69
|
+
{#if below}<p class="below">{@render below()}</p>{/if}
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<style>
|
|
73
|
+
@layer tuidroid {
|
|
74
|
+
.tui-chart {
|
|
75
|
+
margin: 0.3em 0 0.2em;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.ground {
|
|
79
|
+
position: relative;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
svg {
|
|
83
|
+
display: block;
|
|
84
|
+
overflow: visible;
|
|
85
|
+
font-variant-ligatures: none;
|
|
86
|
+
touch-action: pan-y;
|
|
87
|
+
user-select: none;
|
|
88
|
+
-webkit-user-select: none;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.below {
|
|
92
|
+
margin: 0.2em 0 0;
|
|
93
|
+
text-align: center;
|
|
94
|
+
white-space: pre-wrap;
|
|
95
|
+
font-variant-ligatures: none;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* The marks charts draw with. */
|
|
99
|
+
svg :global {
|
|
100
|
+
.axis {
|
|
101
|
+
fill: var(--tui-muted);
|
|
102
|
+
font-size: 0.8em;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.rule {
|
|
106
|
+
stroke: var(--tui-button);
|
|
107
|
+
stroke-width: 1;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.base {
|
|
111
|
+
stroke: var(--tui-border);
|
|
112
|
+
stroke-width: 1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.empty {
|
|
116
|
+
fill: var(--tui-button);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.mark {
|
|
120
|
+
fill: var(--tui-fg);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* While one mark is picked, the rest steps back. */
|
|
124
|
+
g {
|
|
125
|
+
transition: opacity var(--tui-fade) ease;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.dim {
|
|
129
|
+
opacity: 0.3;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The chart's box and the grid it is drawn on, in px. */
|
|
2
|
+
export interface ChartSize {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
ch: number;
|
|
6
|
+
em: number;
|
|
7
|
+
}
|
|
8
|
+
import type { Snippet } from 'svelte';
|
|
9
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
10
|
+
import { type OnPick } from '../gestures/pick';
|
|
11
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
12
|
+
height?: string;
|
|
13
|
+
label: string;
|
|
14
|
+
size?: ChartSize;
|
|
15
|
+
onpick?: OnPick;
|
|
16
|
+
children: Snippet;
|
|
17
|
+
below?: Snippet;
|
|
18
|
+
}
|
|
19
|
+
declare const ChartFrame: import("svelte").Component<Props, {}, "size">;
|
|
20
|
+
type ChartFrame = ReturnType<typeof ChartFrame>;
|
|
21
|
+
export default ChartFrame;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export interface ChartColumn {
|
|
3
|
+
label: string // under it: a weekday
|
|
4
|
+
value: number | null // null: nothing to show, drawn as --
|
|
5
|
+
colour?: string
|
|
6
|
+
}
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import type { Snippet } from 'svelte'
|
|
11
|
+
import ChartFrame, { type ChartSize } from './ChartFrame.svelte'
|
|
12
|
+
import { nextPick } from './scale'
|
|
13
|
+
|
|
14
|
+
// A few values as columns spread across the width, each with its value above it and its
|
|
15
|
+
// label below: average hours by weekday. Tap or drag to pick one.
|
|
16
|
+
interface Props {
|
|
17
|
+
columns: readonly ChartColumn[]
|
|
18
|
+
label: string
|
|
19
|
+
height?: string
|
|
20
|
+
max?: number
|
|
21
|
+
format?: (value: number) => string
|
|
22
|
+
width?: number // a column's width at most, in characters
|
|
23
|
+
picked?: number | null
|
|
24
|
+
readout?: Snippet<[ChartColumn, number]>
|
|
25
|
+
caption?: Snippet
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
columns,
|
|
30
|
+
label,
|
|
31
|
+
height = '4.5em',
|
|
32
|
+
max,
|
|
33
|
+
format = (v) => String(Math.round(v)),
|
|
34
|
+
width = 3,
|
|
35
|
+
picked = $bindable(null),
|
|
36
|
+
readout,
|
|
37
|
+
caption,
|
|
38
|
+
}: Props = $props()
|
|
39
|
+
|
|
40
|
+
let size = $state<ChartSize>({ width: 0, height: 0, ch: 8, em: 16 })
|
|
41
|
+
const top = $derived(max ?? Math.max(1, ...columns.map((c) => c.value ?? 0)))
|
|
42
|
+
const pitch = $derived(columns.length ? size.width / columns.length : 0)
|
|
43
|
+
const w = $derived(Math.max(1, Math.min(pitch - 6, width * size.ch)))
|
|
44
|
+
const room = $derived(Math.max(0, size.height - 2.2 * size.em)) // the columns' height, between their two labels
|
|
45
|
+
const h = (value: number | null) => (value === null ? 0 : (Math.max(0, value) / top) * room)
|
|
46
|
+
const base = $derived(size.height - 1.1 * size.em)
|
|
47
|
+
|
|
48
|
+
function onpick(x: number, _y: number, tap: boolean) {
|
|
49
|
+
const i = Math.floor(x / (pitch || 1))
|
|
50
|
+
picked = nextPick(picked, i >= 0 && i < columns.length ? i : null, tap)
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
{#snippet below()}{#if picked !== null && columns[picked]}{@render readout?.(
|
|
55
|
+
columns[picked],
|
|
56
|
+
picked,
|
|
57
|
+
)}{:else}{@render caption?.()}{/if}{/snippet}
|
|
58
|
+
|
|
59
|
+
<ChartFrame {label} {height} bind:size {onpick} below={readout || caption ? below : undefined}>
|
|
60
|
+
{#each columns as column, i (column.label)}
|
|
61
|
+
{const x = $derived(i * pitch + (pitch - w) / 2)}
|
|
62
|
+
<g class:dim={picked !== null && picked !== i}>
|
|
63
|
+
<text class="axis" x={x + w / 2} y={base - h(column.value) - 0.5 * size.em} text-anchor="middle" dominant-baseline="central"
|
|
64
|
+
>{column.value === null ? '--' : format(column.value)}</text
|
|
65
|
+
>
|
|
66
|
+
<rect {x} y={base - h(column.value)} width={w} height={h(column.value)} style:fill={column.colour ?? 'var(--tui-accent)'} />
|
|
67
|
+
<text class="head" x={x + w / 2} y={base + 0.55 * size.em} text-anchor="middle" dominant-baseline="central">{column.label}</text>
|
|
68
|
+
</g>
|
|
69
|
+
{/each}
|
|
70
|
+
</ChartFrame>
|
|
71
|
+
|
|
72
|
+
<style>
|
|
73
|
+
@layer tuidroid {
|
|
74
|
+
.head {
|
|
75
|
+
fill: var(--tui-fg);
|
|
76
|
+
font-size: 0.8em;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ChartColumn {
|
|
2
|
+
label: string;
|
|
3
|
+
value: number | null;
|
|
4
|
+
colour?: string;
|
|
5
|
+
}
|
|
6
|
+
import type { Snippet } from 'svelte';
|
|
7
|
+
interface Props {
|
|
8
|
+
columns: readonly ChartColumn[];
|
|
9
|
+
label: string;
|
|
10
|
+
height?: string;
|
|
11
|
+
max?: number;
|
|
12
|
+
format?: (value: number) => string;
|
|
13
|
+
width?: number;
|
|
14
|
+
picked?: number | null;
|
|
15
|
+
readout?: Snippet<[ChartColumn, number]>;
|
|
16
|
+
caption?: Snippet;
|
|
17
|
+
}
|
|
18
|
+
declare const ColumnChart: import("svelte").Component<Props, {}, "picked">;
|
|
19
|
+
type ColumnChart = ReturnType<typeof ColumnChart>;
|
|
20
|
+
export default ColumnChart;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { SwatchKind } from '../data/Swatch.svelte'
|
|
3
|
+
|
|
4
|
+
export interface HeatDay {
|
|
5
|
+
colour?: string | null // nothing that day: the empty cell
|
|
6
|
+
kind?: SwatchKind // filled, outlined, or outlined and hatched
|
|
7
|
+
ring?: boolean // today: outlined in the text's colour
|
|
8
|
+
label?: string
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import type { Snippet } from 'svelte'
|
|
14
|
+
import Hatch from '../data/Hatch.svelte'
|
|
15
|
+
import ChartFrame, { type ChartSize } from './ChartFrame.svelte'
|
|
16
|
+
import { nextPick } from './scale'
|
|
17
|
+
|
|
18
|
+
// Days in weeks, a column a week and a row a weekday, in the middle of the width: each
|
|
19
|
+
// day filled, outlined or hatched in its colour (the deepest stage reached, how many
|
|
20
|
+
// reviews), an empty square for a day with nothing, no square for one not yet come
|
|
21
|
+
// (null). `heads` label the rows at the left, every other one. As many weeks as fit at
|
|
22
|
+
// least `minCell` px a cell, the latest at the right. Tap or drag to pick a day.
|
|
23
|
+
interface Props {
|
|
24
|
+
weeks: readonly (readonly (HeatDay | null)[])[]
|
|
25
|
+
label: string
|
|
26
|
+
heads?: readonly string[] // the seven weekdays' names
|
|
27
|
+
maxCell?: number
|
|
28
|
+
minCell?: number
|
|
29
|
+
gutter?: number
|
|
30
|
+
picked?: [week: number, day: number] | null
|
|
31
|
+
readout?: Snippet<[HeatDay, number, number]>
|
|
32
|
+
caption?: Snippet
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let { weeks, label, heads = [], maxCell = 18, minCell = 7, gutter = 3, picked = $bindable(null), readout, caption }: Props = $props()
|
|
36
|
+
|
|
37
|
+
let size = $state<ChartSize>({ width: 0, height: 0, ch: 8, em: 16 })
|
|
38
|
+
const id = $props.id()
|
|
39
|
+
|
|
40
|
+
const left = $derived(gutter * size.ch)
|
|
41
|
+
const plot = $derived(Math.max(0, size.width - left))
|
|
42
|
+
const first = $derived(Math.max(0, weeks.length - Math.max(1, Math.floor(plot / minCell))))
|
|
43
|
+
const shown = $derived(weeks.slice(first))
|
|
44
|
+
const pitch = $derived(Math.min(maxCell, shown.length ? plot / shown.length : maxCell))
|
|
45
|
+
const gap = $derived(pitch >= 9 ? 2 : 1)
|
|
46
|
+
const cell = $derived(pitch - gap)
|
|
47
|
+
// A few weeks sit in the middle, with their row labels just before them.
|
|
48
|
+
const at = $derived(left + Math.max(0, (plot - (shown.length * pitch - gap)) / 2))
|
|
49
|
+
const colours = $derived([...new Set(weeks.flat().flatMap((d) => (d?.kind === 'hatched' && d.colour ? [d.colour] : [])))])
|
|
50
|
+
const hatchOf = (colour: string) => `${id}-hatch-${colours.indexOf(colour)}`
|
|
51
|
+
const index = $derived(picked === null ? null : (picked[0] - first) * 7 + picked[1])
|
|
52
|
+
|
|
53
|
+
function onpick(x: number, y: number, tap: boolean) {
|
|
54
|
+
const [w, d] = [Math.floor((x - at) / pitch), Math.floor(y / pitch)]
|
|
55
|
+
const hit = shown[w]?.[d] ? w * 7 + d : null
|
|
56
|
+
const next = nextPick(index, hit, tap)
|
|
57
|
+
picked = next === null ? null : [first + Math.floor(next / 7), next % 7]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const pickedDay = $derived(picked ? (weeks[picked[0]]?.[picked[1]] ?? null) : null)
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
{#snippet below()}{#if picked && pickedDay}{@render readout?.(pickedDay, picked[0], picked[1])}{:else}{@render caption?.()}{/if}{/snippet}
|
|
64
|
+
|
|
65
|
+
<ChartFrame {label} height="{7 * pitch}px" bind:size {onpick} below={readout || caption ? below : undefined}>
|
|
66
|
+
{#if colours.length}<defs
|
|
67
|
+
>{#each colours as colour, i (colour)}<Hatch id="{id}-hatch-{i}" {colour} />{/each}</defs
|
|
68
|
+
>{/if}
|
|
69
|
+
{#each [0, 2, 4, 6] as row (row)}
|
|
70
|
+
{#if heads[row]}<text class="axis" x={at - size.ch} y={(row + 0.5) * pitch} text-anchor="end" dominant-baseline="central"
|
|
71
|
+
>{heads[row]}</text
|
|
72
|
+
>{/if}
|
|
73
|
+
{/each}
|
|
74
|
+
{#each shown as week, w (first + w)}
|
|
75
|
+
{#each week as day, d (d)}
|
|
76
|
+
{#if day}
|
|
77
|
+
<g class:dim={index !== null && index !== w * 7 + d}>
|
|
78
|
+
{#if day.label}<title>{day.label}</title>{/if}
|
|
79
|
+
{#if !day.colour}
|
|
80
|
+
<rect class="empty" x={at + w * pitch} y={d * pitch} width={cell} height={cell} rx="2" />
|
|
81
|
+
{:else if (day.kind ?? 'filled') === 'filled'}
|
|
82
|
+
<rect x={at + w * pitch} y={d * pitch} width={cell} height={cell} rx="2" style:fill={day.colour} />
|
|
83
|
+
{:else}
|
|
84
|
+
<rect
|
|
85
|
+
x={at + w * pitch + 0.75}
|
|
86
|
+
y={d * pitch + 0.75}
|
|
87
|
+
width={cell - 1.5}
|
|
88
|
+
height={cell - 1.5}
|
|
89
|
+
rx="2"
|
|
90
|
+
stroke-width="1.5"
|
|
91
|
+
style:stroke={day.colour}
|
|
92
|
+
style:fill={day.kind === 'hatched' ? `url(#${hatchOf(day.colour)})` : 'none'}
|
|
93
|
+
/>
|
|
94
|
+
{/if}
|
|
95
|
+
{#if day.ring}<rect class="ring" x={at + w * pitch - 1} y={d * pitch - 1} width={cell + 2} height={cell + 2} rx="3" />{/if}
|
|
96
|
+
</g>
|
|
97
|
+
{/if}
|
|
98
|
+
{/each}
|
|
99
|
+
{/each}
|
|
100
|
+
</ChartFrame>
|
|
101
|
+
|
|
102
|
+
<style>
|
|
103
|
+
@layer tuidroid {
|
|
104
|
+
.ring {
|
|
105
|
+
fill: none;
|
|
106
|
+
stroke: var(--tui-fg);
|
|
107
|
+
stroke-width: 1;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SwatchKind } from '../data/Swatch.svelte';
|
|
2
|
+
export interface HeatDay {
|
|
3
|
+
colour?: string | null;
|
|
4
|
+
kind?: SwatchKind;
|
|
5
|
+
ring?: boolean;
|
|
6
|
+
label?: string;
|
|
7
|
+
}
|
|
8
|
+
import type { Snippet } from 'svelte';
|
|
9
|
+
interface Props {
|
|
10
|
+
weeks: readonly (readonly (HeatDay | null)[])[];
|
|
11
|
+
label: string;
|
|
12
|
+
heads?: readonly string[];
|
|
13
|
+
maxCell?: number;
|
|
14
|
+
minCell?: number;
|
|
15
|
+
gutter?: number;
|
|
16
|
+
picked?: [week: number, day: number] | null;
|
|
17
|
+
readout?: Snippet<[HeatDay, number, number]>;
|
|
18
|
+
caption?: Snippet;
|
|
19
|
+
}
|
|
20
|
+
declare const HeatGrid: import("svelte").Component<Props, {}, "picked">;
|
|
21
|
+
type HeatGrid = ReturnType<typeof HeatGrid>;
|
|
22
|
+
export default HeatGrid;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export interface ChartPoint {
|
|
3
|
+
x: number // a time, a rank, anything along the axis
|
|
4
|
+
y: number
|
|
5
|
+
label?: string
|
|
6
|
+
}
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import type { Snippet } from 'svelte'
|
|
11
|
+
import ChartFrame, { type ChartSize } from './ChartFrame.svelte'
|
|
12
|
+
import { nextPick, niceScale } from './scale'
|
|
13
|
+
|
|
14
|
+
// Values along an axis: each point a dot, and a line through `trend` (or through the
|
|
15
|
+
// points themselves with `line`), on rules at round steps labelled at the left. Dashed
|
|
16
|
+
// `guides` mark values worth seeing (a score's bands). Tap or drag to pick the point
|
|
17
|
+
// nearest the finger: a cursor drops through it and `readout` says what it is.
|
|
18
|
+
interface Props {
|
|
19
|
+
points: readonly ChartPoint[]
|
|
20
|
+
label: string
|
|
21
|
+
trend?: readonly { x: number; y: number }[]
|
|
22
|
+
line?: boolean // join the points themselves
|
|
23
|
+
dots?: boolean
|
|
24
|
+
guides?: readonly number[]
|
|
25
|
+
height?: string
|
|
26
|
+
domain?: [number, number] // the x axis's ends; the points' by default
|
|
27
|
+
step?: number
|
|
28
|
+
format?: (value: number) => string
|
|
29
|
+
gutter?: number
|
|
30
|
+
colour?: string
|
|
31
|
+
picked?: number | null
|
|
32
|
+
readout?: Snippet<[ChartPoint, number]>
|
|
33
|
+
caption?: Snippet
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
points,
|
|
38
|
+
label,
|
|
39
|
+
trend = [],
|
|
40
|
+
line = false,
|
|
41
|
+
dots = true,
|
|
42
|
+
guides = [],
|
|
43
|
+
height = '6em',
|
|
44
|
+
domain,
|
|
45
|
+
step,
|
|
46
|
+
format = String,
|
|
47
|
+
gutter = 5,
|
|
48
|
+
colour = 'var(--tui-accent)',
|
|
49
|
+
picked = $bindable(null),
|
|
50
|
+
readout,
|
|
51
|
+
caption,
|
|
52
|
+
}: Props = $props()
|
|
53
|
+
|
|
54
|
+
let size = $state<ChartSize>({ width: 0, height: 0, ch: 8, em: 16 })
|
|
55
|
+
|
|
56
|
+
const ys = $derived([...points.map((p) => p.y), ...trend.map((t) => t.y), ...guides])
|
|
57
|
+
const scale = $derived(niceScale(Math.min(...ys), Math.max(...ys), { step }))
|
|
58
|
+
const xs = $derived(points.map((p) => p.x))
|
|
59
|
+
const [x0, x1] = $derived(domain ?? [Math.min(...xs), Math.max(...xs)])
|
|
60
|
+
const left = $derived(gutter * size.ch)
|
|
61
|
+
const plot = $derived(Math.max(0, size.width - left - 4))
|
|
62
|
+
const px = (x: number) => left + 2 + (x1 > x0 ? ((x - x0) / (x1 - x0)) * plot : plot / 2)
|
|
63
|
+
const py = (y: number) => 6 + ((scale.to - y) / (scale.to - scale.from || 1)) * (size.height - 12)
|
|
64
|
+
const path = (series: readonly { x: number; y: number }[]) => series.map((p) => `${px(p.x)},${py(p.y)}`).join(' ')
|
|
65
|
+
const decimals = $derived((String(scale.step).split('.')[1] ?? '').length)
|
|
66
|
+
|
|
67
|
+
function onpick(x: number, _y: number, tap: boolean) {
|
|
68
|
+
if (!points.length) return
|
|
69
|
+
const gaps = points.map((p) => Math.abs(px(p.x) - x))
|
|
70
|
+
picked = nextPick(picked, gaps.indexOf(Math.min(...gaps)), tap)
|
|
71
|
+
}
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
{#snippet below()}{#if picked !== null && points[picked]}{@render readout?.(
|
|
75
|
+
points[picked],
|
|
76
|
+
picked,
|
|
77
|
+
)}{:else}{@render caption?.()}{/if}{/snippet}
|
|
78
|
+
|
|
79
|
+
<ChartFrame {label} {height} bind:size {onpick} below={readout || caption ? below : undefined}>
|
|
80
|
+
{#if points.length}
|
|
81
|
+
{#each scale.ticks as value (value)}
|
|
82
|
+
<line class="rule" x1={left} x2={size.width} y1={py(value)} y2={py(value)} />
|
|
83
|
+
<text class="axis" x={left - size.ch} y={py(value)} text-anchor="end" dominant-baseline="central"
|
|
84
|
+
>{step === undefined ? format(Number(value.toFixed(decimals))) : format(value)}</text
|
|
85
|
+
>
|
|
86
|
+
{/each}
|
|
87
|
+
{#each guides as value (value)}<line class="guide" x1={left} x2={size.width} y1={py(value)} y2={py(value)} />{/each}
|
|
88
|
+
{#if dots}
|
|
89
|
+
{#each points as point, i (i)}<circle
|
|
90
|
+
class="dot"
|
|
91
|
+
class:dim={picked !== null && picked !== i}
|
|
92
|
+
cx={px(point.x)}
|
|
93
|
+
cy={py(point.y)}
|
|
94
|
+
r="2"
|
|
95
|
+
/>{/each}
|
|
96
|
+
{/if}
|
|
97
|
+
{#if line && points.length > 1}<polyline class="trend" points={path(points)} style:stroke={colour} />{/if}
|
|
98
|
+
{#if trend.length > 1}<polyline class="trend" points={path(trend)} style:stroke={colour} />{/if}
|
|
99
|
+
{#if picked !== null && points[picked]}
|
|
100
|
+
{const point = $derived(points[picked])}
|
|
101
|
+
<line class="cursor" x1={px(point.x)} x2={px(point.x)} y1="0" y2={size.height} />
|
|
102
|
+
<circle class="picked" cx={px(point.x)} cy={py(point.y)} r="3.5" style:fill={colour} />
|
|
103
|
+
{/if}
|
|
104
|
+
{/if}
|
|
105
|
+
</ChartFrame>
|
|
106
|
+
|
|
107
|
+
<style>
|
|
108
|
+
@layer tuidroid {
|
|
109
|
+
.dot {
|
|
110
|
+
fill: var(--tui-muted);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.trend {
|
|
114
|
+
fill: none;
|
|
115
|
+
stroke-width: 2;
|
|
116
|
+
stroke-linejoin: round;
|
|
117
|
+
stroke-linecap: round;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.guide {
|
|
121
|
+
stroke: var(--tui-border);
|
|
122
|
+
stroke-width: 1;
|
|
123
|
+
stroke-dasharray: 3 3;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.cursor {
|
|
127
|
+
stroke: var(--tui-muted);
|
|
128
|
+
stroke-width: 1;
|
|
129
|
+
stroke-dasharray: 2 2;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
</style>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface ChartPoint {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
label?: string;
|
|
5
|
+
}
|
|
6
|
+
import type { Snippet } from 'svelte';
|
|
7
|
+
interface Props {
|
|
8
|
+
points: readonly ChartPoint[];
|
|
9
|
+
label: string;
|
|
10
|
+
trend?: readonly {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
}[];
|
|
14
|
+
line?: boolean;
|
|
15
|
+
dots?: boolean;
|
|
16
|
+
guides?: readonly number[];
|
|
17
|
+
height?: string;
|
|
18
|
+
domain?: [number, number];
|
|
19
|
+
step?: number;
|
|
20
|
+
format?: (value: number) => string;
|
|
21
|
+
gutter?: number;
|
|
22
|
+
colour?: string;
|
|
23
|
+
picked?: number | null;
|
|
24
|
+
readout?: Snippet<[ChartPoint, number]>;
|
|
25
|
+
caption?: Snippet;
|
|
26
|
+
}
|
|
27
|
+
declare const LineChart: import("svelte").Component<Props, {}, "picked">;
|
|
28
|
+
type LineChart = ReturnType<typeof LineChart>;
|
|
29
|
+
export default LineChart;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export interface StripRow {
|
|
3
|
+
/** Spans of the row, from and to as shares of it (0 to 1), each in its colour. */
|
|
4
|
+
runs: readonly { from: number; to: number; colour?: string }[]
|
|
5
|
+
label?: string // at the left, for the rows worth naming (a week's first day)
|
|
6
|
+
title?: string
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import type { Snippet } from 'svelte'
|
|
12
|
+
import ChartFrame, { type ChartSize } from './ChartFrame.svelte'
|
|
13
|
+
import { nextPick } from './scale'
|
|
14
|
+
|
|
15
|
+
// Rows of spans across a common axis: a day each, from midnight to midnight, filled while
|
|
16
|
+
// fasting in the colour of the stage. The empty track shows under each row. `ticks` label
|
|
17
|
+
// the axis below (00 06 12 18 24). Tap or drag up and down the rows to pick one.
|
|
18
|
+
interface Props {
|
|
19
|
+
rows: readonly StripRow[]
|
|
20
|
+
label: string
|
|
21
|
+
ticks?: readonly { at: number; label: string }[]
|
|
22
|
+
rowHeight?: number // in em
|
|
23
|
+
gutter?: number
|
|
24
|
+
picked?: number | null
|
|
25
|
+
readout?: Snippet<[StripRow, number]>
|
|
26
|
+
caption?: Snippet
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let { rows, label, ticks = [], rowHeight = 0.65, gutter = 5, picked = $bindable(null), readout, caption }: Props = $props()
|
|
30
|
+
|
|
31
|
+
let size = $state<ChartSize>({ width: 0, height: 0, ch: 8, em: 16 })
|
|
32
|
+
const row = $derived(rowHeight * size.em)
|
|
33
|
+
const bar = $derived(Math.max(2, row - 3))
|
|
34
|
+
const left = $derived(gutter * size.ch)
|
|
35
|
+
const plot = $derived(Math.max(0, size.width - left))
|
|
36
|
+
const x = (share: number) => left + Math.min(1, Math.max(0, share)) * plot
|
|
37
|
+
|
|
38
|
+
function onpick(_x: number, y: number, tap: boolean) {
|
|
39
|
+
const i = Math.floor(y / row)
|
|
40
|
+
picked = nextPick(picked, i >= 0 && i < rows.length ? i : null, tap)
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
{#snippet below()}{#if picked !== null && rows[picked]}{@render readout?.(rows[picked], picked)}{:else}{@render caption?.()}{/if}{/snippet}
|
|
45
|
+
|
|
46
|
+
<ChartFrame
|
|
47
|
+
{label}
|
|
48
|
+
height="calc({rows.length * rowHeight}em + {ticks.length ? 1.1 : 0}em)"
|
|
49
|
+
bind:size
|
|
50
|
+
{onpick}
|
|
51
|
+
below={readout || caption ? below : undefined}
|
|
52
|
+
>
|
|
53
|
+
{#each rows as strip, r (r)}
|
|
54
|
+
{#if strip.label}<text class="axis" x={left - size.ch} y={r * row + bar / 2} text-anchor="end" dominant-baseline="central"
|
|
55
|
+
>{strip.label}</text
|
|
56
|
+
>{/if}
|
|
57
|
+
<g class:dim={picked !== null && picked !== r}>
|
|
58
|
+
{#if strip.title}<title>{strip.title}</title>{/if}
|
|
59
|
+
<rect class="empty" x={left} y={r * row} width={plot} height={bar} />
|
|
60
|
+
{#each strip.runs as run, i (i)}
|
|
61
|
+
<rect
|
|
62
|
+
x={x(run.from)}
|
|
63
|
+
y={r * row}
|
|
64
|
+
width={Math.max(1, x(run.to) - x(run.from))}
|
|
65
|
+
height={bar}
|
|
66
|
+
style:fill={run.colour ?? 'var(--tui-accent)'}
|
|
67
|
+
/>
|
|
68
|
+
{/each}
|
|
69
|
+
</g>
|
|
70
|
+
{/each}
|
|
71
|
+
{#each ticks as mark (mark.at)}
|
|
72
|
+
<text
|
|
73
|
+
class="axis"
|
|
74
|
+
x={x(mark.at)}
|
|
75
|
+
y={rows.length * row + 0.55 * size.em}
|
|
76
|
+
text-anchor={mark.at <= 0 ? 'start' : mark.at >= 1 ? 'end' : 'middle'}
|
|
77
|
+
dominant-baseline="central">{mark.label}</text
|
|
78
|
+
>
|
|
79
|
+
{/each}
|
|
80
|
+
</ChartFrame>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface StripRow {
|
|
2
|
+
/** Spans of the row, from and to as shares of it (0 to 1), each in its colour. */
|
|
3
|
+
runs: readonly {
|
|
4
|
+
from: number;
|
|
5
|
+
to: number;
|
|
6
|
+
colour?: string;
|
|
7
|
+
}[];
|
|
8
|
+
label?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
}
|
|
11
|
+
import type { Snippet } from 'svelte';
|
|
12
|
+
interface Props {
|
|
13
|
+
rows: readonly StripRow[];
|
|
14
|
+
label: string;
|
|
15
|
+
ticks?: readonly {
|
|
16
|
+
at: number;
|
|
17
|
+
label: string;
|
|
18
|
+
}[];
|
|
19
|
+
rowHeight?: number;
|
|
20
|
+
gutter?: number;
|
|
21
|
+
picked?: number | null;
|
|
22
|
+
readout?: Snippet<[StripRow, number]>;
|
|
23
|
+
caption?: Snippet;
|
|
24
|
+
}
|
|
25
|
+
declare const StripChart: import("svelte").Component<Props, {}, "picked">;
|
|
26
|
+
type StripChart = ReturnType<typeof StripChart>;
|
|
27
|
+
export default StripChart;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Scale {
|
|
2
|
+
from: number;
|
|
3
|
+
to: number;
|
|
4
|
+
step: number;
|
|
5
|
+
ticks: number[];
|
|
6
|
+
}
|
|
7
|
+
/** A step near `span / count`, rounded to 1, 2, 2.5 or 5 times a power of ten. */
|
|
8
|
+
export declare function niceStep(span: number, count?: number): number;
|
|
9
|
+
/** An axis from `min` to `max` widened to whole steps, about `count` of them. A given
|
|
10
|
+
* `step` is used as it is (12 for hours, say). */
|
|
11
|
+
export declare function niceScale(min: number, max: number, { count, step }?: {
|
|
12
|
+
count?: number;
|
|
13
|
+
step?: number;
|
|
14
|
+
}): Scale;
|
|
15
|
+
/** What is picked after a tap or a drag lands `at` a mark: a tap on the picked one lets
|
|
16
|
+
* go of it, a drag onto another picks it with a haptic tick. */
|
|
17
|
+
export declare function nextPick(current: number | null, at: number | null, tap: boolean): number | null;
|