basalt-ui 2.10.0 → 2.11.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/CHANGELOG.md +15 -0
- package/MIGRATING.md +27 -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 +20 -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/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 +22 -14
- 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/marks.d.ts +1 -1
- package/dist/charts/marks.d.ts.map +1 -1
- package/dist/charts/marks.js +28 -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 +3 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +23 -5
- package/dist/charts/types.d.ts +31 -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 +21 -16
- package/src/charts/Heatmap.tsx +181 -76
- package/src/charts/Sparkline.tsx +106 -5
- package/src/charts/band-fold.ts +11 -0
- package/src/charts/compile.ts +26 -14
- 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/marks.ts +31 -14
- package/src/charts/panel.tsx +18 -5
- package/src/charts/plot-context.ts +109 -0
- package/src/charts/scales.ts +33 -5
- package/src/charts/types.ts +31 -5
- package/src/tokens/core.ts +10 -3
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,9 +140,31 @@ 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
|
+
band: boolean,
|
|
162
|
+
/** Continuous scales only: the explicit `[min, max]` that replaces the data's own extent. */
|
|
163
|
+
xDomain?: readonly [X, X],
|
|
164
|
+
): XScaleModel<X> {
|
|
141
165
|
const values = distinctX(raw)
|
|
142
|
-
|
|
166
|
+
// The kind comes from the data; an empty series has none to read, so the domain stands in.
|
|
167
|
+
const kind = xKindOf(values.length > 0 || xDomain === undefined ? values : [xDomain[0]])
|
|
143
168
|
const n = values.length
|
|
144
169
|
|
|
145
170
|
if (band || kind === 'string') {
|
|
@@ -180,7 +205,7 @@ export function xScaleFor<X extends ChartX>(raw: readonly X[], band: boolean): X
|
|
|
180
205
|
}
|
|
181
206
|
}
|
|
182
207
|
|
|
183
|
-
const nums = values.map(
|
|
208
|
+
const nums = values.map(toNumber)
|
|
184
209
|
// A loop, not Math.min(...nums): a spread of a long series overflows the call stack.
|
|
185
210
|
let lo = Infinity
|
|
186
211
|
let hi = -Infinity
|
|
@@ -194,7 +219,10 @@ export function xScaleFor<X extends ChartX>(raw: readonly X[], band: boolean): X
|
|
|
194
219
|
if (v > hi) hi = v
|
|
195
220
|
}
|
|
196
221
|
if (!Number.isFinite(lo)) [lo, hi] = [0, 1]
|
|
197
|
-
|
|
222
|
+
const explicit = explicitDomain(xDomain)
|
|
223
|
+
if (explicit !== null) {
|
|
224
|
+
;[lo, hi] = explicit
|
|
225
|
+
} else if (lo === hi) {
|
|
198
226
|
// One sample: give the axis a day (or a unit) of width so the point sits in the middle.
|
|
199
227
|
const half = kind === 'date' ? DAY_MS / 2 : 0.5
|
|
200
228
|
lo -= half
|
|
@@ -217,7 +245,7 @@ export function xScaleFor<X extends ChartX>(raw: readonly X[], band: boolean): X
|
|
|
217
245
|
extent: [lo, hi],
|
|
218
246
|
step: medianGap,
|
|
219
247
|
fraction: (x) => {
|
|
220
|
-
const v =
|
|
248
|
+
const v = toNumber(x)
|
|
221
249
|
return typeof v === 'number' && Number.isFinite(v) ? (v - lo) / span : null
|
|
222
250
|
},
|
|
223
251
|
}
|
package/src/charts/types.ts
CHANGED
|
@@ -63,10 +63,13 @@ 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. On a `cursorValue` series
|
|
71
|
+
* only `color` applies, to the cursor dot, and each distinct color is one extra mark: keep colors
|
|
72
|
+
* a small categorical set (statuses, buckets), never a continuous scale. */
|
|
70
73
|
getMarker?:
|
|
71
74
|
| ((d: T) => {
|
|
72
75
|
color?: string | undefined
|
|
@@ -241,9 +244,25 @@ export type PlotContext<T, X extends ChartX = ChartX> = {
|
|
|
241
244
|
highlighted: string | null
|
|
242
245
|
/** The measured container class (`regular` on the server). */
|
|
243
246
|
containerClass: ContainerClass
|
|
244
|
-
/** The chart's
|
|
247
|
+
/** The chart's FRAME in px (plot plus axis gutters), for a kind that lays out labels against it. */
|
|
245
248
|
width: number
|
|
246
249
|
height: number
|
|
250
|
+
/**
|
|
251
|
+
* The plot area in px: the frame less the axis gutters. Pin a mark in pixels with it (a 3 px
|
|
252
|
+
* rail along the top is `yMax - 3 * (yMax - yMin) / plot.plotHeight` down from `yMax`). The
|
|
253
|
+
* engine measures its gutters after `marks` runs, so the first pass (the server HTML, the first
|
|
254
|
+
* client frame) reports the FRAME, one frame-sized draw; the chart then re-renders once with the
|
|
255
|
+
* measured area, and only a chart whose `marks` read these fields pays that render. Every kind,
|
|
256
|
+
* single or composed, reports it the same way.
|
|
257
|
+
*/
|
|
258
|
+
plotWidth: number
|
|
259
|
+
plotHeight: number
|
|
260
|
+
/**
|
|
261
|
+
* Every row of `data`, whatever the legend hides: raw datums (`T`), NOT `PlotRow`s. For bucket-level marks only (absent columns,
|
|
262
|
+
* rails: the slot grid must not vanish with its last visible series); a series' own marks still
|
|
263
|
+
* draw `plot.rows(key)` and gate on `plot.visible`.
|
|
264
|
+
*/
|
|
265
|
+
data: readonly T[]
|
|
247
266
|
/** Bind a mark to the right axis with `yScale: plot.y2` (present only with a `y2` config). */
|
|
248
267
|
y2: 'y2' | undefined
|
|
249
268
|
/** The resolved y domain (and the right axis', with `y2`): basalt's, never the engine's. */
|
|
@@ -268,6 +287,13 @@ export type CartesianChartProps<T, X extends ChartX = ChartX> = BasaltProps & {
|
|
|
268
287
|
y2?: AxisConfig<T> | undefined
|
|
269
288
|
/** A tick count, or the exact x tick values. Default: by container class. */
|
|
270
289
|
xTicks?: number | readonly X[] | undefined
|
|
290
|
+
/**
|
|
291
|
+
* `[min, max]` of the x scale, in `x`'s type. Default: the data's own extent. Charts given the
|
|
292
|
+
* same domain put the same instant on the same pixel column, whatever their data spans; rows
|
|
293
|
+
* outside it are clipped. A domain that is reversed, flat or not finite falls back to the data
|
|
294
|
+
* extent (and warns in dev). A no-op on a string or band x (`Bars`, `MirroredBars`, `BandStrip`).
|
|
295
|
+
*/
|
|
296
|
+
xDomain?: readonly [X, X] | undefined
|
|
271
297
|
/** Tick label for an x value. Default: `DD.MM` for dates, compact numbers, strings verbatim. */
|
|
272
298
|
formatX?: ((x: X) => string) | undefined
|
|
273
299
|
zones?: readonly ZoneSpec[] | undefined
|
|
@@ -279,8 +305,8 @@ export type CartesianChartProps<T, X extends ChartX = ChartX> = BasaltProps & {
|
|
|
279
305
|
* Default: the height law (measured width × class ratio, 160–420px, ≤ 45vh on touch). Always the
|
|
280
306
|
* FRAME, in every kind: the plot plus the axis the engine measures. A `BandStrip` band is the
|
|
281
307
|
* frame less the x axis (about 21 px at the default font and density, so `height: 65` for a
|
|
282
|
-
* 44 px band).
|
|
283
|
-
*
|
|
308
|
+
* 44 px band). The box is CSS-owned before any measurement exists, so the plot area is read back
|
|
309
|
+
* from the engine's layout (`PlotContext.plotWidth`/`plotHeight`), never an input.
|
|
284
310
|
*/
|
|
285
311
|
height?: number | ResponsiveChartHeight | undefined
|
|
286
312
|
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
|
}
|