@adecore/charts 0.39.0 → 0.40.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/dist/Heatmap.js +161 -144
- package/dist/Root.js +71 -60
- package/dist/annotations.js +87 -145
- package/dist/cursor.d.ts +1 -0
- package/dist/cursor.js +5 -1
- package/dist/heat.js +2 -2
- package/dist/overlays.js +242 -233
- package/dist/points.js +0 -1
- package/dist/register.js +2 -3
- package/dist/series.js +147 -155
- package/dist/spark.js +1 -4
- package/dist/store.js +40 -70
- package/dist/timeline-layout.js +6 -1
- package/dist/values-table.d.ts +13 -0
- package/dist/values-table.js +13 -0
- package/package.json +9 -9
- package/src/Heatmap.tsx +20 -14
- package/src/Root.tsx +112 -11
- package/src/SeriesLegend.tsx +9 -0
- package/src/Sparkline.tsx +2 -0
- package/src/access.ts +3 -0
- package/src/annotations.tsx +14 -2
- package/src/axes.tsx +37 -2
- package/src/band.ts +25 -0
- package/src/color.ts +1 -0
- package/src/context.ts +2 -0
- package/src/cursor.ts +24 -1
- package/src/group-axes.ts +8 -0
- package/src/heat.ts +8 -2
- package/src/layer.tsx +3 -0
- package/src/legend.ts +2 -0
- package/src/overlays.tsx +43 -16
- package/src/points.ts +19 -2
- package/src/register.ts +3 -3
- package/src/scale.ts +60 -0
- package/src/scatter.tsx +9 -0
- package/src/series.tsx +51 -8
- package/src/spark.ts +4 -4
- package/src/store.ts +46 -70
- package/src/time-format.ts +1 -0
- package/src/timeline-layout.ts +27 -1
- package/src/timeline.tsx +28 -0
- package/src/use-chart.ts +1 -0
- package/src/values-table.ts +12 -0
package/src/timeline.tsx
CHANGED
|
@@ -103,9 +103,11 @@ const TimelineContext = createContext<TimelineContextValue | null>(null);
|
|
|
103
103
|
|
|
104
104
|
const useTimeline = (part: string): TimelineContextValue => {
|
|
105
105
|
const context = useContext(TimelineContext);
|
|
106
|
+
|
|
106
107
|
if (context === null) {
|
|
107
108
|
throw new Error(`${part} draws inside a Timeline.Root.`);
|
|
108
109
|
}
|
|
110
|
+
|
|
109
111
|
return context;
|
|
110
112
|
};
|
|
111
113
|
|
|
@@ -134,10 +136,12 @@ export function TimelineRoot<Span extends TimelineSpan>({
|
|
|
134
136
|
}: TimelineRootProps<Span>) {
|
|
135
137
|
const rows = timelineTree(data);
|
|
136
138
|
const parents = parentIds(rows);
|
|
139
|
+
|
|
137
140
|
// Uncontrolled, the root keeps what was folded rather than what is open, so a span that arrives later opens.
|
|
138
141
|
const [folded, setFolded] = useState<ReadonlySet<string>>(() =>
|
|
139
142
|
defaultExpanded === undefined ? new Set() : new Set(parents.filter((id) => !defaultExpanded.includes(id)))
|
|
140
143
|
);
|
|
144
|
+
|
|
141
145
|
const [ownValue, setOwnValue] = useState<string | null>(defaultValue);
|
|
142
146
|
const expanded = new Set(expandedProp ?? parents.filter((id) => !folded.has(id)));
|
|
143
147
|
const value = valueProp === undefined ? ownValue : valueProp;
|
|
@@ -146,9 +150,11 @@ export function TimelineRoot<Span extends TimelineSpan>({
|
|
|
146
150
|
|
|
147
151
|
const colorOfKind = (kind: string | undefined): string => {
|
|
148
152
|
const index = kind === undefined ? undefined : kindIndex.get(kind);
|
|
153
|
+
|
|
149
154
|
if (index === undefined) {
|
|
150
155
|
return colorOf('accent')!;
|
|
151
156
|
}
|
|
157
|
+
|
|
152
158
|
return colorOf(kinds[index]!.tone) ?? seriesColor(index);
|
|
153
159
|
};
|
|
154
160
|
|
|
@@ -156,22 +162,27 @@ export function TimelineRoot<Span extends TimelineSpan>({
|
|
|
156
162
|
if (expandedProp === undefined) {
|
|
157
163
|
setFolded((current) => {
|
|
158
164
|
const next = new Set(current);
|
|
165
|
+
|
|
159
166
|
if (open) {
|
|
160
167
|
next.delete(id);
|
|
161
168
|
} else {
|
|
162
169
|
next.add(id);
|
|
163
170
|
}
|
|
171
|
+
|
|
164
172
|
return next;
|
|
165
173
|
});
|
|
166
174
|
}
|
|
175
|
+
|
|
167
176
|
onExpandedChange?.(open ? [...expanded, id] : [...expanded].filter((entry) => entry !== id));
|
|
168
177
|
};
|
|
169
178
|
|
|
170
179
|
const select = (id: string): void => {
|
|
171
180
|
const next = value === id ? null : id;
|
|
181
|
+
|
|
172
182
|
if (valueProp === undefined) {
|
|
173
183
|
setOwnValue(next);
|
|
174
184
|
}
|
|
185
|
+
|
|
175
186
|
onValueChange?.(next);
|
|
176
187
|
};
|
|
177
188
|
|
|
@@ -204,9 +215,11 @@ export function TimelineLegend({ className, ref }: TimelineLegendProps) {
|
|
|
204
215
|
const timeline = useTimeline('Timeline.Legend');
|
|
205
216
|
const times = kindTimes(timeline.rows);
|
|
206
217
|
const shown = timeline.kinds.filter((kind) => (times.get(kind.id) ?? 0) > 0);
|
|
218
|
+
|
|
207
219
|
if (shown.length === 0) {
|
|
208
220
|
return null;
|
|
209
221
|
}
|
|
222
|
+
|
|
210
223
|
return (
|
|
211
224
|
<div ref={ref} className={clsx('flex flex-wrap gap-x-4 gap-y-1 border-b border-border-soft px-4 py-2.5 text-xs text-text-muted', className)}>
|
|
212
225
|
{shown.map((kind) => (
|
|
@@ -224,12 +237,14 @@ export function TimelineLegend({ className, ref }: TimelineLegendProps) {
|
|
|
224
237
|
export function TimelineAxis({ heading, children, className, ref }: TimelineAxisProps) {
|
|
225
238
|
const timeline = useTimeline('Timeline.Axis');
|
|
226
239
|
const { origin, total, ticks } = timeline;
|
|
240
|
+
|
|
227
241
|
return (
|
|
228
242
|
<div ref={ref} className={clsx(COLUMNS, className)}>
|
|
229
243
|
<div className="hidden border-b border-border-soft px-4 py-2 text-xs text-text-muted @xl:block">{heading}</div>
|
|
230
244
|
<div className="relative mx-4 h-8 border-b border-border-soft @xl:ml-0">
|
|
231
245
|
{ticks.map((tick, index) => {
|
|
232
246
|
const left = percentOf(origin + tick, origin, total);
|
|
247
|
+
|
|
233
248
|
// The first label starts at its tick and one near the end ends at it, so neither hangs past the axis.
|
|
234
249
|
return (
|
|
235
250
|
<span
|
|
@@ -256,6 +271,7 @@ export function TimelineMoment({ at, label, tone = 'error' }: TimelineMomentProp
|
|
|
256
271
|
const timeline = useTimeline('Timeline.Moment');
|
|
257
272
|
const { t } = useTranslation('charts');
|
|
258
273
|
const text = t('timeline.moment', { label, offset: timeline.format(Math.max(0, at - timeline.origin)) });
|
|
274
|
+
|
|
259
275
|
return (
|
|
260
276
|
<Tooltip label={text} name>
|
|
261
277
|
<span
|
|
@@ -279,21 +295,26 @@ export function TimelineRows<Span extends TimelineSpan>({ label, detail, classNa
|
|
|
279
295
|
|
|
280
296
|
// The row that takes the tab stop: the one last focused, or the open row that hides it, else the selected or the first.
|
|
281
297
|
const indexOf = (target: string | null): number => shown.findIndex((row) => row.span.id === target);
|
|
298
|
+
|
|
282
299
|
let current = indexOf(focusId);
|
|
300
|
+
|
|
283
301
|
if (current < 0 && focusId !== null) {
|
|
284
302
|
const hidden = rows.find((row) => row.span.id === focusId);
|
|
285
303
|
const ancestor = hidden?.ancestors.find((ancestorId) => !expanded.has(ancestorId));
|
|
286
304
|
current = indexOf(ancestor ?? null);
|
|
287
305
|
}
|
|
306
|
+
|
|
288
307
|
if (current < 0) {
|
|
289
308
|
current = Math.max(0, indexOf(timeline.value));
|
|
290
309
|
}
|
|
291
310
|
|
|
292
311
|
const focusRow = (box: HTMLElement, index: number): void => {
|
|
293
312
|
const target = shown[index];
|
|
313
|
+
|
|
294
314
|
if (target === undefined) {
|
|
295
315
|
return;
|
|
296
316
|
}
|
|
317
|
+
|
|
297
318
|
setFocusId(target.span.id);
|
|
298
319
|
const node = [...box.querySelectorAll<HTMLElement>('[role="treeitem"]')].find((item) => item.dataset.span === target.span.id);
|
|
299
320
|
node?.focus();
|
|
@@ -304,11 +325,15 @@ export function TimelineRows<Span extends TimelineSpan>({ label, detail, classNa
|
|
|
304
325
|
if ((e.target as HTMLElement).getAttribute('role') !== 'treeitem') {
|
|
305
326
|
return;
|
|
306
327
|
}
|
|
328
|
+
|
|
307
329
|
const move = timelineMove(e.key, shown, current, expanded);
|
|
330
|
+
|
|
308
331
|
if (move === undefined) {
|
|
309
332
|
return;
|
|
310
333
|
}
|
|
334
|
+
|
|
311
335
|
e.preventDefault();
|
|
336
|
+
|
|
312
337
|
if ('focus' in move) {
|
|
313
338
|
focusRow(e.currentTarget, move.focus);
|
|
314
339
|
} else if ('expand' in move) {
|
|
@@ -345,6 +370,7 @@ export function TimelineRows<Span extends TimelineSpan>({ label, detail, classNa
|
|
|
345
370
|
const color = colorOf(span.tone) ?? timeline.colorOfKind(span.kind);
|
|
346
371
|
const bar = barOf(span, origin, total);
|
|
347
372
|
const kind = timeline.kinds.find((entry) => entry.id === span.kind);
|
|
373
|
+
|
|
348
374
|
const name = [
|
|
349
375
|
span.label,
|
|
350
376
|
kind?.label,
|
|
@@ -353,8 +379,10 @@ export function TimelineRows<Span extends TimelineSpan>({ label, detail, classNa
|
|
|
353
379
|
]
|
|
354
380
|
.filter(Boolean)
|
|
355
381
|
.join(', ');
|
|
382
|
+
|
|
356
383
|
const detailId = `${id}-${index}-detail`;
|
|
357
384
|
const shownDetail = selected && detail !== undefined;
|
|
385
|
+
|
|
358
386
|
return (
|
|
359
387
|
<div
|
|
360
388
|
key={span.id}
|
package/src/use-chart.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface ChartApi<Row> {
|
|
|
22
22
|
export function useChart<Row = unknown>(): ChartApi<Row> {
|
|
23
23
|
const chart = useChartContext('useChart');
|
|
24
24
|
const active = chart.activeIndex >= 0 ? chart.activeIndex : null;
|
|
25
|
+
|
|
25
26
|
return {
|
|
26
27
|
plot: chart.plot,
|
|
27
28
|
data: chart.data as Row[],
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* A table of values as it is shown; hidden, it stays for a screen reader without any of these. */
|
|
2
|
+
const TABLE_CLASSES = {
|
|
3
|
+
box: 'max-h-80 w-full overflow-auto rounded-md border border-border-soft',
|
|
4
|
+
table: 'w-full border-collapse text-xs tabular-nums',
|
|
5
|
+
head: 'sticky top-0 bg-surface-hover',
|
|
6
|
+
column: 'h-8 px-2 text-right font-medium whitespace-nowrap text-text-muted',
|
|
7
|
+
row: 'border-t border-border-soft',
|
|
8
|
+
rowHeading: 'h-8 px-2 text-left font-normal whitespace-nowrap text-text-muted',
|
|
9
|
+
cell: 'h-8 px-2 text-right whitespace-nowrap text-text'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const tableClasses = (shown: boolean): Partial<typeof TABLE_CLASSES> & { box: string } => (shown ? TABLE_CLASSES : { box: 'sr-only' });
|