@jsudc/react 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +555 -2
- package/dist/all.d.ts +9 -0
- package/dist/all.js +14 -0
- package/dist/all.js.map +1 -0
- package/dist/calendar/CalendarRenderer.d.ts +9 -0
- package/dist/calendar/CalendarRenderer.js +314 -0
- package/dist/calendar/CalendarRenderer.js.map +1 -0
- package/dist/calendar/EventBlock.d.ts +16 -0
- package/dist/calendar/EventBlock.js +57 -0
- package/dist/calendar/EventBlock.js.map +1 -0
- package/dist/calendar/EventDetail.d.ts +20 -0
- package/dist/calendar/EventDetail.js +186 -0
- package/dist/calendar/EventDetail.js.map +1 -0
- package/dist/calendar/MonthGrid.d.ts +19 -0
- package/dist/calendar/MonthGrid.js +121 -0
- package/dist/calendar/MonthGrid.js.map +1 -0
- package/dist/calendar/TimeGrid.d.ts +24 -0
- package/dist/calendar/TimeGrid.js +331 -0
- package/dist/calendar/TimeGrid.js.map +1 -0
- package/dist/calendar/index.d.ts +4 -0
- package/dist/calendar/model.d.ts +97 -0
- package/dist/calendar/model.js +279 -0
- package/dist/calendar/model.js.map +1 -0
- package/dist/calendar/useCalendarUrl.d.ts +13 -0
- package/dist/calendar/useCalendarUrl.js +35 -0
- package/dist/calendar/useCalendarUrl.js.map +1 -0
- package/dist/calendar.d.ts +1 -0
- package/dist/calendar.js +22 -0
- package/dist/calendar.js.map +1 -0
- package/dist/cards/CardRenderer.d.ts +24 -0
- package/dist/cards/CardRenderer.js +277 -0
- package/dist/cards/CardRenderer.js.map +1 -0
- package/dist/cards/cardModel.d.ts +48 -0
- package/dist/cards/cardModel.js +86 -0
- package/dist/cards/cardModel.js.map +1 -0
- package/dist/cards/index.d.ts +4 -0
- package/dist/cards.d.ts +1 -0
- package/dist/cards.js +15 -0
- package/dist/cards.js.map +1 -0
- package/dist/chart/ChartRenderer.d.ts +16 -0
- package/dist/chart/ChartRenderer.js +531 -0
- package/dist/chart/ChartRenderer.js.map +1 -0
- package/dist/chart/ChartWindowControl.d.ts +13 -0
- package/dist/chart/ChartWindowControl.js +103 -0
- package/dist/chart/ChartWindowControl.js.map +1 -0
- package/dist/chart/index.d.ts +7 -0
- package/dist/chart/model.d.ts +45 -0
- package/dist/chart/model.js +184 -0
- package/dist/chart/model.js.map +1 -0
- package/dist/chart/useChartWindow.d.ts +18 -0
- package/dist/chart/useChartWindow.js +70 -0
- package/dist/chart/useChartWindow.js.map +1 -0
- package/dist/chart/window.d.ts +50 -0
- package/dist/chart/window.js +133 -0
- package/dist/chart/window.js.map +1 -0
- package/dist/chart.d.ts +1 -0
- package/dist/chart.js +18 -0
- package/dist/chart.js.map +1 -0
- package/dist/components/ui/button.d.ts +21 -0
- package/dist/components/ui/button.js +30 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +2 -0
- package/dist/components/ui/checkbox.js +23 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +14 -0
- package/dist/components/ui/dialog.js +52 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +12 -0
- package/dist/components/ui/dropdown-menu.js +35 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/input.d.ts +4 -0
- package/dist/components/ui/input.js +24 -0
- package/dist/components/ui/input.js.map +1 -0
- package/dist/components/ui/misc.d.ts +6 -0
- package/dist/components/ui/misc.js +24 -0
- package/dist/components/ui/misc.js.map +1 -0
- package/dist/components/ui/popover.d.ts +6 -0
- package/dist/components/ui/popover.js +21 -0
- package/dist/components/ui/popover.js.map +1 -0
- package/dist/components/ui/segmented.d.ts +11 -0
- package/dist/components/ui/segmented.js +35 -0
- package/dist/components/ui/segmented.js.map +1 -0
- package/dist/components/ui/select.d.ts +12 -0
- package/dist/components/ui/select.js +39 -0
- package/dist/components/ui/select.js.map +1 -0
- package/dist/components/ui/toast.d.ts +10 -0
- package/dist/components/ui/toast.js +72 -0
- package/dist/components/ui/toast.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +9 -0
- package/dist/components/ui/tooltip.js +19 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/data-view/DocTab.d.ts +8 -0
- package/dist/data-view/DocTab.js +26 -0
- package/dist/data-view/DocTab.js.map +1 -0
- package/dist/data-view/FilePreview.d.ts +10 -0
- package/dist/data-view/FilePreview.js +71 -0
- package/dist/data-view/FilePreview.js.map +1 -0
- package/dist/data-view/FilterBuilder.d.ts +26 -0
- package/dist/data-view/FilterBuilder.js +349 -0
- package/dist/data-view/FilterBuilder.js.map +1 -0
- package/dist/data-view/FilterChips.d.ts +12 -0
- package/dist/data-view/FilterChips.js +296 -0
- package/dist/data-view/FilterChips.js.map +1 -0
- package/dist/data-view/FolderBar.d.ts +5 -0
- package/dist/data-view/FolderBar.js +46 -0
- package/dist/data-view/FolderBar.js.map +1 -0
- package/dist/data-view/FolderEntry.d.ts +13 -0
- package/dist/data-view/FolderEntry.js +37 -0
- package/dist/data-view/FolderEntry.js.map +1 -0
- package/dist/data-view/Freshness.d.ts +18 -0
- package/dist/data-view/Freshness.js +87 -0
- package/dist/data-view/Freshness.js.map +1 -0
- package/dist/data-view/SearchBox.d.ts +7 -0
- package/dist/data-view/SearchBox.js +65 -0
- package/dist/data-view/SearchBox.js.map +1 -0
- package/dist/data-view/SourceTab.d.ts +9 -0
- package/dist/data-view/SourceTab.js +104 -0
- package/dist/data-view/SourceTab.js.map +1 -0
- package/dist/data-view/UdcDataView.d.ts +12 -0
- package/dist/data-view/UdcDataView.js +365 -0
- package/dist/data-view/UdcDataView.js.map +1 -0
- package/dist/data-view/compose.d.ts +24 -0
- package/dist/data-view/compose.js +86 -0
- package/dist/data-view/compose.js.map +1 -0
- package/dist/data-view/folder.d.ts +13 -0
- package/dist/data-view/folder.js +52 -0
- package/dist/data-view/folder.js.map +1 -0
- package/dist/data-view/liveView.d.ts +20 -0
- package/dist/data-view/liveView.js +67 -0
- package/dist/data-view/liveView.js.map +1 -0
- package/dist/data-view/urlState.d.ts +44 -0
- package/dist/data-view/urlState.js +139 -0
- package/dist/data-view/urlState.js.map +1 -0
- package/dist/data-view/useDataViewState.d.ts +39 -0
- package/dist/data-view/useDataViewState.js +79 -0
- package/dist/data-view/useDataViewState.js.map +1 -0
- package/dist/headless.d.ts +31 -0
- package/dist/headless.js +31 -0
- package/dist/i18n/i18n.d.ts +71 -0
- package/dist/i18n/i18n.js +151 -0
- package/dist/i18n/i18n.js.map +1 -0
- package/dist/i18n/translations.d.ts +16 -0
- package/dist/i18n/translations.js +967 -0
- package/dist/i18n/translations.js.map +1 -0
- package/dist/icons/lucide.generated.d.ts +2 -0
- package/dist/icons/lucide.generated.js +32 -0
- package/dist/icons/lucide.generated.js.map +1 -0
- package/dist/icons/resolve.d.ts +9 -0
- package/dist/icons/resolve.js +25 -0
- package/dist/icons/resolve.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +23 -0
- package/dist/kanban/CardDetailDialog.d.ts +17 -0
- package/dist/kanban/CardDetailDialog.js +53 -0
- package/dist/kanban/CardDetailDialog.js.map +1 -0
- package/dist/kanban/KanbanBoardSwitcher.d.ts +6 -0
- package/dist/kanban/KanbanBoardSwitcher.js +27 -0
- package/dist/kanban/KanbanBoardSwitcher.js.map +1 -0
- package/dist/kanban/KanbanCard.d.ts +21 -0
- package/dist/kanban/KanbanCard.js +189 -0
- package/dist/kanban/KanbanCard.js.map +1 -0
- package/dist/kanban/KanbanColumn.d.ts +30 -0
- package/dist/kanban/KanbanColumn.js +228 -0
- package/dist/kanban/KanbanColumn.js.map +1 -0
- package/dist/kanban/KanbanRenderer.d.ts +3 -0
- package/dist/kanban/KanbanRenderer.js +472 -0
- package/dist/kanban/KanbanRenderer.js.map +1 -0
- package/dist/kanban/index.d.ts +5 -0
- package/dist/kanban/model.d.ts +89 -0
- package/dist/kanban/model.js +159 -0
- package/dist/kanban/model.js.map +1 -0
- package/dist/kanban/persist.d.ts +27 -0
- package/dist/kanban/persist.js +54 -0
- package/dist/kanban/persist.js.map +1 -0
- package/dist/kanban/useKanbanBoard.d.ts +21 -0
- package/dist/kanban/useKanbanBoard.js +47 -0
- package/dist/kanban/useKanbanBoard.js.map +1 -0
- package/dist/kanban.d.ts +1 -0
- package/dist/kanban.js +17 -0
- package/dist/kanban.js.map +1 -0
- package/dist/lib/storage.d.ts +7 -0
- package/dist/lib/storage.js +24 -0
- package/dist/lib/storage.js.map +1 -0
- package/dist/lib/theme.d.ts +11 -0
- package/dist/lib/theme.js +43 -0
- package/dist/lib/theme.js.map +1 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.js +12 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/map/MapRenderer.d.ts +13 -0
- package/dist/map/MapRenderer.js +405 -0
- package/dist/map/MapRenderer.js.map +1 -0
- package/dist/map/index.d.ts +4 -0
- package/dist/map/model.d.ts +68 -0
- package/dist/map/model.js +143 -0
- package/dist/map/model.js.map +1 -0
- package/dist/map.d.ts +1 -0
- package/dist/map.js +15 -0
- package/dist/map.js.map +1 -0
- package/dist/react-router/UdcReactRouterUrlState.d.ts +10 -0
- package/dist/react-router/UdcReactRouterUrlState.js +35 -0
- package/dist/react-router/UdcReactRouterUrlState.js.map +1 -0
- package/dist/react-router/index.d.ts +1 -0
- package/dist/react-router.d.ts +1 -0
- package/dist/react-router.js +1 -0
- package/dist/renderers/AllRowsStatus.d.ts +8 -0
- package/dist/renderers/AllRowsStatus.js +34 -0
- package/dist/renderers/AllRowsStatus.js.map +1 -0
- package/dist/renderers/context.d.ts +11 -0
- package/dist/renderers/context.js +15 -0
- package/dist/renderers/context.js.map +1 -0
- package/dist/renderers/registry.d.ts +25 -0
- package/dist/renderers/registry.js +40 -0
- package/dist/renderers/registry.js.map +1 -0
- package/dist/renderers/types.d.ts +90 -0
- package/dist/renderers/types.js +8 -0
- package/dist/renderers/types.js.map +1 -0
- package/dist/schema-editor/ColumnHeaderMenu.d.ts +11 -0
- package/dist/schema-editor/ColumnHeaderMenu.js +75 -0
- package/dist/schema-editor/ColumnHeaderMenu.js.map +1 -0
- package/dist/schema-editor/DeleteFieldDialog.d.ts +8 -0
- package/dist/schema-editor/DeleteFieldDialog.js +79 -0
- package/dist/schema-editor/DeleteFieldDialog.js.map +1 -0
- package/dist/schema-editor/FieldFormDialog.d.ts +22 -0
- package/dist/schema-editor/FieldFormDialog.js +312 -0
- package/dist/schema-editor/FieldFormDialog.js.map +1 -0
- package/dist/schema-editor/TagInput.d.ts +9 -0
- package/dist/schema-editor/TagInput.js +46 -0
- package/dist/schema-editor/TagInput.js.map +1 -0
- package/dist/schema-editor/fieldForm.d.ts +52 -0
- package/dist/schema-editor/fieldForm.js +132 -0
- package/dist/schema-editor/fieldForm.js.map +1 -0
- package/dist/schema-editor/index.d.ts +6 -0
- package/dist/schema-editor/useSchemaEditor.d.ts +15 -0
- package/dist/schema-editor/useSchemaEditor.js +87 -0
- package/dist/schema-editor/useSchemaEditor.js.map +1 -0
- package/dist/schema-editor.d.ts +1 -0
- package/dist/schema-editor.js +7 -0
- package/dist/styles.css +2 -0
- package/dist/table/CellEditor.d.ts +31 -0
- package/dist/table/CellEditor.js +145 -0
- package/dist/table/CellEditor.js.map +1 -0
- package/dist/table/Pager.d.ts +8 -0
- package/dist/table/Pager.js +90 -0
- package/dist/table/Pager.js.map +1 -0
- package/dist/table/TableRenderer.d.ts +27 -0
- package/dist/table/TableRenderer.js +458 -0
- package/dist/table/TableRenderer.js.map +1 -0
- package/dist/table/cells.d.ts +16 -0
- package/dist/table/cells.js +106 -0
- package/dist/table/cells.js.map +1 -0
- package/dist/table/format.d.ts +24 -0
- package/dist/table/format.js +117 -0
- package/dist/table/format.js.map +1 -0
- package/dist/table/index.d.ts +6 -0
- package/dist/table/sparkline.d.ts +31 -0
- package/dist/table/sparkline.js +105 -0
- package/dist/table/sparkline.js.map +1 -0
- package/dist/table/states.d.ts +17 -0
- package/dist/table/states.js +86 -0
- package/dist/table/states.js.map +1 -0
- package/dist/table/style.d.ts +15 -0
- package/dist/table/style.js +53 -0
- package/dist/table/style.js.map +1 -0
- package/dist/table/transforms.d.ts +17 -0
- package/dist/table/transforms.js +95 -0
- package/dist/table/transforms.js.map +1 -0
- package/dist/table/useInfiniteSentinel.d.ts +8 -0
- package/dist/table/useInfiniteSentinel.js +34 -0
- package/dist/table/useInfiniteSentinel.js.map +1 -0
- package/dist/table.d.ts +1 -0
- package/dist/table.js +18 -0
- package/dist/table.js.map +1 -0
- package/dist/time/timezone.d.ts +27 -0
- package/dist/time/timezone.js +65 -0
- package/dist/time/timezone.js.map +1 -0
- package/dist/time/zoned.d.ts +65 -0
- package/dist/time/zoned.js +208 -0
- package/dist/time/zoned.js.map +1 -0
- package/dist/tokens.css +457 -0
- package/dist/tree/TreeNode.d.ts +9 -0
- package/dist/tree/TreeNode.js +292 -0
- package/dist/tree/TreeNode.js.map +1 -0
- package/dist/tree/TreeRenderer.d.ts +54 -0
- package/dist/tree/TreeRenderer.js +446 -0
- package/dist/tree/TreeRenderer.js.map +1 -0
- package/dist/tree/expand.d.ts +31 -0
- package/dist/tree/expand.js +80 -0
- package/dist/tree/expand.js.map +1 -0
- package/dist/tree/index.d.ts +4 -0
- package/dist/tree/model.d.ts +108 -0
- package/dist/tree/model.js +294 -0
- package/dist/tree/model.js.map +1 -0
- package/dist/tree.d.ts +1 -0
- package/dist/tree.js +15 -0
- package/dist/tree.js.map +1 -0
- package/dist/udc/client.d.ts +11 -0
- package/dist/udc/client.js +30 -0
- package/dist/udc/client.js.map +1 -0
- package/dist/udc/hooks.d.ts +644 -0
- package/dist/udc/hooks.js +353 -0
- package/dist/udc/hooks.js.map +1 -0
- package/dist/udc/keys.d.ts +19 -0
- package/dist/udc/keys.js +30 -0
- package/dist/udc/keys.js.map +1 -0
- package/dist/udc/provider.d.ts +19 -0
- package/dist/udc/provider.js +29 -0
- package/dist/udc/provider.js.map +1 -0
- package/dist/ui-kit/context.d.ts +11 -0
- package/dist/ui-kit/context.js +19 -0
- package/dist/ui-kit/context.js.map +1 -0
- package/dist/ui-kit/default.d.ts +3 -0
- package/dist/ui-kit/default.js +45 -0
- package/dist/ui-kit/default.js.map +1 -0
- package/dist/ui-kit/index.d.ts +2 -0
- package/dist/ui-kit/types.d.ts +227 -0
- package/dist/ui-kit/ui.d.ts +12 -0
- package/dist/ui.d.ts +1 -0
- package/dist/ui.js +13 -0
- package/dist/url-state/UrlState.d.ts +20 -0
- package/dist/url-state/UrlState.js +27 -0
- package/dist/url-state/UrlState.js.map +1 -0
- package/dist/url-state/adapter.d.ts +24 -0
- package/dist/url-state/adapter.js +33 -0
- package/dist/url-state/adapter.js.map +1 -0
- package/dist/url-state/index.d.ts +2 -0
- package/package.json +185 -4
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useI18n } from "../i18n/i18n.js";
|
|
2
|
+
import { useUiKit } from "../ui-kit/context.js";
|
|
3
|
+
import { wallOf } from "./window.js";
|
|
4
|
+
import { X } from "lucide-react";
|
|
5
|
+
import { useId } from "react";
|
|
6
|
+
import { parseWindowPreset } from "@jsudc/core";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/chart/ChartWindowControl.tsx
|
|
9
|
+
var CUSTOM = "custom";
|
|
10
|
+
/** `24h` → "24h" / "24 č", `7d` → "7d" / "7 d". */
|
|
11
|
+
function presetLabel(preset, t) {
|
|
12
|
+
const p = parseWindowPreset(preset);
|
|
13
|
+
if (!p) return preset;
|
|
14
|
+
return t("APP", p.unit === "h" ? "CHART_PRESET_H" : "CHART_PRESET_D", { n: p.n });
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The window of a chart, in the toolbar row: the presets, "Custom" with a
|
|
18
|
+
* from / to pair of wall times in the header's zone, and (on a tab other than
|
|
19
|
+
* the chart, where the window came along from the URL) a button that drops it.
|
|
20
|
+
*/
|
|
21
|
+
function ChartWindowControl({ win, clearable }) {
|
|
22
|
+
const { Button, Input, Segmented } = useUiKit();
|
|
23
|
+
const { t } = useI18n();
|
|
24
|
+
const id = useId();
|
|
25
|
+
const { cfg, sel, range, timeZone } = win;
|
|
26
|
+
const value = sel.kind === "custom" ? CUSTOM : sel.preset;
|
|
27
|
+
const options = [...cfg.presets.map((p) => ({
|
|
28
|
+
value: p,
|
|
29
|
+
testId: `chart-win-${p}`,
|
|
30
|
+
label: presetLabel(p, t),
|
|
31
|
+
tooltip: t("APP", parseWindowPreset(p)?.unit === "h" ? "CHART_LAST_HOURS" : "CHART_LAST_DAYS", { n: parseWindowPreset(p)?.n ?? 0 })
|
|
32
|
+
})), ...cfg.allow_custom ? [{
|
|
33
|
+
value: CUSTOM,
|
|
34
|
+
testId: "chart-win-custom",
|
|
35
|
+
label: t("APP", "CHART_CUSTOM")
|
|
36
|
+
}] : []];
|
|
37
|
+
const wall = (t) => t === null ? "" : wallOf(t, timeZone);
|
|
38
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
39
|
+
className: "udc:flex udc:flex-wrap udc:items-center udc:gap-2",
|
|
40
|
+
"data-testid": "chart-window",
|
|
41
|
+
children: [
|
|
42
|
+
/* @__PURE__ */ jsx(Segmented, {
|
|
43
|
+
"aria-label": t("APP", "CHART_WINDOW"),
|
|
44
|
+
"data-testid": "chart-presets",
|
|
45
|
+
value,
|
|
46
|
+
onChange: (v) => win.setSel(v === CUSTOM ? {
|
|
47
|
+
kind: "custom",
|
|
48
|
+
from: wall(range[0]) || null,
|
|
49
|
+
to: wall(range[1]) || null
|
|
50
|
+
} : {
|
|
51
|
+
kind: "preset",
|
|
52
|
+
preset: v
|
|
53
|
+
}),
|
|
54
|
+
options
|
|
55
|
+
}),
|
|
56
|
+
sel.kind === "custom" ? /* @__PURE__ */ jsxs("div", {
|
|
57
|
+
className: "udc:flex udc:items-center udc:gap-1.5 udc:text-xs udc:text-muted-foreground",
|
|
58
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
59
|
+
htmlFor: `${id}-from`,
|
|
60
|
+
className: "udc:flex udc:items-center udc:gap-1",
|
|
61
|
+
children: [t("APP", "CHART_FROM"), /* @__PURE__ */ jsx(Input, {
|
|
62
|
+
id: `${id}-from`,
|
|
63
|
+
type: "datetime-local",
|
|
64
|
+
"data-testid": "chart-from",
|
|
65
|
+
className: "udc:h-8 udc:w-auto udc:px-2 udc:text-xs",
|
|
66
|
+
value: sel.from ?? "",
|
|
67
|
+
max: sel.to ?? void 0,
|
|
68
|
+
onChange: (e) => win.setSel({
|
|
69
|
+
...sel,
|
|
70
|
+
from: e.target.value || null
|
|
71
|
+
})
|
|
72
|
+
})]
|
|
73
|
+
}), /* @__PURE__ */ jsxs("label", {
|
|
74
|
+
htmlFor: `${id}-to`,
|
|
75
|
+
className: "udc:flex udc:items-center udc:gap-1",
|
|
76
|
+
children: [t("APP", "CHART_TO"), /* @__PURE__ */ jsx(Input, {
|
|
77
|
+
id: `${id}-to`,
|
|
78
|
+
type: "datetime-local",
|
|
79
|
+
"data-testid": "chart-to",
|
|
80
|
+
className: "udc:h-8 udc:w-auto udc:px-2 udc:text-xs",
|
|
81
|
+
value: sel.to ?? "",
|
|
82
|
+
min: sel.from ?? void 0,
|
|
83
|
+
onChange: (e) => win.setSel({
|
|
84
|
+
...sel,
|
|
85
|
+
to: e.target.value || null
|
|
86
|
+
})
|
|
87
|
+
})]
|
|
88
|
+
})]
|
|
89
|
+
}) : null,
|
|
90
|
+
clearable ? /* @__PURE__ */ jsx(Button, {
|
|
91
|
+
size: "icon-sm",
|
|
92
|
+
variant: "ghost",
|
|
93
|
+
"aria-label": t("APP", "CHART_CLEAR_WINDOW"),
|
|
94
|
+
"data-testid": "chart-win-clear",
|
|
95
|
+
onClick: win.clear,
|
|
96
|
+
children: /* @__PURE__ */ jsx(X, {})
|
|
97
|
+
}) : null
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export { ChartWindowControl, presetLabel };
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=ChartWindowControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartWindowControl.js","names":[],"sources":["../../src/chart/ChartWindowControl.tsx"],"sourcesContent":["import { parseWindowPreset } from \"@jsudc/core\";\nimport { X } from \"lucide-react\";\nimport { useId } from \"react\";\nimport { useI18n } from \"../i18n/i18n.js\";\nimport { useUiKit } from \"../ui-kit/context.js\";\nimport type { ChartWindowState } from \"./useChartWindow.js\";\nimport { wallOf } from \"./window.js\";\n\nconst CUSTOM = \"custom\";\n\n/** `24h` → \"24h\" / \"24 č\", `7d` → \"7d\" / \"7 d\". */\nexport function presetLabel(preset: string, t: ReturnType<typeof useI18n>[\"t\"]): string {\n const p = parseWindowPreset(preset);\n if (!p) return preset;\n return t(\"APP\", p.unit === \"h\" ? \"CHART_PRESET_H\" : \"CHART_PRESET_D\", { n: p.n });\n}\n\n/**\n * The window of a chart, in the toolbar row: the presets, \"Custom\" with a\n * from / to pair of wall times in the header's zone, and (on a tab other than\n * the chart, where the window came along from the URL) a button that drops it.\n */\nexport function ChartWindowControl({\n win,\n clearable,\n}: {\n win: ChartWindowState;\n clearable: boolean;\n}) {\n const { Button, Input, Segmented } = useUiKit();\n const { t } = useI18n();\n const id = useId();\n const { cfg, sel, range, timeZone } = win;\n const value = sel.kind === \"custom\" ? CUSTOM : sel.preset;\n const options = [\n ...cfg.presets.map((p) => ({\n value: p,\n testId: `chart-win-${p}`,\n label: presetLabel(p, t),\n tooltip: t(\n \"APP\",\n parseWindowPreset(p)?.unit === \"h\" ? \"CHART_LAST_HOURS\" : \"CHART_LAST_DAYS\",\n {\n n: parseWindowPreset(p)?.n ?? 0,\n },\n ),\n })),\n ...(cfg.allow_custom\n ? [{ value: CUSTOM, testId: \"chart-win-custom\", label: t(\"APP\", \"CHART_CUSTOM\") }]\n : []),\n ];\n const wall = (t: number | null) => (t === null ? \"\" : wallOf(t, timeZone));\n\n return (\n <div className=\"udc:flex udc:flex-wrap udc:items-center udc:gap-2\" data-testid=\"chart-window\">\n <Segmented<string>\n aria-label={t(\"APP\", \"CHART_WINDOW\")}\n data-testid=\"chart-presets\"\n value={value}\n onChange={(v) =>\n win.setSel(\n v === CUSTOM\n ? { kind: \"custom\", from: wall(range[0]) || null, to: wall(range[1]) || null }\n : { kind: \"preset\", preset: v },\n )\n }\n options={options}\n />\n {sel.kind === \"custom\" ? (\n <div className=\"udc:flex udc:items-center udc:gap-1.5 udc:text-xs udc:text-muted-foreground\">\n <label htmlFor={`${id}-from`} className=\"udc:flex udc:items-center udc:gap-1\">\n {t(\"APP\", \"CHART_FROM\")}\n <Input\n id={`${id}-from`}\n type=\"datetime-local\"\n data-testid=\"chart-from\"\n className=\"udc:h-8 udc:w-auto udc:px-2 udc:text-xs\"\n value={sel.from ?? \"\"}\n max={sel.to ?? undefined}\n onChange={(e) => win.setSel({ ...sel, from: e.target.value || null })}\n />\n </label>\n <label htmlFor={`${id}-to`} className=\"udc:flex udc:items-center udc:gap-1\">\n {t(\"APP\", \"CHART_TO\")}\n <Input\n id={`${id}-to`}\n type=\"datetime-local\"\n data-testid=\"chart-to\"\n className=\"udc:h-8 udc:w-auto udc:px-2 udc:text-xs\"\n value={sel.to ?? \"\"}\n min={sel.from ?? undefined}\n onChange={(e) => win.setSel({ ...sel, to: e.target.value || null })}\n />\n </label>\n </div>\n ) : null}\n {clearable ? (\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n aria-label={t(\"APP\", \"CHART_CLEAR_WINDOW\")}\n data-testid=\"chart-win-clear\"\n onClick={win.clear}\n >\n <X />\n </Button>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAQA,IAAM,SAAS;;AAGf,SAAgB,YAAY,QAAgB,GAA4C;CACtF,MAAM,IAAI,kBAAkB,MAAM;CAClC,IAAI,CAAC,GAAG,OAAO;CACf,OAAO,EAAE,OAAO,EAAE,SAAS,MAAM,mBAAmB,kBAAkB,EA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Y;MACZ,WAAU;MACV,OAAO,IAAI,QAAQ;MACnB,KAAK,IAAI,MAAM,KAAA;MACf,WAAW,MAAM,IAAI,OAAO;OAAE,GAAG;OAAK,MAAM,EAAE,OAAO,SAAS;MAAK,CAAC;KACrE,CAAA,CACI;IACP,CAAA,GAAA,qBAAC,SAAD;KAAO,SAAS,GAAG,GAAG;KAAM,WAAU;KAAtC,UAAA,CACG,EAAE,OAAO,UAAU,GACpB,oBAAC,OAAD;MACE,IAAI,GAAG,GAAG;MACV,MAAK;MACL,eAAY;MACZ,WAAU;MACV,OAAO,IAAI,MAAM;MACjB,KAAK,IAAI,QAAQ,KAAA;MACjB,WAAW,MAAM,IAAI,OAAO;OAAE,GAAG;OAAK,IAAI,EAAE,OAAO,SAAS;MAAK,CAAC;KACnE,CAAA,CACI;IACJ,CAAA,CAAA;GACH,CAAA,IAAA;GACH,YACC,oBAAC,QAAD;IACE,MAAK;IACL,SAAQ;IACR,cAAY,EAAE,OAAO,oBAAoB;IACzC,eAAY;IACZ,SAAS,IAAI;IAEb,UAAA,oBAAC,GAAD,CAAI,CAAA;GACE,CAAA,IACN;EACD;;AAET"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RendererDefinition } from "../renderers/types.js";
|
|
2
|
+
export { ChartRenderer } from "./ChartRenderer.js";
|
|
3
|
+
/**
|
|
4
|
+
* `createRendererRegistry(chartRenderer, …)`: the `chart` tab. The window control is drawn by
|
|
5
|
+
* the data view: once picked it also filters the other tabs.
|
|
6
|
+
*/
|
|
7
|
+
export declare const chartRenderer: RendererDefinition;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type AxisFormat, type AxisFrame, type ChartOptions, type ChartSeries } from "@jsudc/core";
|
|
2
|
+
/** The x value of a point: an instant (ms) on a time axis, the category's text otherwise. */
|
|
3
|
+
export declare const X_KEY = "__x";
|
|
4
|
+
/** How many rows a point stands for (> 1 when bucketed or merged). */
|
|
5
|
+
export declare const COUNT_KEY = "__count";
|
|
6
|
+
export type ChartPoint = Record<string, number | string | null>;
|
|
7
|
+
export interface CartesianData {
|
|
8
|
+
points: ChartPoint[];
|
|
9
|
+
/** The time bucket in ms (`1`: one point per instant); `0` on a category axis. */
|
|
10
|
+
bucket: number;
|
|
11
|
+
}
|
|
12
|
+
/** At most one point per two pixels of plot, and never more than 600. */
|
|
13
|
+
export declare function maxPointsFor(width: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* The points of a line / area / bar chart. On a time axis the rows are
|
|
16
|
+
* bucketed by `bucketByTime` (one point per instant while they fit
|
|
17
|
+
* `maxPoints`, else a readable bucket, each series by its `agg`); on a
|
|
18
|
+
* category axis the rows of one category merge the same way, in the order the
|
|
19
|
+
* categories first appear.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cartesianData(rows: readonly Record<string, unknown>[], opts: ChartOptions, xKind: "time" | "category", maxPoints: number): CartesianData;
|
|
22
|
+
/**
|
|
23
|
+
* The values one y axis draws: every visible series on that side; series of
|
|
24
|
+
* one `stack` (area, bar) count by their per-point sum, which is what the eye
|
|
25
|
+
* sees, positive and negative parts apart.
|
|
26
|
+
*/
|
|
27
|
+
export declare function axisValues(points: readonly ChartPoint[], opts: ChartOptions, side: "left" | "right", hidden: ReadonlySet<string>): number[];
|
|
28
|
+
/** The sides that have a series; the axis of each, framed on what it draws now. */
|
|
29
|
+
export declare function axisFrames(points: readonly ChartPoint[], opts: ChartOptions, hidden: ReadonlySet<string>): Partial<Record<"left" | "right", AxisFrame | null>>;
|
|
30
|
+
/** The palette slot of the series at `index` (the configured order, so a colour follows its series). */
|
|
31
|
+
export declare function seriesColor(s: Pick<ChartSeries, "color">, index: number): string;
|
|
32
|
+
/** `--chart-1` … `--chart-8` in index.css, light and dark. */
|
|
33
|
+
export declare const CHART_SLOTS = 8;
|
|
34
|
+
/** A y tick label: `67 %`, `1.2 MB`, or the number in the UI's locale. */
|
|
35
|
+
export declare function formatAxisValue(v: number, format: AxisFormat | undefined, intlLocale: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Tick instants for `[from, to]` in `timeZone`, at most about `max` of them:
|
|
38
|
+
* the smallest step that fits, on the zone's round wall times (every 3 hours
|
|
39
|
+
* is 00:00, 03:00, … *there*, not in UTC), local midnights for whole days.
|
|
40
|
+
*/
|
|
41
|
+
export declare function timeTicks(from: number, to: number, timeZone: string, max?: number): number[];
|
|
42
|
+
/** A tick label: the wall time (`09:00`), or the day (`27 Oct`) at midnight and for day steps. */
|
|
43
|
+
export declare function formatTimeTick(t: number, ticks: readonly number[], intlLocale: string, timeZone: string): string;
|
|
44
|
+
/** Bars on a time axis have no band: as wide as the plot allows, 2–8 px. */
|
|
45
|
+
export declare function barSize(plotWidth: number, points: number): number;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { formatBytes } from "../table/format.js";
|
|
2
|
+
import { DAY, HOUR, MINUTE, addDays, dayOf, startOfDay, zonedFormat, zonedToInstant } from "../time/zoned.js";
|
|
3
|
+
import { bucketByTime, pickBucket, toChartInstant, toChartNumber, yAxisFrame } from "@jsudc/core";
|
|
4
|
+
// src/chart/model.ts
|
|
5
|
+
/** The x value of a point: an instant (ms) on a time axis, the category's text otherwise. */
|
|
6
|
+
var X_KEY = "__x";
|
|
7
|
+
/** How many rows a point stands for (> 1 when bucketed or merged). */
|
|
8
|
+
var COUNT_KEY = "__count";
|
|
9
|
+
/** At most one point per two pixels of plot, and never more than 600. */
|
|
10
|
+
function maxPointsFor(width) {
|
|
11
|
+
return Math.min(600, Math.max(60, Math.floor(width / 2)));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The points of a line / area / bar chart. On a time axis the rows are
|
|
15
|
+
* bucketed by `bucketByTime` (one point per instant while they fit
|
|
16
|
+
* `maxPoints`, else a readable bucket, each series by its `agg`); on a
|
|
17
|
+
* category axis the rows of one category merge the same way, in the order the
|
|
18
|
+
* categories first appear.
|
|
19
|
+
*/
|
|
20
|
+
function cartesianData(rows, opts, xKind, maxPoints) {
|
|
21
|
+
const x = opts.x_field ?? "";
|
|
22
|
+
const series = opts.series;
|
|
23
|
+
if (xKind === "time") {
|
|
24
|
+
const instants = rows.map((r) => toChartInstant(r[x])).filter((t) => t !== null);
|
|
25
|
+
const distinct = new Set(instants).size;
|
|
26
|
+
const span = instants.length ? instants.reduce((a, b) => Math.max(a, b)) - instants.reduce((a, b) => Math.min(a, b)) : 0;
|
|
27
|
+
const bucket = pickBucket(span, distinct, maxPoints);
|
|
28
|
+
return {
|
|
29
|
+
points: bucketByTime(rows, x, bucket, series).map((p) => ({
|
|
30
|
+
["__x"]: p.t,
|
|
31
|
+
[COUNT_KEY]: p.count,
|
|
32
|
+
...p.values
|
|
33
|
+
})),
|
|
34
|
+
bucket
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
38
|
+
for (const row of rows) {
|
|
39
|
+
const raw = row[x];
|
|
40
|
+
const key = raw === null || raw === void 0 ? "" : String(raw);
|
|
41
|
+
const list = byCategory.get(key);
|
|
42
|
+
if (list) list.push(row);
|
|
43
|
+
else byCategory.set(key, [row]);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
points: [...byCategory.entries()].map(([key, group]) => {
|
|
47
|
+
const point = {
|
|
48
|
+
["__x"]: key,
|
|
49
|
+
[COUNT_KEY]: group.length
|
|
50
|
+
};
|
|
51
|
+
for (const s of series) {
|
|
52
|
+
const values = group.map((r) => toChartNumber(r[s.field])).filter((v) => v !== null);
|
|
53
|
+
point[s.field] = values.length === 0 ? null : aggregate(values, s.agg);
|
|
54
|
+
}
|
|
55
|
+
return point;
|
|
56
|
+
}),
|
|
57
|
+
bucket: 0
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function aggregate(values, agg) {
|
|
61
|
+
if (agg === "max") return values.reduce((a, b) => Math.max(a, b));
|
|
62
|
+
const sum = values.reduce((a, b) => a + b, 0);
|
|
63
|
+
return agg === "sum" ? sum : sum / values.length;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The values one y axis draws: every visible series on that side; series of
|
|
67
|
+
* one `stack` (area, bar) count by their per-point sum, which is what the eye
|
|
68
|
+
* sees, positive and negative parts apart.
|
|
69
|
+
*/
|
|
70
|
+
function axisValues(points, opts, side, hidden) {
|
|
71
|
+
const mine = opts.series.filter((s) => s.axis === side && !hidden.has(s.field));
|
|
72
|
+
const stacks = opts.type === "line" ? false : mine.some((s) => s.stack);
|
|
73
|
+
const out = [];
|
|
74
|
+
for (const p of points) {
|
|
75
|
+
const sums = /* @__PURE__ */ new Map();
|
|
76
|
+
for (const s of mine) {
|
|
77
|
+
const v = p[s.field];
|
|
78
|
+
if (typeof v !== "number" || !Number.isFinite(v)) continue;
|
|
79
|
+
if (!stacks || !s.stack) {
|
|
80
|
+
out.push(v);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const acc = sums.get(s.stack) ?? {
|
|
84
|
+
up: 0,
|
|
85
|
+
down: 0
|
|
86
|
+
};
|
|
87
|
+
if (v >= 0) acc.up += v;
|
|
88
|
+
else acc.down += v;
|
|
89
|
+
sums.set(s.stack, acc);
|
|
90
|
+
}
|
|
91
|
+
for (const { up, down } of sums.values()) out.push(up, down);
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/** The sides that have a series; the axis of each, framed on what it draws now. */
|
|
96
|
+
function axisFrames(points, opts, hidden) {
|
|
97
|
+
const out = {};
|
|
98
|
+
for (const side of ["left", "right"]) {
|
|
99
|
+
if (!opts.series.some((s) => s.axis === side)) continue;
|
|
100
|
+
out[side] = yAxisFrame(axisValues(points, opts, side, hidden), opts.y_axis[side].baseline);
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
/** The palette slot of the series at `index` (the configured order, so a colour follows its series). */
|
|
105
|
+
function seriesColor(s, index) {
|
|
106
|
+
return s.color ?? `var(--chart-${index % 8 + 1})`;
|
|
107
|
+
}
|
|
108
|
+
/** `--chart-1` … `--chart-8` in index.css, light and dark. */
|
|
109
|
+
var CHART_SLOTS = 8;
|
|
110
|
+
/** A y tick label: `67 %`, `1.2 MB`, or the number in the UI's locale. */
|
|
111
|
+
function formatAxisValue(v, format, intlLocale) {
|
|
112
|
+
if (format === "percent") return new Intl.NumberFormat(intlLocale, {
|
|
113
|
+
style: "percent",
|
|
114
|
+
maximumFractionDigits: 1
|
|
115
|
+
}).format(v / 100);
|
|
116
|
+
if (format === "bytes") return formatBytes(v, intlLocale);
|
|
117
|
+
return new Intl.NumberFormat(intlLocale, { maximumFractionDigits: 2 }).format(v);
|
|
118
|
+
}
|
|
119
|
+
/** Tick spacings, smallest first: sub-day ones fall on round wall-clock times of the zone. */
|
|
120
|
+
var TICK_STEPS = [
|
|
121
|
+
15 * MINUTE,
|
|
122
|
+
30 * MINUTE,
|
|
123
|
+
HOUR,
|
|
124
|
+
2 * HOUR,
|
|
125
|
+
3 * HOUR,
|
|
126
|
+
6 * HOUR,
|
|
127
|
+
12 * HOUR,
|
|
128
|
+
DAY,
|
|
129
|
+
2 * DAY,
|
|
130
|
+
7 * DAY
|
|
131
|
+
];
|
|
132
|
+
/**
|
|
133
|
+
* Tick instants for `[from, to]` in `timeZone`, at most about `max` of them:
|
|
134
|
+
* the smallest step that fits, on the zone's round wall times (every 3 hours
|
|
135
|
+
* is 00:00, 03:00, … *there*, not in UTC), local midnights for whole days.
|
|
136
|
+
*/
|
|
137
|
+
function timeTicks(from, to, timeZone, max = 8) {
|
|
138
|
+
if (!(to > from)) return [from];
|
|
139
|
+
const step = TICK_STEPS.find((s) => (to - from) / s <= max) ?? 6048e5;
|
|
140
|
+
const out = [];
|
|
141
|
+
let day = dayOf(from, timeZone);
|
|
142
|
+
const last = dayOf(to, timeZone);
|
|
143
|
+
for (let n = 0; n < 400; n++, day = addDays(day, 1)) {
|
|
144
|
+
if (step >= 864e5) {
|
|
145
|
+
const k = Math.round(step / DAY);
|
|
146
|
+
const t = startOfDay(day, timeZone);
|
|
147
|
+
if (n % k === 0 && t >= from && t <= to) out.push(t);
|
|
148
|
+
} else {
|
|
149
|
+
const minutes = step / MINUTE;
|
|
150
|
+
for (let m = 0; m < 1440; m += minutes) {
|
|
151
|
+
const t = zonedToInstant({
|
|
152
|
+
...day,
|
|
153
|
+
hh: Math.floor(m / 60),
|
|
154
|
+
mm: m % 60
|
|
155
|
+
}, timeZone);
|
|
156
|
+
if (t >= from && t <= to && out.at(-1) !== t) out.push(t);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (day.y === last.y && day.m === last.m && day.d === last.d) break;
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
/** A tick label: the wall time (`09:00`), or the day (`27 Oct`) at midnight and for day steps. */
|
|
164
|
+
function formatTimeTick(t, ticks, intlLocale, timeZone) {
|
|
165
|
+
const step = ticks.length > 1 ? ticks[1] - ticks[0] : DAY;
|
|
166
|
+
const midnight = startOfDay(dayOf(t, timeZone), timeZone) === t;
|
|
167
|
+
if (step >= 828e5 || midnight) return zonedFormat(intlLocale, timeZone, {
|
|
168
|
+
day: "numeric",
|
|
169
|
+
month: "short"
|
|
170
|
+
}).format(t);
|
|
171
|
+
return zonedFormat(intlLocale, timeZone, {
|
|
172
|
+
hour: "2-digit",
|
|
173
|
+
minute: "2-digit",
|
|
174
|
+
hourCycle: "h23"
|
|
175
|
+
}).format(t);
|
|
176
|
+
}
|
|
177
|
+
/** Bars on a time axis have no band: as wide as the plot allows, 2–8 px. */
|
|
178
|
+
function barSize(plotWidth, points) {
|
|
179
|
+
if (points === 0) return 8;
|
|
180
|
+
return Math.max(2, Math.min(8, Math.floor(plotWidth / points * .6)));
|
|
181
|
+
}
|
|
182
|
+
export { CHART_SLOTS, COUNT_KEY, X_KEY, axisFrames, axisValues, barSize, cartesianData, formatAxisValue, formatTimeTick, maxPointsFor, seriesColor, timeTicks };
|
|
183
|
+
|
|
184
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/chart/model.ts"],"sourcesContent":["import {\n type AxisFormat,\n type AxisFrame,\n bucketByTime,\n type ChartOptions,\n type ChartSeries,\n pickBucket,\n toChartInstant,\n toChartNumber,\n yAxisFrame,\n} from \"@jsudc/core\";\nimport { formatBytes } from \"../table/format.js\";\nimport {\n addDays,\n DAY,\n dayOf,\n HOUR,\n MINUTE,\n startOfDay,\n zonedFormat,\n zonedToInstant,\n} from \"../time/zoned.js\";\n\n/** The x value of a point: an instant (ms) on a time axis, the category's text otherwise. */\nexport const X_KEY = \"__x\";\n/** How many rows a point stands for (> 1 when bucketed or merged). */\nexport const COUNT_KEY = \"__count\";\n\nexport type ChartPoint = Record<string, number | string | null>;\n\nexport interface CartesianData {\n points: ChartPoint[];\n /** The time bucket in ms (`1`: one point per instant); `0` on a category axis. */\n bucket: number;\n}\n\n/** At most one point per two pixels of plot, and never more than 600. */\nexport function maxPointsFor(width: number): number {\n return Math.min(600, Math.max(60, Math.floor(width / 2)));\n}\n\n/**\n * The points of a line / area / bar chart. On a time axis the rows are\n * bucketed by `bucketByTime` (one point per instant while they fit\n * `maxPoints`, else a readable bucket, each series by its `agg`); on a\n * category axis the rows of one category merge the same way, in the order the\n * categories first appear.\n */\nexport function cartesianData(\n rows: readonly Record<string, unknown>[],\n opts: ChartOptions,\n xKind: \"time\" | \"category\",\n maxPoints: number,\n): CartesianData {\n const x = opts.x_field ?? \"\";\n const series = opts.series;\n if (xKind === \"time\") {\n const instants = rows.map((r) => toChartInstant(r[x])).filter((t): t is number => t !== null);\n const distinct = new Set(instants).size;\n const span = instants.length\n ? instants.reduce((a, b) => Math.max(a, b)) - instants.reduce((a, b) => Math.min(a, b))\n : 0;\n const bucket = pickBucket(span, distinct, maxPoints);\n const points = bucketByTime(rows, x, bucket, series).map((p) => ({\n [X_KEY]: p.t,\n [COUNT_KEY]: p.count,\n ...p.values,\n }));\n return { points, bucket };\n }\n const byCategory = new Map<string, Record<string, unknown>[]>();\n for (const row of rows) {\n const raw = row[x];\n const key = raw === null || raw === undefined ? \"\" : String(raw);\n const list = byCategory.get(key);\n if (list) list.push(row);\n else byCategory.set(key, [row]);\n }\n const points = [...byCategory.entries()].map(([key, group]) => {\n const point: ChartPoint = { [X_KEY]: key, [COUNT_KEY]: group.length };\n for (const s of series) {\n const values = group.map((r) => toChartNumber(r[s.field])).filter((v) => v !== null);\n point[s.field] = values.length === 0 ? null : aggregate(values, s.agg);\n }\n return point;\n });\n return { points, bucket: 0 };\n}\n\nfunction aggregate(values: number[], agg: ChartSeries[\"agg\"]): number {\n if (agg === \"max\") return values.reduce((a, b) => Math.max(a, b));\n const sum = values.reduce((a, b) => a + b, 0);\n return agg === \"sum\" ? sum : sum / values.length;\n}\n\n/**\n * The values one y axis draws: every visible series on that side; series of\n * one `stack` (area, bar) count by their per-point sum, which is what the eye\n * sees, positive and negative parts apart.\n */\nexport function axisValues(\n points: readonly ChartPoint[],\n opts: ChartOptions,\n side: \"left\" | \"right\",\n hidden: ReadonlySet<string>,\n): number[] {\n const mine = opts.series.filter((s) => s.axis === side && !hidden.has(s.field));\n const stacks = opts.type === \"line\" ? false : mine.some((s) => s.stack);\n const out: number[] = [];\n for (const p of points) {\n const sums = new Map<string, { up: number; down: number }>();\n for (const s of mine) {\n const v = p[s.field];\n if (typeof v !== \"number\" || !Number.isFinite(v)) continue;\n if (!stacks || !s.stack) {\n out.push(v);\n continue;\n }\n const acc = sums.get(s.stack) ?? { up: 0, down: 0 };\n if (v >= 0) acc.up += v;\n else acc.down += v;\n sums.set(s.stack, acc);\n }\n for (const { up, down } of sums.values()) out.push(up, down);\n }\n return out;\n}\n\n/** The sides that have a series; the axis of each, framed on what it draws now. */\nexport function axisFrames(\n points: readonly ChartPoint[],\n opts: ChartOptions,\n hidden: ReadonlySet<string>,\n): Partial<Record<\"left\" | \"right\", AxisFrame | null>> {\n const out: Partial<Record<\"left\" | \"right\", AxisFrame | null>> = {};\n for (const side of [\"left\", \"right\"] as const) {\n if (!opts.series.some((s) => s.axis === side)) continue;\n out[side] = yAxisFrame(axisValues(points, opts, side, hidden), opts.y_axis[side].baseline);\n }\n return out;\n}\n\n/** The palette slot of the series at `index` (the configured order, so a colour follows its series). */\nexport function seriesColor(s: Pick<ChartSeries, \"color\">, index: number): string {\n return s.color ?? `var(--chart-${(index % CHART_SLOTS) + 1})`;\n}\n\n/** `--chart-1` … `--chart-8` in index.css, light and dark. */\nexport const CHART_SLOTS = 8;\n\n/** A y tick label: `67 %`, `1.2 MB`, or the number in the UI's locale. */\nexport function formatAxisValue(v: number, format: AxisFormat | undefined, intlLocale: string) {\n if (format === \"percent\") {\n return new Intl.NumberFormat(intlLocale, { style: \"percent\", maximumFractionDigits: 1 }).format(\n v / 100,\n );\n }\n if (format === \"bytes\") return formatBytes(v, intlLocale);\n return new Intl.NumberFormat(intlLocale, { maximumFractionDigits: 2 }).format(v);\n}\n\n// --- the time axis ----------------------------------------------------------------------\n\n/** Tick spacings, smallest first: sub-day ones fall on round wall-clock times of the zone. */\nconst TICK_STEPS = [\n 15 * MINUTE,\n 30 * MINUTE,\n HOUR,\n 2 * HOUR,\n 3 * HOUR,\n 6 * HOUR,\n 12 * HOUR,\n DAY,\n 2 * DAY,\n 7 * DAY,\n] as const;\n\n/**\n * Tick instants for `[from, to]` in `timeZone`, at most about `max` of them:\n * the smallest step that fits, on the zone's round wall times (every 3 hours\n * is 00:00, 03:00, … *there*, not in UTC), local midnights for whole days.\n */\nexport function timeTicks(from: number, to: number, timeZone: string, max = 8): number[] {\n if (!(to > from)) return [from];\n const step = TICK_STEPS.find((s) => (to - from) / s <= max) ?? 7 * DAY;\n const out: number[] = [];\n let day = dayOf(from, timeZone);\n const last = dayOf(to, timeZone);\n for (let n = 0; n < 400; n++, day = addDays(day, 1)) {\n if (step >= DAY) {\n const k = Math.round(step / DAY);\n const t = startOfDay(day, timeZone);\n if (n % k === 0 && t >= from && t <= to) out.push(t);\n } else {\n const minutes = step / MINUTE;\n for (let m = 0; m < 24 * 60; m += minutes) {\n const t = zonedToInstant({ ...day, hh: Math.floor(m / 60), mm: m % 60 }, timeZone);\n if (t >= from && t <= to && out.at(-1) !== t) out.push(t);\n }\n }\n if (day.y === last.y && day.m === last.m && day.d === last.d) break;\n }\n return out;\n}\n\n/** A tick label: the wall time (`09:00`), or the day (`27 Oct`) at midnight and for day steps. */\nexport function formatTimeTick(\n t: number,\n ticks: readonly number[],\n intlLocale: string,\n timeZone: string,\n): string {\n const step = ticks.length > 1 ? (ticks[1] as number) - (ticks[0] as number) : DAY;\n const midnight = startOfDay(dayOf(t, timeZone), timeZone) === t;\n if (step >= DAY - HOUR || midnight) {\n return zonedFormat(intlLocale, timeZone, { day: \"numeric\", month: \"short\" }).format(t);\n }\n return zonedFormat(intlLocale, timeZone, {\n hour: \"2-digit\",\n minute: \"2-digit\",\n hourCycle: \"h23\",\n }).format(t);\n}\n\n/** Bars on a time axis have no band: as wide as the plot allows, 2–8 px. */\nexport function barSize(plotWidth: number, points: number): number {\n if (points === 0) return 8;\n return Math.max(2, Math.min(8, Math.floor((plotWidth / points) * 0.6)));\n}\n"],"mappings":";;;;;AAwBA,IAAa,QAAQ;;AAErB,IAAa,YAAY;;AAWzB,SAAgB,aAAa,OAAuB;CAClD,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,MAAM,QAAQ,CAAC,CAAC,CAAC;AAC1D;;;;;;;;AASA,SAAgB,cACd,MACA,MACA,OACA,WACe;CACf,MAAM,IAAI,KAAK,WAAW;CAC1B,MAAM,SAAS,KAAK;CACpB,IAAI,UAAU,QAAQ;EACpB,MAAM,WAAW,KAAK,KAAK,MAAM,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,MAAmB,MAAM,IAAI;EAC5F,MAAM,WAAW,IAAI,IAAI,QAAQ,CAAC,CAAC;EACnC,MAAM,OAAO,SAAS,SAClB,SAAS,QAAQ,GAAG,MAAM,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AAK,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,GAAG;CAChE;CACA,OAAO;AACT;;AAGA,SAAgB,eACd,GACA,OACA,YACA,UACQ;CACR,MAAM,OAAO,MAAM,SAAS,IAAK,MAAM,KAAiB,MAAM,KAAgB;CAC9E,MAAM,WAAW,WAAW,MAAM,GAAG,QAAQ,GAAG,QAAQ,MAAM;CAC9D,IAAI,QAAA,SAAsB,UACxB,OAAO,YAAY,YAAY,UAAU;EAAE,KAAK;EAAW,OAAO;CAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;CAEvF,OAAO,YAAY,YAAY,UAAU;EACvC,MAAM;EACN,QAAQ;EACR,WAAW;CACb,CAAC,CAAC,CAAC,OAAO,CAAC;AACb;;AAGA,SAAgB,QAAQ,WAAmB,QAAwB;CACjE,IAAI,WAAW,GAAG,OAAO;CACzB,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,MAAO,YAAY,SAAU,EAAG,CAAC,CAAC;AACxE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChartWindow, FilterNode, ViewConfig } from "@jsudc/core";
|
|
2
|
+
import { type WindowSel } from "./window.js";
|
|
3
|
+
export interface ChartWindowState {
|
|
4
|
+
cfg: ChartWindow;
|
|
5
|
+
sel: WindowSel;
|
|
6
|
+
/** The URL chose the window (`?win=` / `?from=&to=`): every tab of the view applies it. */
|
|
7
|
+
explicit: boolean;
|
|
8
|
+
/** Instants (ms), both ends included; `null` for a side a custom range leaves open. */
|
|
9
|
+
range: [number | null, number | null];
|
|
10
|
+
/** The condition on `cfg.field`, in the header's zone; absent for an empty custom range. */
|
|
11
|
+
cond: FilterNode | undefined;
|
|
12
|
+
timeZone: string;
|
|
13
|
+
setSel: (sel: WindowSel) => void;
|
|
14
|
+
/** Drop the window from the URL (the chart falls back to the default preset). */
|
|
15
|
+
clear: () => void;
|
|
16
|
+
}
|
|
17
|
+
/** The chart window of a view with `chart_options.window`, from the URL and the header's zone. */
|
|
18
|
+
export declare function useChartWindow(view: ViewConfig | undefined): ChartWindowState | null;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useTimezone } from "../time/timezone.js";
|
|
2
|
+
import { useUrlSearchParams } from "../url-state/UrlState.js";
|
|
3
|
+
import { readWindow, windowCondition, windowRange, writeWindow } from "./window.js";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
5
|
+
// src/chart/useChartWindow.ts
|
|
6
|
+
/**
|
|
7
|
+
* The instant a window is computed from. It is taken when the window or the
|
|
8
|
+
* zone changes, and again every `everyMs` when the view polls, so the window
|
|
9
|
+
* of a list key stays put between two polls instead of changing every render.
|
|
10
|
+
*/
|
|
11
|
+
function useWindowNow(key, everyMs) {
|
|
12
|
+
const [state, setState] = useState(() => ({
|
|
13
|
+
key,
|
|
14
|
+
now: Date.now()
|
|
15
|
+
}));
|
|
16
|
+
let current = state;
|
|
17
|
+
if (state.key !== key) {
|
|
18
|
+
current = {
|
|
19
|
+
key,
|
|
20
|
+
now: Date.now()
|
|
21
|
+
};
|
|
22
|
+
setState(current);
|
|
23
|
+
}
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!everyMs || everyMs <= 0) return;
|
|
26
|
+
const id = setInterval(() => setState((s) => ({
|
|
27
|
+
...s,
|
|
28
|
+
now: Date.now()
|
|
29
|
+
})), everyMs);
|
|
30
|
+
return () => clearInterval(id);
|
|
31
|
+
}, [everyMs]);
|
|
32
|
+
return current.now;
|
|
33
|
+
}
|
|
34
|
+
/** The chart window of a view with `chart_options.window`, from the URL and the header's zone. */
|
|
35
|
+
function useChartWindow(view) {
|
|
36
|
+
const cfg = view?.chart_options?.window;
|
|
37
|
+
const [params, setParams] = useUrlSearchParams();
|
|
38
|
+
const { timeZone } = useTimezone();
|
|
39
|
+
const read = cfg ? readWindow(params, cfg) : null;
|
|
40
|
+
const selKey = JSON.stringify(read?.sel ?? null);
|
|
41
|
+
const explicit = read?.explicit ?? false;
|
|
42
|
+
const now = useWindowNow(`${selKey}|${timeZone}`, view?.refresh_interval_ms);
|
|
43
|
+
const setSel = useCallback((sel) => setParams((prev) => writeWindow(prev, sel), { replace: true }), [setParams]);
|
|
44
|
+
const clear = useCallback(() => setParams((prev) => writeWindow(prev, null), { replace: true }), [setParams]);
|
|
45
|
+
return useMemo(() => {
|
|
46
|
+
if (!cfg) return null;
|
|
47
|
+
const sel = JSON.parse(selKey);
|
|
48
|
+
return {
|
|
49
|
+
cfg,
|
|
50
|
+
sel,
|
|
51
|
+
explicit,
|
|
52
|
+
range: windowRange(sel, now, timeZone),
|
|
53
|
+
cond: windowCondition(cfg.field, sel, now, timeZone),
|
|
54
|
+
timeZone,
|
|
55
|
+
setSel,
|
|
56
|
+
clear
|
|
57
|
+
};
|
|
58
|
+
}, [
|
|
59
|
+
cfg,
|
|
60
|
+
selKey,
|
|
61
|
+
explicit,
|
|
62
|
+
now,
|
|
63
|
+
timeZone,
|
|
64
|
+
setSel,
|
|
65
|
+
clear
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
export { useChartWindow };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=useChartWindow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChartWindow.js","names":[],"sources":["../../src/chart/useChartWindow.ts"],"sourcesContent":["import type { ChartWindow, FilterNode, ViewConfig } from \"@jsudc/core\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useTimezone } from \"../time/timezone.js\";\nimport { useUrlSearchParams } from \"../url-state/UrlState.js\";\nimport { readWindow, type WindowSel, windowCondition, windowRange, writeWindow } from \"./window.js\";\n\nexport interface ChartWindowState {\n cfg: ChartWindow;\n sel: WindowSel;\n /** The URL chose the window (`?win=` / `?from=&to=`): every tab of the view applies it. */\n explicit: boolean;\n /** Instants (ms), both ends included; `null` for a side a custom range leaves open. */\n range: [number | null, number | null];\n /** The condition on `cfg.field`, in the header's zone; absent for an empty custom range. */\n cond: FilterNode | undefined;\n timeZone: string;\n setSel: (sel: WindowSel) => void;\n /** Drop the window from the URL (the chart falls back to the default preset). */\n clear: () => void;\n}\n\n/**\n * The instant a window is computed from. It is taken when the window or the\n * zone changes, and again every `everyMs` when the view polls, so the window\n * of a list key stays put between two polls instead of changing every render.\n */\nfunction useWindowNow(key: string, everyMs: number | undefined): number {\n const [state, setState] = useState(() => ({ key, now: Date.now() }));\n let current = state;\n if (state.key !== key) {\n current = { key, now: Date.now() };\n setState(current);\n }\n useEffect(() => {\n if (!everyMs || everyMs <= 0) return;\n const id = setInterval(() => setState((s) => ({ ...s, now: Date.now() })), everyMs);\n return () => clearInterval(id);\n }, [everyMs]);\n return current.now;\n}\n\n/** The chart window of a view with `chart_options.window`, from the URL and the header's zone. */\nexport function useChartWindow(view: ViewConfig | undefined): ChartWindowState | null {\n const cfg = view?.chart_options?.window;\n const [params, setParams] = useUrlSearchParams();\n const { timeZone } = useTimezone();\n const read = cfg ? readWindow(params, cfg) : null;\n const selKey = JSON.stringify(read?.sel ?? null);\n const explicit = read?.explicit ?? false;\n const now = useWindowNow(`${selKey}|${timeZone}`, view?.refresh_interval_ms);\n const setSel = useCallback(\n (sel: WindowSel) => setParams((prev) => writeWindow(prev, sel), { replace: true }),\n [setParams],\n );\n const clear = useCallback(\n () => setParams((prev) => writeWindow(prev, null), { replace: true }),\n [setParams],\n );\n // One object while nothing it is made of changes: renderers keep it in effect dependencies.\n return useMemo(() => {\n if (!cfg) return null;\n const sel = JSON.parse(selKey) as WindowSel;\n return {\n cfg,\n sel,\n explicit,\n range: windowRange(sel, now, timeZone),\n cond: windowCondition(cfg.field, sel, now, timeZone),\n timeZone,\n setSel,\n clear,\n };\n }, [cfg, selKey, explicit, now, timeZone, setSel, clear]);\n}\n"],"mappings":";;;;;;;;;;AA0BA,SAAS,aAAa,KAAa,SAAqC;CACtE,MAAM,CAAC,OAAO,YAAY,gBAAgB;EAAE;EAAK,KAAK,KAAK,IAAI;CAAE,EAAE;CACn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ChartWindow, type FilterNode } from "@jsudc/core";
|
|
2
|
+
import { type WallTime } from "../time/zoned.js";
|
|
3
|
+
export declare const WIN_PARAM = "win";
|
|
4
|
+
export declare const FROM_PARAM = "from";
|
|
5
|
+
export declare const TO_PARAM = "to";
|
|
6
|
+
/** What the window control picked: a preset, or a custom pair of wall times in the header's zone. */
|
|
7
|
+
export type WindowSel = {
|
|
8
|
+
kind: "preset";
|
|
9
|
+
preset: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "custom";
|
|
12
|
+
from: string | null;
|
|
13
|
+
to: string | null;
|
|
14
|
+
};
|
|
15
|
+
export declare function parseWall(raw: string | null | undefined): WallTime | null;
|
|
16
|
+
/**
|
|
17
|
+
* The window in the URL: `?from=&to=` (either may be missing) when the view
|
|
18
|
+
* allows a custom range, else `?win=` when it is one of the presets, else the
|
|
19
|
+
* default preset. `explicit` says the URL chose it, so the other tabs of the
|
|
20
|
+
* view apply it too.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readWindow(params: URLSearchParams, cfg: ChartWindow): {
|
|
23
|
+
sel: WindowSel;
|
|
24
|
+
explicit: boolean;
|
|
25
|
+
};
|
|
26
|
+
/** `params` with `sel` written in (and the other kind's keys removed); `null` clears the window. */
|
|
27
|
+
export declare function writeWindow(params: URLSearchParams, sel: WindowSel | null): URLSearchParams;
|
|
28
|
+
/**
|
|
29
|
+
* The instants (ms) a window spans, both ends included, in `timeZone`; a side
|
|
30
|
+
* a custom range leaves open is `null`.
|
|
31
|
+
*
|
|
32
|
+
* - `Nh` is the last N hours ending now (`now` to the minute): the same
|
|
33
|
+
* instants in every zone, only written with the zone's offset.
|
|
34
|
+
* - `Nd` is the last N calendar days ending at the end of today *in that
|
|
35
|
+
* zone* (today and the N−1 days before it, midnight to midnight), so the
|
|
36
|
+
* zone moves its instants: Tokyo's 7d starts hours before Belgrade's.
|
|
37
|
+
* - A custom range reads its wall times in `timeZone`; `to` takes the whole
|
|
38
|
+
* minute it names.
|
|
39
|
+
*/
|
|
40
|
+
export declare function windowRange(sel: WindowSel, now: number, timeZone: string): [number | null, number | null];
|
|
41
|
+
/**
|
|
42
|
+
* The window as one condition on `field`: `between` with both ends as ISO
|
|
43
|
+
* instants in the zone's offset (`2026-10-27T12:00:00.000+01:00`), `gte` /
|
|
44
|
+
* `lte` for a half-open custom range, nothing for an empty one.
|
|
45
|
+
*/
|
|
46
|
+
export declare function windowCondition(field: string, sel: WindowSel, now: number, timeZone: string): FilterNode | undefined;
|
|
47
|
+
/** `filter` AND the window (either may be missing). */
|
|
48
|
+
export declare function andWindow(filter: FilterNode | undefined, cond: FilterNode | undefined): FilterNode | undefined;
|
|
49
|
+
/** A wall time for `<input type="datetime-local">`: the instant as `timeZone` reads it. */
|
|
50
|
+
export declare function wallOf(instant: number, timeZone: string): string;
|