basalt-ui 2.10.0 → 2.11.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/CHANGELOG.md +25 -0
- package/MIGRATING.md +36 -13
- package/agent/rules/basalt-charts.md +2 -2
- package/agent/skills/basalt-charts/SKILL.md +16 -17
- package/dist/charts/BandStrip.d.ts +3 -2
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/CartesianChart.d.ts +3 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +9 -3
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +21 -15
- package/dist/charts/Heatmap.d.ts +33 -3
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +111 -68
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +7 -45
- package/dist/charts/MirroredBars.js +2 -2
- package/dist/charts/Sparkline.d.ts +12 -0
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +68 -5
- package/dist/charts/band-fold.d.ts +7 -0
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/compile.d.ts +4 -1
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +43 -19
- package/dist/charts/heatmap-fill.d.ts +15 -0
- package/dist/charts/heatmap-fill.d.ts.map +1 -0
- package/dist/charts/heatmap-fill.js +13 -0
- package/dist/charts/host.d.ts +5 -1
- package/dist/charts/host.d.ts.map +1 -1
- package/dist/charts/host.js +37 -1
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/labels.d.ts +34 -0
- package/dist/charts/labels.d.ts.map +1 -0
- package/dist/charts/labels.js +63 -0
- package/dist/charts/marks.d.ts +8 -1
- package/dist/charts/marks.d.ts.map +1 -1
- package/dist/charts/marks.js +50 -13
- package/dist/charts/panel.d.ts +7 -1
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +9 -4
- package/dist/charts/plot-context.d.ts +42 -0
- package/dist/charts/plot-context.d.ts.map +1 -0
- package/dist/charts/plot-context.js +64 -0
- package/dist/charts/scales.d.ts +6 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +28 -8
- package/dist/charts/ticks.d.ts +12 -0
- package/dist/charts/ticks.d.ts.map +1 -0
- package/dist/charts/ticks.js +42 -0
- package/dist/charts/types.d.ts +39 -5
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/tokens/core.d.ts +6 -0
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +5 -3
- package/llms.txt +12 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +2 -5
- package/src/charts/CartesianChart.tsx +13 -2
- package/src/charts/DualPanel.tsx +22 -16
- package/src/charts/Heatmap.tsx +181 -76
- package/src/charts/Lines.tsx +11 -57
- package/src/charts/MirroredBars.tsx +2 -2
- package/src/charts/Sparkline.tsx +106 -5
- package/src/charts/band-fold.ts +11 -0
- package/src/charts/compile.ts +60 -20
- package/src/charts/heatmap-fill.ts +19 -0
- package/src/charts/host.tsx +59 -0
- package/src/charts/index.ts +1 -1
- package/src/charts/labels.ts +118 -0
- package/src/charts/marks.ts +72 -14
- package/src/charts/panel.tsx +18 -5
- package/src/charts/plot-context.ts +109 -0
- package/src/charts/scales.ts +41 -11
- package/src/charts/ticks.ts +61 -0
- package/src/charts/types.ts +39 -5
- package/src/tokens/core.ts +10 -3
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place a `PlotContext` is built (`docs/V2-SPEC.md` § 9.2) and the plot-size feedback loop
|
|
3
|
+
* around it. The engine lays a plot out AFTER `marks` runs, so `plotWidth`/`plotHeight` cannot be
|
|
4
|
+
* known when `marks(plot)` is called: the first pass reports the frame, the host measures the laid-out
|
|
5
|
+
* plot per pane and hands it back, and a definition that READ the size is recompiled with it.
|
|
6
|
+
* `compileCartesian` and every composed kind (`panelDefinition`) build their context here, so all
|
|
7
|
+
* of them report the plot area the same way.
|
|
8
|
+
*/
|
|
9
|
+
import type { ChartX, PlotContext } from './types'
|
|
10
|
+
|
|
11
|
+
/** A plot area in px. */
|
|
12
|
+
export type PlotSize = { width: number; height: number }
|
|
13
|
+
|
|
14
|
+
/** The laid-out plot area of every pane, by pane id. A single chart is one pane, {@link MAIN_PANE}. */
|
|
15
|
+
export type PlotSizes = Readonly<Record<string, PlotSize>>
|
|
16
|
+
|
|
17
|
+
export const MAIN_PANE = 'main'
|
|
18
|
+
|
|
19
|
+
/** Two measurements closer than this are the same plot: layout jitter must not trigger a recompile. */
|
|
20
|
+
export const PLOT_EPSILON_PX = 0.01
|
|
21
|
+
|
|
22
|
+
export const samePlot = (a: PlotSize, b: PlotSize): boolean =>
|
|
23
|
+
Math.abs(a.width - b.width) < PLOT_EPSILON_PX && Math.abs(a.height - b.height) < PLOT_EPSILON_PX
|
|
24
|
+
|
|
25
|
+
export function samePlots(a: PlotSizes | null, b: PlotSizes): boolean {
|
|
26
|
+
if (a === null) return false
|
|
27
|
+
const keys = Object.keys(b)
|
|
28
|
+
return (
|
|
29
|
+
keys.length === Object.keys(a).length &&
|
|
30
|
+
keys.every((k) => {
|
|
31
|
+
const prev = a[k]
|
|
32
|
+
const next = b[k]
|
|
33
|
+
return prev !== undefined && next !== undefined && samePlot(prev, next)
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Per definition: did any `marks` read the plot size, and who to tell when that read comes late. */
|
|
39
|
+
type PlotReads = {
|
|
40
|
+
read: boolean
|
|
41
|
+
onLateRead: (() => void) | undefined
|
|
42
|
+
measured: PlotSizes | null
|
|
43
|
+
}
|
|
44
|
+
const READS = new WeakMap<object, PlotReads>()
|
|
45
|
+
const readsOf = (definition: object): PlotReads => {
|
|
46
|
+
const found = READS.get(definition)
|
|
47
|
+
if (found) return found
|
|
48
|
+
const created: PlotReads = { read: false, onLateRead: undefined, measured: null }
|
|
49
|
+
READS.set(definition, created)
|
|
50
|
+
return created
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Whether `marks` read `plotWidth`/`plotHeight` while building this definition: only such a chart
|
|
54
|
+
* recompiles on the measured plot. A read is registered when the getter runs, so a branch-only read,
|
|
55
|
+
* a destructure and a lazy channel accessor all count. */
|
|
56
|
+
export const readsPlot = (definition: object): boolean => READS.get(definition)?.read === true
|
|
57
|
+
|
|
58
|
+
/** The host's hook for a read that happens AFTER it measured (an accessor the engine calls later):
|
|
59
|
+
* it fires once, on the first read, so the host can report what it already measured. */
|
|
60
|
+
export function watchPlotReads(definition: object, onLateRead: (() => void) | undefined): void {
|
|
61
|
+
readsOf(definition).onLateRead = onLateRead
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The host records what it measured for a definition, so a late read can be answered at once. */
|
|
65
|
+
export const recordPlots = (definition: object, sizes: PlotSizes): void => {
|
|
66
|
+
readsOf(definition).measured = sizes
|
|
67
|
+
}
|
|
68
|
+
export const measuredPlots = (definition: object): PlotSizes | null =>
|
|
69
|
+
READS.get(definition)?.measured ?? null
|
|
70
|
+
|
|
71
|
+
/** What a pane's `PlotContext` reads its plot size through: the measurement and the read hook. */
|
|
72
|
+
export type PlotAccess = { size: () => PlotSize | null; read: () => void }
|
|
73
|
+
|
|
74
|
+
export function plotAccess(
|
|
75
|
+
definition: object,
|
|
76
|
+
sizes: PlotSizes | null | undefined,
|
|
77
|
+
pane: string,
|
|
78
|
+
): PlotAccess {
|
|
79
|
+
return {
|
|
80
|
+
size: () => sizes?.[pane] ?? null,
|
|
81
|
+
read: () => {
|
|
82
|
+
const reads = readsOf(definition)
|
|
83
|
+
if (reads.read) return
|
|
84
|
+
reads.read = true
|
|
85
|
+
reads.onLateRead?.()
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type PlotBase<T, X extends ChartX> = Omit<PlotContext<T, X>, 'plotWidth' | 'plotHeight'>
|
|
91
|
+
|
|
92
|
+
/** A `PlotContext`: `base` plus `plotWidth`/`plotHeight` as read-registering getters, the frame
|
|
93
|
+
* (`base.width`/`height`) until the pane has been measured. */
|
|
94
|
+
export function plotContext<T, X extends ChartX>(
|
|
95
|
+
base: PlotBase<T, X>,
|
|
96
|
+
access: PlotAccess,
|
|
97
|
+
): PlotContext<T, X> {
|
|
98
|
+
const measured = (side: keyof PlotSize): number => {
|
|
99
|
+
access.read()
|
|
100
|
+
return access.size()?.[side] ?? (side === 'width' ? base.width : base.height)
|
|
101
|
+
}
|
|
102
|
+
return Object.defineProperties(
|
|
103
|
+
{ ...base },
|
|
104
|
+
{
|
|
105
|
+
plotWidth: { enumerable: true, get: () => measured('width') },
|
|
106
|
+
plotHeight: { enumerable: true, get: () => measured('height') },
|
|
107
|
+
},
|
|
108
|
+
) as PlotContext<T, X>
|
|
109
|
+
}
|
package/src/charts/scales.ts
CHANGED
|
@@ -94,6 +94,9 @@ export function xKindOf(values: readonly ChartX[]): XKind {
|
|
|
94
94
|
return 'string'
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/** A continuous x value as a number: a `Date` by timestamp. */
|
|
98
|
+
const toNumber = (v: ChartX): number => (v instanceof Date ? v.getTime() : (v as number))
|
|
99
|
+
|
|
97
100
|
const keyOf = (v: ChartX): number | string => (v instanceof Date ? v.getTime() : v)
|
|
98
101
|
|
|
99
102
|
/** Distinct x values in data order (dates by timestamp). */
|
|
@@ -137,20 +140,44 @@ export type XScaleModel<X extends ChartX> = {
|
|
|
137
140
|
|
|
138
141
|
const DAY_MS = 86_400_000
|
|
139
142
|
|
|
140
|
-
|
|
143
|
+
/** The explicit x domain as `[min, max]` numbers, or `null` (unset, reversed, flat or not finite:
|
|
144
|
+
* the data's own extent stands, with a dev warning for a domain that was set but unusable). */
|
|
145
|
+
function explicitDomain(xDomain: readonly [ChartX, ChartX] | undefined): [number, number] | null {
|
|
146
|
+
if (xDomain === undefined) {
|
|
147
|
+
return null
|
|
148
|
+
}
|
|
149
|
+
const [min, max] = [toNumber(xDomain[0]), toNumber(xDomain[1])]
|
|
150
|
+
if (Number.isFinite(min) && Number.isFinite(max) && min < max) {
|
|
151
|
+
return [min, max]
|
|
152
|
+
}
|
|
153
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
154
|
+
console.warn('[basalt] CartesianChart: `xDomain` needs finite min < max; using the data extent')
|
|
155
|
+
}
|
|
156
|
+
return null
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function xScaleFor<X extends ChartX>(
|
|
160
|
+
raw: readonly X[],
|
|
161
|
+
/** `'flush'`: a band scale with no outer padding, so the first and last band meet the plot's
|
|
162
|
+
* edges (`MirroredBars`); `true` pads half a gap-and-a-bit at each end, as `Bars` does. */
|
|
163
|
+
band: boolean | 'flush',
|
|
164
|
+
/** Continuous scales only: the explicit `[min, max]` that replaces the data's own extent. */
|
|
165
|
+
xDomain?: readonly [X, X],
|
|
166
|
+
): XScaleModel<X> {
|
|
141
167
|
const values = distinctX(raw)
|
|
142
|
-
|
|
168
|
+
// The kind comes from the data; an empty series has none to read, so the domain stands in.
|
|
169
|
+
const kind = xKindOf(values.length > 0 || xDomain === undefined ? values : [xDomain[0]])
|
|
143
170
|
const n = values.length
|
|
144
171
|
|
|
145
172
|
if (band || kind === 'string') {
|
|
146
173
|
const keys = values as X[]
|
|
147
174
|
const index = new Map(keys.map((k, i) => [keyOf(k), i] as const))
|
|
148
175
|
if (band) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
176
|
+
const outer = band === 'flush' ? 0 : BAND_PADDING_OUTER
|
|
177
|
+
// Total width in steps; no data has none, so a step of 1 (a lone flush band spans 0.8 of one).
|
|
178
|
+
const steps = n - BAND_PADDING_INNER + 2 * outer
|
|
179
|
+
const step = 1 / (steps > 0 ? steps : 1)
|
|
180
|
+
const scale = scaleBand<X>().domain(keys).paddingInner(BAND_PADDING_INNER).paddingOuter(outer)
|
|
154
181
|
return {
|
|
155
182
|
kind,
|
|
156
183
|
band: true,
|
|
@@ -161,7 +188,7 @@ export function xScaleFor<X extends ChartX>(raw: readonly X[], band: boolean): X
|
|
|
161
188
|
fraction: (x) => {
|
|
162
189
|
const i = index.get(keyOf(x))
|
|
163
190
|
if (i === undefined) return null
|
|
164
|
-
return step * (
|
|
191
|
+
return step * (outer + i + (1 - BAND_PADDING_INNER) / 2)
|
|
165
192
|
},
|
|
166
193
|
}
|
|
167
194
|
}
|
|
@@ -180,7 +207,7 @@ export function xScaleFor<X extends ChartX>(raw: readonly X[], band: boolean): X
|
|
|
180
207
|
}
|
|
181
208
|
}
|
|
182
209
|
|
|
183
|
-
const nums = values.map(
|
|
210
|
+
const nums = values.map(toNumber)
|
|
184
211
|
// A loop, not Math.min(...nums): a spread of a long series overflows the call stack.
|
|
185
212
|
let lo = Infinity
|
|
186
213
|
let hi = -Infinity
|
|
@@ -194,7 +221,10 @@ export function xScaleFor<X extends ChartX>(raw: readonly X[], band: boolean): X
|
|
|
194
221
|
if (v > hi) hi = v
|
|
195
222
|
}
|
|
196
223
|
if (!Number.isFinite(lo)) [lo, hi] = [0, 1]
|
|
197
|
-
|
|
224
|
+
const explicit = explicitDomain(xDomain)
|
|
225
|
+
if (explicit !== null) {
|
|
226
|
+
;[lo, hi] = explicit
|
|
227
|
+
} else if (lo === hi) {
|
|
198
228
|
// One sample: give the axis a day (or a unit) of width so the point sits in the middle.
|
|
199
229
|
const half = kind === 'date' ? DAY_MS / 2 : 0.5
|
|
200
230
|
lo -= half
|
|
@@ -217,7 +247,7 @@ export function xScaleFor<X extends ChartX>(raw: readonly X[], band: boolean): X
|
|
|
217
247
|
extent: [lo, hi],
|
|
218
248
|
step: medianGap,
|
|
219
249
|
fraction: (x) => {
|
|
220
|
-
const v =
|
|
250
|
+
const v = toNumber(x)
|
|
221
251
|
return typeof v === 'number' && Number.isFinite(v) ? (v - lo) / span : null
|
|
222
252
|
},
|
|
223
253
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tick selection that needs no engine: the stride every band axis shares, and the round,
|
|
3
|
+
* bucket-snapped ticks of a bucketed Date axis.
|
|
4
|
+
*/
|
|
5
|
+
import { scaleUtc } from 'd3-scale'
|
|
6
|
+
|
|
7
|
+
/** Every n-th value, n the smallest stride that leaves at most `count` of them. */
|
|
8
|
+
export function strideEvery<V>(values: readonly V[], count: number): V[] {
|
|
9
|
+
const stride = Math.max(1, Math.ceil(values.length / Math.max(1, count)))
|
|
10
|
+
return values.filter((_, i) => i % stride === 0)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The median gap between sorted, DISTINCT numbers: two or more of them leave a positive one. */
|
|
14
|
+
function medianGap(sorted: readonly number[]): number {
|
|
15
|
+
const gaps = sorted.slice(1).map((t, i) => t - (sorted[i] as number))
|
|
16
|
+
return gaps.toSorted((a, b) => a - b)[gaps.length >> 1] as number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The index of the value nearest `target` in an ascending, non-empty array (binary search). */
|
|
20
|
+
function nearestIndex(sorted: readonly number[], target: number): number {
|
|
21
|
+
let lo = 0
|
|
22
|
+
let hi = sorted.length - 1
|
|
23
|
+
while (lo < hi) {
|
|
24
|
+
const mid = (lo + hi) >> 1
|
|
25
|
+
if ((sorted[mid] as number) < target) lo = mid + 1
|
|
26
|
+
else hi = mid
|
|
27
|
+
}
|
|
28
|
+
const before = lo - 1
|
|
29
|
+
return before >= 0 && target - (sorted[before] as number) <= (sorted[lo] as number) - target
|
|
30
|
+
? before
|
|
31
|
+
: lo
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Ticks of a bucketed Date axis: the time scale's own round instants, each snapped to the bucket
|
|
36
|
+
* it falls in. Labelling every bucket and letting the engine thin the collisions leaves an uneven,
|
|
37
|
+
* near-touching subset ("18:13 18:17 18:21"); round instants are evenly spaced whenever the
|
|
38
|
+
* buckets are. A bucket is used once, and a round instant with no bucket within a step of it is
|
|
39
|
+
* dropped. Fewer than two picks falls back to a plain stride over the distinct,
|
|
40
|
+
* sorted buckets. `count` must be finite (`xTickPolicy` guards it). O(ticks · log buckets) after the sort.
|
|
41
|
+
*/
|
|
42
|
+
export function bucketTicks(values: readonly Date[], count: number): Date[] {
|
|
43
|
+
const times = [...new Set(values.map((v) => v.getTime()).filter(Number.isFinite))].toSorted(
|
|
44
|
+
(a, b) => a - b,
|
|
45
|
+
)
|
|
46
|
+
const asDates = (ts: readonly number[]): Date[] => ts.map((t) => new Date(t))
|
|
47
|
+
const first = times[0]
|
|
48
|
+
const last = times.at(-1)
|
|
49
|
+
if (first === undefined || last === undefined || first === last) return asDates(times)
|
|
50
|
+
const step = medianGap(times)
|
|
51
|
+
const want = Math.max(1, Math.floor(count))
|
|
52
|
+
const picked = new Set<number>()
|
|
53
|
+
for (const tick of scaleUtc()
|
|
54
|
+
.domain([new Date(first), new Date(last)])
|
|
55
|
+
.ticks(want)) {
|
|
56
|
+
const t = tick.getTime()
|
|
57
|
+
const near = times[nearestIndex(times, t)]
|
|
58
|
+
if (near !== undefined && Math.abs(near - t) < step) picked.add(near)
|
|
59
|
+
}
|
|
60
|
+
return asDates(picked.size >= 2 ? [...picked] : strideEvery(times, want))
|
|
61
|
+
}
|
package/src/charts/types.ts
CHANGED
|
@@ -63,10 +63,15 @@ export type ChartSeries<T> = {
|
|
|
63
63
|
/**
|
|
64
64
|
* A cursor dot for a series whose mark the consumer draws itself (`marks`, so `getValue` stays
|
|
65
65
|
* `null`): the y of the dot at each datum, `null` for none. The dot shows while the cursor is on
|
|
66
|
-
* that datum's x and takes the series color
|
|
66
|
+
* that datum's x and takes the series color, or `getMarker(d).color` when the series has one: the
|
|
67
|
+
* dot follows the datum. A series drawn from `plot.rows` already has one.
|
|
67
68
|
*/
|
|
68
69
|
cursorValue?: ((d: T) => number | null) | undefined
|
|
69
|
-
/** A marker at a point (a PR star, a status dot); `null` for none.
|
|
70
|
+
/** A marker at a point (a PR star, a status dot); `null` for none. Always-on markers are `Lines`'
|
|
71
|
+
* alone. On a `CartesianChart` with consumer `marks` only the CURSOR dot of a `cursorValue`
|
|
72
|
+
* series reads `getMarker` (its `color`): without `cursorValue` it is ignored there, so draw a
|
|
73
|
+
* persistent dot in `marks` yourself. Each distinct color is one extra mark: keep colors a small
|
|
74
|
+
* categorical set (statuses, buckets), never a continuous scale. */
|
|
70
75
|
getMarker?:
|
|
71
76
|
| ((d: T) => {
|
|
72
77
|
color?: string | undefined
|
|
@@ -241,11 +246,33 @@ export type PlotContext<T, X extends ChartX = ChartX> = {
|
|
|
241
246
|
highlighted: string | null
|
|
242
247
|
/** The measured container class (`regular` on the server). */
|
|
243
248
|
containerClass: ContainerClass
|
|
244
|
-
/** The chart's
|
|
249
|
+
/** The chart's FRAME in px (plot plus axis gutters), for a kind that lays out labels against it. */
|
|
245
250
|
width: number
|
|
246
251
|
height: number
|
|
252
|
+
/**
|
|
253
|
+
* The plot area in px: the frame less the axis gutters. Pin a mark in pixels with it (a 3 px
|
|
254
|
+
* rail along the top is `yMax - 3 * (yMax - yMin) / plot.plotHeight` down from `yMax`). The
|
|
255
|
+
* engine measures its gutters after `marks` runs, so the first pass (the server HTML, the first
|
|
256
|
+
* client frame) reports the FRAME, one frame-sized draw; the chart then re-renders once with the
|
|
257
|
+
* measured area, and only a chart whose `marks` read these fields pays that render. Every kind,
|
|
258
|
+
* single or composed, reports it the same way.
|
|
259
|
+
*/
|
|
260
|
+
plotWidth: number
|
|
261
|
+
plotHeight: number
|
|
262
|
+
/**
|
|
263
|
+
* Every row of `data`, whatever the legend hides: raw datums (`T`), NOT `PlotRow`s. For bucket-level marks only (absent columns,
|
|
264
|
+
* rails: the slot grid must not vanish with its last visible series); a series' own marks still
|
|
265
|
+
* draw `plot.rows(key)` and gate on `plot.visible`.
|
|
266
|
+
*/
|
|
267
|
+
data: readonly T[]
|
|
247
268
|
/** Bind a mark to the right axis with `yScale: plot.y2` (present only with a `y2` config). */
|
|
248
269
|
y2: 'y2' | undefined
|
|
270
|
+
/**
|
|
271
|
+
* Where an x value sits in the plot, 0 (left edge) to 1 (right edge), on the SAME x scale the
|
|
272
|
+
* axis draws: an explicit `xDomain` or the extent of every datum. Outside [0, 1] a value is
|
|
273
|
+
* clipped; `null` for a value the scale cannot place.
|
|
274
|
+
*/
|
|
275
|
+
xFraction: (x: X) => number | null
|
|
249
276
|
/** The resolved y domain (and the right axis', with `y2`): basalt's, never the engine's. */
|
|
250
277
|
yDomain: readonly [number, number]
|
|
251
278
|
y2Domain: readonly [number, number] | undefined
|
|
@@ -268,6 +295,13 @@ export type CartesianChartProps<T, X extends ChartX = ChartX> = BasaltProps & {
|
|
|
268
295
|
y2?: AxisConfig<T> | undefined
|
|
269
296
|
/** A tick count, or the exact x tick values. Default: by container class. */
|
|
270
297
|
xTicks?: number | readonly X[] | undefined
|
|
298
|
+
/**
|
|
299
|
+
* `[min, max]` of the x scale, in `x`'s type. Default: the data's own extent. Charts given the
|
|
300
|
+
* same domain put the same instant on the same pixel column, whatever their data spans; rows
|
|
301
|
+
* outside it are clipped. A domain that is reversed, flat or not finite falls back to the data
|
|
302
|
+
* extent (and warns in dev). A no-op on a string or band x (`Bars`, `MirroredBars`, `BandStrip`).
|
|
303
|
+
*/
|
|
304
|
+
xDomain?: readonly [X, X] | undefined
|
|
271
305
|
/** Tick label for an x value. Default: `DD.MM` for dates, compact numbers, strings verbatim. */
|
|
272
306
|
formatX?: ((x: X) => string) | undefined
|
|
273
307
|
zones?: readonly ZoneSpec[] | undefined
|
|
@@ -279,8 +313,8 @@ export type CartesianChartProps<T, X extends ChartX = ChartX> = BasaltProps & {
|
|
|
279
313
|
* Default: the height law (measured width × class ratio, 160–420px, ≤ 45vh on touch). Always the
|
|
280
314
|
* FRAME, in every kind: the plot plus the axis the engine measures. A `BandStrip` band is the
|
|
281
315
|
* frame less the x axis (about 21 px at the default font and density, so `height: 65` for a
|
|
282
|
-
* 44 px band).
|
|
283
|
-
*
|
|
316
|
+
* 44 px band). The box is CSS-owned before any measurement exists, so the plot area is read back
|
|
317
|
+
* from the engine's layout (`PlotContext.plotWidth`/`plotHeight`), never an input.
|
|
284
318
|
*/
|
|
285
319
|
height?: number | ResponsiveChartHeight | undefined
|
|
286
320
|
state?: ChartState | undefined
|
package/src/tokens/core.ts
CHANGED
|
@@ -347,6 +347,13 @@ export function pxRem(px: number): string {
|
|
|
347
347
|
return `${px / 16}rem`
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
+
/**
|
|
351
|
+
* Reference-line strength: the status solid's share over the panel, in percent. One value for the
|
|
352
|
+
* three lines so they read as one family; 60 keeps the faintest (light-scheme `warn`) at a 2:1
|
|
353
|
+
* composite against the page, where the old 20–30% sat at 1.25–1.5 (`ref-line-contrast.test.ts`).
|
|
354
|
+
*/
|
|
355
|
+
export const REF_LINE_ALPHA = 60
|
|
356
|
+
|
|
350
357
|
/** Emit one prefixed group of pairs for a given scheme side. */
|
|
351
358
|
const groupSide = (prefix: string, map: SeriesMap, side: Side): string =>
|
|
352
359
|
Object.entries(map)
|
|
@@ -713,9 +720,9 @@ function frameworkDerived(data: PaletteData, only: 'core' | 'all'): string {
|
|
|
713
720
|
decl('good-soft', 'color-mix(in srgb, var(--vx-good-solid) 8%, transparent)'),
|
|
714
721
|
decl('bad', 'color-mix(in srgb, var(--vx-bad-solid) 18%, transparent)'),
|
|
715
722
|
decl('warn', 'color-mix(in srgb, var(--vx-warn-solid) 8%, transparent)'),
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
723
|
+
...(['good', 'bad', 'warn'] as const).map((k) =>
|
|
724
|
+
decl(`${k}-ref`, `color-mix(in srgb, var(--vx-${k}-solid) ${REF_LINE_ALPHA}%, transparent)`),
|
|
725
|
+
),
|
|
719
726
|
].join('\n')
|
|
720
727
|
return canonical
|
|
721
728
|
}
|