@r2digisolutions/components 0.21.32 → 0.21.34
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/dist/components/molecules/AreaLineChart/AreaLineChart.svelte +76 -43
- package/dist/components/molecules/BarChart/BarChart.svelte +34 -22
- package/dist/components/molecules/HorizontalBarChart/HorizontalBarChart.svelte +48 -89
- package/dist/components/molecules/HorizontalBarChart/HorizontalBarChart.svelte.d.ts +2 -2
- package/dist/components/molecules/MultiLineChart/MultiLineChart.svelte +18 -9
- package/dist/utils/chart.js +18 -5
- package/dist/utils/formContext.d.ts +14 -13
- package/dist/utils/formContext.js +22 -19
- package/package.json +1 -1
|
@@ -50,27 +50,50 @@
|
|
|
50
50
|
}: AreaLineChartProps = $props();
|
|
51
51
|
|
|
52
52
|
const W = 500;
|
|
53
|
-
const pad: ChartPad = { ...DEFAULT_PAD, b:
|
|
53
|
+
const pad: ChartPad = { ...DEFAULT_PAD, b: 28, l: 40 };
|
|
54
54
|
const uid = `alc-${Math.random().toString(36).slice(2, 8)}`;
|
|
55
55
|
|
|
56
56
|
let tipIndex = $state<number | null>(null);
|
|
57
57
|
|
|
58
58
|
const values = $derived(data.map((d) => d.value));
|
|
59
|
-
const domain = $derived(
|
|
60
|
-
yMin !== undefined && yMax !== undefined
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const domain = $derived.by(() => {
|
|
60
|
+
if (yMin !== undefined && yMax !== undefined) return { min: yMin, max: yMax };
|
|
61
|
+
const auto = scaleDomain(values);
|
|
62
|
+
/** Counts never go below zero unless the caller sets an explicit floor. */
|
|
63
|
+
if (yMin !== undefined) return { min: yMin, max: Math.max(auto.max, yMin + 1) };
|
|
64
|
+
if (values.length > 0 && Math.min(...values) >= 0 && auto.min < 0) {
|
|
65
|
+
return { min: 0, max: auto.max };
|
|
66
|
+
}
|
|
67
|
+
return auto;
|
|
68
|
+
});
|
|
64
69
|
const points = $derived(mapPoints(values, W, height, pad, domain));
|
|
65
70
|
const line = $derived(smooth ? smoothLinePath(points) : linearLinePath(points));
|
|
66
71
|
const area = $derived(areaPath(line, points, height, pad));
|
|
67
72
|
|
|
73
|
+
const integerValues = $derived(values.every((v) => Number.isInteger(v)));
|
|
74
|
+
|
|
68
75
|
const gridYs = $derived.by(() => {
|
|
69
76
|
const { min, max } = domain;
|
|
70
|
-
return [0, 0.5, 1].map((t) =>
|
|
71
|
-
|
|
72
|
-
label
|
|
73
|
-
|
|
77
|
+
return [0, 0.5, 1].map((t) => {
|
|
78
|
+
const raw = min + t * (max - min);
|
|
79
|
+
const label = integerValues ? String(Math.round(raw)) : formatTick(raw);
|
|
80
|
+
return {
|
|
81
|
+
y: pad.t + (1 - t) * (height - pad.t - pad.b),
|
|
82
|
+
label
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/** First / last / sparse middle — HTML so labels stay readable (SVG stretch does not squash them). */
|
|
88
|
+
const xLabels = $derived.by(() => {
|
|
89
|
+
const out: { label: string; leftPct: number }[] = [];
|
|
90
|
+
for (let i = 0; i < data.length; i++) {
|
|
91
|
+
const show = i === 0 || i === data.length - 1 || data.length <= 7;
|
|
92
|
+
const p = points[i];
|
|
93
|
+
if (!show || !p) continue;
|
|
94
|
+
out.push({ label: data[i].label, leftPct: (p.x / W) * 100 });
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
74
97
|
});
|
|
75
98
|
|
|
76
99
|
const tip = $derived.by(() => {
|
|
@@ -93,14 +116,49 @@
|
|
|
93
116
|
}
|
|
94
117
|
</script>
|
|
95
118
|
|
|
96
|
-
<div
|
|
119
|
+
<div
|
|
120
|
+
class={['relative w-full select-none', className]}
|
|
121
|
+
style:height={`${height}px`}
|
|
122
|
+
role="img"
|
|
123
|
+
aria-label="Area line chart"
|
|
124
|
+
>
|
|
125
|
+
<!-- HTML axis labels: preserveAspectRatio=none would distort SVG <text> -->
|
|
126
|
+
{#if showGrid}
|
|
127
|
+
<div class="pointer-events-none absolute inset-0 z-[1]">
|
|
128
|
+
{#each gridYs as g (g.label + g.y)}
|
|
129
|
+
<span
|
|
130
|
+
class="text-secondary absolute -translate-y-1/2 text-[11px] leading-none tabular-nums"
|
|
131
|
+
style:left="0"
|
|
132
|
+
style:top={`${(g.y / height) * 100}%`}
|
|
133
|
+
style:width={`${(pad.l / W) * 100}%`}
|
|
134
|
+
style:text-align="right"
|
|
135
|
+
style:padding-right="6px"
|
|
136
|
+
>
|
|
137
|
+
{g.label}
|
|
138
|
+
</span>
|
|
139
|
+
{/each}
|
|
140
|
+
</div>
|
|
141
|
+
{/if}
|
|
142
|
+
|
|
143
|
+
<div
|
|
144
|
+
class="pointer-events-none absolute inset-x-0 bottom-0 z-[1]"
|
|
145
|
+
style:height={`${(pad.b / height) * 100}%`}
|
|
146
|
+
>
|
|
147
|
+
{#each xLabels as xl (xl.label + xl.leftPct)}
|
|
148
|
+
<span
|
|
149
|
+
class="text-secondary absolute top-1 -translate-x-1/2 text-[11px] leading-none whitespace-nowrap"
|
|
150
|
+
style:left={`${xl.leftPct}%`}
|
|
151
|
+
>
|
|
152
|
+
{xl.label}
|
|
153
|
+
</span>
|
|
154
|
+
{/each}
|
|
155
|
+
</div>
|
|
156
|
+
|
|
97
157
|
<svg
|
|
98
158
|
viewBox={`0 0 ${W} ${height}`}
|
|
99
159
|
preserveAspectRatio="none"
|
|
100
|
-
class="block w-full overflow-visible"
|
|
101
|
-
|
|
102
|
-
role="img"
|
|
103
|
-
aria-label="Area line chart"
|
|
160
|
+
class="absolute inset-0 block h-full w-full overflow-visible"
|
|
161
|
+
aria-hidden="true"
|
|
104
162
|
>
|
|
105
163
|
<defs>
|
|
106
164
|
<linearGradient id="{uid}-fill" x1="0" y1="0" x2="0" y2="1">
|
|
@@ -117,7 +175,7 @@
|
|
|
117
175
|
</defs>
|
|
118
176
|
|
|
119
177
|
{#if showGrid}
|
|
120
|
-
{#each gridYs as g}
|
|
178
|
+
{#each gridYs as g (g.label + g.y)}
|
|
121
179
|
<line
|
|
122
180
|
x1={pad.l}
|
|
123
181
|
x2={W - pad.r}
|
|
@@ -127,15 +185,6 @@
|
|
|
127
185
|
stroke-width="1"
|
|
128
186
|
stroke-dasharray="4 4"
|
|
129
187
|
/>
|
|
130
|
-
<text
|
|
131
|
-
x={pad.l - 8}
|
|
132
|
-
y={g.y + 3}
|
|
133
|
-
text-anchor="end"
|
|
134
|
-
class="fill-muted"
|
|
135
|
-
font-size="10"
|
|
136
|
-
>
|
|
137
|
-
{g.label}
|
|
138
|
-
</text>
|
|
139
188
|
{/each}
|
|
140
189
|
{/if}
|
|
141
190
|
|
|
@@ -155,7 +204,7 @@
|
|
|
155
204
|
/>
|
|
156
205
|
{/if}
|
|
157
206
|
|
|
158
|
-
{#each points as p, i}
|
|
207
|
+
{#each points as p, i (i)}
|
|
159
208
|
{#if showDots}
|
|
160
209
|
<circle
|
|
161
210
|
cx={p.x}
|
|
@@ -170,6 +219,7 @@
|
|
|
170
219
|
{#if interactive}
|
|
171
220
|
<!-- Hit area: pointer-only (no focus ring / square outline) -->
|
|
172
221
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
222
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
173
223
|
<circle
|
|
174
224
|
cx={p.x}
|
|
175
225
|
cy={p.y}
|
|
@@ -180,23 +230,6 @@
|
|
|
180
230
|
/>
|
|
181
231
|
{/if}
|
|
182
232
|
{/each}
|
|
183
|
-
|
|
184
|
-
{#each data as d, i}
|
|
185
|
-
{#if i === 0 || i === data.length - 1 || data.length <= 7}
|
|
186
|
-
{@const p = points[i]}
|
|
187
|
-
{#if p}
|
|
188
|
-
<text
|
|
189
|
-
x={p.x}
|
|
190
|
-
y={height - 8}
|
|
191
|
-
text-anchor="middle"
|
|
192
|
-
class="fill-muted"
|
|
193
|
-
font-size="10"
|
|
194
|
-
>
|
|
195
|
-
{d.label}
|
|
196
|
-
</text>
|
|
197
|
-
{/if}
|
|
198
|
-
{/if}
|
|
199
|
-
{/each}
|
|
200
233
|
</svg>
|
|
201
234
|
|
|
202
235
|
{#if tip}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
}: BarChartProps = $props();
|
|
30
30
|
|
|
31
31
|
const W = 420;
|
|
32
|
-
const pad = { t:
|
|
32
|
+
const pad = { t: 28, r: 12, b: 36, l: 12 };
|
|
33
33
|
const uid = `bc-${Math.random().toString(36).slice(2, 8)}`;
|
|
34
34
|
const color = 'var(--color-brand-500, #6366f1)';
|
|
35
35
|
|
|
@@ -76,14 +76,40 @@
|
|
|
76
76
|
}
|
|
77
77
|
</script>
|
|
78
78
|
|
|
79
|
-
<div
|
|
79
|
+
<div
|
|
80
|
+
class={['relative w-full select-none', className]}
|
|
81
|
+
style:height={`${height}px`}
|
|
82
|
+
role="img"
|
|
83
|
+
aria-label="Bar chart"
|
|
84
|
+
>
|
|
85
|
+
<!-- HTML labels stay readable; SVG stretch would squash <text> -->
|
|
86
|
+
{#each bars as b, i (b.label + i)}
|
|
87
|
+
{#if showValues && b.value > 0}
|
|
88
|
+
<span
|
|
89
|
+
class="text-secondary pointer-events-none absolute z-[1] -translate-x-1/2 -translate-y-full text-[11px] font-semibold tabular-nums"
|
|
90
|
+
style:left={`${(b.cx / W) * 100}%`}
|
|
91
|
+
style:top={`${(b.y / height) * 100}%`}
|
|
92
|
+
style:margin-top="-2px"
|
|
93
|
+
>
|
|
94
|
+
{formatTick(b.value, 0)}{unit}
|
|
95
|
+
</span>
|
|
96
|
+
{/if}
|
|
97
|
+
<span
|
|
98
|
+
class="text-secondary pointer-events-none absolute z-[1] -translate-x-1/2 truncate text-center text-[11px] leading-tight"
|
|
99
|
+
style:left={`${(b.cx / W) * 100}%`}
|
|
100
|
+
style:bottom="4px"
|
|
101
|
+
style:max-width={`${((W - pad.l - pad.r) / Math.max(data.length, 1) / W) * 100}%`}
|
|
102
|
+
title={b.label}
|
|
103
|
+
>
|
|
104
|
+
{axisLabel(b.label)}
|
|
105
|
+
</span>
|
|
106
|
+
{/each}
|
|
107
|
+
|
|
80
108
|
<svg
|
|
81
109
|
viewBox={`0 0 ${W} ${height}`}
|
|
82
110
|
preserveAspectRatio="none"
|
|
83
|
-
class="block w-full overflow-visible"
|
|
84
|
-
|
|
85
|
-
role="img"
|
|
86
|
-
aria-label="Bar chart"
|
|
111
|
+
class="absolute inset-0 block h-full w-full overflow-visible"
|
|
112
|
+
aria-hidden="true"
|
|
87
113
|
>
|
|
88
114
|
<defs>
|
|
89
115
|
<linearGradient id="{uid}-bar" x1="0" y1="0" x2="0" y2="1">
|
|
@@ -92,7 +118,7 @@
|
|
|
92
118
|
</linearGradient>
|
|
93
119
|
</defs>
|
|
94
120
|
|
|
95
|
-
{#each bars as b, i}
|
|
121
|
+
{#each bars as b, i (b.label + i)}
|
|
96
122
|
<rect
|
|
97
123
|
x={b.x}
|
|
98
124
|
y={b.y}
|
|
@@ -103,23 +129,9 @@
|
|
|
103
129
|
opacity={tipIndex == null || tipIndex === i ? 1 : 0.35}
|
|
104
130
|
class="transition-opacity"
|
|
105
131
|
/>
|
|
106
|
-
{#if showValues && b.value > 0}
|
|
107
|
-
<text
|
|
108
|
-
x={b.cx}
|
|
109
|
-
y={b.y - 6}
|
|
110
|
-
text-anchor="middle"
|
|
111
|
-
class="fill-secondary"
|
|
112
|
-
font-size="10"
|
|
113
|
-
font-weight="600"
|
|
114
|
-
>
|
|
115
|
-
{formatTick(b.value, 0)}{unit}
|
|
116
|
-
</text>
|
|
117
|
-
{/if}
|
|
118
|
-
<text x={b.cx} y={height - 8} text-anchor="middle" class="fill-muted" font-size="12">
|
|
119
|
-
{axisLabel(b.label)}
|
|
120
|
-
</text>
|
|
121
132
|
{#if interactive}
|
|
122
133
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
134
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
123
135
|
<rect
|
|
124
136
|
x={b.x - 4}
|
|
125
137
|
y={pad.t}
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
interface HorizontalBarChartProps {
|
|
11
11
|
data?: HBarPoint[];
|
|
12
|
-
/**
|
|
12
|
+
/** Kept for API compat — layout is CSS, not SVG viewBox */
|
|
13
13
|
barWidth?: number;
|
|
14
|
-
/**
|
|
14
|
+
/** Kept for API compat — label column uses CSS */
|
|
15
15
|
labelWidth?: number;
|
|
16
16
|
rowHeight?: number;
|
|
17
17
|
interactive?: boolean;
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
|
|
23
23
|
const {
|
|
24
24
|
data = [],
|
|
25
|
-
barWidth = 280,
|
|
26
25
|
labelWidth = 88,
|
|
27
26
|
rowHeight = 36,
|
|
28
27
|
interactive = true,
|
|
@@ -32,107 +31,67 @@
|
|
|
32
31
|
}: HorizontalBarChartProps = $props();
|
|
33
32
|
|
|
34
33
|
const color = 'var(--color-brand-500, #6366f1)';
|
|
35
|
-
const padR = 48;
|
|
36
|
-
const W = $derived(labelWidth + barWidth + padR);
|
|
37
|
-
const H = $derived(Math.max(data.length, 1) * rowHeight + 8);
|
|
38
|
-
const maxLabelChars = $derived(Math.floor(labelWidth / 6.5));
|
|
39
34
|
|
|
40
35
|
let tipIndex = $state<number | null>(null);
|
|
41
36
|
|
|
42
37
|
const max = $derived(Math.max(...data.map((d) => d.value), 1));
|
|
43
38
|
|
|
44
|
-
const rows = $derived(
|
|
45
|
-
data.map((d, i) => {
|
|
46
|
-
const ratio = Math.max(0, d.value) / max;
|
|
47
|
-
const bw = Math.max(d.value > 0 ? 4 : 0, ratio * barWidth);
|
|
48
|
-
const y = 4 + i * rowHeight;
|
|
49
|
-
return { ...d, bw, y, midY: y + (rowHeight - 10) / 2 };
|
|
50
|
-
})
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
function displayLabel(label: string): string {
|
|
54
|
-
const maxChars = maxLabelChars;
|
|
55
|
-
if (label.length <= maxChars) return label;
|
|
56
|
-
return `${label.slice(0, Math.max(0, maxChars - 1))}…`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
39
|
function select(i: number) {
|
|
60
40
|
if (!interactive) return;
|
|
61
41
|
tipIndex = tipIndex === i ? null : i;
|
|
62
42
|
}
|
|
63
43
|
</script>
|
|
64
44
|
|
|
65
|
-
<div
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
x={labelWidth}
|
|
86
|
-
y={r.y + 4}
|
|
87
|
-
width={barWidth}
|
|
88
|
-
height={rowHeight - 14}
|
|
89
|
-
rx="5"
|
|
90
|
-
class="fill-surface-muted"
|
|
91
|
-
opacity="0.6"
|
|
92
|
-
/>
|
|
93
|
-
<rect
|
|
94
|
-
x={labelWidth}
|
|
95
|
-
y={r.y + 4}
|
|
96
|
-
width={r.bw}
|
|
97
|
-
height={rowHeight - 14}
|
|
98
|
-
rx="5"
|
|
99
|
-
fill={r.color ?? color}
|
|
100
|
-
opacity={tipIndex == null || tipIndex === i ? 1 : 0.35}
|
|
101
|
-
class="transition-opacity"
|
|
102
|
-
/>
|
|
103
|
-
{#if showValues}
|
|
104
|
-
<text
|
|
105
|
-
x={labelWidth + r.bw + 6}
|
|
106
|
-
y={r.midY + 4}
|
|
107
|
-
class="fill-muted"
|
|
108
|
-
font-size="10"
|
|
109
|
-
font-weight="600"
|
|
110
|
-
>
|
|
111
|
-
{formatTick(r.value, 0)}{unit}
|
|
112
|
-
</text>
|
|
113
|
-
{/if}
|
|
114
|
-
{#if interactive}
|
|
115
|
-
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
116
|
-
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
117
|
-
<rect
|
|
118
|
-
x={0}
|
|
119
|
-
y={r.y}
|
|
120
|
-
width={W}
|
|
121
|
-
height={rowHeight}
|
|
122
|
-
fill="transparent"
|
|
123
|
-
class="cursor-pointer"
|
|
45
|
+
<div
|
|
46
|
+
class={['relative w-full select-none', className]}
|
|
47
|
+
role="img"
|
|
48
|
+
aria-label="Horizontal bar chart"
|
|
49
|
+
>
|
|
50
|
+
<ul class="flex flex-col" style:gap="2px">
|
|
51
|
+
{#each data as r, i (r.label + i)}
|
|
52
|
+
{@const ratio = Math.max(0, r.value) / max}
|
|
53
|
+
{@const pct = Math.max(r.value > 0 ? 1.5 : 0, ratio * 100)}
|
|
54
|
+
<li>
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
class={[
|
|
58
|
+
'grid w-full items-center gap-2 rounded-lg px-0.5 py-0.5 text-left transition-opacity',
|
|
59
|
+
interactive && 'hover:bg-surface-overlay/80 cursor-pointer',
|
|
60
|
+
!interactive && 'cursor-default',
|
|
61
|
+
tipIndex != null && tipIndex !== i && 'opacity-40'
|
|
62
|
+
]}
|
|
63
|
+
style:min-height={`${rowHeight}px`}
|
|
64
|
+
style:grid-template-columns={`minmax(0, ${labelWidth}px) minmax(0, 1fr) auto`}
|
|
124
65
|
onclick={() => select(i)}
|
|
125
|
-
|
|
126
|
-
|
|
66
|
+
disabled={!interactive}
|
|
67
|
+
>
|
|
68
|
+
<span
|
|
69
|
+
class="text-secondary truncate text-right text-xs leading-snug"
|
|
70
|
+
title={r.label}
|
|
71
|
+
>
|
|
72
|
+
{r.label}
|
|
73
|
+
</span>
|
|
74
|
+
<span class="bg-surface-overlay relative block h-4 overflow-hidden rounded-md">
|
|
75
|
+
<span
|
|
76
|
+
class="absolute inset-y-0 left-0 rounded-md transition-[width]"
|
|
77
|
+
style:width={`${pct}%`}
|
|
78
|
+
style:background={r.color ?? color}
|
|
79
|
+
></span>
|
|
80
|
+
</span>
|
|
81
|
+
{#if showValues}
|
|
82
|
+
<span class="text-secondary min-w-[2ch] text-right text-xs font-semibold tabular-nums">
|
|
83
|
+
{formatTick(r.value, 0)}{unit}
|
|
84
|
+
</span>
|
|
85
|
+
{/if}
|
|
86
|
+
</button>
|
|
87
|
+
</li>
|
|
127
88
|
{/each}
|
|
128
|
-
</
|
|
89
|
+
</ul>
|
|
129
90
|
|
|
130
|
-
{#if tipIndex != null &&
|
|
131
|
-
{@const t =
|
|
91
|
+
{#if tipIndex != null && data[tipIndex]}
|
|
92
|
+
{@const t = data[tipIndex]}
|
|
132
93
|
<div
|
|
133
|
-
class="pointer-events-none absolute z-10 rounded-lg border border-border bg-surface-elevated px-2.5 py-1.5 shadow-lg"
|
|
134
|
-
style:left={`${((labelWidth + t.bw) / W) * 100}%`}
|
|
135
|
-
style:top={`${(t.y / H) * 100}%`}
|
|
94
|
+
class="pointer-events-none absolute top-0 right-0 z-10 rounded-lg border border-border bg-surface-elevated px-2.5 py-1.5 shadow-lg"
|
|
136
95
|
role="status"
|
|
137
96
|
>
|
|
138
97
|
<p class="text-[10px] font-medium text-muted">{t.label}</p>
|
|
@@ -5,9 +5,9 @@ export interface HBarPoint {
|
|
|
5
5
|
}
|
|
6
6
|
interface HorizontalBarChartProps {
|
|
7
7
|
data?: HBarPoint[];
|
|
8
|
-
/**
|
|
8
|
+
/** Kept for API compat — layout is CSS, not SVG viewBox */
|
|
9
9
|
barWidth?: number;
|
|
10
|
-
/**
|
|
10
|
+
/** Kept for API compat — label column uses CSS */
|
|
11
11
|
labelWidth?: number;
|
|
12
12
|
rowHeight?: number;
|
|
13
13
|
interactive?: boolean;
|
|
@@ -55,11 +55,15 @@
|
|
|
55
55
|
let tipIndex = $state<number | null>(null);
|
|
56
56
|
|
|
57
57
|
const allValues = $derived(series.flatMap((s) => s.values));
|
|
58
|
-
const domain = $derived(
|
|
59
|
-
yMin !== undefined && yMax !== undefined
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
const domain = $derived.by(() => {
|
|
59
|
+
if (yMin !== undefined && yMax !== undefined) return { min: yMin, max: yMax };
|
|
60
|
+
const auto = scaleDomain(allValues);
|
|
61
|
+
if (yMin !== undefined) return { min: yMin, max: Math.max(auto.max, yMin + 1) };
|
|
62
|
+
if (allValues.length > 0 && Math.min(...allValues) >= 0 && auto.min < 0) {
|
|
63
|
+
return { min: 0, max: auto.max };
|
|
64
|
+
}
|
|
65
|
+
return auto;
|
|
66
|
+
});
|
|
63
67
|
|
|
64
68
|
const plotted = $derived(
|
|
65
69
|
series.map((s, si) => {
|
|
@@ -74,12 +78,17 @@
|
|
|
74
78
|
})
|
|
75
79
|
);
|
|
76
80
|
|
|
81
|
+
const integerValues = $derived(allValues.every((v) => Number.isInteger(v)));
|
|
82
|
+
|
|
77
83
|
const gridYs = $derived.by(() => {
|
|
78
84
|
const { min, max } = domain;
|
|
79
|
-
return [0, 0.5, 1].map((t) =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
return [0, 0.5, 1].map((t) => {
|
|
86
|
+
const raw = min + t * (max - min);
|
|
87
|
+
return {
|
|
88
|
+
y: pad.t + (1 - t) * (height - pad.t - pad.b),
|
|
89
|
+
label: integerValues ? String(Math.round(raw)) : formatTick(raw)
|
|
90
|
+
};
|
|
91
|
+
});
|
|
83
92
|
});
|
|
84
93
|
|
|
85
94
|
const tip = $derived.by(() => {
|
package/dist/utils/chart.js
CHANGED
|
@@ -5,13 +5,23 @@ export function scaleDomain(values, padRatio = 0.08) {
|
|
|
5
5
|
return { min: 0, max: 1 };
|
|
6
6
|
let min = Math.min(...values);
|
|
7
7
|
let max = Math.max(...values);
|
|
8
|
+
const nonNegative = min >= 0;
|
|
8
9
|
if (min === max) {
|
|
9
|
-
|
|
10
|
+
if (min === 0)
|
|
11
|
+
return { min: 0, max: 1 };
|
|
12
|
+
const bump = Math.abs(min) * 0.05 || 1;
|
|
10
13
|
min -= bump;
|
|
11
14
|
max += bump;
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
else {
|
|
17
|
+
const span = max - min;
|
|
18
|
+
min -= span * padRatio;
|
|
19
|
+
max += span * padRatio;
|
|
20
|
+
}
|
|
21
|
+
/** Counts / rates ≥ 0 should never show a negative floor (e.g. visits → -2.7). */
|
|
22
|
+
if (nonNegative && min < 0)
|
|
23
|
+
min = 0;
|
|
24
|
+
return { min, max };
|
|
15
25
|
}
|
|
16
26
|
export function mapPoints(values, width, height, pad = DEFAULT_PAD, domain) {
|
|
17
27
|
if (values.length === 0)
|
|
@@ -62,7 +72,10 @@ export function tipAlign(leftPct) {
|
|
|
62
72
|
return 'center';
|
|
63
73
|
}
|
|
64
74
|
export function formatTick(n, digits = 1) {
|
|
65
|
-
if (
|
|
75
|
+
if (!Number.isFinite(n))
|
|
76
|
+
return '0';
|
|
77
|
+
if (Math.abs(n) >= 100 || Number.isInteger(n))
|
|
66
78
|
return String(Math.round(n));
|
|
67
|
-
|
|
79
|
+
const fixed = n.toFixed(digits).replace(/\.0+$/, '').replace(/(\.\d*?)0+$/, '$1');
|
|
80
|
+
return fixed;
|
|
68
81
|
}
|
|
@@ -58,30 +58,31 @@ export type ResolvedRemoteInputProps = {
|
|
|
58
58
|
export declare function getRemoteFormId(action: string | undefined | null): string | null;
|
|
59
59
|
/**
|
|
60
60
|
* Resolve HTML input props for a field inside a Kit remote form.
|
|
61
|
-
* Prefer a precomputed `formId` string so fields never touch Kit proxies.
|
|
62
61
|
*
|
|
63
|
-
* Kit
|
|
64
|
-
* `
|
|
62
|
+
* Kit 2.70+ `.as()` emits the logical path only (`email`, `n:age`, `b:active`).
|
|
63
|
+
* The remote id lives on the form `action` (`?/remote=…`), not on each field name.
|
|
64
|
+
* Appending `/${formId}` breaks `convert_formdata` / `split_path` — especially with
|
|
65
|
+
* keyed instances (`.for(key)` → `…/"default"`), which surfaces as:
|
|
66
|
+
* `Invalid path status/…/updateProduct_remote/"default"`.
|
|
67
|
+
*
|
|
68
|
+
* `formId` is kept for call-site compatibility / legacy stripping in
|
|
69
|
+
* {@link parseRemoteFieldName}; it is not appended to `name`.
|
|
65
70
|
*/
|
|
66
|
-
export declare function resolveRemoteInputProps(
|
|
71
|
+
export declare function resolveRemoteInputProps(_formId: string | null | undefined, logicalName: string | undefined, type?: string): ResolvedRemoteInputProps;
|
|
67
72
|
export type ParsedRemoteFieldName = {
|
|
68
73
|
/** Field path for errors / `form.data` (`email`, `items[0].name`) */
|
|
69
74
|
logicalName: string | undefined;
|
|
70
75
|
/** Exact HTML `name` to put on the input (Kit-encoded or plain) */
|
|
71
76
|
htmlName: string | undefined;
|
|
72
|
-
/** True when `name`
|
|
77
|
+
/** True when `name` still has a legacy `/${formId}` suffix */
|
|
73
78
|
isEncoded: boolean;
|
|
74
79
|
};
|
|
75
80
|
/**
|
|
76
|
-
* Split a
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* When `formId` is known, uses Kit’s suffix rule (`/${formId}`).
|
|
80
|
-
* Otherwise treats the first `/` after an optional `n:`/`b:` prefix as the form-id boundary
|
|
81
|
-
* (logical paths use `.` / `[n]`, never `/`).
|
|
81
|
+
* Split a (possibly legacy) HTML `name` into logical + html parts.
|
|
82
|
+
* Plain Kit 2.70+ names (`email`, `n:age`) pass through unchanged.
|
|
82
83
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
84
|
+
* Still strips a legacy `/${formId}` suffix when present (older lib builds
|
|
85
|
+
* appended the remote action id to every field name).
|
|
85
86
|
*/
|
|
86
87
|
export declare function parseRemoteFieldName(name: string | undefined, formId?: string | null): ParsedRemoteFieldName;
|
|
87
88
|
/**
|
|
@@ -19,15 +19,20 @@ export function getRemoteFormId(action) {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Resolve HTML input props for a field inside a Kit remote form.
|
|
22
|
-
* Prefer a precomputed `formId` string so fields never touch Kit proxies.
|
|
23
22
|
*
|
|
24
|
-
* Kit
|
|
25
|
-
* `
|
|
23
|
+
* Kit 2.70+ `.as()` emits the logical path only (`email`, `n:age`, `b:active`).
|
|
24
|
+
* The remote id lives on the form `action` (`?/remote=…`), not on each field name.
|
|
25
|
+
* Appending `/${formId}` breaks `convert_formdata` / `split_path` — especially with
|
|
26
|
+
* keyed instances (`.for(key)` → `…/"default"`), which surfaces as:
|
|
27
|
+
* `Invalid path status/…/updateProduct_remote/"default"`.
|
|
28
|
+
*
|
|
29
|
+
* `formId` is kept for call-site compatibility / legacy stripping in
|
|
30
|
+
* {@link parseRemoteFieldName}; it is not appended to `name`.
|
|
26
31
|
*/
|
|
27
|
-
export function resolveRemoteInputProps(
|
|
32
|
+
export function resolveRemoteInputProps(_formId, logicalName, type = 'text') {
|
|
28
33
|
if (!logicalName)
|
|
29
34
|
return {};
|
|
30
|
-
// Already Kit-encoded
|
|
35
|
+
// Already Kit-encoded or legacy `field/formId` — leave as-is.
|
|
31
36
|
if (logicalName.includes('/')) {
|
|
32
37
|
return { name: logicalName };
|
|
33
38
|
}
|
|
@@ -36,21 +41,14 @@ export function resolveRemoteInputProps(formId, logicalName, type = 'text') {
|
|
|
36
41
|
prefix = 'n:';
|
|
37
42
|
else if (type === 'checkbox' || type === 'boolean')
|
|
38
43
|
prefix = 'b:';
|
|
39
|
-
|
|
40
|
-
if (!formId)
|
|
41
|
-
return { name: base };
|
|
42
|
-
return { name: `${base}/${formId}` };
|
|
44
|
+
return { name: `${prefix}${logicalName}` };
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
|
-
* Split a
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* When `formId` is known, uses Kit’s suffix rule (`/${formId}`).
|
|
49
|
-
* Otherwise treats the first `/` after an optional `n:`/`b:` prefix as the form-id boundary
|
|
50
|
-
* (logical paths use `.` / `[n]`, never `/`).
|
|
47
|
+
* Split a (possibly legacy) HTML `name` into logical + html parts.
|
|
48
|
+
* Plain Kit 2.70+ names (`email`, `n:age`) pass through unchanged.
|
|
51
49
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* Still strips a legacy `/${formId}` suffix when present (older lib builds
|
|
51
|
+
* appended the remote action id to every field name).
|
|
54
52
|
*/
|
|
55
53
|
export function parseRemoteFieldName(name, formId) {
|
|
56
54
|
if (!name) {
|
|
@@ -65,7 +63,7 @@ export function parseRemoteFieldName(name, formId) {
|
|
|
65
63
|
logical = logical.slice(0, -2);
|
|
66
64
|
return { logicalName: logical, htmlName, isEncoded: true };
|
|
67
65
|
}
|
|
68
|
-
//
|
|
66
|
+
// Legacy heuristic: names with `/` used to mean `field/formId`
|
|
69
67
|
if (name.includes('/')) {
|
|
70
68
|
let rest = name;
|
|
71
69
|
if (rest.startsWith('n:') || rest.startsWith('b:'))
|
|
@@ -78,7 +76,12 @@ export function parseRemoteFieldName(name, formId) {
|
|
|
78
76
|
return { logicalName: logical, htmlName, isEncoded: true };
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
|
-
|
|
79
|
+
let logical = name;
|
|
80
|
+
if (logical.startsWith('n:') || logical.startsWith('b:'))
|
|
81
|
+
logical = logical.slice(2);
|
|
82
|
+
if (logical.endsWith('[]'))
|
|
83
|
+
logical = logical.slice(0, -2);
|
|
84
|
+
return { logicalName: logical, htmlName: name, isEncoded: false };
|
|
82
85
|
}
|
|
83
86
|
/**
|
|
84
87
|
* Safe props to spread onto `FormField` / `FormPasswordInput` from Kit `.as(...)`.
|