@seanyeh77/ui 0.36.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 +3 -3
- 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 +99 -4
- package/dist/index.js +397 -61
- package/dist/index.js.map +1 -1
- package/dist/styles.css +235 -0
- package/docs/LineChart.md +42 -1
- package/docs/Meter.md +12 -0
- package/docs/StatusBand.md +24 -0
- package/docs/guidelines.md +6 -1
- 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";
|
|
@@ -8720,107 +8720,328 @@ function LayerGraph(p) {
|
|
|
8720
8720
|
]
|
|
8721
8721
|
});
|
|
8722
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
|
+
}
|
|
8723
8758
|
// src/components/LineChart/LineChart.tsx
|
|
8759
|
+
const W = 640;
|
|
8724
8760
|
const L = 40;
|
|
8725
8761
|
const R = 630;
|
|
8762
|
+
const T = 10;
|
|
8726
8763
|
const B = 210;
|
|
8727
|
-
/**
|
|
8728
|
-
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 }) {
|
|
8729
8781
|
const [hi, setHi] = React.useState(-1);
|
|
8730
|
-
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;
|
|
8731
8786
|
const n = labels.length || series[0]?.values.length || 0;
|
|
8732
8787
|
const step = 590 / Math.max(1, n - 1);
|
|
8733
8788
|
const X = (i) => L + i * step;
|
|
8734
|
-
const Y = (v) => B - v / top * 200;
|
|
8735
|
-
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));
|
|
8736
8791
|
const suffix = unit ? " " + unit : "";
|
|
8792
|
+
const num = (v) => v == null ? "—" : format.number(v, decimals) + suffix;
|
|
8793
|
+
const replay = playhead != null && !!onPlayheadChange;
|
|
8737
8794
|
const show = (j) => {
|
|
8738
8795
|
setHi(j);
|
|
8739
|
-
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)));
|
|
8740
8806
|
};
|
|
8741
8807
|
const edge = {
|
|
8742
|
-
left: (L - step / 2) /
|
|
8743
|
-
right: (10 - step / 2) /
|
|
8808
|
+
left: (L - step / 2) / W * 100 + "%",
|
|
8809
|
+
right: (10 - step / 2) / W * 100 + "%"
|
|
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;
|
|
8744
8844
|
};
|
|
8845
|
+
const shown = hi >= 0 ? hi : -1;
|
|
8745
8846
|
return /* @__PURE__ */ jsxs("div", {
|
|
8746
8847
|
className: cx("ui-chart", className),
|
|
8747
8848
|
children: [
|
|
8748
|
-
|
|
8849
|
+
headline ? /* @__PURE__ */ jsx("div", {
|
|
8850
|
+
className: "ui-chart-headline",
|
|
8851
|
+
children: headline
|
|
8852
|
+
}) : null,
|
|
8853
|
+
legend ? /* @__PURE__ */ jsxs("div", {
|
|
8749
8854
|
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
|
-
|
|
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]
|
|
8754
8862
|
}) : null,
|
|
8755
8863
|
/* @__PURE__ */ jsxs("div", {
|
|
8756
|
-
className: "ui-chart-plot",
|
|
8864
|
+
className: cx("ui-chart-plot", replay && "is-replay"),
|
|
8757
8865
|
tabIndex: n ? 0 : void 0,
|
|
8758
8866
|
role: "group",
|
|
8759
8867
|
"aria-label": label,
|
|
8760
|
-
"aria-description": tr("左右方向鍵查看每一個時間點的數值"),
|
|
8761
|
-
onMouseLeave: () => setHi(-1),
|
|
8762
|
-
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),
|
|
8763
8871
|
onBlur: () => setHi(-1),
|
|
8764
8872
|
onKeyDown: (e) => {
|
|
8765
|
-
const to = chartKey(e, hi, n);
|
|
8766
|
-
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;
|
|
8767
8892
|
},
|
|
8768
8893
|
children: [
|
|
8769
8894
|
/* @__PURE__ */ jsxs("svg", {
|
|
8770
|
-
viewBox:
|
|
8895
|
+
viewBox: `0 0 ${W} 240`,
|
|
8771
8896
|
width: "100%",
|
|
8772
8897
|
"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
|
-
|
|
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
|
+
]
|
|
8794
8999
|
}),
|
|
8795
9000
|
/* @__PURE__ */ jsx("div", {
|
|
8796
9001
|
className: "ui-chart-hit",
|
|
8797
9002
|
style: edge,
|
|
8798
9003
|
children: labels.map((_, j) => /* @__PURE__ */ jsx("div", {
|
|
8799
|
-
onMouseEnter: () => setHi(j),
|
|
9004
|
+
onMouseEnter: () => !dragging.current && setHi(j),
|
|
8800
9005
|
className: "ui-chart-col",
|
|
8801
|
-
children:
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
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
|
|
8808
9016
|
}, j))
|
|
8809
9017
|
}),
|
|
8810
|
-
|
|
8811
|
-
|
|
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],
|
|
8812
9024
|
style: {
|
|
8813
|
-
left: X(
|
|
8814
|
-
transform:
|
|
9025
|
+
left: X(shown) / W * 100 + "%",
|
|
9026
|
+
transform: shown > n * .65 ? "translateX(calc(-100% - 12px))" : "translateX(12px)"
|
|
8815
9027
|
},
|
|
8816
|
-
rows:
|
|
8817
|
-
color: seriesColor(i),
|
|
8818
|
-
name: s.name,
|
|
8819
|
-
value: format.number(s.values[hi], decimals) + suffix
|
|
8820
|
-
}))
|
|
9028
|
+
rows: tipRows(shown)
|
|
8821
9029
|
}) : null
|
|
8822
9030
|
]
|
|
8823
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,
|
|
8824
9045
|
/* @__PURE__ */ jsx("div", {
|
|
8825
9046
|
className: "ui-chart-xlabels",
|
|
8826
9047
|
style: {
|
|
@@ -8828,7 +9049,122 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
|
|
|
8828
9049
|
marginRight: edge.right
|
|
8829
9050
|
},
|
|
8830
9051
|
children: labels.map((lb, j) => /* @__PURE__ */ jsx("span", { children: labelEvery > 1 && j % labelEvery ? "" : digits(lb) }, j))
|
|
8831
|
-
})
|
|
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
|
|
8832
9168
|
]
|
|
8833
9169
|
});
|
|
8834
9170
|
}
|
|
@@ -12042,6 +12378,6 @@ function Workbench({ ref, ...p }) {
|
|
|
12042
12378
|
})
|
|
12043
12379
|
});
|
|
12044
12380
|
}
|
|
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 };
|
|
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 };
|
|
12046
12382
|
|
|
12047
12383
|
//# sourceMappingURL=index.js.map
|