@tangle-network/ui 11.41.0 → 11.43.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.
@@ -0,0 +1,155 @@
1
+ import { cn } from "../lib/utils.js";
2
+ import { chartPresentation } from "../presentation.js";
3
+ import { normalizeSeries, seriesAreaPath, seriesExtent, seriesLinePath, seriesMean, seriesScale } from "../lib/series.js";
4
+ import * as React from "react";
5
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/primitives/metric-chart.tsx
7
+ const defaultTimeLabel = (at) => new Date(at).toLocaleDateString(void 0, {
8
+ month: "short",
9
+ day: "numeric"
10
+ });
11
+ const defaultValueLabel = (decimals) => (value) => value.toLocaleString(void 0, decimals === void 0 ? { maximumFractionDigits: 2 } : {
12
+ minimumFractionDigits: decimals,
13
+ maximumFractionDigits: decimals
14
+ });
15
+ /**
16
+ * A labelled line chart: y gridlines, x date ticks, optional dashed
17
+ * reference lines and a dotted secondary series for dual readings
18
+ * (`value2`). Hand-rolled SVG, viewBox-scaled, currentColor throughout.
19
+ */
20
+ const MetricChart = React.forwardRef(({ points, title, unit, decimals, referenceLines, description, formatValue, formatTime, className, ...props }, ref) => {
21
+ const series = normalizeSeries(points);
22
+ const width = 680;
23
+ const height = 260;
24
+ const padX = 46;
25
+ const padY = 16;
26
+ const dual = series.some((point) => point.value2 !== void 0);
27
+ const lines = (referenceLines ?? []).filter((line) => line.series !== "secondary" || dual);
28
+ const extent = seriesExtent(series, { include: lines.map((line) => line.value) });
29
+ const plot = seriesScale(extent, 626, height, padY);
30
+ const xAt = (at) => padX + plot.x(at);
31
+ const yAt = plot.y;
32
+ const { lo, hi, tLo, tHi } = extent;
33
+ const primary = series.map((point) => ({
34
+ x: xAt(point.at),
35
+ y: yAt(point.value)
36
+ }));
37
+ const secondary = series.filter((point) => point.value2 !== void 0).map((point) => ({
38
+ x: xAt(point.at),
39
+ y: yAt(point.value2)
40
+ }));
41
+ const ticks = Array.from({ length: 4 }, (_, index) => lo + (hi - lo) * (index + 1) / 5);
42
+ const xTicks = [
43
+ tLo,
44
+ tLo + (tHi - tLo) / 2,
45
+ tHi
46
+ ];
47
+ const lastPrimary = primary[primary.length - 1];
48
+ const valueLabel = formatValue ?? defaultValueLabel(decimals);
49
+ const timeLabel = formatTime ?? defaultTimeLabel;
50
+ const values = series.map((point) => point.value);
51
+ const describe = description ?? `${title}: ${series.length} readings from ${timeLabel(tLo)} to ${timeLabel(tHi)}, min ${valueLabel(series.length > 0 ? Math.min(...values) : 0)}, max ${valueLabel(series.length > 0 ? Math.max(...values) : 0)}, average ${valueLabel(seriesMean(values) ?? 0)}${unit ? ` ${unit}` : ""}.`;
52
+ return /* @__PURE__ */ jsxs("svg", {
53
+ ref,
54
+ viewBox: `0 0 ${width} ${height}`,
55
+ role: "img",
56
+ "aria-label": title,
57
+ className: cn(chartPresentation.root, className),
58
+ ...props,
59
+ children: [
60
+ /* @__PURE__ */ jsx("title", { children: title }),
61
+ /* @__PURE__ */ jsx("desc", { children: describe }),
62
+ series.length > 0 && /* @__PURE__ */ jsxs(Fragment$1, { children: [
63
+ ticks.map((tick) => /* @__PURE__ */ jsxs("g", {
64
+ className: chartPresentation.axis,
65
+ children: [/* @__PURE__ */ jsx("line", {
66
+ x1: padX,
67
+ x2: 672,
68
+ y1: yAt(tick),
69
+ y2: yAt(tick),
70
+ stroke: "currentColor",
71
+ strokeWidth: "1",
72
+ className: chartPresentation.gridLine
73
+ }), /* @__PURE__ */ jsx("text", {
74
+ x: 38,
75
+ y: yAt(tick) + 4,
76
+ textAnchor: "end",
77
+ fontSize: "11",
78
+ fill: "currentColor",
79
+ children: valueLabel(tick)
80
+ })]
81
+ }, tick)),
82
+ xTicks.map((tick, index) => /* @__PURE__ */ jsx("text", {
83
+ className: chartPresentation.axis,
84
+ fontSize: "11",
85
+ fill: "currentColor",
86
+ x: xAt(tick),
87
+ y: 256,
88
+ textAnchor: index === 0 ? "start" : index === xTicks.length - 1 ? "end" : "middle",
89
+ children: timeLabel(tick)
90
+ }, tick)),
91
+ lines.map((line, index) => /* @__PURE__ */ jsxs("g", {
92
+ className: chartPresentation.axis,
93
+ children: [/* @__PURE__ */ jsx("line", {
94
+ x1: padX,
95
+ x2: 672,
96
+ y1: yAt(line.value),
97
+ y2: yAt(line.value),
98
+ stroke: "currentColor",
99
+ strokeWidth: "1.25",
100
+ strokeDasharray: "5 4",
101
+ className: chartPresentation.referenceLine
102
+ }), line.label && /* @__PURE__ */ jsx("text", {
103
+ x: 668,
104
+ y: yAt(line.value) - 5,
105
+ textAnchor: "end",
106
+ fontSize: "11",
107
+ fill: "currentColor",
108
+ children: line.label
109
+ })]
110
+ }, line.label ?? index)),
111
+ primary.length > 1 && /* @__PURE__ */ jsx("path", {
112
+ d: seriesAreaPath(primary, yAt(lo)),
113
+ fill: "currentColor",
114
+ stroke: "none",
115
+ className: cn(chartPresentation.primarySeries, chartPresentation.area)
116
+ }),
117
+ /* @__PURE__ */ jsx("path", {
118
+ d: seriesLinePath(primary),
119
+ fill: "none",
120
+ stroke: "currentColor",
121
+ strokeWidth: "2",
122
+ strokeLinejoin: "round",
123
+ strokeLinecap: "round",
124
+ className: chartPresentation.primarySeries
125
+ }),
126
+ secondary.length > 0 && /* @__PURE__ */ jsx("path", {
127
+ d: seriesLinePath(secondary),
128
+ fill: "none",
129
+ stroke: "currentColor",
130
+ strokeWidth: "2",
131
+ strokeLinejoin: "round",
132
+ strokeLinecap: "round",
133
+ strokeDasharray: "2 5",
134
+ className: chartPresentation.secondarySeries
135
+ }),
136
+ primary.length === 1 ? /* @__PURE__ */ jsx("circle", {
137
+ cx: primary[0].x,
138
+ cy: primary[0].y,
139
+ r: "4",
140
+ fill: "currentColor",
141
+ className: chartPresentation.primarySeries
142
+ }) : lastPrimary && /* @__PURE__ */ jsx("circle", {
143
+ cx: lastPrimary.x,
144
+ cy: lastPrimary.y,
145
+ r: "3.5",
146
+ fill: "currentColor",
147
+ className: chartPresentation.primarySeries
148
+ })
149
+ ] })
150
+ ]
151
+ });
152
+ });
153
+ MetricChart.displayName = "MetricChart";
154
+ //#endregion
155
+ export { MetricChart };
@@ -0,0 +1,16 @@
1
+ import { SeriesPointInput } from "../lib/series.js";
2
+ import * as React from "react";
3
+ //#region src/primitives/series-sparkline.d.ts
4
+ export type SeriesSparklineProps = Omit<React.SVGAttributes<SVGSVGElement>, "points"> & {
5
+ points: SeriesPointInput[];
6
+ /** Accessible name; also rendered as the svg title. */
7
+ label: string;
8
+ };
9
+ /** Inline trend glyph: viewBox-scaled, currentColor against `text-primary`. */
10
+ declare const SeriesSparkline: React.ForwardRefExoticComponent<Omit<React.SVGAttributes<SVGSVGElement>, "points"> & {
11
+ points: SeriesPointInput[];
12
+ /** Accessible name; also rendered as the svg title. */
13
+ label: string;
14
+ } & React.RefAttributes<SVGSVGElement>>;
15
+ //#endregion
16
+ export { SeriesSparkline };
@@ -0,0 +1,53 @@
1
+ import { cn } from "../lib/utils.js";
2
+ import { chartPresentation } from "../presentation.js";
3
+ import { normalizeSeries, seriesAreaPath, seriesExtent, seriesLinePath, seriesScale } from "../lib/series.js";
4
+ import * as React from "react";
5
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/primitives/series-sparkline.tsx
7
+ /** Inline trend glyph: viewBox-scaled, currentColor against `text-primary`. */
8
+ const SeriesSparkline = React.forwardRef(({ points, label, className, ...props }, ref) => {
9
+ const series = normalizeSeries(points);
10
+ const width = 120;
11
+ const height = 36;
12
+ const scale = seriesScale(seriesExtent(series), width, height, 3);
13
+ const placed = series.map((point) => ({
14
+ x: scale.x(point.at),
15
+ y: scale.y(point.value)
16
+ }));
17
+ const last = placed[placed.length - 1];
18
+ return /* @__PURE__ */ jsxs("svg", {
19
+ ref,
20
+ viewBox: `0 0 ${width} ${height}`,
21
+ preserveAspectRatio: "none",
22
+ role: "img",
23
+ "aria-label": label,
24
+ className: cn(chartPresentation.sparkline, className),
25
+ ...props,
26
+ children: [
27
+ /* @__PURE__ */ jsx("title", { children: label }),
28
+ placed.length > 1 && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("path", {
29
+ d: seriesAreaPath(placed, 33),
30
+ fill: "currentColor",
31
+ className: chartPresentation.area,
32
+ stroke: "none"
33
+ }), /* @__PURE__ */ jsx("path", {
34
+ d: seriesLinePath(placed),
35
+ fill: "none",
36
+ stroke: "currentColor",
37
+ strokeWidth: "1.5",
38
+ strokeLinejoin: "round",
39
+ strokeLinecap: "round",
40
+ vectorEffect: "non-scaling-stroke"
41
+ })] }),
42
+ last && /* @__PURE__ */ jsx("circle", {
43
+ cx: last.x,
44
+ cy: last.y,
45
+ r: "2",
46
+ fill: "currentColor"
47
+ })
48
+ ]
49
+ });
50
+ });
51
+ SeriesSparkline.displayName = "SeriesSparkline";
52
+ //#endregion
53
+ export { SeriesSparkline };
@@ -50,12 +50,16 @@ import { PageHeader, PageHeaderProps } from "./primitives/page-header.js";
50
50
  import { Alert, AlertDescription, AlertProps, AlertTitle, AlertTone } from "./primitives/alert.js";
51
51
  import { Pagination, PaginationProps } from "./primitives/pagination.js";
52
52
  import { StatusPill, StatusPillProps, StatusTone } from "./primitives/status-pill.js";
53
+ import { ComplianceBadge, ComplianceBadgeProps, ComplianceProduct, ComplianceStatus } from "./primitives/compliance-badge.js";
53
54
  import { Tag, TagProps } from "./primitives/tag.js";
54
55
  import { Chip, ChipProps } from "./primitives/chip.js";
55
56
  import { Wizard, WizardProps, WizardStep, WizardStepProps } from "./primitives/wizard.js";
56
57
  import { HoverCard, HoverCardContent, HoverCardDescription, HoverCardHeader, HoverCardTitle, HoverCardTrigger } from "./primitives/hover-card.js";
57
58
  import { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "./primitives/breadcrumb.js";
58
59
  import { Metric, MetricProps, MetricStrip, MetricStripProps } from "./primitives/metric-strip.js";
60
+ import { PeriodDelta, SeriesExtent, SeriesPoint, SeriesPointInput, SeriesScale, normalizeSeries, periodDelta, seriesAreaPath, seriesExtent, seriesLinePath, seriesMean, seriesScale } from "./lib/series.js";
61
+ import { SeriesSparkline, SeriesSparklineProps } from "./primitives/series-sparkline.js";
62
+ import { ChartReferenceLine, MetricChart, MetricChartProps } from "./primitives/metric-chart.js";
59
63
  import { FilterField, FilterFieldProps, Toolbar, ToolbarProps } from "./primitives/toolbar.js";
60
64
  import { Logo, LogoProps, TangleKnot } from "@tangle-network/brand";
61
- export { Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, type AlertProps, AlertTitle, type AlertTone, ArtifactPane, type ArtifactPaneProps, Avatar, AvatarFallback, AvatarImage, type AvatarProps, Badge, type BadgeProps, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, type ButtonProps, CATEGORY_TONES, Calendar, type CalendarDate, type CalendarProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type CardTitleProps, type CategoryTone, Checkbox, Chip, type ChipProps, CodeBlock, type CodeBlockProps, Collapsible, CollapsibleContent, CollapsibleTrigger, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CopyButton, DatePicker, type DatePickerProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropZone, type DropZoneProps, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmptyState, type EmptyStateProps, Field, type FieldProps, FilterField, type FilterFieldProps, Heading, type HeadingProps, type HeadingVariant, HelpText, type HelpTextProps, HoverCard, HoverCardContent, HoverCardDescription, HoverCardHeader, HoverCardTitle, HoverCardTrigger, IconTile, type IconTileProps, InlineCode, type InlineCodeProps, Input, type InputProps, Label, Logo, type LogoProps, Metric, type MetricProps, MetricStrip, type MetricStripProps, PageHeader, type PageHeaderProps, PageShell, type PageShellProps, Pagination, type PaginationProps, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, SegmentedControl, type SegmentedControlOption, type SegmentedControlProps, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SettingsList, type SettingsListAction, type SettingsListColumns, SettingsListItem, type SettingsListItemProps, type SettingsListMenuItem, type SettingsListProps, SettingsRow, type SettingsRowLayout, type SettingsRowProps, SettingsSection, type SettingsSectionProps, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, SidebarDropZone, type SidebarDropZoneProps, Skeleton, SkeletonCard, SkeletonTable, Slider, StatCard, type StatCardProps, StatusPill, type StatusPillProps, type StatusTone, Switch, TONE_CLASSES, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, type TableProps, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Tag, type TagProps, TangleKnot, TerminalCursor, TerminalDisplay, TerminalInput, TerminalLine, TextShimmer, type TextShimmerProps, Textarea, type TextareaProps, ThemeToggle, TimeSelect, type TimeSelectProps, type Toast, ToastContainer, ToastProvider, type Tone, type ToneClasses, Toolbar, type ToolbarProps, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UploadFile, UploadProgress, type UploadProgressProps, Wizard, type WizardProps, WizardStep, type WizardStepProps, badgeVariants, buttonVariants, fieldMessageId, formatCalendarDate, initialsOf, localToday, parseCalendarDate, toneFor, useTheme, useToast };
65
+ export { Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, type AlertProps, AlertTitle, type AlertTone, ArtifactPane, type ArtifactPaneProps, Avatar, AvatarFallback, AvatarImage, type AvatarProps, Badge, type BadgeProps, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, type ButtonProps, CATEGORY_TONES, Calendar, type CalendarDate, type CalendarProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type CardTitleProps, type CategoryTone, type ChartReferenceLine, Checkbox, Chip, type ChipProps, CodeBlock, type CodeBlockProps, Collapsible, CollapsibleContent, CollapsibleTrigger, ComplianceBadge, type ComplianceBadgeProps, type ComplianceProduct, type ComplianceStatus, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CopyButton, DatePicker, type DatePickerProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropZone, type DropZoneProps, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmptyState, type EmptyStateProps, Field, type FieldProps, FilterField, type FilterFieldProps, Heading, type HeadingProps, type HeadingVariant, HelpText, type HelpTextProps, HoverCard, HoverCardContent, HoverCardDescription, HoverCardHeader, HoverCardTitle, HoverCardTrigger, IconTile, type IconTileProps, InlineCode, type InlineCodeProps, Input, type InputProps, Label, Logo, type LogoProps, Metric, MetricChart, type MetricChartProps, type MetricProps, MetricStrip, type MetricStripProps, PageHeader, type PageHeaderProps, PageShell, type PageShellProps, Pagination, type PaginationProps, type PeriodDelta, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, SegmentedControl, type SegmentedControlOption, type SegmentedControlProps, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, type SeriesExtent, type SeriesPoint, type SeriesPointInput, type SeriesScale, SeriesSparkline, type SeriesSparklineProps, SettingsList, type SettingsListAction, type SettingsListColumns, SettingsListItem, type SettingsListItemProps, type SettingsListMenuItem, type SettingsListProps, SettingsRow, type SettingsRowLayout, type SettingsRowProps, SettingsSection, type SettingsSectionProps, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, SidebarDropZone, type SidebarDropZoneProps, Skeleton, SkeletonCard, SkeletonTable, Slider, StatCard, type StatCardProps, StatusPill, type StatusPillProps, type StatusTone, Switch, TONE_CLASSES, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, type TableProps, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Tag, type TagProps, TangleKnot, TerminalCursor, TerminalDisplay, TerminalInput, TerminalLine, TextShimmer, type TextShimmerProps, Textarea, type TextareaProps, ThemeToggle, TimeSelect, type TimeSelectProps, type Toast, ToastContainer, ToastProvider, type Tone, type ToneClasses, Toolbar, type ToolbarProps, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UploadFile, UploadProgress, type UploadProgressProps, Wizard, type WizardProps, WizardStep, type WizardStepProps, badgeVariants, buttonVariants, fieldMessageId, formatCalendarDate, initialsOf, localToday, normalizeSeries, parseCalendarDate, periodDelta, seriesAreaPath, seriesExtent, seriesLinePath, seriesMean, seriesScale, toneFor, useTheme, useToast };
@@ -48,6 +48,7 @@ import { PageHeader } from "./primitives/page-header.js";
48
48
  import { Alert, AlertDescription, AlertTitle } from "./primitives/alert.js";
49
49
  import { Pagination } from "./primitives/pagination.js";
50
50
  import { StatusPill } from "./primitives/status-pill.js";
51
+ import { ComplianceBadge } from "./primitives/compliance-badge.js";
51
52
  import { CATEGORY_TONES, TONE_CLASSES, toneFor } from "./primitives/tone.js";
52
53
  import { Tag } from "./primitives/tag.js";
53
54
  import { Chip } from "./primitives/chip.js";
@@ -56,6 +57,9 @@ import { HoverCard, HoverCardContent, HoverCardDescription, HoverCardHeader, Hov
56
57
  import { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "./primitives/breadcrumb.js";
57
58
  import { IconTile, initialsOf } from "./primitives/icon-tile.js";
58
59
  import { Metric, MetricStrip } from "./primitives/metric-strip.js";
60
+ import { normalizeSeries, periodDelta, seriesAreaPath, seriesExtent, seriesLinePath, seriesMean, seriesScale } from "./lib/series.js";
61
+ import { SeriesSparkline } from "./primitives/series-sparkline.js";
62
+ import { MetricChart } from "./primitives/metric-chart.js";
59
63
  import { FilterField, Toolbar } from "./primitives/toolbar.js";
60
64
  import { Logo, TangleKnot } from "@tangle-network/brand";
61
- export { Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, ArtifactPane, Avatar, AvatarFallback, AvatarImage, Badge, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, CATEGORY_TONES, Calendar, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Chip, CodeBlock, Collapsible, CollapsibleContent, CollapsibleTrigger, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CopyButton, DatePicker, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropZone, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmptyState, Field, FilterField, Heading, HelpText, HoverCard, HoverCardContent, HoverCardDescription, HoverCardHeader, HoverCardTitle, HoverCardTrigger, IconTile, InlineCode, Input, Label, Logo, Metric, MetricStrip, PageHeader, PageShell, Pagination, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, SegmentedControl, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SettingsList, SettingsListItem, SettingsRow, SettingsSection, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, SidebarDropZone, Skeleton, SkeletonCard, SkeletonTable, Slider, StatCard, StatusPill, Switch, TONE_CLASSES, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Tag, TangleKnot, TerminalCursor, TerminalDisplay, TerminalInput, TerminalLine, TextShimmer, Textarea, ThemeToggle, TimeSelect, ToastContainer, ToastProvider, Toolbar, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, UploadProgress, Wizard, WizardStep, badgeVariants, buttonVariants, fieldMessageId, formatCalendarDate, initialsOf, localToday, parseCalendarDate, toneFor, useTheme, useToast };
65
+ export { Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, ArtifactPane, Avatar, AvatarFallback, AvatarImage, Badge, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, CATEGORY_TONES, Calendar, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Chip, CodeBlock, Collapsible, CollapsibleContent, CollapsibleTrigger, ComplianceBadge, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CopyButton, DatePicker, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropZone, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmptyState, Field, FilterField, Heading, HelpText, HoverCard, HoverCardContent, HoverCardDescription, HoverCardHeader, HoverCardTitle, HoverCardTrigger, IconTile, InlineCode, Input, Label, Logo, Metric, MetricChart, MetricStrip, PageHeader, PageShell, Pagination, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, SegmentedControl, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SeriesSparkline, SettingsList, SettingsListItem, SettingsRow, SettingsSection, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, SidebarDropZone, Skeleton, SkeletonCard, SkeletonTable, Slider, StatCard, StatusPill, Switch, TONE_CLASSES, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Tag, TangleKnot, TerminalCursor, TerminalDisplay, TerminalInput, TerminalLine, TextShimmer, Textarea, ThemeToggle, TimeSelect, ToastContainer, ToastProvider, Toolbar, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, UploadProgress, Wizard, WizardStep, badgeVariants, buttonVariants, fieldMessageId, formatCalendarDate, initialsOf, localToday, normalizeSeries, parseCalendarDate, periodDelta, seriesAreaPath, seriesExtent, seriesLinePath, seriesMean, seriesScale, toneFor, useTheme, useToast };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/ui",
3
- "version": "11.41.0",
3
+ "version": "11.43.0",
4
4
  "description": "Generic React UI components for Tangle products — primitives, chat, run, files, editor, markdown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -166,7 +166,7 @@
166
166
  "peerDependencies": {
167
167
  "@hocuspocus/provider": ">=2.15.0 <5.0.0",
168
168
  "@nanostores/react": ">=0.8.4 <3.0.0",
169
- "@tangle-network/brand": "^1.26.2",
169
+ "@tangle-network/brand": "^1.27.0",
170
170
  "@tiptap/core": ">=3.20.4 <4.0.0",
171
171
  "@tiptap/extension-collaboration": ">=3.20.4 <4.0.0",
172
172
  "@tiptap/extension-collaboration-caret": ">=3.7.0 <4.0.0",
@@ -0,0 +1,172 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ normalizeSeries,
4
+ periodDelta,
5
+ seriesAreaPath,
6
+ seriesExtent,
7
+ seriesLinePath,
8
+ seriesMean,
9
+ seriesScale,
10
+ type SeriesPoint,
11
+ } from "./series";
12
+
13
+ const DAY = 86_400_000;
14
+
15
+ describe("normalizeSeries", () => {
16
+ it("parses epoch, ISO and Date times, drops non-finite readings and sorts", () => {
17
+ const points = normalizeSeries([
18
+ { at: "2026-10-21T07:00:00.000Z", value: 63 },
19
+ { at: 1_000, value: 61 },
20
+ { at: new Date("2026-10-20T07:00:00.000Z"), value: 62, value2: 40 },
21
+ { at: "not a date", value: 99 },
22
+ { at: 2_000, value: Number.NaN },
23
+ { at: 3_000, value: 65, value2: Number.POSITIVE_INFINITY },
24
+ ]);
25
+ expect(points.map((point) => point.value)).toEqual([61, 65, 62, 63]);
26
+ expect(points[0]!.at).toBe(1_000);
27
+ // A non-finite second reading drops value2, not the point.
28
+ expect(points[1]!.value2).toBeUndefined();
29
+ expect(points[2]!.value2).toBe(40);
30
+ for (let i = 1; i < points.length; i += 1) {
31
+ expect(points[i]!.at).toBeGreaterThanOrEqual(points[i - 1]!.at);
32
+ }
33
+ });
34
+
35
+ it("returns an empty series for empty input", () => {
36
+ expect(normalizeSeries([])).toEqual([]);
37
+ });
38
+ });
39
+
40
+ describe("seriesExtent", () => {
41
+ const points: SeriesPoint[] = [
42
+ { at: 10 * DAY, value: 60 },
43
+ { at: 20 * DAY, value: 80 },
44
+ { at: 30 * DAY, value: 70, value2: 45 },
45
+ ];
46
+
47
+ it("spans both readings with twelve percent padding by default", () => {
48
+ const extent = seriesExtent(points);
49
+ const span = 80 - 45;
50
+ expect(extent.lo).toBeCloseTo(45 - span * 0.12);
51
+ expect(extent.hi).toBeCloseTo(80 + span * 0.12);
52
+ expect(extent.tLo).toBe(10 * DAY);
53
+ expect(extent.tHi).toBe(30 * DAY);
54
+ });
55
+
56
+ it("widens the domain to cover included reference values", () => {
57
+ const extent = seriesExtent(points, { include: [95, 30] });
58
+ expect(extent.hi).toBeGreaterThanOrEqual(95);
59
+ expect(extent.lo).toBeLessThanOrEqual(30);
60
+ });
61
+
62
+ it("honours an explicit padding of zero", () => {
63
+ const extent = seriesExtent(points, { padding: 0 });
64
+ expect(extent.lo).toBe(45);
65
+ expect(extent.hi).toBe(80);
66
+ });
67
+
68
+ it("opens up a degenerate value span so a flat series still centres", () => {
69
+ const extent = seriesExtent([
70
+ { at: DAY, value: 50 },
71
+ { at: 2 * DAY, value: 50 },
72
+ ]);
73
+ expect(extent.lo).toBeLessThan(50);
74
+ expect(extent.hi).toBeGreaterThan(50);
75
+ });
76
+
77
+ it("opens up a degenerate time span for a single reading", () => {
78
+ const extent = seriesExtent([{ at: DAY, value: 50 }]);
79
+ expect(extent.tHi - extent.tLo).toBe(24 * 3_600_000);
80
+ expect((extent.tLo + extent.tHi) / 2).toBe(DAY);
81
+ });
82
+
83
+ it("returns a usable default extent for an empty series", () => {
84
+ const extent = seriesExtent([]);
85
+ expect(extent.lo).toBeLessThan(extent.hi);
86
+ expect(extent.tLo).toBeLessThan(extent.tHi);
87
+ });
88
+ });
89
+
90
+ describe("seriesScale", () => {
91
+ it("maps extent corners to the padded box corners", () => {
92
+ const extent = { lo: 0, hi: 10, tLo: 0, tHi: 100 };
93
+ const scale = seriesScale(extent, 200, 100, 10);
94
+ expect(scale.x(0)).toBe(10);
95
+ expect(scale.x(100)).toBe(190);
96
+ expect(scale.y(0)).toBe(90);
97
+ expect(scale.y(10)).toBe(10);
98
+ expect(scale.x(50)).toBeCloseTo(100);
99
+ expect(scale.y(5)).toBeCloseTo(50);
100
+ });
101
+ });
102
+
103
+ describe("seriesMean", () => {
104
+ it("averages finite values and ignores non-finite ones", () => {
105
+ expect(seriesMean([2, 4, 6])).toBe(4);
106
+ expect(seriesMean([2, Number.NaN, 4])).toBe(3);
107
+ });
108
+
109
+ it("returns null when there is nothing to average", () => {
110
+ expect(seriesMean([])).toBeNull();
111
+ });
112
+ });
113
+
114
+ describe("periodDelta", () => {
115
+ const latest = 60 * DAY;
116
+ const points: SeriesPoint[] = [
117
+ { at: latest - 45 * DAY, value: 80 }, // prior window
118
+ { at: latest - 40 * DAY, value: 60 }, // prior window
119
+ { at: latest - 10 * DAY, value: 50 }, // recent window
120
+ { at: latest, value: 70 }, // recent window
121
+ ];
122
+
123
+ it("measures both windows back from the latest measurement, not the wall clock", () => {
124
+ const result = periodDelta(points, 30 * DAY)!;
125
+ expect(result.current).toBe(60);
126
+ expect(result.previous).toBe(70);
127
+ expect(result.delta).toBe(-10);
128
+ });
129
+
130
+ it("reports a null delta when the prior window has no data", () => {
131
+ const result = periodDelta(points.slice(2), 30 * DAY)!;
132
+ expect(result.current).toBe(60);
133
+ expect(result.previous).toBeNull();
134
+ expect(result.delta).toBeNull();
135
+ });
136
+
137
+ it("excludes readings exactly on the window boundary from the recent window", () => {
138
+ const boundary: SeriesPoint[] = [
139
+ { at: latest - 30 * DAY, value: 100 },
140
+ { at: latest, value: 50 },
141
+ ];
142
+ const result = periodDelta(boundary, 30 * DAY)!;
143
+ expect(result.current).toBe(50);
144
+ expect(result.previous).toBe(100);
145
+ });
146
+
147
+ it("returns null for an empty series", () => {
148
+ expect(periodDelta([], 30 * DAY)).toBeNull();
149
+ });
150
+ });
151
+
152
+ describe("seriesLinePath / seriesAreaPath", () => {
153
+ const placed = [
154
+ { x: 0, y: 10 },
155
+ { x: 5, y: 0 },
156
+ { x: 10, y: 10 },
157
+ ];
158
+
159
+ it("builds a move/line path", () => {
160
+ expect(seriesLinePath(placed)).toBe("M0.00,10.00 L5.00,0.00 L10.00,10.00");
161
+ });
162
+
163
+ it("closes the area path along the baseline", () => {
164
+ expect(seriesAreaPath(placed, 12)).toBe(
165
+ "M0.00,10.00 L5.00,0.00 L10.00,10.00L10.00,12L0.00,12Z",
166
+ );
167
+ });
168
+
169
+ it("draws no area for fewer than two points", () => {
170
+ expect(seriesAreaPath([{ x: 0, y: 0 }], 12)).toBe("");
171
+ });
172
+ });
@@ -0,0 +1,174 @@
1
+ /**
2
+ * src/lib/series.ts — pure time-series math shared by the chart primitives.
3
+ * No React, no DOM: unit-tested directly. All periods are relative to the
4
+ * LATEST measurement in the series, never to the wall clock, so a seeded
5
+ * demo or a backfilled import never goes stale.
6
+ */
7
+
8
+ /** A point as callers supply it: `at` accepts epoch ms, ISO text or a Date. */
9
+ export interface SeriesPointInput {
10
+ at: number | string | Date;
11
+ value: number;
12
+ /** Second reading for dual series (diastolic next to systolic). */
13
+ value2?: number;
14
+ }
15
+
16
+ /** A normalized point: finite numbers, epoch-ms time, ascending order. */
17
+ export interface SeriesPoint {
18
+ at: number;
19
+ value: number;
20
+ value2?: number;
21
+ }
22
+
23
+ const asTime = (at: number | string | Date): number | null => {
24
+ const time =
25
+ at instanceof Date ? at.getTime() : typeof at === "number" ? at : Date.parse(at);
26
+ return Number.isFinite(time) ? time : null;
27
+ };
28
+
29
+ /** Drop non-finite readings and sort by measurement time. */
30
+ export function normalizeSeries(
31
+ points: readonly SeriesPointInput[],
32
+ ): SeriesPoint[] {
33
+ const normalized: SeriesPoint[] = [];
34
+ for (const point of points) {
35
+ const at = asTime(point.at);
36
+ if (at === null || !Number.isFinite(point.value)) continue;
37
+ const { value2 } = point;
38
+ normalized.push(
39
+ value2 !== undefined && Number.isFinite(value2)
40
+ ? { at, value: point.value, value2 }
41
+ : { at, value: point.value },
42
+ );
43
+ }
44
+ return normalized.sort((a, b) => a.at - b.at);
45
+ }
46
+
47
+ export interface SeriesExtent {
48
+ /** Padded value domain. */
49
+ lo: number;
50
+ hi: number;
51
+ /** Time domain, never degenerate. */
52
+ tLo: number;
53
+ tHi: number;
54
+ }
55
+
56
+ const TWELVE_HOURS_MS = 12 * 3_600_000;
57
+
58
+ /**
59
+ * Value and time extents across both readings of every point. The value
60
+ * domain is padded by `padding` (fraction of the span, default 0.12) and
61
+ * widened to cover `include`d values (reference lines). Degenerate spans
62
+ * open up so a flat or single-reading series still centres.
63
+ */
64
+ export function seriesExtent(
65
+ points: readonly SeriesPoint[],
66
+ options: { padding?: number; include?: readonly number[] } = {},
67
+ ): SeriesExtent {
68
+ const values = [
69
+ ...points.flatMap((point) =>
70
+ point.value2 === undefined ? [point.value] : [point.value, point.value2]
71
+ ),
72
+ ...(options.include ?? []),
73
+ ];
74
+ let lo = values.length > 0 ? Math.min(...values) : 0;
75
+ let hi = values.length > 0 ? Math.max(...values) : 1;
76
+ if (lo === hi) {
77
+ lo -= 1;
78
+ hi += 1;
79
+ }
80
+ const pad = (hi - lo) * (options.padding ?? 0.12);
81
+ lo -= pad;
82
+ hi += pad;
83
+ let tLo = points.length > 0 ? points[0]!.at : 0;
84
+ let tHi = points.length > 0 ? points[points.length - 1]!.at : 1;
85
+ if (tLo === tHi) {
86
+ tLo -= TWELVE_HOURS_MS;
87
+ tHi += TWELVE_HOURS_MS;
88
+ }
89
+ return { lo, hi, tLo, tHi };
90
+ }
91
+
92
+ export interface SeriesScale {
93
+ x: (at: number) => number;
94
+ y: (value: number) => number;
95
+ extent: SeriesExtent;
96
+ }
97
+
98
+ /** Project an extent into a `width` × `height` box with `pad` inset. */
99
+ export function seriesScale(
100
+ extent: SeriesExtent,
101
+ width: number,
102
+ height: number,
103
+ pad: number,
104
+ ): SeriesScale {
105
+ const { lo, hi, tLo, tHi } = extent;
106
+ return {
107
+ extent,
108
+ x: (at) => pad + ((at - tLo) / (tHi - tLo)) * (width - 2 * pad),
109
+ y: (value) => height - pad - ((value - lo) / (hi - lo)) * (height - 2 * pad),
110
+ };
111
+ }
112
+
113
+ export interface PeriodDelta {
114
+ /** Mean of the latest `windowMs` of data, ending at the last measurement. */
115
+ current: number;
116
+ /** Mean of the window before that, when such data exists. */
117
+ previous: number | null;
118
+ /** `current - previous`, or null without a populated prior window. */
119
+ delta: number | null;
120
+ }
121
+
122
+ /** Mean of finite values, or null when there is nothing to average. */
123
+ export function seriesMean(values: readonly number[]): number | null {
124
+ const finite = values.filter((value) => Number.isFinite(value));
125
+ if (finite.length === 0) return null;
126
+ return finite.reduce((sum, value) => sum + value, 0) / finite.length;
127
+ }
128
+
129
+ /**
130
+ * Compare the latest `windowMs` of primary readings against the window
131
+ * before it. Both windows end at the LATEST measurement, never the wall
132
+ * clock. Returns null for an empty series.
133
+ */
134
+ export function periodDelta(
135
+ points: readonly SeriesPoint[],
136
+ windowMs: number,
137
+ ): PeriodDelta | null {
138
+ if (points.length === 0) return null;
139
+ const latest = points[points.length - 1]!.at;
140
+ const recentStart = latest - windowMs;
141
+ const previousStart = latest - 2 * windowMs;
142
+ const recent = points
143
+ .filter((point) => point.at > recentStart)
144
+ .map((point) => point.value);
145
+ const previous = points
146
+ .filter((point) => point.at > previousStart && point.at <= recentStart)
147
+ .map((point) => point.value);
148
+ const current = seriesMean(recent)!;
149
+ const previousMean = seriesMean(previous);
150
+ return {
151
+ current,
152
+ previous: previousMean,
153
+ delta: previousMean !== null ? current - previousMean : null,
154
+ };
155
+ }
156
+
157
+ /** Polyline path data for already-projected points. */
158
+ export function seriesLinePath(points: ReadonlyArray<{ x: number; y: number }>): string {
159
+ return points
160
+ .map(
161
+ (point, index) =>
162
+ `${index === 0 ? "M" : "L"}${point.x.toFixed(2)},${point.y.toFixed(2)}`,
163
+ )
164
+ .join(" ");
165
+ }
166
+
167
+ /** Closed area path down to `baseline`, empty for fewer than two points. */
168
+ export function seriesAreaPath(
169
+ points: ReadonlyArray<{ x: number; y: number }>,
170
+ baseline: number,
171
+ ): string {
172
+ if (points.length < 2) return "";
173
+ return `${seriesLinePath(points)}L${points[points.length - 1]!.x.toFixed(2)},${baseline}L${points[0]!.x.toFixed(2)},${baseline}Z`;
174
+ }
@@ -116,6 +116,20 @@ export const metricLayouts = {
116
116
  6: "grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 max-sm:[&>div:not(:nth-child(2n+1))]:border-l sm:max-lg:[&>div:not(:nth-child(3n+1))]:border-l lg:[&>div:not(:nth-child(6n+1))]:border-l",
117
117
  } as const;
118
118
 
119
+ /** Hand-rolled SVG charts: every stroke and fill is currentColor against a
120
+ * token class, so ink stays theme-aware with no hardcoded hues. Charts draw
121
+ * lines and text only; the grouping plane (border, surface) is caller-owned. */
122
+ export const chartPresentation = {
123
+ sparkline: "h-9 w-full text-primary",
124
+ root: "h-auto w-full",
125
+ axis: "text-muted-foreground",
126
+ gridLine: "opacity-20",
127
+ referenceLine: "opacity-60",
128
+ primarySeries: "text-primary",
129
+ secondarySeries: "text-muted-foreground",
130
+ area: "opacity-10",
131
+ } as const;
132
+
119
133
  export const dialogPresentation = {
120
134
  overlay: "fixed inset-0 z-50 bg-black/40",
121
135
  transition: surfaceMotion,