@seanyeh77/ui 0.35.0 → 0.37.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 +15 -15
- package/dist/bundle.js.map +1 -1
- package/dist/{format-entry-CubJQqC9.js → format-entry-Mxi5pqut.js} +11 -1
- package/dist/format-entry-Mxi5pqut.js.map +1 -0
- package/dist/format.js +1 -1
- package/dist/index.d.ts +119 -7
- package/dist/index.js +426 -65
- package/dist/index.js.map +1 -1
- package/dist/styles.css +272 -0
- package/dist/tokens.css +28 -0
- package/docs/DataColors.md +46 -0
- package/docs/LineChart.md +43 -2
- package/docs/Meter.md +12 -0
- package/docs/StatusBand.md +24 -0
- package/docs/Tag.md +9 -0
- package/docs/guidelines.md +12 -2
- 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-Mxi5pqut.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";
|
|
@@ -1473,6 +1473,29 @@ function initTheme() {
|
|
|
1473
1473
|
if (storedTheme() === "auto") setTheme("auto");
|
|
1474
1474
|
});
|
|
1475
1475
|
}
|
|
1476
|
+
/** The text color for something drawn on a fill (a heat-scale zone, a status band): the near-black ink of the light
|
|
1477
|
+
* theme (#171512) or white, whichever contrasts more with the fill. `fill` is a color (#hex, rgb()) or a token name
|
|
1478
|
+
* such as 'heat-6', read from el (default: the root) so it follows the theme. Every step of heat-*, diverge-* and
|
|
1479
|
+
* chart-* reaches 4.5:1 with its pick. Unreadable colors give the near-black ink. */
|
|
1480
|
+
function textOn(fill, el) {
|
|
1481
|
+
let c = fill.trim();
|
|
1482
|
+
if (/^[a-z][a-z0-9-]*$/.test(c) && typeof document !== "undefined") c = getComputedStyle(el ?? document.documentElement).getPropertyValue("--" + c);
|
|
1483
|
+
const hex = toHex(c);
|
|
1484
|
+
if (!hex) return "#171512";
|
|
1485
|
+
return contrast(hex, "#171512") >= contrast(hex, "#ffffff") ? "#171512" : "#ffffff";
|
|
1486
|
+
}
|
|
1487
|
+
/** The heat-scale token for a value: min (or below) is heat-1, max (or above) is heat-7, evenly in between. */
|
|
1488
|
+
function heatToken(value, min, max) {
|
|
1489
|
+
const t = max > min ? (value - min) / (max - min) : 0;
|
|
1490
|
+
return `heat-${Math.min(7, Math.max(1, Math.round(t * 6) + 1))}`;
|
|
1491
|
+
}
|
|
1492
|
+
/** The diverging-scale token for a difference: within ±zero it is diverge-zero; from ±strong on, the -strong step. */
|
|
1493
|
+
function divergeToken(diff, limits) {
|
|
1494
|
+
const a = Math.abs(diff);
|
|
1495
|
+
if (a <= limits.zero) return "diverge-zero";
|
|
1496
|
+
const strong = a >= limits.strong;
|
|
1497
|
+
return diff < 0 ? strong ? "diverge-neg-strong" : "diverge-neg" : strong ? "diverge-pos-strong" : "diverge-pos";
|
|
1498
|
+
}
|
|
1476
1499
|
// src/components/AccentPicker/AccentPicker.tsx
|
|
1477
1500
|
const SWATCHES = [
|
|
1478
1501
|
["藍", "#2457d6"],
|
|
@@ -1892,7 +1915,8 @@ function smoothPath(p) {
|
|
|
1892
1915
|
const CHART = [
|
|
1893
1916
|
"var(--chart-1)",
|
|
1894
1917
|
"var(--chart-2)",
|
|
1895
|
-
"var(--chart-3)"
|
|
1918
|
+
"var(--chart-3)",
|
|
1919
|
+
"var(--chart-4)"
|
|
1896
1920
|
];
|
|
1897
1921
|
/** The color of series i. */
|
|
1898
1922
|
const seriesColor = (i) => CHART[i % CHART.length];
|
|
@@ -8696,107 +8720,328 @@ function LayerGraph(p) {
|
|
|
8696
8720
|
]
|
|
8697
8721
|
});
|
|
8698
8722
|
}
|
|
8723
|
+
// src/components/StatusBand/StatusBand.tsx
|
|
8724
|
+
/** 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
|
|
8725
|
+
* 10 minutes; under a LineChart (its `status`) or on its own. The legend below gives the words. */
|
|
8726
|
+
function StatusBand({ segments, classes, label, count, times, legend = true, className }) {
|
|
8727
|
+
const color = (v) => seriesColor(Math.max(0, classes.findIndex((c) => c.value === v)));
|
|
8728
|
+
const name = (v) => classes.find((c) => c.value === v)?.label ?? v;
|
|
8729
|
+
const said = segments.map((s) => (times ? times[s.from] + " " + tr("到") + " " + (times[s.to] ?? times[times.length - 1]) + " " : "") + name(s.value)).join(tr(","));
|
|
8730
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
8731
|
+
className: cx("ui-statusband", className),
|
|
8732
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
8733
|
+
className: "ui-statusband-bar",
|
|
8734
|
+
role: "img",
|
|
8735
|
+
"aria-label": label + tr(":") + (said || tr("沒有資料")),
|
|
8736
|
+
children: segments.map((s, i) => /* @__PURE__ */ jsx("span", { style: {
|
|
8737
|
+
left: s.from / count * 100 + "%",
|
|
8738
|
+
width: (Math.min(count, s.to) - s.from) / count * 100 + "%",
|
|
8739
|
+
background: color(s.value)
|
|
8740
|
+
} }, i))
|
|
8741
|
+
}), legend ? /* @__PURE__ */ jsx(StatusLegend, {
|
|
8742
|
+
classes,
|
|
8743
|
+
label
|
|
8744
|
+
}) : null]
|
|
8745
|
+
});
|
|
8746
|
+
}
|
|
8747
|
+
/** The legend of a StatusBand: its label, then a swatch and the words for each class. */
|
|
8748
|
+
function StatusLegend({ classes, label }) {
|
|
8749
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
8750
|
+
className: "ui-chart-legend ui-statusband-legend",
|
|
8751
|
+
"aria-hidden": "true",
|
|
8752
|
+
children: [/* @__PURE__ */ jsx("span", { children: label }), classes.map((c, i) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
|
|
8753
|
+
className: "ui-chart-swatch",
|
|
8754
|
+
style: { background: seriesColor(i) }
|
|
8755
|
+
}), c.label] }, c.value))]
|
|
8756
|
+
});
|
|
8757
|
+
}
|
|
8699
8758
|
// src/components/LineChart/LineChart.tsx
|
|
8759
|
+
const W = 640;
|
|
8700
8760
|
const L = 40;
|
|
8701
8761
|
const R = 630;
|
|
8762
|
+
const T = 10;
|
|
8702
8763
|
const B = 210;
|
|
8703
|
-
/**
|
|
8704
|
-
function
|
|
8764
|
+
/** Runs of consecutive points that have values. */
|
|
8765
|
+
function runs(values, X, Y) {
|
|
8766
|
+
const out = [];
|
|
8767
|
+
let cur = [];
|
|
8768
|
+
values.forEach((v, i) => {
|
|
8769
|
+
if (v == null || Number.isNaN(v)) {
|
|
8770
|
+
if (cur.length) out.push(cur);
|
|
8771
|
+
cur = [];
|
|
8772
|
+
} else cur.push([X(i), Y(v)]);
|
|
8773
|
+
});
|
|
8774
|
+
if (cur.length) out.push(cur);
|
|
8775
|
+
return out;
|
|
8776
|
+
}
|
|
8777
|
+
/** A trend over time: smooth lines, 5 grid lines, a guide and tooltip on hover. For monitoring it can also compare a
|
|
8778
|
+
* forecast with what happened (band, now, thresholds, marker) and replay with a playhead. */
|
|
8779
|
+
const colorOf = (s, i) => s?.color ? seriesColor(s.color - 1) : seriesColor(i);
|
|
8780
|
+
function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelEvery = 1, band, now, thresholds, marker, playhead, onPlayheadChange, headline, status, empty, className }) {
|
|
8705
8781
|
const [hi, setHi] = React.useState(-1);
|
|
8706
|
-
const
|
|
8782
|
+
const stripes = "ui-stripes-" + React.useId().replace(/:/g, "");
|
|
8783
|
+
const dragging = React.useRef(false);
|
|
8784
|
+
const all = series.flatMap((s) => s.values.filter((v) => v != null));
|
|
8785
|
+
const top = max ?? niceMax(Math.max(min + 1, ...all, ...(thresholds ?? []).map((t) => t.value)) - min) + min;
|
|
8707
8786
|
const n = labels.length || series[0]?.values.length || 0;
|
|
8708
8787
|
const step = 590 / Math.max(1, n - 1);
|
|
8709
8788
|
const X = (i) => L + i * step;
|
|
8710
|
-
const Y = (v) => B - v / top * 200;
|
|
8711
|
-
const ticks = TICKS.map((f) => f * top);
|
|
8789
|
+
const Y = (v) => B - (v - min) / (top - min) * 200;
|
|
8790
|
+
const ticks = TICKS.map((f) => min + f * (top - min));
|
|
8712
8791
|
const suffix = unit ? " " + unit : "";
|
|
8792
|
+
const num = (v) => v == null ? "—" : format.number(v, decimals) + suffix;
|
|
8793
|
+
const replay = playhead != null && !!onPlayheadChange;
|
|
8713
8794
|
const show = (j) => {
|
|
8714
8795
|
setHi(j);
|
|
8715
|
-
announce(labels[j] + tr(":") + series.map((s) => (series.length > 1 ? s.name + " " : "") +
|
|
8796
|
+
announce(labels[j] + tr(":") + series.filter((s) => s.values[j] != null).map((s) => (series.length > 1 ? s.name + " " : "") + num(s.values[j])).join(tr(",")));
|
|
8797
|
+
};
|
|
8798
|
+
const move = (j) => {
|
|
8799
|
+
if (replay) onPlayheadChange(j);
|
|
8800
|
+
show(j);
|
|
8801
|
+
};
|
|
8802
|
+
const at = (e) => {
|
|
8803
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
8804
|
+
const x = (e.clientX - r.left) / r.width * W;
|
|
8805
|
+
return Math.max(0, Math.min(n - 1, Math.round((x - L) / step)));
|
|
8716
8806
|
};
|
|
8717
8807
|
const edge = {
|
|
8718
|
-
left: (L - step / 2) /
|
|
8719
|
-
right: (10 - step / 2) /
|
|
8808
|
+
left: (L - step / 2) / W * 100 + "%",
|
|
8809
|
+
right: (10 - step / 2) / W * 100 + "%"
|
|
8720
8810
|
};
|
|
8811
|
+
const legend = series.length > 1 || band;
|
|
8812
|
+
const bandShapes = [];
|
|
8813
|
+
if (band) {
|
|
8814
|
+
const a = series[band.between[0]]?.values ?? [];
|
|
8815
|
+
const b = series[band.between[1]]?.values ?? [];
|
|
8816
|
+
for (let i = 0; i < n - 1; i++) {
|
|
8817
|
+
const a0 = a[i], a1 = a[i + 1], b0 = b[i], b1 = b[i + 1];
|
|
8818
|
+
if (a0 == null || a1 == null || b0 == null || b1 == null) continue;
|
|
8819
|
+
bandShapes.push({
|
|
8820
|
+
d: `M${X(i)},${Y(a0)} L${X(i + 1)},${Y(a1)} L${X(i + 1)},${Y(b1)} L${X(i)},${Y(b0)} Z`,
|
|
8821
|
+
up: a0 + a1 >= b0 + b1
|
|
8822
|
+
});
|
|
8823
|
+
}
|
|
8824
|
+
}
|
|
8825
|
+
const tipRows = (j) => {
|
|
8826
|
+
const rows = series.map((s, i) => ({
|
|
8827
|
+
color: colorOf(series[i], i),
|
|
8828
|
+
name: s.name,
|
|
8829
|
+
value: s.values[j]
|
|
8830
|
+
})).filter((r) => r.value != null).map((r) => ({
|
|
8831
|
+
...r,
|
|
8832
|
+
value: num(r.value)
|
|
8833
|
+
}));
|
|
8834
|
+
if (band) {
|
|
8835
|
+
const a = series[band.between[0]]?.values[j];
|
|
8836
|
+
const b = series[band.between[1]]?.values[j];
|
|
8837
|
+
if (a != null && b != null) rows.push({
|
|
8838
|
+
color: "",
|
|
8839
|
+
name: tr("差"),
|
|
8840
|
+
value: (a - b > 0 ? "+" : "") + num(a - b)
|
|
8841
|
+
});
|
|
8842
|
+
}
|
|
8843
|
+
return rows;
|
|
8844
|
+
};
|
|
8845
|
+
const shown = hi >= 0 ? hi : -1;
|
|
8721
8846
|
return /* @__PURE__ */ jsxs("div", {
|
|
8722
8847
|
className: cx("ui-chart", className),
|
|
8723
8848
|
children: [
|
|
8724
|
-
|
|
8849
|
+
headline ? /* @__PURE__ */ jsx("div", {
|
|
8850
|
+
className: "ui-chart-headline",
|
|
8851
|
+
children: headline
|
|
8852
|
+
}) : null,
|
|
8853
|
+
legend ? /* @__PURE__ */ jsxs("div", {
|
|
8725
8854
|
className: "ui-chart-legend",
|
|
8726
|
-
children: series.map((s, i) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
|
|
8727
|
-
className: "ui-chart-swatch",
|
|
8728
|
-
style: {
|
|
8729
|
-
|
|
8855
|
+
children: [series.map((s, i) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
|
|
8856
|
+
className: cx("ui-chart-swatch", s.dashed && "is-dashed"),
|
|
8857
|
+
style: {
|
|
8858
|
+
background: s.dashed ? void 0 : colorOf(series[i], i),
|
|
8859
|
+
color: colorOf(series[i], i)
|
|
8860
|
+
}
|
|
8861
|
+
}), s.name] }, i)), band ? /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", { className: cx("ui-chart-swatch", "is-band", "is-" + band.tone) }), band.label] }) : null]
|
|
8730
8862
|
}) : null,
|
|
8731
8863
|
/* @__PURE__ */ jsxs("div", {
|
|
8732
|
-
className: "ui-chart-plot",
|
|
8864
|
+
className: cx("ui-chart-plot", replay && "is-replay"),
|
|
8733
8865
|
tabIndex: n ? 0 : void 0,
|
|
8734
8866
|
role: "group",
|
|
8735
8867
|
"aria-label": label,
|
|
8736
|
-
"aria-description": tr("左右方向鍵查看每一個時間點的數值"),
|
|
8737
|
-
onMouseLeave: () => setHi(-1),
|
|
8738
|
-
onFocus: () => hi < 0 && n && show(0),
|
|
8868
|
+
"aria-description": replay ? tr("左右方向鍵移動播放頭") : tr("左右方向鍵查看每一個時間點的數值"),
|
|
8869
|
+
onMouseLeave: () => !dragging.current && setHi(-1),
|
|
8870
|
+
onFocus: () => hi < 0 && n && show(replay ? playhead : 0),
|
|
8739
8871
|
onBlur: () => setHi(-1),
|
|
8740
8872
|
onKeyDown: (e) => {
|
|
8741
|
-
const to = chartKey(e, hi, n);
|
|
8742
|
-
if (to != null)
|
|
8873
|
+
const to = chartKey(e, replay ? playhead : hi, n);
|
|
8874
|
+
if (to != null) move(to);
|
|
8875
|
+
},
|
|
8876
|
+
onPointerDown: replay ? (e) => {
|
|
8877
|
+
if (e.button !== 0) return;
|
|
8878
|
+
dragging.current = true;
|
|
8879
|
+
try {
|
|
8880
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
8881
|
+
} catch {}
|
|
8882
|
+
move(at(e));
|
|
8883
|
+
} : void 0,
|
|
8884
|
+
onPointerMove: replay ? (e) => {
|
|
8885
|
+
if (dragging.current) move(at(e));
|
|
8886
|
+
} : void 0,
|
|
8887
|
+
onPointerUp: () => {
|
|
8888
|
+
dragging.current = false;
|
|
8889
|
+
},
|
|
8890
|
+
onPointerCancel: () => {
|
|
8891
|
+
dragging.current = false;
|
|
8743
8892
|
},
|
|
8744
8893
|
children: [
|
|
8745
8894
|
/* @__PURE__ */ jsxs("svg", {
|
|
8746
|
-
viewBox:
|
|
8895
|
+
viewBox: `0 0 ${W} 240`,
|
|
8747
8896
|
width: "100%",
|
|
8748
8897
|
"aria-hidden": "true",
|
|
8749
|
-
children: [
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
8757
|
-
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8898
|
+
children: [
|
|
8899
|
+
now != null && now < n - 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("pattern", {
|
|
8900
|
+
id: stripes,
|
|
8901
|
+
width: "9",
|
|
8902
|
+
height: "9",
|
|
8903
|
+
patternUnits: "userSpaceOnUse",
|
|
8904
|
+
patternTransform: "rotate(45)",
|
|
8905
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
8906
|
+
width: "4",
|
|
8907
|
+
height: "9",
|
|
8908
|
+
className: "ui-chart-stripe"
|
|
8909
|
+
})
|
|
8910
|
+
}) }), /* @__PURE__ */ jsx("rect", {
|
|
8911
|
+
x: X(now),
|
|
8912
|
+
y: T,
|
|
8913
|
+
width: R - X(now),
|
|
8914
|
+
height: 200,
|
|
8915
|
+
fill: `url(#${stripes})`
|
|
8916
|
+
})] }) : null,
|
|
8917
|
+
ticks.map((v, i) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
|
|
8918
|
+
x1: L,
|
|
8919
|
+
x2: R,
|
|
8920
|
+
y1: Y(v),
|
|
8921
|
+
y2: Y(v),
|
|
8922
|
+
className: i ? "ui-chart-grid" : "ui-chart-axis"
|
|
8923
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
8924
|
+
x: 32,
|
|
8925
|
+
y: Y(v) + 4,
|
|
8926
|
+
textAnchor: "end",
|
|
8927
|
+
className: "ui-chart-tick",
|
|
8928
|
+
children: format.number(v, tickDecimals(top - min))
|
|
8929
|
+
})] }, i)),
|
|
8930
|
+
bandShapes.map((s, i) => /* @__PURE__ */ jsx("path", {
|
|
8931
|
+
d: s.d,
|
|
8932
|
+
className: cx("ui-chart-band", band?.tone === "success" ? "is-success" : s.up ? "is-pos" : "is-neg")
|
|
8933
|
+
}, i)),
|
|
8934
|
+
(thresholds ?? []).map((t, i) => /* @__PURE__ */ jsxs("g", {
|
|
8935
|
+
className: "ui-chart-threshold is-" + t.tone,
|
|
8936
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
8937
|
+
x1: L,
|
|
8938
|
+
x2: R,
|
|
8939
|
+
y1: Y(t.value),
|
|
8940
|
+
y2: Y(t.value)
|
|
8941
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
8942
|
+
x: 628,
|
|
8943
|
+
y: Y(t.value) - 5,
|
|
8944
|
+
textAnchor: "end",
|
|
8945
|
+
children: t.label
|
|
8946
|
+
})]
|
|
8947
|
+
}, i)),
|
|
8948
|
+
series.map((s, i) => runs(s.values, X, Y).map((pts, k) => /* @__PURE__ */ jsx("path", {
|
|
8949
|
+
d: smoothPath(pts),
|
|
8950
|
+
pathLength: s.dashed ? void 0 : 1,
|
|
8951
|
+
className: cx("ui-chart-line", s.dashed && "is-dashed"),
|
|
8952
|
+
style: {
|
|
8953
|
+
stroke: colorOf(series[i], i),
|
|
8954
|
+
animationDelay: i * 150 + "ms"
|
|
8955
|
+
}
|
|
8956
|
+
}, i + "-" + k))),
|
|
8957
|
+
now != null ? /* @__PURE__ */ jsxs("g", {
|
|
8958
|
+
className: "ui-chart-now",
|
|
8959
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
8960
|
+
x1: X(now),
|
|
8961
|
+
x2: X(now),
|
|
8962
|
+
y1: 6,
|
|
8963
|
+
y2: B
|
|
8964
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
8965
|
+
x: X(now),
|
|
8966
|
+
y: 2,
|
|
8967
|
+
textAnchor: "middle",
|
|
8968
|
+
children: tr("現在")
|
|
8969
|
+
})]
|
|
8970
|
+
}) : null,
|
|
8971
|
+
marker ? /* @__PURE__ */ jsxs("g", {
|
|
8972
|
+
className: "ui-chart-marker",
|
|
8973
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
8974
|
+
cx: X(marker.at),
|
|
8975
|
+
cy: Y(marker.value),
|
|
8976
|
+
r: 5.5,
|
|
8977
|
+
style: { stroke: colorOf(series[marker.series ?? series.length - 1], marker.series ?? series.length - 1) }
|
|
8978
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
8979
|
+
x: X(marker.at) + (marker.at > n * .7 ? -10 : 10),
|
|
8980
|
+
y: Y(marker.value) + 20,
|
|
8981
|
+
textAnchor: marker.at > n * .7 ? "end" : "start",
|
|
8982
|
+
children: marker.label
|
|
8983
|
+
})]
|
|
8984
|
+
}) : null,
|
|
8985
|
+
replay ? /* @__PURE__ */ jsxs("g", {
|
|
8986
|
+
className: "ui-chart-playhead",
|
|
8987
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
8988
|
+
x1: X(playhead),
|
|
8989
|
+
x2: X(playhead),
|
|
8990
|
+
y1: T,
|
|
8991
|
+
y2: B
|
|
8992
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
8993
|
+
cx: X(playhead),
|
|
8994
|
+
cy: B,
|
|
8995
|
+
r: 8
|
|
8996
|
+
})]
|
|
8997
|
+
}) : null
|
|
8998
|
+
]
|
|
8770
8999
|
}),
|
|
8771
9000
|
/* @__PURE__ */ jsx("div", {
|
|
8772
9001
|
className: "ui-chart-hit",
|
|
8773
9002
|
style: edge,
|
|
8774
9003
|
children: labels.map((_, j) => /* @__PURE__ */ jsx("div", {
|
|
8775
|
-
onMouseEnter: () => setHi(j),
|
|
9004
|
+
onMouseEnter: () => !dragging.current && setHi(j),
|
|
8776
9005
|
className: "ui-chart-col",
|
|
8777
|
-
children:
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
9006
|
+
children: shown === j ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", { className: "ui-chart-guide" }), series.map((s, i) => {
|
|
9007
|
+
const v = s.values[j];
|
|
9008
|
+
return v == null ? null : /* @__PURE__ */ jsx("span", {
|
|
9009
|
+
className: "ui-chart-dot",
|
|
9010
|
+
style: {
|
|
9011
|
+
top: Y(v) / B * 100 + "%",
|
|
9012
|
+
background: colorOf(series[i], i)
|
|
9013
|
+
}
|
|
9014
|
+
}, i);
|
|
9015
|
+
})] }) : null
|
|
8784
9016
|
}, j))
|
|
8785
9017
|
}),
|
|
8786
|
-
|
|
8787
|
-
|
|
9018
|
+
!all.length ? /* @__PURE__ */ jsx("div", {
|
|
9019
|
+
className: "ui-chart-empty",
|
|
9020
|
+
children: empty ?? tr("這段時間沒有資料")
|
|
9021
|
+
}) : null,
|
|
9022
|
+
shown >= 0 ? /* @__PURE__ */ jsx(ChartTip, {
|
|
9023
|
+
title: labels[shown],
|
|
8788
9024
|
style: {
|
|
8789
|
-
left: X(
|
|
8790
|
-
transform:
|
|
9025
|
+
left: X(shown) / W * 100 + "%",
|
|
9026
|
+
transform: shown > n * .65 ? "translateX(calc(-100% - 12px))" : "translateX(12px)"
|
|
8791
9027
|
},
|
|
8792
|
-
rows:
|
|
8793
|
-
color: seriesColor(i),
|
|
8794
|
-
name: s.name,
|
|
8795
|
-
value: format.number(s.values[hi], decimals) + suffix
|
|
8796
|
-
}))
|
|
9028
|
+
rows: tipRows(shown)
|
|
8797
9029
|
}) : null
|
|
8798
9030
|
]
|
|
8799
9031
|
}),
|
|
9032
|
+
status ? /* @__PURE__ */ jsx("div", {
|
|
9033
|
+
style: {
|
|
9034
|
+
marginLeft: edge.left,
|
|
9035
|
+
marginRight: edge.right
|
|
9036
|
+
},
|
|
9037
|
+
children: /* @__PURE__ */ jsx(StatusBand, {
|
|
9038
|
+
...status,
|
|
9039
|
+
count: n,
|
|
9040
|
+
times: labels,
|
|
9041
|
+
legend: false,
|
|
9042
|
+
className: "is-attached"
|
|
9043
|
+
})
|
|
9044
|
+
}) : null,
|
|
8800
9045
|
/* @__PURE__ */ jsx("div", {
|
|
8801
9046
|
className: "ui-chart-xlabels",
|
|
8802
9047
|
style: {
|
|
@@ -8804,7 +9049,122 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
|
|
|
8804
9049
|
marginRight: edge.right
|
|
8805
9050
|
},
|
|
8806
9051
|
children: labels.map((lb, j) => /* @__PURE__ */ jsx("span", { children: labelEvery > 1 && j % labelEvery ? "" : digits(lb) }, j))
|
|
8807
|
-
})
|
|
9052
|
+
}),
|
|
9053
|
+
status ? /* @__PURE__ */ jsx(StatusLegend, {
|
|
9054
|
+
classes: status.classes,
|
|
9055
|
+
label: status.label
|
|
9056
|
+
}) : null
|
|
9057
|
+
]
|
|
9058
|
+
});
|
|
9059
|
+
}
|
|
9060
|
+
// src/components/Meter/Meter.tsx
|
|
9061
|
+
/** A value against its levels: an 8 px bar shaded normal, watch and over the limit, a dot at the value, and the value
|
|
9062
|
+
* with its state in words above. Meters stacked in a card line up: the state and the value end at the same places. */
|
|
9063
|
+
function Meter({ label, value, min, max, warn, limit, unit, decimals = 0, className }) {
|
|
9064
|
+
const span = max - min || 1;
|
|
9065
|
+
const pct = (v) => Math.max(0, Math.min(100, (v - min) / span * 100));
|
|
9066
|
+
const tone = limit != null && value >= limit ? "danger" : warn != null && value >= warn ? "warning" : "success";
|
|
9067
|
+
const state = tone === "danger" ? tr("⚠ 超過上限") : tone === "warning" ? tr("⚠ 注意") : tr("正常");
|
|
9068
|
+
const num = (v) => format.number(v, decimals) + (unit ? " " + unit : "");
|
|
9069
|
+
const markNum = (v) => format.number(v, (String(v).split(".")[1] ?? "").length);
|
|
9070
|
+
const marksRef = React.useRef(null);
|
|
9071
|
+
const [stack, setStack] = React.useState(false);
|
|
9072
|
+
const w = warn != null ? pct(warn) : null;
|
|
9073
|
+
const l = limit != null ? pct(limit) : null;
|
|
9074
|
+
const stops = [
|
|
9075
|
+
[
|
|
9076
|
+
"var(--meter-ok)",
|
|
9077
|
+
0,
|
|
9078
|
+
w ?? l ?? 100
|
|
9079
|
+
],
|
|
9080
|
+
...w != null ? [[
|
|
9081
|
+
"var(--meter-warn)",
|
|
9082
|
+
w,
|
|
9083
|
+
l ?? 100
|
|
9084
|
+
]] : [],
|
|
9085
|
+
...l != null ? [[
|
|
9086
|
+
"var(--meter-over)",
|
|
9087
|
+
l,
|
|
9088
|
+
100
|
|
9089
|
+
]] : []
|
|
9090
|
+
];
|
|
9091
|
+
const marks = [...warn != null ? [{
|
|
9092
|
+
v: warn,
|
|
9093
|
+
at: w,
|
|
9094
|
+
tone: "warning",
|
|
9095
|
+
text: tr("注意 {v}", { v: markNum(warn) })
|
|
9096
|
+
}] : [], ...limit != null ? [{
|
|
9097
|
+
v: limit,
|
|
9098
|
+
at: l,
|
|
9099
|
+
tone: "danger",
|
|
9100
|
+
text: tr("上限 {v}", { v: markNum(limit) })
|
|
9101
|
+
}] : []];
|
|
9102
|
+
React.useLayoutEffect(() => {
|
|
9103
|
+
const box = marksRef.current;
|
|
9104
|
+
if (!box) return;
|
|
9105
|
+
const check = () => {
|
|
9106
|
+
const [a, b] = [...box.children].map((c) => c.getBoundingClientRect());
|
|
9107
|
+
setStack(!!a && !!b && a.right + 8 > b.left && a.left < b.right + 8);
|
|
9108
|
+
};
|
|
9109
|
+
check();
|
|
9110
|
+
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(check) : null;
|
|
9111
|
+
ro?.observe(box);
|
|
9112
|
+
return () => ro?.disconnect();
|
|
9113
|
+
}, [
|
|
9114
|
+
warn,
|
|
9115
|
+
limit,
|
|
9116
|
+
min,
|
|
9117
|
+
max
|
|
9118
|
+
]);
|
|
9119
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
9120
|
+
className: cx("ui-meter", className),
|
|
9121
|
+
role: "meter",
|
|
9122
|
+
"aria-label": label,
|
|
9123
|
+
"aria-valuenow": value,
|
|
9124
|
+
"aria-valuemin": min,
|
|
9125
|
+
"aria-valuemax": max,
|
|
9126
|
+
"aria-valuetext": num(value) + tr(",") + state.replace("⚠ ", "") + marks.map((m) => tr(",") + m.text).join(""),
|
|
9127
|
+
children: [
|
|
9128
|
+
/* @__PURE__ */ jsxs("div", {
|
|
9129
|
+
className: "ui-meter-head",
|
|
9130
|
+
"aria-hidden": "true",
|
|
9131
|
+
children: [
|
|
9132
|
+
/* @__PURE__ */ jsx("span", {
|
|
9133
|
+
className: "ui-meter-label",
|
|
9134
|
+
children: label
|
|
9135
|
+
}),
|
|
9136
|
+
/* @__PURE__ */ jsx("span", {
|
|
9137
|
+
className: "ui-meter-state is-" + tone,
|
|
9138
|
+
children: state
|
|
9139
|
+
}),
|
|
9140
|
+
/* @__PURE__ */ jsx("span", {
|
|
9141
|
+
className: "ui-meter-value",
|
|
9142
|
+
children: num(value)
|
|
9143
|
+
})
|
|
9144
|
+
]
|
|
9145
|
+
}),
|
|
9146
|
+
/* @__PURE__ */ jsxs("div", {
|
|
9147
|
+
className: "ui-meter-track",
|
|
9148
|
+
"aria-hidden": "true",
|
|
9149
|
+
style: { background: `linear-gradient(90deg, ${stops.map(([c, a, b]) => `${c} ${a}% ${b}%`).join(", ")})` },
|
|
9150
|
+
children: [marks.map((m) => /* @__PURE__ */ jsx("span", {
|
|
9151
|
+
className: "ui-meter-mark is-" + m.tone,
|
|
9152
|
+
style: { left: m.at + "%" }
|
|
9153
|
+
}, m.tone)), /* @__PURE__ */ jsx("span", {
|
|
9154
|
+
className: "ui-meter-dot is-" + tone,
|
|
9155
|
+
style: { left: pct(value) + "%" }
|
|
9156
|
+
})]
|
|
9157
|
+
}),
|
|
9158
|
+
marks.length ? /* @__PURE__ */ jsx("div", {
|
|
9159
|
+
ref: marksRef,
|
|
9160
|
+
className: cx("ui-meter-marks", stack && "is-stacked"),
|
|
9161
|
+
"aria-hidden": "true",
|
|
9162
|
+
children: marks.map((m) => /* @__PURE__ */ jsx("span", {
|
|
9163
|
+
className: "is-" + m.tone,
|
|
9164
|
+
style: m.tone === "warning" && marks.length > 1 ? { right: 100 - m.at + "%" } : m.at > 80 ? { right: 0 } : { left: m.at + "%" },
|
|
9165
|
+
children: m.text
|
|
9166
|
+
}, m.tone))
|
|
9167
|
+
}) : null
|
|
8808
9168
|
]
|
|
8809
9169
|
});
|
|
8810
9170
|
}
|
|
@@ -9698,10 +10058,11 @@ function SegmentedControl({ items, value, onChange, label, iconOnly = false, cla
|
|
|
9698
10058
|
});
|
|
9699
10059
|
}
|
|
9700
10060
|
// src/components/Tag/Tag.tsx
|
|
9701
|
-
/** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead.
|
|
9702
|
-
|
|
10061
|
+
/** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead. Two filled kinds say
|
|
10062
|
+
* where numbers come from: forecast and demo. */
|
|
10063
|
+
function Tag({ children, variant = "plain", className }) {
|
|
9703
10064
|
return /* @__PURE__ */ jsx("span", {
|
|
9704
|
-
className: cx("ui-tag", className),
|
|
10065
|
+
className: cx("ui-tag", variant !== "plain" && "is-" + variant, className),
|
|
9705
10066
|
children
|
|
9706
10067
|
});
|
|
9707
10068
|
}
|
|
@@ -12017,6 +12378,6 @@ function Workbench({ ref, ...p }) {
|
|
|
12017
12378
|
})
|
|
12018
12379
|
});
|
|
12019
12380
|
}
|
|
12020
|
-
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, focusMain, format, icons, initTheme, isCodeRef, safeHref, setAccent, setLocale, setTheme, tr as t, useTour, useWorkbench };
|
|
12381
|
+
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, 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, 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 };
|
|
12021
12382
|
|
|
12022
12383
|
//# sourceMappingURL=index.js.map
|