@seanyeh77/ui 0.36.0 → 0.38.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/dist/bundle.js +3 -3
- package/dist/bundle.js.map +1 -1
- package/dist/{format-entry-CubJQqC9.js → format-entry-DEIDX9E5.js} +21 -1
- package/dist/format-entry-DEIDX9E5.js.map +1 -0
- package/dist/format.js +1 -1
- package/dist/index.d.ts +200 -9
- package/dist/index.js +604 -69
- package/dist/index.js.map +1 -1
- package/dist/styles.css +543 -17
- package/docs/EventTimeline.md +16 -0
- package/docs/KpiCard.md +18 -0
- package/docs/LineChart.md +42 -1
- package/docs/Meter.md +12 -0
- package/docs/StatusBand.md +24 -0
- package/docs/Tag.md +3 -5
- package/docs/TimeControl.md +21 -0
- package/docs/ZoneMap.md +27 -0
- package/docs/guidelines.md +12 -3
- package/package.json +2 -2
- package/dist/format-entry-CubJQqC9.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as parseDate, c as addMessages, d as unitFor, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-
|
|
2
|
+
import { a as parseDate, c as addMessages, d as unitFor, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-DEIDX9E5.js";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { Tooltip as Tooltip$1 } from "@base-ui/react/tooltip";
|
|
@@ -109,7 +109,10 @@ const PH = {
|
|
|
109
109
|
"sort-ascending": "<path d=\"M128,128a8,8,0,0,1-8,8H48a8,8,0,0,1,0-16h72A8,8,0,0,1,128,128ZM48,72H184a8,8,0,0,0,0-16H48a8,8,0,0,0,0,16Zm56,112H48a8,8,0,0,0,0,16h56a8,8,0,0,0,0-16Zm125.66-21.66a8,8,0,0,0-11.32,0L192,188.69V112a8,8,0,0,0-16,0v76.69l-26.34-26.35a8,8,0,0,0-11.32,11.32l40,40a8,8,0,0,0,11.32,0l40-40A8,8,0,0,0,229.66,162.34Z\"/>",
|
|
110
110
|
"dots-six-vertical": "<path d=\"M104,60A12,12,0,1,1,92,48,12,12,0,0,1,104,60Zm60,12a12,12,0,1,0-12-12A12,12,0,0,0,164,72ZM92,116a12,12,0,1,0,12,12A12,12,0,0,0,92,116Zm72,0a12,12,0,1,0,12,12A12,12,0,0,0,164,116ZM92,184a12,12,0,1,0,12,12A12,12,0,0,0,92,184Zm72,0a12,12,0,1,0,12,12A12,12,0,0,0,164,184Z\"/>",
|
|
111
111
|
"push-pin": "<path d=\"M235.32,81.37,174.63,20.69a16,16,0,0,0-22.63,0L98.37,74.49c-10.66-3.34-35-7.37-60.4,13.14a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33c19.64-26.1,17.75-47.32,13.19-60L235.33,104A16,16,0,0,0,235.32,81.37ZM224,92.69h0l-57.27,57.46a8,8,0,0,0-1.49,9.22c9.46,18.93-1.8,38.59-9.34,48.62L48,100.08c12.08-9.74,23.64-12.31,32.48-12.31A40.13,40.13,0,0,1,96.81,91a8,8,0,0,0,9.25-1.51L163.32,32,224,92.68Z\"/>",
|
|
112
|
-
keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm0,144H32V64H224V192Zm-16-64a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,128Zm0-32a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,96ZM72,160a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16h8A8,8,0,0,1,72,160Zm96,0a8,8,0,0,1-8,8H96a8,8,0,0,1,0-16h64A8,8,0,0,1,168,160Zm40,0a8,8,0,0,1-8,8h-8a8,8,0,0,1,0-16h8A8,8,0,0,1,208,160Z\"/>"
|
|
112
|
+
keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm0,144H32V64H224V192Zm-16-64a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,128Zm0-32a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,96ZM72,160a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16h8A8,8,0,0,1,72,160Zm96,0a8,8,0,0,1-8,8H96a8,8,0,0,1,0-16h64A8,8,0,0,1,168,160Zm40,0a8,8,0,0,1-8,8h-8a8,8,0,0,1,0-16h8A8,8,0,0,1,208,160Z\"/>",
|
|
113
|
+
"arrows-left-right": "<path d=\"M213.66,181.66l-32,32a8,8,0,0,1-11.32-11.32L188.69,184H48a8,8,0,0,1,0-16H188.69l-18.35-18.34a8,8,0,0,1,11.32-11.32l32,32A8,8,0,0,1,213.66,181.66Zm-139.32-64a8,8,0,0,0,11.32-11.32L67.31,88H208a8,8,0,0,0,0-16H67.31L85.66,53.66A8,8,0,0,0,74.34,42.34l-32,32a8,8,0,0,0,0,11.32Z\"/>",
|
|
114
|
+
sparkle: "<path d=\"M197.58,129.06,146,110l-19-51.62a15.92,15.92,0,0,0-29.88,0L78,110l-51.62,19a15.92,15.92,0,0,0,0,29.88L78,178l19,51.62a15.92,15.92,0,0,0,29.88,0L146,178l51.62-19a15.92,15.92,0,0,0,0-29.88ZM137,164.22a8,8,0,0,0-4.74,4.74L112,223.85,91.78,169A8,8,0,0,0,87,164.22L32.15,144,87,123.78A8,8,0,0,0,91.78,119L112,64.15,132.22,119a8,8,0,0,0,4.74,4.74L191.85,144ZM144,40a8,8,0,0,1,8-8h16V16a8,8,0,0,1,16,0V32h16a8,8,0,0,1,0,16H184V64a8,8,0,0,1-16,0V48H152A8,8,0,0,1,144,40ZM248,88a8,8,0,0,1-8,8h-8v8a8,8,0,0,1-16,0V96h-8a8,8,0,0,1,0-16h8V72a8,8,0,0,1,16,0v8h8A8,8,0,0,1,248,88Z\"/>",
|
|
115
|
+
"trend-up": "<path d=\"M240,56v64a8,8,0,0,1-16,0V75.31l-82.34,82.35a8,8,0,0,1-11.32,0L96,123.31,29.66,189.66a8,8,0,0,1-11.32-11.32l72-72a8,8,0,0,1,11.32,0L136,140.69,212.69,64H168a8,8,0,0,1,0-16h64A8,8,0,0,1,240,56Z\"/>"
|
|
113
116
|
};
|
|
114
117
|
const PH_FILL = {
|
|
115
118
|
archive: "<path d=\"M224,48H32A16,16,0,0,0,16,64V88a16,16,0,0,0,16,16v88a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V104a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm-72,96H104a8,8,0,0,1,0-16h48a8,8,0,0,1,0,16Zm72-56H32V64H224V88Z\"/>",
|
|
@@ -209,7 +212,10 @@ const PH_FILL = {
|
|
|
209
212
|
"sort-ascending": "<path d=\"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM72,72h96a8,8,0,0,1,0,16H72a8,8,0,0,1,0-16Zm40,112H72a8,8,0,0,1,0-16h40a8,8,0,0,1,0,16Zm8-48H72a8,8,0,0,1,0-16h48a8,8,0,0,1,0,16Zm77.66,29.66-24,24a8,8,0,0,1-11.32,0l-24-24a8,8,0,0,1,11.32-11.32L160,164.69V120a8,8,0,0,1,16,0v44.69l10.34-10.35a8,8,0,0,1,11.32,11.32Z\"/>",
|
|
210
213
|
"dots-six-vertical": "<path d=\"M192,16H64A16,16,0,0,0,48,32V224a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V32A16,16,0,0,0,192,16ZM100,200a12,12,0,1,1,12-12A12,12,0,0,1,100,200Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,100,140Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,100,80Zm56,120a12,12,0,1,1,12-12A12,12,0,0,1,156,200Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,156,140Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,156,80Z\"/>",
|
|
211
214
|
"push-pin": "<path d=\"M235.33,104l-53.47,53.65c4.56,12.67,6.45,33.89-13.19,60A15.93,15.93,0,0,1,157,224c-.38,0-.75,0-1.13,0a16,16,0,0,1-11.32-4.69L96.29,171,53.66,213.66a8,8,0,0,1-11.32-11.32L85,159.71l-48.3-48.3A16,16,0,0,1,38,87.63c25.42-20.51,49.75-16.48,60.4-13.14L152,20.7a16,16,0,0,1,22.63,0l60.69,60.68A16,16,0,0,1,235.33,104Z\"/>",
|
|
212
|
-
keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48ZM64,168H48a8,8,0,0,1,0-16H64a8,8,0,0,1,0,16Zm96,0H96a8,8,0,0,1,0-16h64a8,8,0,0,1,0,16Zm48,0H192a8,8,0,0,1,0-16h16a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Z\"/>"
|
|
215
|
+
keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48ZM64,168H48a8,8,0,0,1,0-16H64a8,8,0,0,1,0,16Zm96,0H96a8,8,0,0,1,0-16h64a8,8,0,0,1,0,16Zm48,0H192a8,8,0,0,1,0-16h16a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Z\"/>",
|
|
216
|
+
"arrows-left-right": "<path d=\"M42.34,85.66a8,8,0,0,1,0-11.32l32-32A8,8,0,0,1,88,48V72H208a8,8,0,0,1,0,16H88v24a8,8,0,0,1-13.66,5.66Zm171.32,84.68-32-32A8,8,0,0,0,168,144v24H48a8,8,0,0,0,0,16H168v24a8,8,0,0,0,13.66,5.66l32-32A8,8,0,0,0,213.66,170.34Z\"/>",
|
|
217
|
+
sparkle: "<path d=\"M208,144a15.78,15.78,0,0,1-10.42,14.94L146,178l-19,51.62a15.92,15.92,0,0,1-29.88,0L78,178l-51.62-19a15.92,15.92,0,0,1,0-29.88L78,110l19-51.62a15.92,15.92,0,0,1,29.88,0L146,110l51.62,19A15.78,15.78,0,0,1,208,144ZM152,48h16V64a8,8,0,0,0,16,0V48h16a8,8,0,0,0,0-16H184V16a8,8,0,0,0-16,0V32H152a8,8,0,0,0,0,16Zm88,32h-8V72a8,8,0,0,0-16,0v8h-8a8,8,0,0,0,0,16h8v8a8,8,0,0,0,16,0V96h8a8,8,0,0,0,0-16Z\"/>",
|
|
218
|
+
"trend-up": "<path d=\"M240,56v64a8,8,0,0,1-13.66,5.66L200,99.31l-58.34,58.35a8,8,0,0,1-11.32,0L96,123.31,29.66,189.66a8,8,0,0,1-11.32-11.32l72-72a8,8,0,0,1,11.32,0L136,140.69,188.69,88,162.34,61.66A8,8,0,0,1,168,48h64A8,8,0,0,1,240,56Z\"/>"
|
|
213
219
|
};
|
|
214
220
|
/** Lucide names that map to a Phosphor icon. */
|
|
215
221
|
const PH_ALIAS = {
|
|
@@ -6974,7 +6980,9 @@ function SectionGroupToggle({ className }) {
|
|
|
6974
6980
|
// src/components/KpiCard/KpiCard.tsx
|
|
6975
6981
|
/** One figure with its change and a sparkline. It is a card: put several in a grid, not inside another Card. */
|
|
6976
6982
|
function KpiCard(props) {
|
|
6977
|
-
const { label, value, unit, decimals = 0, delta, deltaUnit, good, spark, compareLabel, className } = props;
|
|
6983
|
+
const { label, value, unit, decimals = 0, delta, deltaUnit, good, spark, compareLabel, size = "default", verdict, target, className } = props;
|
|
6984
|
+
const compact = size === "compact";
|
|
6985
|
+
devWarn(compact && !!spark, "KpiCard", "size=\"compact\" 不畫迷你折線,spark 會被忽略。拿掉 spark,或改用一般大小。");
|
|
6978
6986
|
devWarn(props.format === "percent" && !unit, "KpiCard", "format='percent' shows the number only; pass unit=\"%\" for the smaller % after it.");
|
|
6979
6987
|
const t = useCountUp(value, 900);
|
|
6980
6988
|
const valRef = React.useRef(null);
|
|
@@ -6992,14 +7000,14 @@ function KpiCard(props) {
|
|
|
6992
7000
|
const isGood = good ?? up;
|
|
6993
7001
|
const dTxt = hasDelta ? deltaUnit === "pt" ? tr("{n} 個百分點", { n: format.number(Math.abs(delta), 2) }) : format.percent(Math.abs(delta)) : "";
|
|
6994
7002
|
let sparkD = null;
|
|
6995
|
-
if (spark && spark.length > 1) {
|
|
7003
|
+
if (!compact && spark && spark.length > 1) {
|
|
6996
7004
|
const mx = Math.max(...spark);
|
|
6997
7005
|
const mn = Math.min(...spark);
|
|
6998
7006
|
sparkD = smoothPath(spark.map((v, i) => [i * 160 / (spark.length - 1), 32 - (v - mn) / (mx - mn || 1) * 28]));
|
|
6999
7007
|
}
|
|
7000
7008
|
const showUnit = unit && props.format !== "money";
|
|
7001
7009
|
return /* @__PURE__ */ jsxs("section", {
|
|
7002
|
-
className: cx("ui-kpi", className),
|
|
7010
|
+
className: cx("ui-kpi", compact && "is-compact", className),
|
|
7003
7011
|
children: [
|
|
7004
7012
|
/* @__PURE__ */ jsx("div", {
|
|
7005
7013
|
className: "ui-kpi-label",
|
|
@@ -7050,6 +7058,19 @@ function KpiCard(props) {
|
|
|
7050
7058
|
className: "ui-kpi-note",
|
|
7051
7059
|
children: compareLabel || tr("較上週")
|
|
7052
7060
|
})]
|
|
7061
|
+
}) : null,
|
|
7062
|
+
verdict || target ? verdict && verdict.tone !== "success" ? /* @__PURE__ */ jsx("div", {
|
|
7063
|
+
className: "ui-kpi-target ui-kpi-verdict is-" + verdict.tone,
|
|
7064
|
+
children: target ? tr("{v}({t})", {
|
|
7065
|
+
v: verdict.text,
|
|
7066
|
+
t: target
|
|
7067
|
+
}) : verdict.text
|
|
7068
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
7069
|
+
className: "ui-kpi-target",
|
|
7070
|
+
children: [verdict ? /* @__PURE__ */ jsx("span", {
|
|
7071
|
+
className: "ui-visually-hidden",
|
|
7072
|
+
children: verdict.text + tr(",")
|
|
7073
|
+
}) : null, target]
|
|
7053
7074
|
}) : null
|
|
7054
7075
|
]
|
|
7055
7076
|
});
|
|
@@ -8720,107 +8741,328 @@ function LayerGraph(p) {
|
|
|
8720
8741
|
]
|
|
8721
8742
|
});
|
|
8722
8743
|
}
|
|
8744
|
+
// src/components/StatusBand/StatusBand.tsx
|
|
8745
|
+
/** A 12 px band along a time axis, one color per class (chart-1 to chart-4), e.g. which strategy was in use every
|
|
8746
|
+
* 10 minutes; under a LineChart (its `status`) or on its own. The legend below gives the words. */
|
|
8747
|
+
function StatusBand({ segments, classes, label, count, times, legend = true, className }) {
|
|
8748
|
+
const color = (v) => seriesColor(Math.max(0, classes.findIndex((c) => c.value === v)));
|
|
8749
|
+
const name = (v) => classes.find((c) => c.value === v)?.label ?? v;
|
|
8750
|
+
const said = segments.map((s) => (times ? times[s.from] + " " + tr("到") + " " + (times[s.to] ?? times[times.length - 1]) + " " : "") + name(s.value)).join(tr(","));
|
|
8751
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
8752
|
+
className: cx("ui-statusband", className),
|
|
8753
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
8754
|
+
className: "ui-statusband-bar",
|
|
8755
|
+
role: "img",
|
|
8756
|
+
"aria-label": label + tr(":") + (said || tr("沒有資料")),
|
|
8757
|
+
children: segments.map((s, i) => /* @__PURE__ */ jsx("span", { style: {
|
|
8758
|
+
left: s.from / count * 100 + "%",
|
|
8759
|
+
width: (Math.min(count, s.to) - s.from) / count * 100 + "%",
|
|
8760
|
+
background: color(s.value)
|
|
8761
|
+
} }, i))
|
|
8762
|
+
}), legend ? /* @__PURE__ */ jsx(StatusLegend, {
|
|
8763
|
+
classes,
|
|
8764
|
+
label
|
|
8765
|
+
}) : null]
|
|
8766
|
+
});
|
|
8767
|
+
}
|
|
8768
|
+
/** The legend of a StatusBand: its label, then a swatch and the words for each class. */
|
|
8769
|
+
function StatusLegend({ classes, label }) {
|
|
8770
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
8771
|
+
className: "ui-chart-legend ui-statusband-legend",
|
|
8772
|
+
"aria-hidden": "true",
|
|
8773
|
+
children: [/* @__PURE__ */ jsx("span", { children: label }), classes.map((c, i) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
|
|
8774
|
+
className: "ui-chart-swatch",
|
|
8775
|
+
style: { background: seriesColor(i) }
|
|
8776
|
+
}), c.label] }, c.value))]
|
|
8777
|
+
});
|
|
8778
|
+
}
|
|
8723
8779
|
// src/components/LineChart/LineChart.tsx
|
|
8780
|
+
const W = 640;
|
|
8724
8781
|
const L = 40;
|
|
8725
8782
|
const R = 630;
|
|
8783
|
+
const T = 10;
|
|
8726
8784
|
const B = 210;
|
|
8727
|
-
/**
|
|
8728
|
-
function
|
|
8785
|
+
/** Runs of consecutive points that have values. */
|
|
8786
|
+
function runs(values, X, Y) {
|
|
8787
|
+
const out = [];
|
|
8788
|
+
let cur = [];
|
|
8789
|
+
values.forEach((v, i) => {
|
|
8790
|
+
if (v == null || Number.isNaN(v)) {
|
|
8791
|
+
if (cur.length) out.push(cur);
|
|
8792
|
+
cur = [];
|
|
8793
|
+
} else cur.push([X(i), Y(v)]);
|
|
8794
|
+
});
|
|
8795
|
+
if (cur.length) out.push(cur);
|
|
8796
|
+
return out;
|
|
8797
|
+
}
|
|
8798
|
+
/** A trend over time: smooth lines, 5 grid lines, a guide and tooltip on hover. For monitoring it can also compare a
|
|
8799
|
+
* forecast with what happened (band, now, thresholds, marker) and replay with a playhead. */
|
|
8800
|
+
const colorOf = (s, i) => s?.color ? seriesColor(s.color - 1) : seriesColor(i);
|
|
8801
|
+
function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelEvery = 1, band, now, thresholds, marker, playhead, onPlayheadChange, headline, status, empty, className }) {
|
|
8729
8802
|
const [hi, setHi] = React.useState(-1);
|
|
8730
|
-
const
|
|
8803
|
+
const stripes = "ui-stripes-" + React.useId().replace(/:/g, "");
|
|
8804
|
+
const dragging = React.useRef(false);
|
|
8805
|
+
const all = series.flatMap((s) => s.values.filter((v) => v != null));
|
|
8806
|
+
const top = max ?? niceMax(Math.max(min + 1, ...all, ...(thresholds ?? []).map((t) => t.value)) - min) + min;
|
|
8731
8807
|
const n = labels.length || series[0]?.values.length || 0;
|
|
8732
8808
|
const step = 590 / Math.max(1, n - 1);
|
|
8733
8809
|
const X = (i) => L + i * step;
|
|
8734
|
-
const Y = (v) => B - v / top * 200;
|
|
8735
|
-
const ticks = TICKS.map((f) => f * top);
|
|
8810
|
+
const Y = (v) => B - (v - min) / (top - min) * 200;
|
|
8811
|
+
const ticks = TICKS.map((f) => min + f * (top - min));
|
|
8736
8812
|
const suffix = unit ? " " + unit : "";
|
|
8813
|
+
const num = (v) => v == null ? "—" : format.number(v, decimals) + suffix;
|
|
8814
|
+
const replay = playhead != null && !!onPlayheadChange;
|
|
8737
8815
|
const show = (j) => {
|
|
8738
8816
|
setHi(j);
|
|
8739
|
-
announce(labels[j] + tr(":") + series.map((s) => (series.length > 1 ? s.name + " " : "") +
|
|
8817
|
+
announce(labels[j] + tr(":") + series.filter((s) => s.values[j] != null).map((s) => (series.length > 1 ? s.name + " " : "") + num(s.values[j])).join(tr(",")));
|
|
8818
|
+
};
|
|
8819
|
+
const move = (j) => {
|
|
8820
|
+
if (replay) onPlayheadChange(j);
|
|
8821
|
+
show(j);
|
|
8822
|
+
};
|
|
8823
|
+
const at = (e) => {
|
|
8824
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
8825
|
+
const x = (e.clientX - r.left) / r.width * W;
|
|
8826
|
+
return Math.max(0, Math.min(n - 1, Math.round((x - L) / step)));
|
|
8740
8827
|
};
|
|
8741
8828
|
const edge = {
|
|
8742
|
-
left: (L - step / 2) /
|
|
8743
|
-
right: (10 - step / 2) /
|
|
8829
|
+
left: (L - step / 2) / W * 100 + "%",
|
|
8830
|
+
right: (10 - step / 2) / W * 100 + "%"
|
|
8831
|
+
};
|
|
8832
|
+
const legend = series.length > 1 || band;
|
|
8833
|
+
const bandShapes = [];
|
|
8834
|
+
if (band) {
|
|
8835
|
+
const a = series[band.between[0]]?.values ?? [];
|
|
8836
|
+
const b = series[band.between[1]]?.values ?? [];
|
|
8837
|
+
for (let i = 0; i < n - 1; i++) {
|
|
8838
|
+
const a0 = a[i], a1 = a[i + 1], b0 = b[i], b1 = b[i + 1];
|
|
8839
|
+
if (a0 == null || a1 == null || b0 == null || b1 == null) continue;
|
|
8840
|
+
bandShapes.push({
|
|
8841
|
+
d: `M${X(i)},${Y(a0)} L${X(i + 1)},${Y(a1)} L${X(i + 1)},${Y(b1)} L${X(i)},${Y(b0)} Z`,
|
|
8842
|
+
up: a0 + a1 >= b0 + b1
|
|
8843
|
+
});
|
|
8844
|
+
}
|
|
8845
|
+
}
|
|
8846
|
+
const tipRows = (j) => {
|
|
8847
|
+
const rows = series.map((s, i) => ({
|
|
8848
|
+
color: colorOf(series[i], i),
|
|
8849
|
+
name: s.name,
|
|
8850
|
+
value: s.values[j]
|
|
8851
|
+
})).filter((r) => r.value != null).map((r) => ({
|
|
8852
|
+
...r,
|
|
8853
|
+
value: num(r.value)
|
|
8854
|
+
}));
|
|
8855
|
+
if (band) {
|
|
8856
|
+
const a = series[band.between[0]]?.values[j];
|
|
8857
|
+
const b = series[band.between[1]]?.values[j];
|
|
8858
|
+
if (a != null && b != null) rows.push({
|
|
8859
|
+
color: "",
|
|
8860
|
+
name: tr("差"),
|
|
8861
|
+
value: (a - b > 0 ? "+" : "") + num(a - b)
|
|
8862
|
+
});
|
|
8863
|
+
}
|
|
8864
|
+
return rows;
|
|
8744
8865
|
};
|
|
8866
|
+
const shown = hi >= 0 ? hi : -1;
|
|
8745
8867
|
return /* @__PURE__ */ jsxs("div", {
|
|
8746
8868
|
className: cx("ui-chart", className),
|
|
8747
8869
|
children: [
|
|
8748
|
-
|
|
8870
|
+
headline ? /* @__PURE__ */ jsx("div", {
|
|
8871
|
+
className: "ui-chart-headline",
|
|
8872
|
+
children: headline
|
|
8873
|
+
}) : null,
|
|
8874
|
+
legend ? /* @__PURE__ */ jsxs("div", {
|
|
8749
8875
|
className: "ui-chart-legend",
|
|
8750
|
-
children: series.map((s, i) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
|
|
8751
|
-
className: "ui-chart-swatch",
|
|
8752
|
-
style: {
|
|
8753
|
-
|
|
8876
|
+
children: [series.map((s, i) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
|
|
8877
|
+
className: cx("ui-chart-swatch", s.dashed && "is-dashed"),
|
|
8878
|
+
style: {
|
|
8879
|
+
background: s.dashed ? void 0 : colorOf(series[i], i),
|
|
8880
|
+
color: colorOf(series[i], i)
|
|
8881
|
+
}
|
|
8882
|
+
}), s.name] }, i)), band ? /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", { className: cx("ui-chart-swatch", "is-band", "is-" + band.tone) }), band.label] }) : null]
|
|
8754
8883
|
}) : null,
|
|
8755
8884
|
/* @__PURE__ */ jsxs("div", {
|
|
8756
|
-
className: "ui-chart-plot",
|
|
8885
|
+
className: cx("ui-chart-plot", replay && "is-replay"),
|
|
8757
8886
|
tabIndex: n ? 0 : void 0,
|
|
8758
8887
|
role: "group",
|
|
8759
8888
|
"aria-label": label,
|
|
8760
|
-
"aria-description": tr("左右方向鍵查看每一個時間點的數值"),
|
|
8761
|
-
onMouseLeave: () => setHi(-1),
|
|
8762
|
-
onFocus: () => hi < 0 && n && show(0),
|
|
8889
|
+
"aria-description": replay ? tr("左右方向鍵移動播放頭") : tr("左右方向鍵查看每一個時間點的數值"),
|
|
8890
|
+
onMouseLeave: () => !dragging.current && setHi(-1),
|
|
8891
|
+
onFocus: () => hi < 0 && n && show(replay ? playhead : 0),
|
|
8763
8892
|
onBlur: () => setHi(-1),
|
|
8764
8893
|
onKeyDown: (e) => {
|
|
8765
|
-
const to = chartKey(e, hi, n);
|
|
8766
|
-
if (to != null)
|
|
8894
|
+
const to = chartKey(e, replay ? playhead : hi, n);
|
|
8895
|
+
if (to != null) move(to);
|
|
8896
|
+
},
|
|
8897
|
+
onPointerDown: replay ? (e) => {
|
|
8898
|
+
if (e.button !== 0) return;
|
|
8899
|
+
dragging.current = true;
|
|
8900
|
+
try {
|
|
8901
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
8902
|
+
} catch {}
|
|
8903
|
+
move(at(e));
|
|
8904
|
+
} : void 0,
|
|
8905
|
+
onPointerMove: replay ? (e) => {
|
|
8906
|
+
if (dragging.current) move(at(e));
|
|
8907
|
+
} : void 0,
|
|
8908
|
+
onPointerUp: () => {
|
|
8909
|
+
dragging.current = false;
|
|
8910
|
+
},
|
|
8911
|
+
onPointerCancel: () => {
|
|
8912
|
+
dragging.current = false;
|
|
8767
8913
|
},
|
|
8768
8914
|
children: [
|
|
8769
8915
|
/* @__PURE__ */ jsxs("svg", {
|
|
8770
|
-
viewBox:
|
|
8916
|
+
viewBox: `0 0 ${W} 240`,
|
|
8771
8917
|
width: "100%",
|
|
8772
8918
|
"aria-hidden": "true",
|
|
8773
|
-
children: [
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8919
|
+
children: [
|
|
8920
|
+
now != null && now < n - 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("pattern", {
|
|
8921
|
+
id: stripes,
|
|
8922
|
+
width: "9",
|
|
8923
|
+
height: "9",
|
|
8924
|
+
patternUnits: "userSpaceOnUse",
|
|
8925
|
+
patternTransform: "rotate(45)",
|
|
8926
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
8927
|
+
width: "4",
|
|
8928
|
+
height: "9",
|
|
8929
|
+
className: "ui-chart-stripe"
|
|
8930
|
+
})
|
|
8931
|
+
}) }), /* @__PURE__ */ jsx("rect", {
|
|
8932
|
+
x: X(now),
|
|
8933
|
+
y: T,
|
|
8934
|
+
width: R - X(now),
|
|
8935
|
+
height: 200,
|
|
8936
|
+
fill: `url(#${stripes})`
|
|
8937
|
+
})] }) : null,
|
|
8938
|
+
ticks.map((v, i) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
|
|
8939
|
+
x1: L,
|
|
8940
|
+
x2: R,
|
|
8941
|
+
y1: Y(v),
|
|
8942
|
+
y2: Y(v),
|
|
8943
|
+
className: i ? "ui-chart-grid" : "ui-chart-axis"
|
|
8944
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
8945
|
+
x: 32,
|
|
8946
|
+
y: Y(v) + 4,
|
|
8947
|
+
textAnchor: "end",
|
|
8948
|
+
className: "ui-chart-tick",
|
|
8949
|
+
children: format.number(v, tickDecimals(top - min))
|
|
8950
|
+
})] }, i)),
|
|
8951
|
+
bandShapes.map((s, i) => /* @__PURE__ */ jsx("path", {
|
|
8952
|
+
d: s.d,
|
|
8953
|
+
className: cx("ui-chart-band", band?.tone === "success" ? "is-success" : s.up ? "is-pos" : "is-neg")
|
|
8954
|
+
}, i)),
|
|
8955
|
+
(thresholds ?? []).map((t, i) => /* @__PURE__ */ jsxs("g", {
|
|
8956
|
+
className: "ui-chart-threshold is-" + t.tone,
|
|
8957
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
8958
|
+
x1: L,
|
|
8959
|
+
x2: R,
|
|
8960
|
+
y1: Y(t.value),
|
|
8961
|
+
y2: Y(t.value)
|
|
8962
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
8963
|
+
x: 628,
|
|
8964
|
+
y: Y(t.value) - 5,
|
|
8965
|
+
textAnchor: "end",
|
|
8966
|
+
children: t.label
|
|
8967
|
+
})]
|
|
8968
|
+
}, i)),
|
|
8969
|
+
series.map((s, i) => runs(s.values, X, Y).map((pts, k) => /* @__PURE__ */ jsx("path", {
|
|
8970
|
+
d: smoothPath(pts),
|
|
8971
|
+
pathLength: s.dashed ? void 0 : 1,
|
|
8972
|
+
className: cx("ui-chart-line", s.dashed && "is-dashed"),
|
|
8973
|
+
style: {
|
|
8974
|
+
stroke: colorOf(series[i], i),
|
|
8975
|
+
animationDelay: i * 150 + "ms"
|
|
8976
|
+
}
|
|
8977
|
+
}, i + "-" + k))),
|
|
8978
|
+
now != null ? /* @__PURE__ */ jsxs("g", {
|
|
8979
|
+
className: "ui-chart-now",
|
|
8980
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
8981
|
+
x1: X(now),
|
|
8982
|
+
x2: X(now),
|
|
8983
|
+
y1: 6,
|
|
8984
|
+
y2: B
|
|
8985
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
8986
|
+
x: X(now),
|
|
8987
|
+
y: 2,
|
|
8988
|
+
textAnchor: "middle",
|
|
8989
|
+
children: tr("現在")
|
|
8990
|
+
})]
|
|
8991
|
+
}) : null,
|
|
8992
|
+
marker ? /* @__PURE__ */ jsxs("g", {
|
|
8993
|
+
className: "ui-chart-marker",
|
|
8994
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
8995
|
+
cx: X(marker.at),
|
|
8996
|
+
cy: Y(marker.value),
|
|
8997
|
+
r: 5.5,
|
|
8998
|
+
style: { stroke: colorOf(series[marker.series ?? series.length - 1], marker.series ?? series.length - 1) }
|
|
8999
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
9000
|
+
x: X(marker.at) + (marker.at > n * .7 ? -10 : 10),
|
|
9001
|
+
y: Y(marker.value) + 20,
|
|
9002
|
+
textAnchor: marker.at > n * .7 ? "end" : "start",
|
|
9003
|
+
children: marker.label
|
|
9004
|
+
})]
|
|
9005
|
+
}) : null,
|
|
9006
|
+
replay ? /* @__PURE__ */ jsxs("g", {
|
|
9007
|
+
className: "ui-chart-playhead",
|
|
9008
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
9009
|
+
x1: X(playhead),
|
|
9010
|
+
x2: X(playhead),
|
|
9011
|
+
y1: T,
|
|
9012
|
+
y2: B
|
|
9013
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
9014
|
+
cx: X(playhead),
|
|
9015
|
+
cy: B,
|
|
9016
|
+
r: 8
|
|
9017
|
+
})]
|
|
9018
|
+
}) : null
|
|
9019
|
+
]
|
|
8794
9020
|
}),
|
|
8795
9021
|
/* @__PURE__ */ jsx("div", {
|
|
8796
9022
|
className: "ui-chart-hit",
|
|
8797
9023
|
style: edge,
|
|
8798
9024
|
children: labels.map((_, j) => /* @__PURE__ */ jsx("div", {
|
|
8799
|
-
onMouseEnter: () => setHi(j),
|
|
9025
|
+
onMouseEnter: () => !dragging.current && setHi(j),
|
|
8800
9026
|
className: "ui-chart-col",
|
|
8801
|
-
children:
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
9027
|
+
children: shown === j ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", { className: "ui-chart-guide" }), series.map((s, i) => {
|
|
9028
|
+
const v = s.values[j];
|
|
9029
|
+
return v == null ? null : /* @__PURE__ */ jsx("span", {
|
|
9030
|
+
className: "ui-chart-dot",
|
|
9031
|
+
style: {
|
|
9032
|
+
top: Y(v) / B * 100 + "%",
|
|
9033
|
+
background: colorOf(series[i], i)
|
|
9034
|
+
}
|
|
9035
|
+
}, i);
|
|
9036
|
+
})] }) : null
|
|
8808
9037
|
}, j))
|
|
8809
9038
|
}),
|
|
8810
|
-
|
|
8811
|
-
|
|
9039
|
+
!all.length ? /* @__PURE__ */ jsx("div", {
|
|
9040
|
+
className: "ui-chart-empty",
|
|
9041
|
+
children: empty ?? tr("這段時間沒有資料")
|
|
9042
|
+
}) : null,
|
|
9043
|
+
shown >= 0 ? /* @__PURE__ */ jsx(ChartTip, {
|
|
9044
|
+
title: labels[shown],
|
|
8812
9045
|
style: {
|
|
8813
|
-
left: X(
|
|
8814
|
-
transform:
|
|
9046
|
+
left: X(shown) / W * 100 + "%",
|
|
9047
|
+
transform: shown > n * .65 ? "translateX(calc(-100% - 12px))" : "translateX(12px)"
|
|
8815
9048
|
},
|
|
8816
|
-
rows:
|
|
8817
|
-
color: seriesColor(i),
|
|
8818
|
-
name: s.name,
|
|
8819
|
-
value: format.number(s.values[hi], decimals) + suffix
|
|
8820
|
-
}))
|
|
9049
|
+
rows: tipRows(shown)
|
|
8821
9050
|
}) : null
|
|
8822
9051
|
]
|
|
8823
9052
|
}),
|
|
9053
|
+
status ? /* @__PURE__ */ jsx("div", {
|
|
9054
|
+
style: {
|
|
9055
|
+
marginLeft: edge.left,
|
|
9056
|
+
marginRight: edge.right
|
|
9057
|
+
},
|
|
9058
|
+
children: /* @__PURE__ */ jsx(StatusBand, {
|
|
9059
|
+
...status,
|
|
9060
|
+
count: n,
|
|
9061
|
+
times: labels,
|
|
9062
|
+
legend: false,
|
|
9063
|
+
className: "is-attached"
|
|
9064
|
+
})
|
|
9065
|
+
}) : null,
|
|
8824
9066
|
/* @__PURE__ */ jsx("div", {
|
|
8825
9067
|
className: "ui-chart-xlabels",
|
|
8826
9068
|
style: {
|
|
@@ -8828,6 +9070,293 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
|
|
|
8828
9070
|
marginRight: edge.right
|
|
8829
9071
|
},
|
|
8830
9072
|
children: labels.map((lb, j) => /* @__PURE__ */ jsx("span", { children: labelEvery > 1 && j % labelEvery ? "" : digits(lb) }, j))
|
|
9073
|
+
}),
|
|
9074
|
+
status ? /* @__PURE__ */ jsx(StatusLegend, {
|
|
9075
|
+
classes: status.classes,
|
|
9076
|
+
label: status.label
|
|
9077
|
+
}) : null
|
|
9078
|
+
]
|
|
9079
|
+
});
|
|
9080
|
+
}
|
|
9081
|
+
// src/components/Meter/Meter.tsx
|
|
9082
|
+
/** A value against its levels: an 8 px bar shaded normal, watch and over the limit, a dot at the value, and the value
|
|
9083
|
+
* with its state in words above. Meters stacked in a card line up: the state and the value end at the same places. */
|
|
9084
|
+
function Meter({ label, value, min, max, warn, limit, unit, decimals = 0, className }) {
|
|
9085
|
+
const span = max - min || 1;
|
|
9086
|
+
const pct = (v) => Math.max(0, Math.min(100, (v - min) / span * 100));
|
|
9087
|
+
const tone = limit != null && value >= limit ? "danger" : warn != null && value >= warn ? "warning" : "success";
|
|
9088
|
+
const state = tone === "danger" ? tr("⚠ 超過上限") : tone === "warning" ? tr("⚠ 注意") : tr("正常");
|
|
9089
|
+
const num = (v) => format.number(v, decimals) + (unit ? " " + unit : "");
|
|
9090
|
+
const markNum = (v) => format.number(v, (String(v).split(".")[1] ?? "").length);
|
|
9091
|
+
const marksRef = React.useRef(null);
|
|
9092
|
+
const [stack, setStack] = React.useState(false);
|
|
9093
|
+
const w = warn != null ? pct(warn) : null;
|
|
9094
|
+
const l = limit != null ? pct(limit) : null;
|
|
9095
|
+
const stops = [
|
|
9096
|
+
[
|
|
9097
|
+
"var(--meter-ok)",
|
|
9098
|
+
0,
|
|
9099
|
+
w ?? l ?? 100
|
|
9100
|
+
],
|
|
9101
|
+
...w != null ? [[
|
|
9102
|
+
"var(--meter-warn)",
|
|
9103
|
+
w,
|
|
9104
|
+
l ?? 100
|
|
9105
|
+
]] : [],
|
|
9106
|
+
...l != null ? [[
|
|
9107
|
+
"var(--meter-over)",
|
|
9108
|
+
l,
|
|
9109
|
+
100
|
|
9110
|
+
]] : []
|
|
9111
|
+
];
|
|
9112
|
+
const marks = [...warn != null ? [{
|
|
9113
|
+
v: warn,
|
|
9114
|
+
at: w,
|
|
9115
|
+
tone: "warning",
|
|
9116
|
+
text: tr("注意 {v}", { v: markNum(warn) })
|
|
9117
|
+
}] : [], ...limit != null ? [{
|
|
9118
|
+
v: limit,
|
|
9119
|
+
at: l,
|
|
9120
|
+
tone: "danger",
|
|
9121
|
+
text: tr("上限 {v}", { v: markNum(limit) })
|
|
9122
|
+
}] : []];
|
|
9123
|
+
React.useLayoutEffect(() => {
|
|
9124
|
+
const box = marksRef.current;
|
|
9125
|
+
if (!box) return;
|
|
9126
|
+
const check = () => {
|
|
9127
|
+
const [a, b] = [...box.children].map((c) => c.getBoundingClientRect());
|
|
9128
|
+
setStack(!!a && !!b && a.right + 8 > b.left && a.left < b.right + 8);
|
|
9129
|
+
};
|
|
9130
|
+
check();
|
|
9131
|
+
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(check) : null;
|
|
9132
|
+
ro?.observe(box);
|
|
9133
|
+
return () => ro?.disconnect();
|
|
9134
|
+
}, [
|
|
9135
|
+
warn,
|
|
9136
|
+
limit,
|
|
9137
|
+
min,
|
|
9138
|
+
max
|
|
9139
|
+
]);
|
|
9140
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
9141
|
+
className: cx("ui-meter", className),
|
|
9142
|
+
role: "meter",
|
|
9143
|
+
"aria-label": label,
|
|
9144
|
+
"aria-valuenow": value,
|
|
9145
|
+
"aria-valuemin": min,
|
|
9146
|
+
"aria-valuemax": max,
|
|
9147
|
+
"aria-valuetext": num(value) + tr(",") + state.replace("⚠ ", "") + marks.map((m) => tr(",") + m.text).join(""),
|
|
9148
|
+
children: [
|
|
9149
|
+
/* @__PURE__ */ jsxs("div", {
|
|
9150
|
+
className: "ui-meter-head",
|
|
9151
|
+
"aria-hidden": "true",
|
|
9152
|
+
children: [
|
|
9153
|
+
/* @__PURE__ */ jsx("span", {
|
|
9154
|
+
className: "ui-meter-label",
|
|
9155
|
+
children: label
|
|
9156
|
+
}),
|
|
9157
|
+
/* @__PURE__ */ jsx("span", {
|
|
9158
|
+
className: "ui-meter-state is-" + tone,
|
|
9159
|
+
children: state
|
|
9160
|
+
}),
|
|
9161
|
+
/* @__PURE__ */ jsx("span", {
|
|
9162
|
+
className: "ui-meter-value",
|
|
9163
|
+
children: num(value)
|
|
9164
|
+
})
|
|
9165
|
+
]
|
|
9166
|
+
}),
|
|
9167
|
+
/* @__PURE__ */ jsxs("div", {
|
|
9168
|
+
className: "ui-meter-track",
|
|
9169
|
+
"aria-hidden": "true",
|
|
9170
|
+
style: { background: `linear-gradient(90deg, ${stops.map(([c, a, b]) => `${c} ${a}% ${b}%`).join(", ")})` },
|
|
9171
|
+
children: [marks.map((m) => /* @__PURE__ */ jsx("span", {
|
|
9172
|
+
className: "ui-meter-mark is-" + m.tone,
|
|
9173
|
+
style: { left: m.at + "%" }
|
|
9174
|
+
}, m.tone)), /* @__PURE__ */ jsx("span", {
|
|
9175
|
+
className: "ui-meter-dot is-" + tone,
|
|
9176
|
+
style: { left: pct(value) + "%" }
|
|
9177
|
+
})]
|
|
9178
|
+
}),
|
|
9179
|
+
marks.length ? /* @__PURE__ */ jsx("div", {
|
|
9180
|
+
ref: marksRef,
|
|
9181
|
+
className: cx("ui-meter-marks", stack && "is-stacked"),
|
|
9182
|
+
"aria-hidden": "true",
|
|
9183
|
+
children: marks.map((m) => /* @__PURE__ */ jsx("span", {
|
|
9184
|
+
className: "is-" + m.tone,
|
|
9185
|
+
style: m.tone === "warning" && marks.length > 1 ? { right: 100 - m.at + "%" } : m.at > 80 ? { right: 0 } : { left: m.at + "%" },
|
|
9186
|
+
children: m.text
|
|
9187
|
+
}, m.tone))
|
|
9188
|
+
}) : null
|
|
9189
|
+
]
|
|
9190
|
+
});
|
|
9191
|
+
}
|
|
9192
|
+
// src/components/ZoneMap/ZoneMap.tsx
|
|
9193
|
+
/** A floor plan of zones as rectangles on a grid, each filled by its value (heat scale) with its name, state, figure
|
|
9194
|
+
* and one detail line. Zones are buttons: Tab moves between them, Enter or Space selects. The selected zone has an
|
|
9195
|
+
* ink outline outside it; a zone needing attention has a 4 px warning or danger border and 「⚠」 in its state. */
|
|
9196
|
+
const DATA_TOKEN = /^(heat-[1-7]|diverge-(neg|pos)(-strong)?|diverge-zero|chart-[1-4])$/;
|
|
9197
|
+
function ZoneMap({ zones, label, columns = 4, rowHeight = 120, min = 20, max = 30, selectedId, onSelect, className }) {
|
|
9198
|
+
return /* @__PURE__ */ jsx("div", {
|
|
9199
|
+
className: cx("ui-zonemap", className),
|
|
9200
|
+
role: "group",
|
|
9201
|
+
"aria-label": label,
|
|
9202
|
+
style: {
|
|
9203
|
+
"--zone-cols": columns,
|
|
9204
|
+
gridAutoRows: rowHeight + "px"
|
|
9205
|
+
},
|
|
9206
|
+
children: zones.map((z) => {
|
|
9207
|
+
const place = z.area ? {
|
|
9208
|
+
gridRow: `${z.area.row} / span ${z.area.rows ?? 1}`,
|
|
9209
|
+
gridColumn: `${z.area.col} / span ${z.area.cols ?? 1}`
|
|
9210
|
+
} : void 0;
|
|
9211
|
+
if (z.value == null && !z.forecast) return /* @__PURE__ */ jsxs("div", {
|
|
9212
|
+
className: "ui-zone is-empty",
|
|
9213
|
+
style: place,
|
|
9214
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
9215
|
+
className: "ui-zone-name",
|
|
9216
|
+
children: z.name
|
|
9217
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
9218
|
+
className: "ui-zone-detail",
|
|
9219
|
+
children: tr("沒有資料")
|
|
9220
|
+
})]
|
|
9221
|
+
}, z.id);
|
|
9222
|
+
const tone = z.tone ?? "normal";
|
|
9223
|
+
const fill = z.fill ?? (z.value != null ? heatToken(z.value, min, max) : "surface-sub");
|
|
9224
|
+
const bg = /^[a-z][a-z0-9-]*$/.test(fill) ? `var(--${fill})` : fill;
|
|
9225
|
+
const state = (tone === "normal" ? "" : "⚠ ") + (z.state ?? (z.forecast ? tr("預測") : tr("正常")));
|
|
9226
|
+
const figure = z.value != null ? format.number(z.value, z.decimals ?? 1) : "—";
|
|
9227
|
+
const on = selectedId === z.id;
|
|
9228
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
9229
|
+
type: "button",
|
|
9230
|
+
className: cx("ui-zone", "is-" + tone, z.forecast && "ui-forecast", on && "is-selected"),
|
|
9231
|
+
"data-fill": fill,
|
|
9232
|
+
style: {
|
|
9233
|
+
...place,
|
|
9234
|
+
background: bg,
|
|
9235
|
+
color: DATA_TOKEN.test(fill) ? void 0 : textOn(fill)
|
|
9236
|
+
},
|
|
9237
|
+
"aria-pressed": on,
|
|
9238
|
+
"aria-label": [
|
|
9239
|
+
z.name,
|
|
9240
|
+
figure + (z.unit ? " " + z.unit : ""),
|
|
9241
|
+
state.replace("⚠ ", ""),
|
|
9242
|
+
z.detail
|
|
9243
|
+
].filter(Boolean).join(tr(",")),
|
|
9244
|
+
onClick: () => onSelect?.(z),
|
|
9245
|
+
children: [
|
|
9246
|
+
/* @__PURE__ */ jsxs("span", {
|
|
9247
|
+
className: "ui-zone-head",
|
|
9248
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
9249
|
+
className: "ui-zone-name",
|
|
9250
|
+
children: z.name
|
|
9251
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
9252
|
+
className: "ui-zone-state",
|
|
9253
|
+
children: state
|
|
9254
|
+
})]
|
|
9255
|
+
}),
|
|
9256
|
+
/* @__PURE__ */ jsxs("span", {
|
|
9257
|
+
className: "ui-zone-value",
|
|
9258
|
+
children: [figure, z.unit ? /* @__PURE__ */ jsx("span", {
|
|
9259
|
+
className: "ui-zone-unit",
|
|
9260
|
+
children: z.unit
|
|
9261
|
+
}) : null]
|
|
9262
|
+
}),
|
|
9263
|
+
z.detail ? /* @__PURE__ */ jsx("span", {
|
|
9264
|
+
className: "ui-zone-detail",
|
|
9265
|
+
children: z.detail
|
|
9266
|
+
}) : null
|
|
9267
|
+
]
|
|
9268
|
+
}, z.id);
|
|
9269
|
+
})
|
|
9270
|
+
});
|
|
9271
|
+
}
|
|
9272
|
+
// src/components/EventTimeline/EventTimeline.tsx
|
|
9273
|
+
const KIND = {
|
|
9274
|
+
alert: {
|
|
9275
|
+
icon: "warning",
|
|
9276
|
+
name: "告警"
|
|
9277
|
+
},
|
|
9278
|
+
switch: {
|
|
9279
|
+
icon: "arrows-left-right",
|
|
9280
|
+
name: "切換"
|
|
9281
|
+
},
|
|
9282
|
+
ai: {
|
|
9283
|
+
icon: "sparkle",
|
|
9284
|
+
name: "AI"
|
|
9285
|
+
},
|
|
9286
|
+
manual: {
|
|
9287
|
+
icon: "user",
|
|
9288
|
+
name: "人工"
|
|
9289
|
+
}
|
|
9290
|
+
};
|
|
9291
|
+
/** Events newest first, one row each: the time (Geist Mono), an icon for the kind, and what happened. */
|
|
9292
|
+
function EventTimeline({ events, label, empty, className }) {
|
|
9293
|
+
const list = [...events].sort((a, b) => b.time.getTime() - a.time.getTime());
|
|
9294
|
+
if (!list.length) return /* @__PURE__ */ jsx("p", {
|
|
9295
|
+
className: cx("ui-events-empty", className),
|
|
9296
|
+
children: empty ?? tr("沒有事件")
|
|
9297
|
+
});
|
|
9298
|
+
return /* @__PURE__ */ jsx("ol", {
|
|
9299
|
+
className: cx("ui-events", className),
|
|
9300
|
+
"aria-label": label,
|
|
9301
|
+
children: list.map((e, i) => /* @__PURE__ */ jsxs("li", {
|
|
9302
|
+
className: "is-" + e.kind,
|
|
9303
|
+
children: [
|
|
9304
|
+
/* @__PURE__ */ jsx("time", {
|
|
9305
|
+
className: "ui-events-time",
|
|
9306
|
+
dateTime: e.time.toISOString(),
|
|
9307
|
+
children: format.time(e.time)
|
|
9308
|
+
}),
|
|
9309
|
+
/* @__PURE__ */ jsx("span", {
|
|
9310
|
+
className: "ui-events-kind",
|
|
9311
|
+
role: "img",
|
|
9312
|
+
"aria-label": tr(KIND[e.kind].name),
|
|
9313
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
9314
|
+
name: KIND[e.kind].icon,
|
|
9315
|
+
size: 20
|
|
9316
|
+
})
|
|
9317
|
+
}),
|
|
9318
|
+
/* @__PURE__ */ jsx("span", {
|
|
9319
|
+
className: "ui-events-text",
|
|
9320
|
+
children: e.text
|
|
9321
|
+
})
|
|
9322
|
+
]
|
|
9323
|
+
}, e.id ?? i))
|
|
9324
|
+
});
|
|
9325
|
+
}
|
|
9326
|
+
// src/components/TimeControl/TimeControl.tsx
|
|
9327
|
+
/** The clock of a monitoring screen with replay: the time in 28 px Geist Mono, two lines on what is on show, and
|
|
9328
|
+
* 「回放」 (「停止回放」 while replaying) and 「回到現在」. Laid out as a column for a 400 px side panel. Moving within
|
|
9329
|
+
* the replay is LineChart's playhead. */
|
|
9330
|
+
function TimeControl({ time, replaying, onReplayChange, onNow, status, detail, className }) {
|
|
9331
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
9332
|
+
className: cx("ui-timecontrol", className),
|
|
9333
|
+
"aria-label": tr("時間控制"),
|
|
9334
|
+
children: [
|
|
9335
|
+
/* @__PURE__ */ jsx("time", {
|
|
9336
|
+
className: "ui-timecontrol-clock",
|
|
9337
|
+
dateTime: time.toISOString(),
|
|
9338
|
+
"aria-live": "off",
|
|
9339
|
+
children: format.time(time)
|
|
9340
|
+
}),
|
|
9341
|
+
/* @__PURE__ */ jsx("p", {
|
|
9342
|
+
className: "ui-timecontrol-status",
|
|
9343
|
+
"aria-live": "polite",
|
|
9344
|
+
children: status
|
|
9345
|
+
}),
|
|
9346
|
+
detail ? /* @__PURE__ */ jsx("p", {
|
|
9347
|
+
className: "ui-timecontrol-detail",
|
|
9348
|
+
children: detail
|
|
9349
|
+
}) : null,
|
|
9350
|
+
/* @__PURE__ */ jsxs("div", {
|
|
9351
|
+
className: "ui-timecontrol-actions",
|
|
9352
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
9353
|
+
onClick: () => onReplayChange(!replaying),
|
|
9354
|
+
children: replaying ? tr("停止回放") : tr("回放")
|
|
9355
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
9356
|
+
onClick: onNow,
|
|
9357
|
+
disabled: !replaying,
|
|
9358
|
+
children: tr("回到現在")
|
|
9359
|
+
})]
|
|
8831
9360
|
})
|
|
8832
9361
|
]
|
|
8833
9362
|
});
|
|
@@ -9722,12 +10251,18 @@ function SegmentedControl({ items, value, onChange, label, iconOnly = false, cla
|
|
|
9722
10251
|
});
|
|
9723
10252
|
}
|
|
9724
10253
|
// src/components/Tag/Tag.tsx
|
|
9725
|
-
/** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead. Two
|
|
9726
|
-
*
|
|
10254
|
+
/** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead. Two kinds say where
|
|
10255
|
+
* numbers come from, with an icon and color but no fill: forecast and demo. */
|
|
9727
10256
|
function Tag({ children, variant = "plain", className }) {
|
|
9728
|
-
return /* @__PURE__ */
|
|
10257
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
9729
10258
|
className: cx("ui-tag", variant !== "plain" && "is-" + variant, className),
|
|
9730
|
-
children
|
|
10259
|
+
children: [variant === "forecast" ? /* @__PURE__ */ jsx(Icon, {
|
|
10260
|
+
name: "trend-up",
|
|
10261
|
+
size: 16
|
|
10262
|
+
}) : variant === "demo" ? /* @__PURE__ */ jsx(Icon, {
|
|
10263
|
+
name: "info",
|
|
10264
|
+
size: 16
|
|
10265
|
+
}) : null, children]
|
|
9731
10266
|
});
|
|
9732
10267
|
}
|
|
9733
10268
|
// src/components/TextArea/TextArea.tsx
|
|
@@ -12042,6 +12577,6 @@ function Workbench({ ref, ...p }) {
|
|
|
12042
12577
|
})
|
|
12043
12578
|
});
|
|
12044
12579
|
}
|
|
12045
|
-
export { AccentPicker, ActionBar, AiMark, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Markdown, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Section, SectionGroup, SectionGroupToggle, SegmentedControl, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, Workbench, addMessages, announce, divergeToken, focusMain, format, heatToken, icons, initTheme, isCodeRef, safeHref, setAccent, setLocale, setTheme, tr as t, textOn, useTour, useWorkbench };
|
|
12580
|
+
export { AccentPicker, ActionBar, AiMark, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, EventTimeline, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Markdown, Menu, Meter, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Section, SectionGroup, SectionGroupToggle, SegmentedControl, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, StatusBand, StatusLegend, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, TimeControl, Toast, Tooltip, TopBar, Tour, TreeList, Workbench, ZoneMap, addMessages, announce, divergeToken, focusMain, format, heatToken, icons, initTheme, isCodeRef, safeHref, setAccent, setLocale, setTheme, tr as t, textOn, useTour, useWorkbench };
|
|
12046
12581
|
|
|
12047
12582
|
//# sourceMappingURL=index.js.map
|