basalt-ui 2.21.0 → 2.23.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 +60 -0
- package/MIGRATING.md +452 -12
- package/agent/agents/basalt-design-reviewer.md +1 -1
- package/agent/rules/basalt-tokens.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +1 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +73 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +6 -0
- package/dist/charts/CartesianChart.d.ts +10 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +8 -5
- package/dist/charts/ChartCard.d.ts +12 -3
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +39 -8
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +5 -8
- package/dist/charts/Heatmap.d.ts +12 -1
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +34 -5
- package/dist/charts/Lines.d.ts +3 -0
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +29 -6
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +4 -6
- package/dist/charts/Sparkline.d.ts +14 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +101 -22
- package/dist/charts/StackedArea.d.ts +4 -1
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +9 -3
- package/dist/charts/band-fold.d.ts +38 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +18 -1
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- package/dist/charts/chart-dates.d.ts +12 -0
- package/dist/charts/chart-dates.d.ts.map +1 -0
- package/dist/charts/chart-dates.js +16 -0
- package/dist/charts/chart-legend.module.css +7 -0
- package/dist/charts/compile.d.ts +25 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +152 -72
- package/dist/charts/date-tick-format.d.ts +5 -5
- package/dist/charts/date-tick-format.d.ts.map +1 -1
- package/dist/charts/date-tick-format.js +3 -7
- package/dist/charts/labels.d.ts +21 -6
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +52 -17
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +7 -21
- package/dist/charts/marks.js +1 -1
- package/dist/charts/panel.d.ts +0 -6
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -10
- package/dist/charts/ref-label.d.ts +43 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +75 -0
- package/dist/charts/scales.d.ts +4 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +14 -3
- package/dist/charts/sparkline.module.css +13 -17
- package/dist/charts/sparkline.module.css.d.ts +1 -2
- package/dist/charts/state.d.ts +2 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +5 -2
- package/dist/charts/types.d.ts +18 -8
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.d.ts +1 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +1 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +68 -4
- package/dist/cli/shot/capture.d.ts +21 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +202 -36
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +17 -1
- package/dist/cli/shot/playwright.d.ts +13 -2
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/playwright.js +5 -1
- package/dist/cli/shot/types.d.ts +4 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +2 -0
- package/dist/cli/tokens-css.d.ts +5 -7
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +11 -12
- package/dist/controls/controls.module.css +11 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +1 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +22 -3
- package/dist/controls/sync-button.module.css +34 -2
- package/dist/controls/sync-button.module.css.d.ts +1 -0
- package/dist/dashboard/bar-list.d.ts +6 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +15 -8
- package/dist/dashboard/bar-list.module.css +83 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +2 -2
- package/dist/dashboard/index.d.ts +1 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/meter-model.d.ts +84 -5
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +100 -15
- package/dist/dashboard/meter-parts.d.ts +9 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +276 -74
- package/dist/dashboard/meter.d.ts +54 -65
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +21 -4
- package/dist/dashboard/meter.module.css +76 -0
- package/dist/dashboard/meter.module.css.d.ts +6 -0
- package/dist/dashboard/page-summary.d.ts +20 -0
- package/dist/dashboard/page-summary.d.ts.map +1 -0
- package/dist/dashboard/page-summary.js +28 -0
- package/dist/dashboard/page-summary.module.css +89 -0
- package/dist/dashboard/page-summary.module.css.d.ts +15 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/section.d.ts +25 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +10 -5
- package/dist/dashboard/section.module.css +23 -0
- package/dist/dashboard/section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.d.ts +4 -2
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +7 -5
- package/dist/dashboard/stat-card.module.css +36 -0
- package/dist/dashboard/stat-group.module.css +7 -0
- package/dist/dashboard/stat-strip.d.ts +22 -6
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +104 -60
- package/dist/dashboard/stat-strip.module.css +122 -53
- package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts +7 -1
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +3 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +0 -5
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +43 -4
- package/dist/theme/chrome-vars.d.ts +20 -5
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +46 -3
- package/dist/theme/controls.module.css +37 -0
- package/dist/theme/controls.module.css.d.ts +2 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +18 -27
- package/dist/theme/status-verdict.d.ts.map +1 -1
- package/dist/theme/status-verdict.js +9 -1
- package/dist/tokens/core.d.ts +2 -1
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -1
- package/dist/tokens/derive.d.ts +3 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +16 -1
- package/dist/tokens/palette.d.ts +11 -10
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +11 -10
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +42 -22
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +83 -3
- package/src/charts/Bars.tsx +7 -0
- package/src/charts/CartesianChart.tsx +18 -3
- package/src/charts/ChartCard.tsx +54 -13
- package/src/charts/DualPanel.tsx +3 -6
- package/src/charts/Heatmap.tsx +54 -5
- package/src/charts/Lines.tsx +56 -10
- package/src/charts/MirroredBars.tsx +3 -5
- package/src/charts/Sparkline.tsx +135 -25
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +50 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-dates.ts +30 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +253 -87
- package/src/charts/date-tick-format.ts +10 -13
- package/src/charts/labels.ts +81 -26
- package/src/charts/legend.tsx +10 -20
- package/src/charts/marks.ts +1 -1
- package/src/charts/panel.tsx +1 -16
- package/src/charts/ref-label.ts +131 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +13 -17
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +9 -4
- package/src/charts/types.ts +18 -8
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/init.ts +100 -3
- package/src/cli/shot/capture.ts +266 -35
- package/src/cli/shot/detect.ts +18 -1
- package/src/cli/shot/playwright.ts +20 -4
- package/src/cli/shot/types.ts +5 -0
- package/src/cli/tokens-css.ts +18 -20
- package/src/controls/controls.module.css +11 -1
- package/src/controls/filter-pill.tsx +2 -0
- package/src/controls/sync-button.module.css +34 -2
- package/src/controls/sync-button.module.css.d.ts +1 -0
- package/src/controls/sync-button.tsx +40 -4
- package/src/dashboard/bar-list.module.css +83 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +107 -69
- package/src/dashboard/delta-badge.tsx +6 -2
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +207 -24
- package/src/dashboard/meter-parts.tsx +349 -67
- package/src/dashboard/meter.module.css +76 -0
- package/src/dashboard/meter.module.css.d.ts +6 -0
- package/src/dashboard/meter.tsx +72 -18
- package/src/dashboard/page-summary.module.css +89 -0
- package/src/dashboard/page-summary.module.css.d.ts +15 -0
- package/src/dashboard/page-summary.tsx +95 -0
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/section.module.css +23 -0
- package/src/dashboard/section.module.css.d.ts +1 -0
- package/src/dashboard/section.tsx +59 -11
- package/src/dashboard/stat-card-parts.tsx +5 -1
- package/src/dashboard/stat-card.module.css +36 -0
- package/src/dashboard/stat-card.tsx +12 -6
- package/src/dashboard/stat-group.module.css +7 -0
- package/src/dashboard/stat-strip.module.css +122 -53
- package/src/dashboard/stat-strip.module.css.d.ts +4 -0
- package/src/dashboard/stat-strip.tsx +176 -91
- package/src/dashboard/visual-slot.ts +12 -3
- package/src/guard/index.ts +0 -5
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +43 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +200 -68
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +37 -0
- package/src/theme/controls.module.css.d.ts +2 -0
- package/src/theme/index.ts +22 -32
- package/src/theme/status-verdict.tsx +5 -1
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/palette.ts +11 -10
- package/src/tokens/status-text.ts +2 -0
package/src/charts/ChartCard.tsx
CHANGED
|
@@ -87,16 +87,36 @@ const bodyClipStyle: CSSProperties = {
|
|
|
87
87
|
padding: '2px var(--vx-space-card-inset-x, 1rem) var(--vx-space-card-inset-y, 0.75rem)',
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
const PERIOD_SEPARATOR = '· '
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A period list joins with `·`; behind a unit it leads with one too, so a one-item list is
|
|
94
|
+
* separated from the unit as the items are from each other (an item that already leads with it
|
|
95
|
+
* is not doubled). A plain string is written as is.
|
|
96
|
+
*/
|
|
97
|
+
function periodText(period: string | readonly string[], afterUnit: boolean): string {
|
|
98
|
+
if (typeof period === 'string') return period
|
|
99
|
+
if (period.length === 0) return ''
|
|
100
|
+
const text = period.join(' · ')
|
|
101
|
+
return afterUnit && !text.startsWith(PERIOD_SEPARATOR.trim()) ? PERIOD_SEPARATOR + text : text
|
|
102
|
+
}
|
|
103
|
+
|
|
90
104
|
/** One headline figure: the value is the hero, then its unit, a comparison node and the period. */
|
|
91
105
|
export type ChartFact = {
|
|
92
106
|
value: ReactNode
|
|
93
107
|
unit?: string | undefined
|
|
94
108
|
/** Usually a `DeltaBadge`. */
|
|
95
109
|
comparison?: ReactNode
|
|
96
|
-
/** Plain text the figure covers, e.g. `last 30 d`.
|
|
97
|
-
|
|
110
|
+
/** Plain text the figure covers, e.g. `last 30 d`. A list is joined by ` · ` (`['last entry 3 d
|
|
111
|
+
* ago', '12 entries']`) and, behind a `unit`, led by one. */
|
|
112
|
+
period?: string | readonly string[] | undefined
|
|
113
|
+
/** Ink for the whole fact (text only, never a fill): a stale or off-target figure reads `warn`. */
|
|
114
|
+
tone?: ChartFactTone | undefined
|
|
98
115
|
}
|
|
99
116
|
|
|
117
|
+
/** The status inks a fact can take, plus the muted one. */
|
|
118
|
+
export type ChartFactTone = 'good' | 'warn' | 'bad' | 'muted'
|
|
119
|
+
|
|
100
120
|
/** The three boxes a `ChartCard` paints. */
|
|
101
121
|
export type ChartCardSlot = 'root' | 'header' | 'body'
|
|
102
122
|
|
|
@@ -124,6 +144,10 @@ type ChartCardBaseProps = BasaltProps &
|
|
|
124
144
|
* unsized chart takes — pass the chart's own `height` when it states one, so a `<Suspense
|
|
125
145
|
* fallback={<ChartCard state={{ pending: true }} …/>}>` reserves the final size. */
|
|
126
146
|
placeholderHeight?: number | ResponsiveChartHeight | undefined
|
|
147
|
+
/** Placeholder data is showing: the facts row dims with the plot (a strip cell's `stale`). */
|
|
148
|
+
stale?: boolean | undefined
|
|
149
|
+
/** What an errored `state` names: "Could not load {stateNoun}". Default: no noun. */
|
|
150
|
+
stateNoun?: string | undefined
|
|
127
151
|
/** An errored `state` shows the shared Retry button (the one `ErrorState` renders). */
|
|
128
152
|
onRetry?: (() => void) | undefined
|
|
129
153
|
/** A refetch is in flight: Retry is inert and marked busy. */
|
|
@@ -162,24 +186,38 @@ const HEADER_TRIGGERS = ['title', 'info', 'value', 'icon', 'count'] as const
|
|
|
162
186
|
function Facts({
|
|
163
187
|
facts,
|
|
164
188
|
basis,
|
|
189
|
+
stale,
|
|
165
190
|
}: {
|
|
166
191
|
facts: ChartFact | readonly ChartFact[]
|
|
167
192
|
basis?: string | undefined
|
|
193
|
+
stale?: boolean | undefined
|
|
168
194
|
}): ReactElement {
|
|
169
195
|
const list: readonly ChartFact[] = Array.isArray(facts) ? facts : [facts as ChartFact]
|
|
170
196
|
return (
|
|
171
197
|
<div data-basalt-facts="" className={classes.facts}>
|
|
172
|
-
<div
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
198
|
+
<div
|
|
199
|
+
data-basalt-facts-row=""
|
|
200
|
+
{...(stale && { 'data-stale': 'true' })}
|
|
201
|
+
className={classes.factsRow}
|
|
202
|
+
>
|
|
203
|
+
{list.map((f, i) => {
|
|
204
|
+
const period = f.period === undefined ? '' : periodText(f.period, f.unit !== undefined)
|
|
205
|
+
return (
|
|
206
|
+
<span
|
|
207
|
+
key={i}
|
|
208
|
+
data-basalt-fact=""
|
|
209
|
+
{...(f.tone !== undefined && { 'data-tone': f.tone })}
|
|
210
|
+
className={classes.fact}
|
|
211
|
+
>
|
|
212
|
+
<span data-basalt-fact-value="" className={classes.factValue}>
|
|
213
|
+
{f.value}
|
|
214
|
+
</span>
|
|
215
|
+
{f.unit !== undefined && <span className={classes.factUnit}>{f.unit}</span>}
|
|
216
|
+
{f.comparison}
|
|
217
|
+
{period !== '' && <span className={classes.factPeriod}>{period}</span>}
|
|
177
218
|
</span>
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
{f.period !== undefined && <span className={classes.factPeriod}>{f.period}</span>}
|
|
181
|
-
</span>
|
|
182
|
-
))}
|
|
219
|
+
)
|
|
220
|
+
})}
|
|
183
221
|
</div>
|
|
184
222
|
{basis !== undefined && (
|
|
185
223
|
<p data-basalt-facts-basis="" className={classes.factsBasis}>
|
|
@@ -195,6 +233,8 @@ export function ChartCard({
|
|
|
195
233
|
state,
|
|
196
234
|
placeholderHeight,
|
|
197
235
|
stateAction,
|
|
236
|
+
stale,
|
|
237
|
+
stateNoun,
|
|
198
238
|
onRetry,
|
|
199
239
|
retrying,
|
|
200
240
|
className,
|
|
@@ -233,7 +273,7 @@ export function ChartCard({
|
|
|
233
273
|
actions: <span data-basalt-tier="widget">{actions}</span>,
|
|
234
274
|
})}
|
|
235
275
|
/>
|
|
236
|
-
{showFacts && <Facts facts={facts} basis={subtitle} />}
|
|
276
|
+
{showFacts && <Facts facts={facts} basis={subtitle} stale={stale} />}
|
|
237
277
|
</div>
|
|
238
278
|
)}
|
|
239
279
|
<div
|
|
@@ -246,6 +286,7 @@ export function ChartCard({
|
|
|
246
286
|
<ChartPlaceholder
|
|
247
287
|
state={state}
|
|
248
288
|
{...(placeholderHeight !== undefined && { height: placeholderHeight })}
|
|
289
|
+
{...(stateNoun !== undefined && { noun: stateNoun })}
|
|
249
290
|
{...(onRetry !== undefined && { onRetry })}
|
|
250
291
|
{...(retrying !== undefined && { retrying })}
|
|
251
292
|
action={stateAction}
|
package/src/charts/DualPanel.tsx
CHANGED
|
@@ -16,7 +16,7 @@ import { VX, alpha } from '../tokens'
|
|
|
16
16
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
17
17
|
import { defaultNumberFormat, engineRow, seriesRow, visibleSeries } from './compile'
|
|
18
18
|
import { barMark, emphasis, lineMark, markersOf, thinFill } from './marks'
|
|
19
|
-
import { PanelRung,
|
|
19
|
+
import { PanelRung, paneX, paneY, rowsOf } from './panel'
|
|
20
20
|
import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
|
|
21
21
|
import { plotContext } from './plot-context'
|
|
22
22
|
import type { SignedSeries } from './legend'
|
|
@@ -283,15 +283,13 @@ export function DualPanel<T, X extends Date | number = Date | number>(
|
|
|
283
283
|
format: topFormat,
|
|
284
284
|
ticks: TOP_TICKS,
|
|
285
285
|
cls,
|
|
286
|
-
height: chartHeightOf(h, topFraction, PANE_GAP),
|
|
287
286
|
}),
|
|
288
287
|
},
|
|
289
288
|
}
|
|
290
289
|
}
|
|
291
290
|
|
|
292
|
-
const barPane: PaneBuilder = ({ width
|
|
291
|
+
const barPane: PaneBuilder = ({ width }) => {
|
|
293
292
|
const cls = resolveContainerClass(width)
|
|
294
|
-
const whole = chartHeightOf(h, 1 - topFraction, PANE_GAP)
|
|
295
293
|
const barRows = barOn ? rowsOf(data, x, barSeries) : []
|
|
296
294
|
const dim = emphasis(highlighted, { key: BAR_KEY })
|
|
297
295
|
return {
|
|
@@ -306,14 +304,13 @@ export function DualPanel<T, X extends Date | number = Date | number>(
|
|
|
306
304
|
}),
|
|
307
305
|
],
|
|
308
306
|
scales: {
|
|
309
|
-
x: paneX({ scale: xScale(), model, format, cls
|
|
307
|
+
x: paneX({ scale: xScale(), model, format, cls }),
|
|
310
308
|
y: paneY({
|
|
311
309
|
scale: barScale,
|
|
312
310
|
domain: barDomain,
|
|
313
311
|
format: bar.format,
|
|
314
312
|
ticks: BAR_TICKS,
|
|
315
313
|
cls,
|
|
316
|
-
height: whole,
|
|
317
314
|
}),
|
|
318
315
|
},
|
|
319
316
|
}
|
package/src/charts/Heatmap.tsx
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* There is no cursor and no crosshair — the tooltip is per cell, its rows are `tooltip.rows(d)` data.
|
|
9
9
|
*/
|
|
10
10
|
import { colorGradientLegend } from '@tanstack/charts/legend'
|
|
11
|
+
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
11
12
|
import { cell } from '@tanstack/charts/rect'
|
|
13
|
+
import { text } from '@tanstack/charts/text'
|
|
12
14
|
import { scaleBand } from '@tanstack/charts/scales/band'
|
|
13
15
|
import { portal } from '@tanstack/charts/tooltip/portal'
|
|
14
16
|
import type { ChartBuildContext, ChartPoint, StoredChartSpec } from '@tanstack/charts/types/core'
|
|
@@ -20,7 +22,7 @@ import { alpha, VX } from '../tokens'
|
|
|
20
22
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
21
23
|
import { engineRow, strideTicks } from './compile'
|
|
22
24
|
import type { CartesianDefinition } from './compile'
|
|
23
|
-
import { resolveNamedState } from './band-fold'
|
|
25
|
+
import { GLYPH_MIN_PX, glyphOf, resolveNamedState } from './band-fold'
|
|
24
26
|
import type { NamedChartState } from './band-fold'
|
|
25
27
|
import { ABSENT_OPACITY, RAMP_LEVELS, RAMP_OPACITIES } from './heatmap-fill'
|
|
26
28
|
import { engineTooltip } from './cursor'
|
|
@@ -37,11 +39,29 @@ import type { ChartSeries, ChartState, ChartTooltipRow, ResponsiveChartHeight }
|
|
|
37
39
|
* `fillOpacity` (default 1) are its flat fill, `label` its legend entry and tooltip reading, `note`
|
|
38
40
|
* a muted qualifier after the label in the legend, `legend: false` keeps it out of the legend.
|
|
39
41
|
* `tooltip` is omitted: a cell's tooltip always names its state, so there is no row to hide.
|
|
42
|
+
*
|
|
43
|
+
* A categorical STATUS grid (up / degraded / down) names a `tone` instead of a `color`:
|
|
44
|
+
*
|
|
45
|
+
* ```tsx
|
|
46
|
+
* <Heatmap getState={(d) => d.status} getValue={() => null} …
|
|
47
|
+
* states={[{ key: 'up', label: 'Up', tone: 'good' }, { key: 'down', label: 'Down', tone: 'bad' }]} />
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* `warn` and `bad` draw `!` and `×` in the cell; `glyph` overrides them, `glyph: ''` opts out.
|
|
40
51
|
*/
|
|
41
|
-
export type HeatmapState<K extends string = string> = Omit<
|
|
52
|
+
export type HeatmapState<K extends string = string> = Omit<
|
|
53
|
+
NamedChartState,
|
|
54
|
+
'key' | 'tooltip' | 'color'
|
|
55
|
+
> & {
|
|
42
56
|
key: K
|
|
57
|
+
/** The flat fill, a `VX.*` ref. Needed unless `tone` is set; `color` wins over `tone`. */
|
|
58
|
+
color?: string | undefined
|
|
43
59
|
}
|
|
44
60
|
|
|
61
|
+
/** The fill a state resolves to: its `color`, else its tone's status colour, else neutral. */
|
|
62
|
+
const fillOf = (s: HeatmapState | undefined): string =>
|
|
63
|
+
s?.color ?? (s?.tone === undefined ? VX.neutral : VX.status[s.tone])
|
|
64
|
+
|
|
45
65
|
export type HeatmapProps<T, K extends string = string> = BasaltProps & {
|
|
46
66
|
/** The accessible name. Required. */
|
|
47
67
|
ariaLabel: string
|
|
@@ -137,7 +157,7 @@ function valueRows<K extends string>(
|
|
|
137
157
|
formatValue: (v: number) => string,
|
|
138
158
|
pointColor: string | undefined,
|
|
139
159
|
): ChartTooltipRow[] {
|
|
140
|
-
if (named) return [{ label, value: named.label, color: named
|
|
160
|
+
if (named) return [{ label, value: named.label, color: fillOf(named) }]
|
|
141
161
|
if (c.value === null) return [{ label, value: 'No data' }]
|
|
142
162
|
return [{ label, value: formatValue(c.value), ...(pointColor && { color: pointColor }) }]
|
|
143
163
|
}
|
|
@@ -241,6 +261,9 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
241
261
|
? {
|
|
242
262
|
use: engineTooltip,
|
|
243
263
|
portal,
|
|
264
|
+
// Below the hovered cell (flipping above only when there is no room): the default sits
|
|
265
|
+
// above it and covers the caption row over the grid.
|
|
266
|
+
placement: ['bottom', 'top'] as const,
|
|
244
267
|
content: (points: readonly ChartPoint[]) => {
|
|
245
268
|
const point = points[0]
|
|
246
269
|
const c = point?.datum as Cell<T, K> | undefined
|
|
@@ -265,6 +288,31 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
265
288
|
opacity: 1,
|
|
266
289
|
thin: true,
|
|
267
290
|
}
|
|
291
|
+
// A stated cell's glyph, centred in the cell; skipped when the cell is too narrow to hold it.
|
|
292
|
+
const glyphMarks = (plotWidth: number) => {
|
|
293
|
+
const drawn = [...stated].flatMap(([key, group]) => {
|
|
294
|
+
const named = stateByKey.get(key)
|
|
295
|
+
const glyph = named && glyphOf({ ...named, color: fillOf(named) })
|
|
296
|
+
return glyph ? group.map((c) => ({ ...c, glyph })) : []
|
|
297
|
+
})
|
|
298
|
+
return drawn.length > 0 && plotWidth / Math.max(cols.length, 1) >= GLYPH_MIN_PX
|
|
299
|
+
? [
|
|
300
|
+
decorative(
|
|
301
|
+
text(drawn, {
|
|
302
|
+
id: 'state-glyphs',
|
|
303
|
+
x: 'col',
|
|
304
|
+
y: 'row',
|
|
305
|
+
key: 'id',
|
|
306
|
+
text: 'glyph',
|
|
307
|
+
fill: VX.surface.panel,
|
|
308
|
+
fontSize: VX.text.xs,
|
|
309
|
+
fontWeight: 600,
|
|
310
|
+
anchor: 'middle',
|
|
311
|
+
}),
|
|
312
|
+
),
|
|
313
|
+
]
|
|
314
|
+
: []
|
|
315
|
+
}
|
|
268
316
|
const marks = [
|
|
269
317
|
// Inert, not decorative: it must still win the hit test, so a pointer over an empty
|
|
270
318
|
// position lands on THIS cell (whose tooltip is empty) instead of snapping to a neighbour.
|
|
@@ -273,11 +321,12 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
273
321
|
...[...stated].map(([key, group]) => {
|
|
274
322
|
const named = stateByKey.get(key)
|
|
275
323
|
return cellMark(`state:${key}`, group, {
|
|
276
|
-
fill: named
|
|
324
|
+
fill: fillOf(named),
|
|
277
325
|
...(named?.fillOpacity !== undefined && { fillOpacity: named.fillOpacity }),
|
|
278
326
|
})
|
|
279
327
|
}),
|
|
280
328
|
cellMark('cells', present, { color: 'value' }),
|
|
329
|
+
...glyphMarks(width),
|
|
281
330
|
]
|
|
282
331
|
return {
|
|
283
332
|
marks,
|
|
@@ -351,7 +400,7 @@ export function Heatmap<T, K extends string = string>(props: HeatmapProps<T, K>)
|
|
|
351
400
|
: states.map((s) => ({
|
|
352
401
|
key: s.key,
|
|
353
402
|
label: s.label,
|
|
354
|
-
color: s
|
|
403
|
+
color: fillOf(s),
|
|
355
404
|
mark: 'bar' as const,
|
|
356
405
|
...(s.fillOpacity !== undefined && { fillOpacity: s.fillOpacity }),
|
|
357
406
|
...(s.legend !== undefined && { legend: s.legend }),
|
package/src/charts/Lines.tsx
CHANGED
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* `thresholds` (fills between the first series and a value, Date/number x only). Zones, x-zones,
|
|
5
5
|
* reference lines, `y2`, legend, cursor and tooltip are the rung's.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* `naming` is the one switch for who names the series. `auto` (default): from the wide class up, a
|
|
8
|
+
* chart of ≤ 3 lines and no `y2` names them with end labels and its legend goes; below it the
|
|
9
|
+
* legend names them. `legend`: the legend at every width, no end labels. `endLabels`: end labels at
|
|
10
|
+
* every width, no legend (a chart with a `y2` keeps its legend). A label that would not fit between
|
|
11
|
+
* its last point and the plot's right edge ends at the point instead, above it; labels that would
|
|
12
|
+
* collide are spread apart. Before the engine has measured the plot (the server HTML, the first
|
|
13
|
+
* client frame) the room is read off the frame, which is wider by the axis gutters; the measured
|
|
14
|
+
* render corrects it.
|
|
12
15
|
*/
|
|
13
16
|
import { areaY } from '@tanstack/charts/area'
|
|
14
17
|
import { differenceY } from '@tanstack/charts/difference'
|
|
@@ -19,11 +22,13 @@ import { CartesianRung } from './CartesianChart'
|
|
|
19
22
|
import { areaGradientId } from './compile'
|
|
20
23
|
import { chartCurve } from './curves'
|
|
21
24
|
import { endLabelMarks, endLabelPlan } from './labels'
|
|
25
|
+
import type { LinesNaming } from './labels'
|
|
22
26
|
import { drawnRows, lineMark, loneDots, markersOf, yScaleOf } from './marks'
|
|
23
27
|
import { rowX } from './types'
|
|
24
28
|
import type {
|
|
25
29
|
CartesianChartProps,
|
|
26
30
|
ChartMarks,
|
|
31
|
+
ChartSeries,
|
|
27
32
|
ChartX,
|
|
28
33
|
PlotContext,
|
|
29
34
|
PlotRow,
|
|
@@ -36,13 +41,47 @@ export type LinesProps<T, X extends ChartX = ChartX> = Omit<CartesianChartProps<
|
|
|
36
41
|
* x: the engine's `differenceY` takes a Date or number x only.
|
|
37
42
|
*/
|
|
38
43
|
thresholds?: [X] extends [string] ? never : readonly Threshold[]
|
|
44
|
+
/** Who names the series: `'auto'` (default; end labels from the wide class, the legend below it),
|
|
45
|
+
* `'legend'` or `'endLabels'`. */
|
|
46
|
+
naming?: 'auto' | 'legend' | 'endLabels' | undefined
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
const hasValue = <T, X extends ChartX>(r: PlotRow<T, X>): boolean => r.y !== null
|
|
42
50
|
|
|
51
|
+
/** Whether a series' last non-null point exists and sits inside the chart's x domain. */
|
|
52
|
+
function lastIsPlaceable<T, X extends ChartX>(
|
|
53
|
+
props: Pick<LinesProps<T, X>, 'data' | 'x' | 'xDomain'>,
|
|
54
|
+
s: ChartSeries<T>,
|
|
55
|
+
): boolean {
|
|
56
|
+
const last = props.data.findLast((d) => s.getValue(d) !== null)
|
|
57
|
+
if (last === undefined) return false
|
|
58
|
+
const { xDomain } = props
|
|
59
|
+
if (xDomain === undefined) return true
|
|
60
|
+
const at = +props.x(last) // a Date's timestamp, or the number itself
|
|
61
|
+
return Number.isNaN(at) || (at >= +xDomain[0] && at <= +xDomain[1])
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The most lines `auto` names with end labels (and so the most a legend gives way for). */
|
|
65
|
+
const AUTO_END_LABELS = 3
|
|
66
|
+
|
|
43
67
|
export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): ReactElement {
|
|
44
|
-
const { thresholds, ...rest } = props
|
|
68
|
+
const { thresholds, naming = 'auto', ...rest } = props
|
|
45
69
|
const { series } = props
|
|
70
|
+
// Whether end labels can name every legend entry: only then may the legend give way to them.
|
|
71
|
+
const labelled = series.filter((s) => s.role !== 'reference')
|
|
72
|
+
const namedByLabels =
|
|
73
|
+
props.y2 === undefined &&
|
|
74
|
+
series.every((s) => s.legend === false || s.role !== 'reference') &&
|
|
75
|
+
!(props.refLines ?? []).some((r) => r.legend !== undefined)
|
|
76
|
+
// When the legend must name something the labels cannot (a right axis, a named reference line),
|
|
77
|
+
// it stays and the labels are not drawn: one naming, never two.
|
|
78
|
+
const effective: LinesNaming = namedByLabels ? naming : 'legend'
|
|
79
|
+
// The legend gives way only to labels that WILL draw for every line: each labelled series needs a
|
|
80
|
+
// last value the plot can place (a narrower `xDomain` can clip it away).
|
|
81
|
+
const placeable = labelled.every((s) => lastIsPlaceable(props, s))
|
|
82
|
+
const labelsOnly = effective === 'endLabels'
|
|
83
|
+
const hideAtWide =
|
|
84
|
+
effective === 'auto' && placeable && labelled.length > 0 && labelled.length <= AUTO_END_LABELS
|
|
46
85
|
const marks = useCallback(
|
|
47
86
|
(plot: PlotContext<T, X>): ChartMarks => {
|
|
48
87
|
const indexOf = new Map(series.map((s, i) => [s.key, i]))
|
|
@@ -83,7 +122,7 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
|
|
|
83
122
|
y1: () => 0,
|
|
84
123
|
fill: `url(#${areaGradientId(indexOf.get(s.key) ?? 0)})`,
|
|
85
124
|
fillOpacity: 1,
|
|
86
|
-
curve: chartCurve(s.curve ?? '
|
|
125
|
+
curve: chartCurve(s.curve ?? 'linear'),
|
|
87
126
|
...(yScaleOf(plot, s) !== undefined && { yScale: 'y2' }),
|
|
88
127
|
}),
|
|
89
128
|
),
|
|
@@ -96,10 +135,17 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
|
|
|
96
135
|
out.push(...markersOf(s, plot.rows(s.key), yScale))
|
|
97
136
|
}
|
|
98
137
|
const labelled = plotted.filter((s) => s.role !== 'reference')
|
|
99
|
-
out.push(...endLabelMarks(endLabelPlan(plot, labelled)))
|
|
138
|
+
out.push(...endLabelMarks(endLabelPlan(plot, labelled, effective)))
|
|
100
139
|
return out
|
|
101
140
|
},
|
|
102
|
-
[series, thresholds],
|
|
141
|
+
[series, thresholds, effective],
|
|
142
|
+
)
|
|
143
|
+
return (
|
|
144
|
+
<CartesianRung
|
|
145
|
+
{...rest}
|
|
146
|
+
marks={marks}
|
|
147
|
+
{...(labelsOnly && { legend: false as const })}
|
|
148
|
+
{...(hideAtWide && { hideLegendAtWide: true })}
|
|
149
|
+
/>
|
|
103
150
|
)
|
|
104
|
-
return <CartesianRung {...rest} marks={marks} />
|
|
105
151
|
}
|
|
@@ -23,7 +23,7 @@ import { VX, alpha } from '../tokens'
|
|
|
23
23
|
import { resolveContainerClass } from '../tokens/size-classes'
|
|
24
24
|
import { defaultNumberFormat, seriesRow, visibleSeries } from './compile'
|
|
25
25
|
import { barMark, emphasis } from './marks'
|
|
26
|
-
import { PanelRung,
|
|
26
|
+
import { PanelRung, paneX, paneY, rowsOf } from './panel'
|
|
27
27
|
import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
|
|
28
28
|
import { xScaleFor } from './scales'
|
|
29
29
|
import { foldBands, resolveNamedState } from './band-fold'
|
|
@@ -206,9 +206,8 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
206
206
|
on: boolean,
|
|
207
207
|
max: number,
|
|
208
208
|
): PaneBuilder =>
|
|
209
|
-
({ width: w
|
|
209
|
+
({ width: w }) => {
|
|
210
210
|
const cls = resolveContainerClass(w)
|
|
211
|
-
const whole = chartHeightOf(h, side === 'up' ? upFraction : 1 - upFraction, 0)
|
|
212
211
|
// The down pane's zero is at its top.
|
|
213
212
|
const domain: [number, number] = side === 'up' ? [0, max] : [max, 0]
|
|
214
213
|
const rows: PlotRow<T, X>[] = on ? rowsOf(drawn, x, s) : []
|
|
@@ -282,7 +281,7 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
282
281
|
scales: {
|
|
283
282
|
x:
|
|
284
283
|
side === 'down'
|
|
285
|
-
? paneX({ scale: bandScale(), model, format, cls
|
|
284
|
+
? paneX({ scale: bandScale(), model, format, cls })
|
|
286
285
|
: { scale: bandScale(), axis: false },
|
|
287
286
|
y: paneY({
|
|
288
287
|
scale: scaleLinear().domain(domain),
|
|
@@ -290,7 +289,6 @@ export function MirroredBars<T, X extends ChartX = ChartX, K extends string = st
|
|
|
290
289
|
format: cfg.format,
|
|
291
290
|
ticks: cfg.ticks ?? DEFAULT_PANE_TICKS,
|
|
292
291
|
cls,
|
|
293
|
-
height: whole,
|
|
294
292
|
}),
|
|
295
293
|
zx: { channel: 'x', scale: scaleLinear().domain([0, 1]), axis: false },
|
|
296
294
|
},
|