@modelform/react-native 0.5.0 → 0.7.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/README.md +21 -1
- package/dist/{chunk-5SGVTAFJ.mjs → chunk-BW6HKFAB.mjs} +932 -371
- package/dist/{chunk-5UE6Q6CQ.js → chunk-YUXA7I4J.js} +1036 -475
- package/dist/core/index.js +28 -2
- package/dist/core/index.mjs +27 -1
- package/dist/core/inputs.d.ts +71 -1
- package/dist/core/local.d.ts +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +658 -318
- package/dist/index.mjs +645 -305
- package/dist/ui/inputs/InputGroup.d.ts +13 -0
- package/dist/ui/inputs/formContext.d.ts +24 -1
- package/package.json +1 -1
- package/schema/dashboard.schema.json +113 -2
package/dist/index.mjs
CHANGED
|
@@ -9,10 +9,12 @@ import {
|
|
|
9
9
|
DEFAULT_GAZETTEER,
|
|
10
10
|
EDITABLE_VARIABLE_TYPES,
|
|
11
11
|
GRID_COLUMNS,
|
|
12
|
+
GROUP_FIELD_TYPES,
|
|
12
13
|
GrafanaClient,
|
|
13
14
|
GrafanaDataSource,
|
|
14
15
|
GrafanaError,
|
|
15
16
|
HttpConfigFiles,
|
|
17
|
+
INPUT_GROUP,
|
|
16
18
|
INPUT_OPTION_KEYS,
|
|
17
19
|
INPUT_TYPES,
|
|
18
20
|
LOCAL_DATASOURCE_TYPE,
|
|
@@ -63,6 +65,7 @@ import {
|
|
|
63
65
|
dropTarget,
|
|
64
66
|
duplicatePanel,
|
|
65
67
|
entriesSavedWith,
|
|
68
|
+
entriesToItems,
|
|
66
69
|
entryToInputValue,
|
|
67
70
|
expandRow,
|
|
68
71
|
fetchBundle,
|
|
@@ -81,8 +84,12 @@ import {
|
|
|
81
84
|
getPath,
|
|
82
85
|
gridOffsetPx,
|
|
83
86
|
gridUnitsToPx,
|
|
87
|
+
groupFields,
|
|
88
|
+
groupProblems,
|
|
89
|
+
groupToEntries,
|
|
84
90
|
httpFetchJson,
|
|
85
91
|
initialVariableValues,
|
|
92
|
+
inputGroups,
|
|
86
93
|
inputPanels,
|
|
87
94
|
inputProblem,
|
|
88
95
|
insertPanel,
|
|
@@ -90,6 +97,9 @@ import {
|
|
|
90
97
|
interpolateDeep,
|
|
91
98
|
isBundleResponse,
|
|
92
99
|
isEditableVariableType,
|
|
100
|
+
isEmptyItem,
|
|
101
|
+
isFormPanelType,
|
|
102
|
+
isInputGroup,
|
|
93
103
|
isInputPanel,
|
|
94
104
|
isInputType,
|
|
95
105
|
isLocalDatasource,
|
|
@@ -111,6 +121,7 @@ import {
|
|
|
111
121
|
movePanel,
|
|
112
122
|
newDocument,
|
|
113
123
|
newPanel,
|
|
124
|
+
newSaveId,
|
|
114
125
|
newVariable,
|
|
115
126
|
nextPanelId,
|
|
116
127
|
normalizeRef,
|
|
@@ -137,6 +148,7 @@ import {
|
|
|
137
148
|
parseTime,
|
|
138
149
|
pasteSnippet,
|
|
139
150
|
placePanel,
|
|
151
|
+
plainInputPanels,
|
|
140
152
|
pointerToPath,
|
|
141
153
|
prepareDashboard,
|
|
142
154
|
previewPaste,
|
|
@@ -163,6 +175,7 @@ import {
|
|
|
163
175
|
resolveVariables,
|
|
164
176
|
revalidateBundle,
|
|
165
177
|
rowsToMappings,
|
|
178
|
+
sameSave,
|
|
166
179
|
sampleEntries,
|
|
167
180
|
screenDocuments,
|
|
168
181
|
screenOfType,
|
|
@@ -207,7 +220,7 @@ import {
|
|
|
207
220
|
variableWithType,
|
|
208
221
|
visibleVariables,
|
|
209
222
|
zoomRange
|
|
210
|
-
} from "./chunk-
|
|
223
|
+
} from "./chunk-BW6HKFAB.mjs";
|
|
211
224
|
|
|
212
225
|
// src/ui/theme.tsx
|
|
213
226
|
import { createContext, useContext } from "react";
|
|
@@ -559,15 +572,15 @@ function usePanelLinks(panel) {
|
|
|
559
572
|
}
|
|
560
573
|
|
|
561
574
|
// src/ui/DashboardView.tsx
|
|
562
|
-
import { useCallback as useCallback3, useContext as useContext4, useMemo as
|
|
575
|
+
import { useCallback as useCallback3, useContext as useContext4, useMemo as useMemo9, useRef as useRef5, useState as useState11 } from "react";
|
|
563
576
|
import {
|
|
564
577
|
ActivityIndicator,
|
|
565
|
-
Pressable as
|
|
578
|
+
Pressable as Pressable12,
|
|
566
579
|
RefreshControl,
|
|
567
|
-
ScrollView as
|
|
568
|
-
StyleSheet as
|
|
569
|
-
Text as
|
|
570
|
-
View as
|
|
580
|
+
ScrollView as ScrollView6,
|
|
581
|
+
StyleSheet as StyleSheet14,
|
|
582
|
+
Text as Text13,
|
|
583
|
+
View as View13,
|
|
571
584
|
useWindowDimensions
|
|
572
585
|
} from "react-native";
|
|
573
586
|
import { useSafeAreaInsets as useSafeAreaInsets4 } from "react-native-safe-area-context";
|
|
@@ -593,6 +606,7 @@ var RenderBoundary = class extends Component {
|
|
|
593
606
|
|
|
594
607
|
// src/ui/inputs/formContext.ts
|
|
595
608
|
import { createContext as createContext3, useContext as useContext3 } from "react";
|
|
609
|
+
var groupKey = (g) => g.id != null ? `#${g.id}` : groupFields(g).map((f) => f.options.metric).join("|");
|
|
596
610
|
var InputFormContext = createContext3(null);
|
|
597
611
|
function useInputForm() {
|
|
598
612
|
const v = useContext3(InputFormContext);
|
|
@@ -600,6 +614,10 @@ function useInputForm() {
|
|
|
600
614
|
return v;
|
|
601
615
|
}
|
|
602
616
|
|
|
617
|
+
// src/ui/inputs/InputGroup.tsx
|
|
618
|
+
import { useMemo as useMemo2, useRef as useRef2, useState as useState6 } from "react";
|
|
619
|
+
import { Pressable as Pressable6, ScrollView as ScrollView4, StyleSheet as StyleSheet7, Text as Text7, View as View6 } from "react-native";
|
|
620
|
+
|
|
603
621
|
// src/ui/inputs/InputPanels.tsx
|
|
604
622
|
import { useEffect as useEffect2, useState as useState5 } from "react";
|
|
605
623
|
import { Platform, Pressable as Pressable5, ScrollView as ScrollView3, StyleSheet as StyleSheet6, Switch, Text as Text6, TextInput as TextInput2, View as View5 } from "react-native";
|
|
@@ -1762,22 +1780,236 @@ var styles6 = StyleSheet6.create({
|
|
|
1762
1780
|
counterBtnText: { color: "#fff", fontSize: 18, fontWeight: "700" }
|
|
1763
1781
|
});
|
|
1764
1782
|
|
|
1783
|
+
// src/ui/inputs/InputGroup.tsx
|
|
1784
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1785
|
+
function titleText(v) {
|
|
1786
|
+
if (v == null || v === "") return void 0;
|
|
1787
|
+
if (Array.isArray(v)) return v.length ? v.join(", ") : void 0;
|
|
1788
|
+
return typeof v === "boolean" ? void 0 : String(v);
|
|
1789
|
+
}
|
|
1790
|
+
function summaryText(f, v) {
|
|
1791
|
+
if (v == null || v === "" || Array.isArray(v) && !v.length) return void 0;
|
|
1792
|
+
if (f.type === "input-toggle") return v ? f.title || "Yes" : void 0;
|
|
1793
|
+
if (f.type === "input-duration" && typeof v === "number") return formatClock(v);
|
|
1794
|
+
if (f.type === "input-select" && f.options.choices) {
|
|
1795
|
+
const label = (x) => f.options.choices.find((c) => c.value === x)?.label ?? String(x);
|
|
1796
|
+
return Array.isArray(v) ? v.map(label).join(", ") : label(v);
|
|
1797
|
+
}
|
|
1798
|
+
const text = Array.isArray(v) ? v.join(", ") : String(v);
|
|
1799
|
+
return f.options.unit ? `${text} ${f.options.unit}` : text;
|
|
1800
|
+
}
|
|
1801
|
+
var GAP = 8;
|
|
1802
|
+
function dropIndex(from, dy, keys, span) {
|
|
1803
|
+
let to = from;
|
|
1804
|
+
let left = dy;
|
|
1805
|
+
while (left > 0 && to < keys.length - 1 && left > span(keys[to + 1]) / 2) left -= span(keys[++to]);
|
|
1806
|
+
while (left < 0 && to > 0 && -left > span(keys[to - 1]) / 2) left += span(keys[--to]);
|
|
1807
|
+
return to;
|
|
1808
|
+
}
|
|
1809
|
+
function InputGroupBody({ panel }) {
|
|
1810
|
+
const theme = useDashTheme();
|
|
1811
|
+
const form = useInputForm();
|
|
1812
|
+
const group = form.group?.(panel);
|
|
1813
|
+
const [collapsed, setCollapsed] = useState6(/* @__PURE__ */ new Set());
|
|
1814
|
+
const [drag, setDrag] = useState6(null);
|
|
1815
|
+
const [heights, setHeights] = useState6({});
|
|
1816
|
+
const dragging = useRef2(null);
|
|
1817
|
+
const [wasEdited, setWasEdited] = useState6(group?.edited);
|
|
1818
|
+
if (group && group.edited !== wasEdited) {
|
|
1819
|
+
setWasEdited(group.edited);
|
|
1820
|
+
if (!group.edited) setCollapsed(/* @__PURE__ */ new Set());
|
|
1821
|
+
}
|
|
1822
|
+
if (!group) return null;
|
|
1823
|
+
const label = panel.options.itemTitle || "Item";
|
|
1824
|
+
const collapseFilled = (except) => setCollapsed(new Set(group.items.filter((i) => i.key !== except && !isEmptyItem(panel, i.values)).map((i) => i.key)));
|
|
1825
|
+
const toggle = (key) => setCollapsed((c) => {
|
|
1826
|
+
const next = new Set(c);
|
|
1827
|
+
if (!next.delete(key)) next.add(key);
|
|
1828
|
+
return next;
|
|
1829
|
+
});
|
|
1830
|
+
const setDragging = (d) => {
|
|
1831
|
+
dragging.current = d;
|
|
1832
|
+
setDrag(d);
|
|
1833
|
+
};
|
|
1834
|
+
const span = (key) => (heights[key] ?? 0) + GAP;
|
|
1835
|
+
const keys = group.items.map((i) => i.key);
|
|
1836
|
+
const startDrag = (key, e) => setDragging({ key, from: keys.indexOf(key), startY: e.nativeEvent.pageY, dy: 0 });
|
|
1837
|
+
const moveDrag = (e) => {
|
|
1838
|
+
const d = dragging.current;
|
|
1839
|
+
if (d) setDragging({ ...d, dy: e.nativeEvent.pageY - d.startY });
|
|
1840
|
+
};
|
|
1841
|
+
const dropDrag = () => {
|
|
1842
|
+
const d = dragging.current;
|
|
1843
|
+
setDragging(null);
|
|
1844
|
+
if (!d) return;
|
|
1845
|
+
const to2 = dropIndex(d.from, d.dy, keys, span);
|
|
1846
|
+
for (let i = d.from; i !== to2; i += to2 > i ? 1 : -1) group.move(i, to2 > i ? 1 : -1);
|
|
1847
|
+
};
|
|
1848
|
+
const endDrag = () => setDragging(null);
|
|
1849
|
+
const to = drag ? dropIndex(drag.from, drag.dy, keys, span) : -1;
|
|
1850
|
+
const shift = (i, key) => {
|
|
1851
|
+
if (!drag) return void 0;
|
|
1852
|
+
if (key === drag.key) return drag.dy;
|
|
1853
|
+
const room = span(drag.key);
|
|
1854
|
+
if (drag.from < i && i <= to) return -room;
|
|
1855
|
+
if (to <= i && i < drag.from) return room;
|
|
1856
|
+
return 0;
|
|
1857
|
+
};
|
|
1858
|
+
return /* @__PURE__ */ jsxs7(ScrollView4, { style: styles7.fill, contentContainerStyle: styles7.list, nestedScrollEnabled: true, keyboardShouldPersistTaps: "handled", scrollEnabled: !drag, children: [
|
|
1859
|
+
group.items.map((item, i) => {
|
|
1860
|
+
const named = panel.options.titleFrom ? titleText(item.values[panel.options.titleFrom]) : void 0;
|
|
1861
|
+
const title = named ?? `${label} ${i + 1}`;
|
|
1862
|
+
const troubled = groupFields(panel).some((f) => group.fieldProblem(i, f.options.metric));
|
|
1863
|
+
return /* @__PURE__ */ jsx9(
|
|
1864
|
+
ItemCard,
|
|
1865
|
+
{
|
|
1866
|
+
panel,
|
|
1867
|
+
group,
|
|
1868
|
+
form,
|
|
1869
|
+
index: i,
|
|
1870
|
+
title,
|
|
1871
|
+
last: i === group.items.length - 1,
|
|
1872
|
+
collapsed: collapsed.has(item.key) && !troubled,
|
|
1873
|
+
onToggle: () => toggle(item.key),
|
|
1874
|
+
onDuplicate: () => {
|
|
1875
|
+
collapseFilled();
|
|
1876
|
+
group.duplicate(i);
|
|
1877
|
+
},
|
|
1878
|
+
dragOffset: shift(i, item.key),
|
|
1879
|
+
lifted: drag?.key === item.key,
|
|
1880
|
+
onLayout: (h) => setHeights((all) => all[item.key] === h ? all : { ...all, [item.key]: h }),
|
|
1881
|
+
handle: {
|
|
1882
|
+
onStartShouldSetResponder: () => true,
|
|
1883
|
+
onMoveShouldSetResponder: () => true,
|
|
1884
|
+
onResponderTerminationRequest: () => false,
|
|
1885
|
+
onResponderGrant: (e) => startDrag(item.key, e),
|
|
1886
|
+
onResponderMove: moveDrag,
|
|
1887
|
+
onResponderRelease: dropDrag,
|
|
1888
|
+
onResponderTerminate: endDrag
|
|
1889
|
+
}
|
|
1890
|
+
},
|
|
1891
|
+
item.key
|
|
1892
|
+
);
|
|
1893
|
+
}),
|
|
1894
|
+
group.canAdd && /* @__PURE__ */ jsx9(
|
|
1895
|
+
Pressable6,
|
|
1896
|
+
{
|
|
1897
|
+
onPress: () => {
|
|
1898
|
+
collapseFilled();
|
|
1899
|
+
group.add();
|
|
1900
|
+
},
|
|
1901
|
+
accessibilityRole: "button",
|
|
1902
|
+
style: ({ pressed }) => [styles7.add, { borderColor: theme.accent, opacity: pressed ? 0.7 : 1 }],
|
|
1903
|
+
children: /* @__PURE__ */ jsxs7(Text7, { style: { color: theme.accent, fontWeight: "600" }, children: [
|
|
1904
|
+
"+ ",
|
|
1905
|
+
panel.options.addLabel || `Add ${label.toLowerCase()}`
|
|
1906
|
+
] })
|
|
1907
|
+
}
|
|
1908
|
+
)
|
|
1909
|
+
] });
|
|
1910
|
+
}
|
|
1911
|
+
function ItemCard({ panel, group, form, index, title, last, collapsed, onToggle, onDuplicate, dragOffset, lifted, onLayout, handle }) {
|
|
1912
|
+
const theme = useDashTheme();
|
|
1913
|
+
const fields = useMemo2(() => groupFields(panel), [panel]);
|
|
1914
|
+
const item = group.items[index];
|
|
1915
|
+
const scoped = useMemo2(
|
|
1916
|
+
() => ({
|
|
1917
|
+
...form,
|
|
1918
|
+
value: (m) => item.values[m] ?? null,
|
|
1919
|
+
setValue: (m, v) => group.setValue(index, m, v),
|
|
1920
|
+
isDirty: (m) => item.edited.includes(m),
|
|
1921
|
+
problem: (m) => group.fieldProblem(index, m)
|
|
1922
|
+
}),
|
|
1923
|
+
[form, group, index, item]
|
|
1924
|
+
);
|
|
1925
|
+
const button = (text, onPress, a11y, disabled = false) => /* @__PURE__ */ jsx9(
|
|
1926
|
+
Pressable6,
|
|
1927
|
+
{
|
|
1928
|
+
onPress,
|
|
1929
|
+
disabled,
|
|
1930
|
+
accessibilityRole: "button",
|
|
1931
|
+
accessibilityLabel: a11y,
|
|
1932
|
+
hitSlop: 6,
|
|
1933
|
+
style: ({ pressed }) => [styles7.iconBtn, { opacity: disabled ? 0.3 : pressed ? 0.6 : 1 }],
|
|
1934
|
+
children: /* @__PURE__ */ jsx9(Text7, { style: { color: theme.textSecondary, fontSize: 15 }, children: text })
|
|
1935
|
+
}
|
|
1936
|
+
);
|
|
1937
|
+
const summary = collapsed ? fields.filter((f) => f.options.metric !== panel.options.titleFrom).map((f) => summaryText(f, item.values[f.options.metric])).filter(Boolean).join(" \xB7 ") : "";
|
|
1938
|
+
return /* @__PURE__ */ jsxs7(
|
|
1939
|
+
View6,
|
|
1940
|
+
{
|
|
1941
|
+
onLayout: (e) => onLayout(e.nativeEvent.layout.height),
|
|
1942
|
+
style: [
|
|
1943
|
+
styles7.item,
|
|
1944
|
+
{ borderColor: lifted ? theme.accent : theme.border, backgroundColor: theme.surface },
|
|
1945
|
+
!!dragOffset && { transform: [{ translateY: dragOffset }] },
|
|
1946
|
+
lifted && { zIndex: 1, opacity: 0.95 }
|
|
1947
|
+
],
|
|
1948
|
+
children: [
|
|
1949
|
+
/* @__PURE__ */ jsxs7(View6, { style: styles7.itemHeader, children: [
|
|
1950
|
+
/* @__PURE__ */ jsx9(View6, { ...handle, style: styles7.handle, accessibilityLabel: `Drag ${title} to reorder`, children: /* @__PURE__ */ jsx9(Text7, { style: { color: theme.textMuted, fontSize: 16 }, children: "\u2261" }) }),
|
|
1951
|
+
/* @__PURE__ */ jsxs7(Pressable6, { onPress: onToggle, style: styles7.titleArea, accessibilityRole: "button", accessibilityLabel: `${collapsed ? "Expand" : "Collapse"} ${title}`, accessibilityState: { expanded: !collapsed }, children: [
|
|
1952
|
+
/* @__PURE__ */ jsxs7(Text7, { style: [styles7.itemTitle, { color: theme.text }], numberOfLines: 1, children: [
|
|
1953
|
+
collapsed ? "\u25B8 " : "\u25BE ",
|
|
1954
|
+
title
|
|
1955
|
+
] }),
|
|
1956
|
+
!!summary && /* @__PURE__ */ jsx9(Text7, { style: [styles7.summary, { color: theme.textSecondary }], numberOfLines: 1, children: summary })
|
|
1957
|
+
] }),
|
|
1958
|
+
button("\u2191", () => group.move(index, -1), `Move ${title} up`, index === 0),
|
|
1959
|
+
button("\u2193", () => group.move(index, 1), `Move ${title} down`, last),
|
|
1960
|
+
button("\u29C9", onDuplicate, `Duplicate ${title}`, !group.canAdd),
|
|
1961
|
+
button("\u2715", () => group.remove(index), `Remove ${title}`)
|
|
1962
|
+
] }),
|
|
1963
|
+
!collapsed && /* @__PURE__ */ jsx9(InputFormContext.Provider, { value: scoped, children: /* @__PURE__ */ jsx9(View6, { style: styles7.fields, children: fields.map((f) => {
|
|
1964
|
+
const problem = scoped.problem?.(f.options.metric);
|
|
1965
|
+
return /* @__PURE__ */ jsxs7(View6, { style: [styles7.field, { width: `${Math.min(24, Math.max(1, f.gridPos.w)) / 24 * 100}%` }], children: [
|
|
1966
|
+
/* @__PURE__ */ jsxs7(View6, { style: styles7.fieldHeader, children: [
|
|
1967
|
+
!!f.title && /* @__PURE__ */ jsx9(Text7, { style: [styles7.fieldTitle, { color: theme.textSecondary }], numberOfLines: 1, children: f.title }),
|
|
1968
|
+
!!problem && /* @__PURE__ */ jsx9(Text7, { style: [styles7.problem, { color: theme.danger }], numberOfLines: 1, accessibilityRole: "alert", children: problem })
|
|
1969
|
+
] }),
|
|
1970
|
+
/* @__PURE__ */ jsx9(View6, { style: styles7.fieldBody, children: /* @__PURE__ */ jsx9(InputPanelBody, { panel: f }) })
|
|
1971
|
+
] }, f.options.metric);
|
|
1972
|
+
}) }) })
|
|
1973
|
+
]
|
|
1974
|
+
}
|
|
1975
|
+
);
|
|
1976
|
+
}
|
|
1977
|
+
var styles7 = StyleSheet7.create({
|
|
1978
|
+
fill: { flex: 1 },
|
|
1979
|
+
list: { gap: 8, paddingBottom: 4 },
|
|
1980
|
+
item: { borderWidth: 1, borderRadius: 8, padding: 8, gap: 6 },
|
|
1981
|
+
itemHeader: { flexDirection: "row", alignItems: "center", gap: 4 },
|
|
1982
|
+
titleArea: { flex: 1, flexDirection: "row", alignItems: "baseline", gap: 8, minHeight: 28, paddingVertical: 4 },
|
|
1983
|
+
itemTitle: { fontSize: 14, fontWeight: "600", flexShrink: 0, maxWidth: "60%" },
|
|
1984
|
+
summary: { flex: 1, fontSize: 13 },
|
|
1985
|
+
// Web: no text selection or page scroll from dragging the handle.
|
|
1986
|
+
handle: { width: 24, height: 28, alignItems: "center", justifyContent: "center", cursor: "grab", userSelect: "none", touchAction: "none" },
|
|
1987
|
+
iconBtn: { width: 28, height: 28, alignItems: "center", justifyContent: "center" },
|
|
1988
|
+
fields: { flexDirection: "row", flexWrap: "wrap", marginHorizontal: -4 },
|
|
1989
|
+
field: { paddingHorizontal: 4, paddingVertical: 4, gap: 4 },
|
|
1990
|
+
fieldHeader: { flexDirection: "row", gap: 6, alignItems: "baseline" },
|
|
1991
|
+
fieldTitle: { flex: 1, fontSize: 12, fontWeight: "600" },
|
|
1992
|
+
problem: { fontSize: 11, fontWeight: "600", flexShrink: 1 },
|
|
1993
|
+
fieldBody: { minHeight: 44 },
|
|
1994
|
+
add: { borderWidth: 1, borderStyle: "dashed", borderRadius: 8, paddingVertical: 10, alignItems: "center" }
|
|
1995
|
+
});
|
|
1996
|
+
|
|
1765
1997
|
// src/ui/panels/GaugePanels.tsx
|
|
1766
|
-
import { useMemo as
|
|
1767
|
-
import { Pressable as
|
|
1998
|
+
import { useMemo as useMemo4 } from "react";
|
|
1999
|
+
import { Pressable as Pressable8, StyleSheet as StyleSheet9, Text as Text9, View as View8 } from "react-native";
|
|
1768
2000
|
import Svg5, { Path as Path5 } from "react-native-svg";
|
|
1769
2001
|
|
|
1770
2002
|
// src/ui/panels/StatPanel.tsx
|
|
1771
|
-
import { useMemo as
|
|
1772
|
-
import { Pressable as
|
|
2003
|
+
import { useMemo as useMemo3 } from "react";
|
|
2004
|
+
import { Pressable as Pressable7, StyleSheet as StyleSheet8, Text as Text8, View as View7 } from "react-native";
|
|
1773
2005
|
import Svg4, { Path as Path4 } from "react-native-svg";
|
|
1774
|
-
import { jsx as
|
|
2006
|
+
import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1775
2007
|
function StatPanel({ panel, frames }) {
|
|
1776
2008
|
const theme = useDashTheme();
|
|
1777
|
-
const values =
|
|
1778
|
-
if (!values.length) return /* @__PURE__ */
|
|
2009
|
+
const values = useMemo3(() => reducedValues(panel, frames, theme.scheme), [panel, frames, theme.scheme]);
|
|
2010
|
+
if (!values.length) return /* @__PURE__ */ jsx10(NoData, {});
|
|
1779
2011
|
const horizontal = panel.options?.orientation === "horizontal";
|
|
1780
|
-
return /* @__PURE__ */
|
|
2012
|
+
return /* @__PURE__ */ jsx10(View7, { style: [styles8.grid, { flexDirection: horizontal ? "column" : "row" }], children: values.map((v) => /* @__PURE__ */ jsx10(StatTile, { v, showName: values.length > 1, panel }, v.key)) });
|
|
1781
2013
|
}
|
|
1782
2014
|
function StatTile({ v, showName, panel }) {
|
|
1783
2015
|
const theme = useDashTheme();
|
|
@@ -1787,25 +2019,25 @@ function StatTile({ v, showName, panel }) {
|
|
|
1787
2019
|
const fontSize = Math.max(18, Math.min(56, size.height * (graph ? 0.4 : 0.5), size.width / 4.5));
|
|
1788
2020
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
1789
2021
|
const hasLinks = !!v.config.links?.length;
|
|
1790
|
-
return /* @__PURE__ */
|
|
1791
|
-
|
|
2022
|
+
return /* @__PURE__ */ jsxs8(
|
|
2023
|
+
Pressable7,
|
|
1792
2024
|
{
|
|
1793
2025
|
onLayout,
|
|
1794
2026
|
disabled: !hasLinks,
|
|
1795
2027
|
onPress: () => openLinks(valueLinks(panel, v, resolve), v.name),
|
|
1796
2028
|
accessibilityRole: hasLinks ? "link" : void 0,
|
|
1797
2029
|
style: ({ pressed }) => [
|
|
1798
|
-
|
|
2030
|
+
styles8.tile,
|
|
1799
2031
|
// With a sparkline, the number sits in the top half so the line runs beneath it.
|
|
1800
2032
|
graph && { justifyContent: "flex-start", paddingTop: 4 },
|
|
1801
2033
|
colorMode === "background" && { backgroundColor: withAlpha(v.stateColor, 0.14) },
|
|
1802
2034
|
pressed && { opacity: 0.7 }
|
|
1803
2035
|
],
|
|
1804
2036
|
children: [
|
|
1805
|
-
colorMode !== "none" && /* @__PURE__ */
|
|
1806
|
-
graph && size.width > 0 && /* @__PURE__ */
|
|
1807
|
-
showName && /* @__PURE__ */
|
|
1808
|
-
/* @__PURE__ */
|
|
2037
|
+
colorMode !== "none" && /* @__PURE__ */ jsx10(View7, { style: [styles8.accent, { backgroundColor: v.stateColor }] }),
|
|
2038
|
+
graph && size.width > 0 && /* @__PURE__ */ jsx10(Sparkline, { values: v.sparkline, width: size.width, height: size.height * 0.4, color: v.stateColor }),
|
|
2039
|
+
showName && /* @__PURE__ */ jsx10(Text8, { style: [styles8.name, { color: theme.textSecondary }], numberOfLines: 1, children: v.name }),
|
|
2040
|
+
/* @__PURE__ */ jsx10(Text8, { style: [styles8.value, { color: theme.text, fontSize }], numberOfLines: 1, adjustsFontSizeToFit: true, children: v.text })
|
|
1809
2041
|
]
|
|
1810
2042
|
}
|
|
1811
2043
|
);
|
|
@@ -1820,16 +2052,16 @@ function Sparkline({ values, width, height, color }) {
|
|
|
1820
2052
|
values.forEach((v, i) => {
|
|
1821
2053
|
if (v != null) line += `${line ? "L" : "M"}${x(i)},${y(v)}`;
|
|
1822
2054
|
});
|
|
1823
|
-
return /* @__PURE__ */
|
|
1824
|
-
/* @__PURE__ */
|
|
1825
|
-
/* @__PURE__ */
|
|
2055
|
+
return /* @__PURE__ */ jsxs8(Svg4, { width, height, style: styles8.spark, children: [
|
|
2056
|
+
/* @__PURE__ */ jsx10(Path4, { d: `${line}L${width},${height}L0,${height}Z`, fill: color, opacity: 0.1 }),
|
|
2057
|
+
/* @__PURE__ */ jsx10(Path4, { d: line, stroke: color, strokeWidth: 2, fill: "none", strokeLinejoin: "round" })
|
|
1826
2058
|
] });
|
|
1827
2059
|
}
|
|
1828
2060
|
function withAlpha(hex, alpha) {
|
|
1829
2061
|
if (!/^#[0-9a-f]{6}$/i.test(hex)) return hex;
|
|
1830
2062
|
return `${hex}${Math.round(alpha * 255).toString(16).padStart(2, "0")}`;
|
|
1831
2063
|
}
|
|
1832
|
-
var
|
|
2064
|
+
var styles8 = StyleSheet8.create({
|
|
1833
2065
|
grid: { flex: 1, gap: 8 },
|
|
1834
2066
|
tile: { flex: 1, justifyContent: "center", paddingLeft: 12, borderRadius: 6, overflow: "hidden" },
|
|
1835
2067
|
accent: { position: "absolute", left: 0, top: 6, bottom: 6, width: 3, borderRadius: 2 },
|
|
@@ -1839,13 +2071,13 @@ var styles7 = StyleSheet7.create({
|
|
|
1839
2071
|
});
|
|
1840
2072
|
|
|
1841
2073
|
// src/ui/panels/GaugePanels.tsx
|
|
1842
|
-
import { jsx as
|
|
2074
|
+
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1843
2075
|
var SWEEP = 240;
|
|
1844
2076
|
function GaugePanel({ panel, frames }) {
|
|
1845
2077
|
const theme = useDashTheme();
|
|
1846
|
-
const values =
|
|
1847
|
-
if (!values.length) return /* @__PURE__ */
|
|
1848
|
-
return /* @__PURE__ */
|
|
2078
|
+
const values = useMemo4(() => reducedValues(panel, frames, theme.scheme), [panel, frames, theme.scheme]);
|
|
2079
|
+
if (!values.length) return /* @__PURE__ */ jsx11(NoData, {});
|
|
2080
|
+
return /* @__PURE__ */ jsx11(View8, { style: styles9.row, children: values.map((v) => /* @__PURE__ */ jsx11(Gauge, { v, showName: values.length > 1, panel }, v.key)) });
|
|
1849
2081
|
}
|
|
1850
2082
|
function Gauge({ v, showName, panel }) {
|
|
1851
2083
|
const theme = useDashTheme();
|
|
@@ -1860,22 +2092,22 @@ function Gauge({ v, showName, panel }) {
|
|
|
1860
2092
|
const r = d / 2 - stroke;
|
|
1861
2093
|
const cx = size.width / 2;
|
|
1862
2094
|
const cy = size.height / 2 + d * 0.08;
|
|
1863
|
-
return /* @__PURE__ */
|
|
1864
|
-
|
|
2095
|
+
return /* @__PURE__ */ jsxs9(
|
|
2096
|
+
Pressable8,
|
|
1865
2097
|
{
|
|
1866
|
-
style: ({ pressed }) => [
|
|
2098
|
+
style: ({ pressed }) => [styles9.fill, pressed && { opacity: 0.7 }],
|
|
1867
2099
|
onLayout,
|
|
1868
2100
|
disabled: !hasLinks,
|
|
1869
2101
|
onPress: () => openLinks(valueLinks(panel, v, resolve), v.name),
|
|
1870
2102
|
accessibilityRole: hasLinks ? "link" : void 0,
|
|
1871
2103
|
children: [
|
|
1872
|
-
size.width > 0 && r > 0 && /* @__PURE__ */
|
|
1873
|
-
/* @__PURE__ */
|
|
1874
|
-
frac > 0 && /* @__PURE__ */
|
|
2104
|
+
size.width > 0 && r > 0 && /* @__PURE__ */ jsxs9(Svg5, { width: size.width, height: size.height, children: [
|
|
2105
|
+
/* @__PURE__ */ jsx11(Path5, { d: arc(cx, cy, r, 0, 1), stroke: withAlpha(v.stateColor, 0.18), strokeWidth: stroke, fill: "none", strokeLinecap: "round" }),
|
|
2106
|
+
frac > 0 && /* @__PURE__ */ jsx11(Path5, { d: arc(cx, cy, r, 0, frac), stroke: v.stateColor, strokeWidth: stroke, fill: "none", strokeLinecap: "round" })
|
|
1875
2107
|
] }),
|
|
1876
|
-
/* @__PURE__ */
|
|
1877
|
-
/* @__PURE__ */
|
|
1878
|
-
showName && /* @__PURE__ */
|
|
2108
|
+
/* @__PURE__ */ jsxs9(View8, { style: [StyleSheet9.absoluteFill, styles9.center, { top: d * 0.12 }], pointerEvents: "none", children: [
|
|
2109
|
+
/* @__PURE__ */ jsx11(Text9, { style: [styles9.value, { color: theme.text, fontSize: Math.max(14, d * 0.18) }], numberOfLines: 1, adjustsFontSizeToFit: true, children: v.text }),
|
|
2110
|
+
showName && /* @__PURE__ */ jsx11(Text9, { style: [styles9.name, { color: theme.textSecondary }], numberOfLines: 1, children: v.name })
|
|
1879
2111
|
] })
|
|
1880
2112
|
]
|
|
1881
2113
|
}
|
|
@@ -1891,35 +2123,35 @@ function arc(cx, cy, r, a, b) {
|
|
|
1891
2123
|
}
|
|
1892
2124
|
function BarGaugePanel({ panel, frames }) {
|
|
1893
2125
|
const theme = useDashTheme();
|
|
1894
|
-
const values =
|
|
2126
|
+
const values = useMemo4(() => reducedValues(panel, frames, theme.scheme), [panel, frames, theme.scheme]);
|
|
1895
2127
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
1896
|
-
if (!values.length) return /* @__PURE__ */
|
|
1897
|
-
return /* @__PURE__ */
|
|
2128
|
+
if (!values.length) return /* @__PURE__ */ jsx11(NoData, {});
|
|
2129
|
+
return /* @__PURE__ */ jsx11(View8, { style: styles9.bars, children: values.map((v) => {
|
|
1898
2130
|
const min = v.config.min ?? 0;
|
|
1899
2131
|
const max = v.config.max ?? Math.max(...values.map((o) => o.value ?? 0), 1);
|
|
1900
2132
|
const frac = v.value == null ? 0 : Math.min(1, Math.max(0, (v.value - min) / (max - min || 1)));
|
|
1901
2133
|
const color = v.config.thresholds || v.mapped?.color ? v.stateColor : resolveColor(v.config.color?.fixedColor, v.color);
|
|
1902
2134
|
const hasLinks = !!v.config.links?.length;
|
|
1903
|
-
return /* @__PURE__ */
|
|
1904
|
-
|
|
2135
|
+
return /* @__PURE__ */ jsxs9(
|
|
2136
|
+
Pressable8,
|
|
1905
2137
|
{
|
|
1906
|
-
style: ({ pressed }) => [
|
|
2138
|
+
style: ({ pressed }) => [styles9.barRow, pressed && { opacity: 0.7 }],
|
|
1907
2139
|
disabled: !hasLinks,
|
|
1908
2140
|
onPress: () => openLinks(valueLinks(panel, v, resolve), v.name),
|
|
1909
2141
|
accessibilityRole: hasLinks ? "link" : void 0,
|
|
1910
2142
|
children: [
|
|
1911
|
-
/* @__PURE__ */
|
|
1912
|
-
/* @__PURE__ */
|
|
1913
|
-
/* @__PURE__ */
|
|
2143
|
+
/* @__PURE__ */ jsxs9(View8, { style: styles9.barLabels, children: [
|
|
2144
|
+
/* @__PURE__ */ jsx11(Text9, { style: [styles9.name, { color: theme.textSecondary }], numberOfLines: 1, children: v.name }),
|
|
2145
|
+
/* @__PURE__ */ jsx11(Text9, { style: [styles9.barValue, { color: theme.text }], children: v.text })
|
|
1914
2146
|
] }),
|
|
1915
|
-
/* @__PURE__ */
|
|
2147
|
+
/* @__PURE__ */ jsx11(View8, { style: [styles9.track, { backgroundColor: withAlpha(color, 0.18) }], children: /* @__PURE__ */ jsx11(View8, { style: [styles9.meter, { width: `${frac * 100}%`, backgroundColor: color }] }) })
|
|
1916
2148
|
]
|
|
1917
2149
|
},
|
|
1918
2150
|
v.key
|
|
1919
2151
|
);
|
|
1920
2152
|
}) });
|
|
1921
2153
|
}
|
|
1922
|
-
var
|
|
2154
|
+
var styles9 = StyleSheet9.create({
|
|
1923
2155
|
fill: { flex: 1 },
|
|
1924
2156
|
row: { flex: 1, flexDirection: "row", gap: 8 },
|
|
1925
2157
|
center: { alignItems: "center", justifyContent: "center" },
|
|
@@ -1934,8 +2166,8 @@ var styles8 = StyleSheet8.create({
|
|
|
1934
2166
|
});
|
|
1935
2167
|
|
|
1936
2168
|
// src/ui/panels/GeomapPanel.tsx
|
|
1937
|
-
import { useEffect as useEffect3, useMemo as
|
|
1938
|
-
import { Image, PixelRatio, Pressable as
|
|
2169
|
+
import { useEffect as useEffect3, useMemo as useMemo5, useRef as useRef3, useState as useState7 } from "react";
|
|
2170
|
+
import { Image, PixelRatio, Pressable as Pressable9, StyleSheet as StyleSheet10, Text as Text10, View as View9 } from "react-native";
|
|
1939
2171
|
import Svg6, { Path as Path6, Text as SvgText2 } from "react-native-svg";
|
|
1940
2172
|
|
|
1941
2173
|
// src/ui/geomap.ts
|
|
@@ -2352,7 +2584,7 @@ function heatmapCells(px, py, weights, radius, blur, width, height, cell = 4) {
|
|
|
2352
2584
|
}
|
|
2353
2585
|
|
|
2354
2586
|
// src/ui/panels/GeomapPanel.tsx
|
|
2355
|
-
import { jsx as
|
|
2587
|
+
import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2356
2588
|
var HIT_PX = 24;
|
|
2357
2589
|
var DRAG_PX = 6;
|
|
2358
2590
|
var MAX_LABELS = 300;
|
|
@@ -2361,15 +2593,15 @@ function GeomapPanel({ panel, frames }) {
|
|
|
2361
2593
|
const [size, onLayout] = useLayout();
|
|
2362
2594
|
const retina = PixelRatio.get() > 1;
|
|
2363
2595
|
const { gazetteers, error } = useGazetteers(panel, frames);
|
|
2364
|
-
const layers =
|
|
2365
|
-
const home =
|
|
2366
|
-
const [moved, setMoved] =
|
|
2367
|
-
const [picked, setPicked] =
|
|
2596
|
+
const layers = useMemo5(() => geomapLayers(panel, frames, theme.scheme, retina, gazetteers), [panel, frames, theme.scheme, retina, gazetteers]);
|
|
2597
|
+
const home = useMemo5(() => initialView(panel, layers, size.width, size.height), [panel, layers, size.width, size.height]);
|
|
2598
|
+
const [moved, setMoved] = useState7(null);
|
|
2599
|
+
const [picked, setPicked] = useState7(null);
|
|
2368
2600
|
const links = usePanelLinks(panel);
|
|
2369
2601
|
const view = moved ?? home;
|
|
2370
2602
|
const [minZoom, maxZoom] = zoomLimits(panel);
|
|
2371
2603
|
const zoomTo = (v, zoom) => setMoved({ ...v, zoom: Math.min(maxZoom, Math.max(minZoom, zoom)) });
|
|
2372
|
-
const screen =
|
|
2604
|
+
const screen = useMemo5(() => {
|
|
2373
2605
|
const at = screenProjector(view, size.width, size.height);
|
|
2374
2606
|
return new Map(
|
|
2375
2607
|
layers.map((l) => [
|
|
@@ -2405,7 +2637,7 @@ function GeomapPanel({ panel, frames }) {
|
|
|
2405
2637
|
}
|
|
2406
2638
|
return best;
|
|
2407
2639
|
};
|
|
2408
|
-
const gesture =
|
|
2640
|
+
const gesture = useRef3(null);
|
|
2409
2641
|
const responder = {
|
|
2410
2642
|
onStartShouldSetResponder: () => true,
|
|
2411
2643
|
// Keep the gesture while panning instead of handing it to the dashboard's scroll view.
|
|
@@ -2447,14 +2679,14 @@ function GeomapPanel({ panel, frames }) {
|
|
|
2447
2679
|
const attribution = [...new Set(layers.flatMap((l) => l.type === "tiles" && l.source.attribution ? [l.source.attribution] : []))].join(" ");
|
|
2448
2680
|
const legend = layers.flatMap((l) => l.type === "markers" || l.type === "route" ? l.legend : []);
|
|
2449
2681
|
const ready = size.width > 0 && size.height > 0;
|
|
2450
|
-
return /* @__PURE__ */
|
|
2451
|
-
/* @__PURE__ */
|
|
2682
|
+
return /* @__PURE__ */ jsxs10(View9, { style: styles10.fill, children: [
|
|
2683
|
+
/* @__PURE__ */ jsxs10(View9, { style: [styles10.fill, styles10.map, { backgroundColor: theme.grid }], onLayout, ...responder, children: [
|
|
2452
2684
|
ready && // Nothing inside takes touches, so locationX/Y are always relative to the map.
|
|
2453
|
-
/* @__PURE__ */
|
|
2685
|
+
/* @__PURE__ */ jsxs10(View9, { pointerEvents: "none", style: StyleSheet10.absoluteFill, children: [
|
|
2454
2686
|
layers.map(
|
|
2455
|
-
(l) => l.type === "tiles" ? /* @__PURE__ */
|
|
2687
|
+
(l) => l.type === "tiles" ? /* @__PURE__ */ jsx12(Tiles, { layer: l, view, width: size.width, height: size.height }, l.key) : /* @__PURE__ */ jsx12(DataLayerSvg, { layer: l, screen: screen.get(l.key) ?? [], width: size.width, height: size.height, textColor: theme.text }, l.key)
|
|
2456
2688
|
),
|
|
2457
|
-
shown && /* @__PURE__ */
|
|
2689
|
+
shown && /* @__PURE__ */ jsx12(Svg6, { width: size.width, height: size.height, style: StyleSheet10.absoluteFill, children: /* @__PURE__ */ jsx12(
|
|
2458
2690
|
Path6,
|
|
2459
2691
|
{
|
|
2460
2692
|
d: symbolPath("circle", shown.px, shown.py, Math.max(shown.layer.type === "markers" ? shown.radius + 2 : 5, 5)),
|
|
@@ -2464,7 +2696,7 @@ function GeomapPanel({ panel, frames }) {
|
|
|
2464
2696
|
}
|
|
2465
2697
|
) })
|
|
2466
2698
|
] }),
|
|
2467
|
-
shown && /* @__PURE__ */
|
|
2699
|
+
shown && /* @__PURE__ */ jsx12(
|
|
2468
2700
|
RowTooltip,
|
|
2469
2701
|
{
|
|
2470
2702
|
at: { x: shown.px, y: shown.py },
|
|
@@ -2476,22 +2708,22 @@ function GeomapPanel({ panel, frames }) {
|
|
|
2476
2708
|
onOpenLink: (l) => links.openLinks([l])
|
|
2477
2709
|
}
|
|
2478
2710
|
),
|
|
2479
|
-
controls.showZoom !== false && /* @__PURE__ */
|
|
2480
|
-
/* @__PURE__ */
|
|
2481
|
-
/* @__PURE__ */
|
|
2482
|
-
moved && /* @__PURE__ */
|
|
2711
|
+
controls.showZoom !== false && /* @__PURE__ */ jsxs10(View9, { style: styles10.zoom, children: [
|
|
2712
|
+
/* @__PURE__ */ jsx12(MapButton, { label: "+", onPress: () => zoomTo(view, Math.round(view.zoom) + 1) }),
|
|
2713
|
+
/* @__PURE__ */ jsx12(MapButton, { label: "\u2212", onPress: () => zoomTo(view, Math.round(view.zoom) - 1) }),
|
|
2714
|
+
moved && /* @__PURE__ */ jsx12(MapButton, { label: "\u27F2", onPress: () => setMoved(null) })
|
|
2483
2715
|
] }),
|
|
2484
|
-
error ? /* @__PURE__ */
|
|
2485
|
-
controls.showAttribution !== false && attribution ? /* @__PURE__ */
|
|
2716
|
+
error ? /* @__PURE__ */ jsx12(Text10, { pointerEvents: "none", style: [styles10.error, { color: theme.danger, backgroundColor: theme.surface }], numberOfLines: 2, children: error }) : null,
|
|
2717
|
+
controls.showAttribution !== false && attribution ? /* @__PURE__ */ jsx12(Text10, { pointerEvents: "none", style: [styles10.attribution, { color: theme.textSecondary, backgroundColor: theme.surface }], numberOfLines: 1, children: attribution }) : null
|
|
2486
2718
|
] }),
|
|
2487
|
-
legend.length > 0 && /* @__PURE__ */
|
|
2719
|
+
legend.length > 0 && /* @__PURE__ */ jsx12(Legend, { items: legend })
|
|
2488
2720
|
] });
|
|
2489
2721
|
}
|
|
2490
2722
|
var NONE = {};
|
|
2491
2723
|
function useGazetteers(panel, frames) {
|
|
2492
2724
|
const { resolve } = useDashboard();
|
|
2493
2725
|
const key = gazetteerPaths(panel, frames).join("\n");
|
|
2494
|
-
const [state, setState] =
|
|
2726
|
+
const [state, setState] = useState7({ key: "", gazetteers: NONE });
|
|
2495
2727
|
useEffect3(() => {
|
|
2496
2728
|
if (!key) return;
|
|
2497
2729
|
let live = true;
|
|
@@ -2519,13 +2751,13 @@ function useGazetteers(panel, frames) {
|
|
|
2519
2751
|
}
|
|
2520
2752
|
function MapButton({ label, onPress }) {
|
|
2521
2753
|
const theme = useDashTheme();
|
|
2522
|
-
return /* @__PURE__ */
|
|
2754
|
+
return /* @__PURE__ */ jsx12(Pressable9, { onPress, hitSlop: 4, style: [styles10.button, { backgroundColor: theme.surface, borderColor: theme.border }], children: /* @__PURE__ */ jsx12(Text10, { style: [styles10.buttonText, { color: theme.text }], children: label }) });
|
|
2523
2755
|
}
|
|
2524
2756
|
function Tiles({ layer, view, width, height }) {
|
|
2525
2757
|
const tiles = visibleTiles(layer.source, view, width, height);
|
|
2526
|
-
return /* @__PURE__ */
|
|
2758
|
+
return /* @__PURE__ */ jsx12(View9, { style: [StyleSheet10.absoluteFill, { opacity: layer.opacity }], children: tiles.map((t) => (
|
|
2527
2759
|
// Half a pixel of overlap hides seams between scaled tiles.
|
|
2528
|
-
/* @__PURE__ */
|
|
2760
|
+
/* @__PURE__ */ jsx12(
|
|
2529
2761
|
Image,
|
|
2530
2762
|
{
|
|
2531
2763
|
source: { uri: t.url },
|
|
@@ -2537,17 +2769,17 @@ function Tiles({ layer, view, width, height }) {
|
|
|
2537
2769
|
)) });
|
|
2538
2770
|
}
|
|
2539
2771
|
function DataLayerSvg({ layer, screen, width, height, textColor }) {
|
|
2540
|
-
const body =
|
|
2772
|
+
const body = useMemo5(() => {
|
|
2541
2773
|
if (layer.type === "heatmap") {
|
|
2542
2774
|
const px = screen.flatMap((s) => s.px);
|
|
2543
2775
|
const py = screen.flatMap((s) => s.py);
|
|
2544
2776
|
const weights = layer.points.flatMap((p) => p.sizes);
|
|
2545
|
-
return heatmapCells(px, py, weights, layer.radius, layer.blur, width, height).map((c) => /* @__PURE__ */
|
|
2777
|
+
return heatmapCells(px, py, weights, layer.radius, layer.blur, width, height).map((c) => /* @__PURE__ */ jsx12(Path6, { d: c.d, fill: c.color, fillOpacity: c.opacity }, c.color));
|
|
2546
2778
|
}
|
|
2547
2779
|
if (layer.type === "route") return routePaths(layer, screen);
|
|
2548
2780
|
return markerPaths(layer, screen, width, height, textColor);
|
|
2549
2781
|
}, [layer, screen, width, height, textColor]);
|
|
2550
|
-
return /* @__PURE__ */
|
|
2782
|
+
return /* @__PURE__ */ jsx12(Svg6, { width, height, style: [StyleSheet10.absoluteFill, { opacity: layer.opacity }], children: body });
|
|
2551
2783
|
}
|
|
2552
2784
|
function markerPaths(layer, screen, width, height, textColor) {
|
|
2553
2785
|
const byColor = /* @__PURE__ */ new Map();
|
|
@@ -2562,7 +2794,7 @@ function markerPaths(layer, screen, width, height, textColor) {
|
|
|
2562
2794
|
const label = p.labels?.[i];
|
|
2563
2795
|
if (label && labels.length < MAX_LABELS)
|
|
2564
2796
|
labels.push(
|
|
2565
|
-
/* @__PURE__ */
|
|
2797
|
+
/* @__PURE__ */ jsx12(
|
|
2566
2798
|
SvgText2,
|
|
2567
2799
|
{
|
|
2568
2800
|
x: px[i] + layer.labelOffset[0],
|
|
@@ -2579,7 +2811,7 @@ function markerPaths(layer, screen, width, height, textColor) {
|
|
|
2579
2811
|
});
|
|
2580
2812
|
const outline = layer.symbol === "cross" || layer.symbol === "x";
|
|
2581
2813
|
return [
|
|
2582
|
-
...[...byColor].map(([color, parts]) => /* @__PURE__ */
|
|
2814
|
+
...[...byColor].map(([color, parts]) => /* @__PURE__ */ jsx12(Path6, { d: parts.join(""), fill: outline ? "none" : color, fillOpacity: layer.fillOpacity, stroke: color, strokeWidth: outline ? 2 : 1 }, color)),
|
|
2583
2815
|
...labels
|
|
2584
2816
|
];
|
|
2585
2817
|
}
|
|
@@ -2592,7 +2824,7 @@ function routePaths(layer, screen) {
|
|
|
2592
2824
|
parts.push(`M${px[i]},${py[i]}L${px[i + 1]},${py[i + 1]}`);
|
|
2593
2825
|
}
|
|
2594
2826
|
});
|
|
2595
|
-
return [...byColor].map(([color, parts]) => /* @__PURE__ */
|
|
2827
|
+
return [...byColor].map(([color, parts]) => /* @__PURE__ */ jsx12(Path6, { d: parts.join(""), stroke: color, strokeWidth: layer.lineWidth, strokeLinecap: "round", fill: "none" }, color));
|
|
2596
2828
|
}
|
|
2597
2829
|
function resolvePicked(layers, screen, picked) {
|
|
2598
2830
|
const layer = layers.find((l) => l.key === picked.layer);
|
|
@@ -2610,7 +2842,7 @@ function resolvePicked(layers, screen, picked) {
|
|
|
2610
2842
|
py: s.py[picked.index]
|
|
2611
2843
|
};
|
|
2612
2844
|
}
|
|
2613
|
-
var
|
|
2845
|
+
var styles10 = StyleSheet10.create({
|
|
2614
2846
|
fill: { flex: 1 },
|
|
2615
2847
|
map: { overflow: "hidden", borderRadius: 4 },
|
|
2616
2848
|
zoom: { position: "absolute", top: 6, left: 6, gap: 4 },
|
|
@@ -2618,7 +2850,7 @@ var styles9 = StyleSheet9.create({
|
|
|
2618
2850
|
width: 28,
|
|
2619
2851
|
height: 28,
|
|
2620
2852
|
borderRadius: 4,
|
|
2621
|
-
borderWidth:
|
|
2853
|
+
borderWidth: StyleSheet10.hairlineWidth,
|
|
2622
2854
|
alignItems: "center",
|
|
2623
2855
|
justifyContent: "center"
|
|
2624
2856
|
},
|
|
@@ -2628,8 +2860,8 @@ var styles9 = StyleSheet9.create({
|
|
|
2628
2860
|
});
|
|
2629
2861
|
|
|
2630
2862
|
// src/ui/panels/OtherPanels.tsx
|
|
2631
|
-
import { useMemo as
|
|
2632
|
-
import { Pressable as
|
|
2863
|
+
import { useMemo as useMemo6, useState as useState8 } from "react";
|
|
2864
|
+
import { Pressable as Pressable10, ScrollView as ScrollView5, StyleSheet as StyleSheet11, Text as Text11, View as View10 } from "react-native";
|
|
2633
2865
|
import Svg7, { Path as Path7 } from "react-native-svg";
|
|
2634
2866
|
|
|
2635
2867
|
// src/ui/table.ts
|
|
@@ -2768,15 +3000,15 @@ function sortedRows(columns, length, sort) {
|
|
|
2768
3000
|
var compareText = typeof Intl !== "undefined" && typeof Intl.Collator === "function" ? new Intl.Collator(void 0, { numeric: true, sensitivity: "base" }).compare : (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
2769
3001
|
|
|
2770
3002
|
// src/ui/panels/OtherPanels.tsx
|
|
2771
|
-
import { jsx as
|
|
3003
|
+
import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2772
3004
|
function PieChartPanel({ panel, frames }) {
|
|
2773
3005
|
const theme = useDashTheme();
|
|
2774
3006
|
const [size, onLayout] = useLayout();
|
|
2775
|
-
const values =
|
|
3007
|
+
const values = useMemo6(
|
|
2776
3008
|
() => reducedValues(panel, frames, theme.scheme).filter((v) => (v.value ?? 0) > 0),
|
|
2777
3009
|
[panel, frames, theme.scheme]
|
|
2778
3010
|
);
|
|
2779
|
-
if (!values.length) return /* @__PURE__ */
|
|
3011
|
+
if (!values.length) return /* @__PURE__ */ jsx13(NoData, {});
|
|
2780
3012
|
const total = values.reduce((a, v) => a + (v.value ?? 0), 0);
|
|
2781
3013
|
const r = Math.min(size.width, size.height) / 2 - 2;
|
|
2782
3014
|
const inner = panel.options?.pieType === "pie" ? 0 : r * 0.62;
|
|
@@ -2790,9 +3022,9 @@ function PieChartPanel({ panel, frames }) {
|
|
|
2790
3022
|
slices.push({ key: v.key, d: donutSlice(cx, cy, r, inner, angle + gap / 2, angle + sweep - gap / 2), color: v.color });
|
|
2791
3023
|
angle += sweep;
|
|
2792
3024
|
}
|
|
2793
|
-
return /* @__PURE__ */
|
|
2794
|
-
/* @__PURE__ */
|
|
2795
|
-
/* @__PURE__ */
|
|
3025
|
+
return /* @__PURE__ */ jsxs11(View10, { style: styles11.fill, children: [
|
|
3026
|
+
/* @__PURE__ */ jsx13(View10, { style: styles11.fill, onLayout, children: r > 0 && /* @__PURE__ */ jsx13(Svg7, { width: size.width, height: size.height, children: slices.map((s) => /* @__PURE__ */ jsx13(Path7, { d: s.d, fill: s.color }, s.key)) }) }),
|
|
3027
|
+
/* @__PURE__ */ jsx13(
|
|
2796
3028
|
Legend,
|
|
2797
3029
|
{
|
|
2798
3030
|
items: values.map((v) => ({
|
|
@@ -2816,27 +3048,27 @@ function TablePanel({ panel, frames }) {
|
|
|
2816
3048
|
const theme = useDashTheme();
|
|
2817
3049
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
2818
3050
|
const frame = frames[0];
|
|
2819
|
-
const columns =
|
|
2820
|
-
const [tapped, setSort] =
|
|
3051
|
+
const columns = useMemo6(() => frame ? tableColumns(panel, frame, frames.length > 1) : [], [panel, frame, frames.length]);
|
|
3052
|
+
const [tapped, setSort] = useState8();
|
|
2821
3053
|
const sort = tapped === void 0 ? initialSort(panel, columns) : tapped;
|
|
2822
|
-
const order =
|
|
2823
|
-
if (!frame || !frameLength(frame)) return /* @__PURE__ */
|
|
3054
|
+
const order = useMemo6(() => sortedRows(columns, frame ? frameLength(frame) : 0, sort), [columns, frame, sort]);
|
|
3055
|
+
if (!frame || !frameLength(frame)) return /* @__PURE__ */ jsx13(NoData, {});
|
|
2824
3056
|
const shown = order.slice(0, 500);
|
|
2825
3057
|
const rowColumn = columns.find((c) => c.applyToRow);
|
|
2826
3058
|
const footer = tableFooter(columns);
|
|
2827
|
-
return /* @__PURE__ */
|
|
2828
|
-
/* @__PURE__ */
|
|
2829
|
-
/* @__PURE__ */
|
|
3059
|
+
return /* @__PURE__ */ jsx13(ScrollView5, { horizontal: true, children: /* @__PURE__ */ jsxs11(View10, { style: styles11.fill, children: [
|
|
3060
|
+
/* @__PURE__ */ jsxs11(ScrollView5, { nestedScrollEnabled: true, style: styles11.fill, children: [
|
|
3061
|
+
/* @__PURE__ */ jsx13(View10, { style: [styles11.tr, { borderBottomColor: theme.border }], children: columns.map((c) => {
|
|
2830
3062
|
const active = sort?.key === c.key;
|
|
2831
|
-
return /* @__PURE__ */
|
|
2832
|
-
|
|
3063
|
+
return /* @__PURE__ */ jsx13(
|
|
3064
|
+
Pressable10,
|
|
2833
3065
|
{
|
|
2834
3066
|
onPress: () => setSort(nextSort(sort, c.key)),
|
|
2835
3067
|
accessibilityRole: "button",
|
|
2836
3068
|
accessibilityLabel: `Sort by ${c.name}`,
|
|
2837
3069
|
accessibilityState: { selected: active },
|
|
2838
3070
|
style: { width: c.width },
|
|
2839
|
-
children: /* @__PURE__ */
|
|
3071
|
+
children: /* @__PURE__ */ jsxs11(Text11, { style: [styles11.th, { color: active ? theme.text : theme.textSecondary, textAlign: c.align }], numberOfLines: 2, children: [
|
|
2840
3072
|
c.name,
|
|
2841
3073
|
active ? sort.desc ? " \u2193" : " \u2191" : ""
|
|
2842
3074
|
] })
|
|
@@ -2846,14 +3078,14 @@ function TablePanel({ panel, frames }) {
|
|
|
2846
3078
|
}) }),
|
|
2847
3079
|
shown.map((i) => {
|
|
2848
3080
|
const rowBg = rowColumn ? cellDisplay(rowColumn, rowColumn.field.values[i], theme.accent).background : void 0;
|
|
2849
|
-
return /* @__PURE__ */
|
|
3081
|
+
return /* @__PURE__ */ jsx13(View10, { style: [styles11.tr, { borderBottomColor: theme.grid }, rowBg ? { backgroundColor: rowBg } : null], children: columns.map((c) => {
|
|
2850
3082
|
const d = cellDisplay(c, c.field.values[i], theme.accent);
|
|
2851
3083
|
const bg = d.background ?? rowBg;
|
|
2852
3084
|
const linked = !!c.config.links?.length;
|
|
2853
3085
|
const color = d.color ?? (bg ? contrastText(bg, theme.text) : linked ? theme.accent : theme.text);
|
|
2854
|
-
const cellStyle = [
|
|
2855
|
-
return /* @__PURE__ */
|
|
2856
|
-
|
|
3086
|
+
const cellStyle = [styles11.td, { width: c.width }, d.background ? { backgroundColor: d.background } : null];
|
|
3087
|
+
return /* @__PURE__ */ jsxs11(
|
|
3088
|
+
Pressable10,
|
|
2857
3089
|
{
|
|
2858
3090
|
disabled: !linked,
|
|
2859
3091
|
onPress: () => openLinks(
|
|
@@ -2863,8 +3095,8 @@ function TablePanel({ panel, frames }) {
|
|
|
2863
3095
|
accessibilityRole: linked ? "link" : void 0,
|
|
2864
3096
|
style: ({ pressed }) => [cellStyle, pressed && { opacity: 0.6 }],
|
|
2865
3097
|
children: [
|
|
2866
|
-
d.gauge != null && /* @__PURE__ */
|
|
2867
|
-
/* @__PURE__ */
|
|
3098
|
+
d.gauge != null && /* @__PURE__ */ jsx13(View10, { style: [styles11.gaugeTrack, { backgroundColor: theme.grid }], children: /* @__PURE__ */ jsx13(View10, { style: [styles11.gaugeFill, { width: `${d.gauge * 100}%`, backgroundColor: d.gaugeColor ?? theme.accent }] }) }),
|
|
3099
|
+
/* @__PURE__ */ jsx13(Text11, { style: [styles11.cellText, { color, textAlign: c.align }, c.field.type === "number" && styles11.num], numberOfLines: c.wrap ? void 0 : 1, children: d.text })
|
|
2868
3100
|
]
|
|
2869
3101
|
},
|
|
2870
3102
|
c.key
|
|
@@ -2872,8 +3104,8 @@ function TablePanel({ panel, frames }) {
|
|
|
2872
3104
|
}) }, i);
|
|
2873
3105
|
})
|
|
2874
3106
|
] }),
|
|
2875
|
-
footer && /* @__PURE__ */
|
|
2876
|
-
line.label ? /* @__PURE__ */
|
|
3107
|
+
footer && /* @__PURE__ */ jsx13(View10, { style: [styles11.tr, styles11.footer, { borderTopColor: theme.border }], children: columns.map((c, ci) => /* @__PURE__ */ jsx13(View10, { style: [styles11.td, { width: c.width }], children: footer[ci].map((line, li) => /* @__PURE__ */ jsxs11(Text11, { style: [styles11.cellText, styles11.footerText, { color: theme.text, textAlign: c.align }], numberOfLines: 1, children: [
|
|
3108
|
+
line.label ? /* @__PURE__ */ jsx13(Text11, { style: { color: theme.textMuted, fontWeight: "400" }, children: `${line.label} ` }) : null,
|
|
2877
3109
|
line.text
|
|
2878
3110
|
] }, li)) }, c.key)) })
|
|
2879
3111
|
] }) });
|
|
@@ -2883,24 +3115,24 @@ function TextPanel({ panel }) {
|
|
|
2883
3115
|
const raw = panel.options?.content;
|
|
2884
3116
|
const content = typeof raw === "string" ? raw : "";
|
|
2885
3117
|
const text = panel.options?.mode === "html" ? content.replace(/<[^>]+>/g, "") : content;
|
|
2886
|
-
return /* @__PURE__ */
|
|
3118
|
+
return /* @__PURE__ */ jsx13(ScrollView5, { children: text.split(/\n{2,}/).map((block, i) => {
|
|
2887
3119
|
const heading = /^#{1,6}\s+/.test(block);
|
|
2888
|
-
return /* @__PURE__ */
|
|
3120
|
+
return /* @__PURE__ */ jsx13(Text11, { style: [styles11.para, { color: heading ? theme.text : theme.textSecondary }, heading && styles11.heading], children: block.replace(/^#{1,6}\s+/, "").replace(/\*\*(.+?)\*\*/g, "$1").replace(/\[(.+?)\]\(.+?\)/g, "$1") }, i);
|
|
2889
3121
|
}) });
|
|
2890
3122
|
}
|
|
2891
3123
|
function BarChartPanel({ panel, frames, width }) {
|
|
2892
3124
|
const theme = useDashTheme();
|
|
2893
3125
|
const [plot, onPlotLayout] = useLayout();
|
|
2894
|
-
const values =
|
|
3126
|
+
const values = useMemo6(() => reducedValues(panel, frames, theme.scheme), [panel, frames, theme.scheme]);
|
|
2895
3127
|
const frame = frames[0];
|
|
2896
3128
|
const category = frame && barCategory(panel, frame);
|
|
2897
|
-
if (!frame || !values.length) return /* @__PURE__ */
|
|
3129
|
+
if (!frame || !values.length) return /* @__PURE__ */ jsx13(NoData, {});
|
|
2898
3130
|
const xField = panel.options?.xField;
|
|
2899
|
-
if (xField && !category) return /* @__PURE__ */
|
|
3131
|
+
if (xField && !category) return /* @__PURE__ */ jsx13(NoData, { message: `No field named \u201C${String(xField)}\u201D` });
|
|
2900
3132
|
const allNumeric = frame.fields.filter((f) => f.type === "number");
|
|
2901
3133
|
const at = (f) => values[allNumeric.indexOf(f)];
|
|
2902
3134
|
const numeric = category ? allNumeric.filter((f) => f !== category) : [];
|
|
2903
|
-
if (category && !numeric.length) return /* @__PURE__ */
|
|
3135
|
+
if (category && !numeric.length) return /* @__PURE__ */ jsx13(NoData, { message: `No number fields to draw besides \u201C${category.name}\u201D` });
|
|
2904
3136
|
const fields = category ? numeric.map((f) => ({ key: f.name, name: at(f)?.name ?? f.name, color: at(f)?.color ?? theme.accent, config: at(f)?.config ?? {}, values: f.values.map(num2) })) : [{ key: "reduced", name: "", color: theme.accent, config: values[0].config, values: values.map((v) => v.value) }];
|
|
2905
3137
|
const labels = category ? categoryLabels(category) : values.map((v) => v.name);
|
|
2906
3138
|
const colorAt = (fi, i) => category ? fields[fi].color : values[i].color;
|
|
@@ -2915,34 +3147,34 @@ function BarChartPanel({ panel, frames, width }) {
|
|
|
2915
3147
|
const gridAxis = left ?? right;
|
|
2916
3148
|
const plotW = width - (left ? AXIS_W : 0) - (right ? AXIS_W : 0);
|
|
2917
3149
|
const every = Math.max(1, Math.ceil(labels.length / Math.max(1, Math.floor(plotW / 44))));
|
|
2918
|
-
const axisColumn = (axis) => /* @__PURE__ */
|
|
2919
|
-
|
|
3150
|
+
const axisColumn = (axis) => /* @__PURE__ */ jsx13(View10, { style: [styles11.axis, axis.side === "left" ? styles11.axisLeft : styles11.axisRight], children: plot.height > 0 && axis.ticks.map((t) => /* @__PURE__ */ jsx13(
|
|
3151
|
+
Text11,
|
|
2920
3152
|
{
|
|
2921
|
-
style: [
|
|
3153
|
+
style: [styles11.tick, { color: theme.textMuted, top: plot.height * (1 - barFraction(axis, t)) - 7 }, axis.side === "left" ? styles11.tickLeft : styles11.tickRight],
|
|
2922
3154
|
numberOfLines: 1,
|
|
2923
3155
|
children: formatValue(t, { ...axis.config, decimals: tickDecimals(axis.ticks) })
|
|
2924
3156
|
},
|
|
2925
3157
|
t
|
|
2926
3158
|
)) });
|
|
2927
|
-
return /* @__PURE__ */
|
|
2928
|
-
(left?.label || right?.label) && /* @__PURE__ */
|
|
2929
|
-
/* @__PURE__ */
|
|
2930
|
-
/* @__PURE__ */
|
|
3159
|
+
return /* @__PURE__ */ jsxs11(View10, { style: styles11.fill, children: [
|
|
3160
|
+
(left?.label || right?.label) && /* @__PURE__ */ jsxs11(View10, { style: styles11.axisLabels, children: [
|
|
3161
|
+
/* @__PURE__ */ jsx13(Text11, { style: [styles11.axisLabel, { color: theme.textMuted }], children: left?.label ?? "" }),
|
|
3162
|
+
/* @__PURE__ */ jsx13(Text11, { style: [styles11.axisLabel, { color: theme.textMuted }], children: right?.label ?? "" })
|
|
2931
3163
|
] }),
|
|
2932
|
-
/* @__PURE__ */
|
|
3164
|
+
/* @__PURE__ */ jsxs11(View10, { style: styles11.barRow, children: [
|
|
2933
3165
|
left && axisColumn(left),
|
|
2934
|
-
/* @__PURE__ */
|
|
2935
|
-
gridAxis && plot.height > 0 && gridAxis.ticks.map((t) => /* @__PURE__ */
|
|
2936
|
-
/* @__PURE__ */
|
|
3166
|
+
/* @__PURE__ */ jsxs11(View10, { style: styles11.fill, onLayout: onPlotLayout, children: [
|
|
3167
|
+
gridAxis && plot.height > 0 && gridAxis.ticks.map((t) => /* @__PURE__ */ jsx13(View10, { style: [styles11.gridLine, { backgroundColor: theme.grid, top: plot.height * (1 - barFraction(gridAxis, t)) }] }, t)),
|
|
3168
|
+
/* @__PURE__ */ jsx13(View10, { style: styles11.barchart, children: labels.map((_, i) => /* @__PURE__ */ jsx13(View10, { style: styles11.barStack, children: fields.map((f, fi) => {
|
|
2937
3169
|
const axis = axisOf(fi);
|
|
2938
3170
|
const base = barFraction(axis, Math.min(Math.max(0, axis.bottom), axis.top));
|
|
2939
3171
|
const end = barFraction(axis, f.values[i] ?? 0);
|
|
2940
|
-
return /* @__PURE__ */
|
|
2941
|
-
|
|
3172
|
+
return /* @__PURE__ */ jsx13(View10, { style: styles11.barSlot, children: /* @__PURE__ */ jsx13(
|
|
3173
|
+
View10,
|
|
2942
3174
|
{
|
|
2943
3175
|
style: [
|
|
2944
|
-
|
|
2945
|
-
end < base &&
|
|
3176
|
+
styles11.bar,
|
|
3177
|
+
end < base && styles11.barDown,
|
|
2946
3178
|
{ bottom: `${Math.min(base, end) * 100}%`, height: `${Math.abs(end - base) * 100}%`, backgroundColor: colorAt(fi, i) }
|
|
2947
3179
|
]
|
|
2948
3180
|
}
|
|
@@ -2951,8 +3183,8 @@ function BarChartPanel({ panel, frames, width }) {
|
|
|
2951
3183
|
] }),
|
|
2952
3184
|
right && axisColumn(right)
|
|
2953
3185
|
] }),
|
|
2954
|
-
/* @__PURE__ */
|
|
2955
|
-
category && fields.length > 1 && /* @__PURE__ */
|
|
3186
|
+
/* @__PURE__ */ jsx13(View10, { style: [styles11.barLabels, { marginLeft: left ? AXIS_W : 0, marginRight: right ? AXIS_W : 0 }], children: labels.map((label, i) => /* @__PURE__ */ jsx13(Text11, { style: [styles11.barLabel, { color: theme.textMuted }], numberOfLines: 1, children: i % every === 0 ? label : " " }, i)) }),
|
|
3187
|
+
category && fields.length > 1 && /* @__PURE__ */ jsx13(Legend, { items: fields })
|
|
2956
3188
|
] });
|
|
2957
3189
|
}
|
|
2958
3190
|
var AXIS_W = 40;
|
|
@@ -2962,15 +3194,15 @@ function num2(v) {
|
|
|
2962
3194
|
return Number.isFinite(n) ? n : null;
|
|
2963
3195
|
}
|
|
2964
3196
|
function UnsupportedPanel({ panel }) {
|
|
2965
|
-
return /* @__PURE__ */
|
|
3197
|
+
return /* @__PURE__ */ jsx13(NoData, { message: `"${panel.type}" panels aren't supported yet` });
|
|
2966
3198
|
}
|
|
2967
|
-
var
|
|
3199
|
+
var styles11 = StyleSheet11.create({
|
|
2968
3200
|
fill: { flex: 1 },
|
|
2969
|
-
tr: { flexDirection: "row", borderBottomWidth:
|
|
3201
|
+
tr: { flexDirection: "row", borderBottomWidth: StyleSheet11.hairlineWidth },
|
|
2970
3202
|
th: { paddingVertical: 6, paddingHorizontal: 6, fontSize: 12, fontWeight: "600" },
|
|
2971
3203
|
td: { paddingVertical: 6, paddingHorizontal: 6, justifyContent: "center" },
|
|
2972
3204
|
cellText: { fontSize: 12 },
|
|
2973
|
-
footer: { borderBottomWidth: 0, borderTopWidth:
|
|
3205
|
+
footer: { borderBottomWidth: 0, borderTopWidth: StyleSheet11.hairlineWidth },
|
|
2974
3206
|
footerText: { fontWeight: "600", fontVariant: ["tabular-nums"] },
|
|
2975
3207
|
gaugeTrack: { position: "absolute", left: 6, right: 6, bottom: 3, height: 3, borderRadius: 2, overflow: "hidden" },
|
|
2976
3208
|
gaugeFill: { height: "100%", borderRadius: 2 },
|
|
@@ -2986,7 +3218,7 @@ var styles10 = StyleSheet10.create({
|
|
|
2986
3218
|
barDown: { borderTopLeftRadius: 0, borderTopRightRadius: 0, borderBottomLeftRadius: 4, borderBottomRightRadius: 4 },
|
|
2987
3219
|
barLabels: { flexDirection: "row", gap: 2 },
|
|
2988
3220
|
barLabel: { flex: 1, fontSize: 10, marginTop: 4, textAlign: "center" },
|
|
2989
|
-
gridLine: { position: "absolute", left: 0, right: 0, height:
|
|
3221
|
+
gridLine: { position: "absolute", left: 0, right: 0, height: StyleSheet11.hairlineWidth },
|
|
2990
3222
|
axis: { width: AXIS_W },
|
|
2991
3223
|
axisLeft: { paddingRight: 6 },
|
|
2992
3224
|
axisRight: { paddingLeft: 6 },
|
|
@@ -2998,10 +3230,10 @@ var styles10 = StyleSheet10.create({
|
|
|
2998
3230
|
});
|
|
2999
3231
|
|
|
3000
3232
|
// src/ui/panels/TimeSeriesPanel.tsx
|
|
3001
|
-
import { useId, useMemo as
|
|
3002
|
-
import { Pressable as
|
|
3233
|
+
import { useId, useMemo as useMemo7, useRef as useRef4, useState as useState9 } from "react";
|
|
3234
|
+
import { Pressable as Pressable11, StyleSheet as StyleSheet12, Text as Text12, View as View11 } from "react-native";
|
|
3003
3235
|
import Svg8, { Circle, ClipPath, Defs, G, Line, Path as Path8, Rect, Text as SvgText3 } from "react-native-svg";
|
|
3004
|
-
import { jsx as
|
|
3236
|
+
import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
3005
3237
|
var BASE_PAD = { top: 8, right: 8, bottom: 20, left: 44 };
|
|
3006
3238
|
var BAR_MAX = 24;
|
|
3007
3239
|
function TimeSeriesPanel({ panel, frames }) {
|
|
@@ -3009,20 +3241,20 @@ function TimeSeriesPanel({ panel, frames }) {
|
|
|
3009
3241
|
const { range: range3, setRawRange, pinned, setPinned } = useDashboard();
|
|
3010
3242
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
3011
3243
|
const [size, onLayout] = useLayout();
|
|
3012
|
-
const [hoverX, setHoverX] =
|
|
3013
|
-
const [preview, setPreview] =
|
|
3014
|
-
const [xZoom, setXZoom] =
|
|
3015
|
-
const pinch =
|
|
3016
|
-
const originX =
|
|
3244
|
+
const [hoverX, setHoverX] = useState9(null);
|
|
3245
|
+
const [preview, setPreview] = useState9(null);
|
|
3246
|
+
const [xZoom, setXZoom] = useState9(null);
|
|
3247
|
+
const pinch = useRef4(null);
|
|
3248
|
+
const originX = useRef4(0);
|
|
3017
3249
|
const id = useId();
|
|
3018
3250
|
const clipId = `plot${id.replace(/[^a-zA-Z0-9]/g, "")}`;
|
|
3019
|
-
const [touching, setTouching] =
|
|
3251
|
+
const [touching, setTouching] = useState9(false);
|
|
3020
3252
|
const numericX = panel.type === "trend";
|
|
3021
|
-
const { series, xConfig } =
|
|
3253
|
+
const { series, xConfig } = useMemo7(
|
|
3022
3254
|
() => numericX ? styledXYSeries(panel, frames, theme.scheme) : { series: styledSeries(panel, frames, theme.scheme), xConfig: {} },
|
|
3023
3255
|
[numericX, panel, frames, theme.scheme]
|
|
3024
3256
|
);
|
|
3025
|
-
if (!series.length || series.every((s) => s.values.every((v) => v == null))) return /* @__PURE__ */
|
|
3257
|
+
if (!series.length || series.every((s) => s.values.every((v) => v == null))) return /* @__PURE__ */ jsx14(NoData, {});
|
|
3026
3258
|
const style = (s) => s.config.custom?.drawStyle ?? (panel.type === "graph" && panel.bars ? "bars" : "line");
|
|
3027
3259
|
const anyBars = series.some((s) => style(s) === "bars");
|
|
3028
3260
|
const anyFill = series.some((s) => (s.config.custom?.fillOpacity ?? 0) > 0);
|
|
@@ -3081,11 +3313,11 @@ function TimeSeriesPanel({ panel, frames }) {
|
|
|
3081
3313
|
)
|
|
3082
3314
|
) : [];
|
|
3083
3315
|
const isPinned = !!hover && pinned === id;
|
|
3084
|
-
return /* @__PURE__ */
|
|
3085
|
-
/* @__PURE__ */
|
|
3086
|
-
|
|
3316
|
+
return /* @__PURE__ */ jsxs12(View11, { style: styles12.fill, children: [
|
|
3317
|
+
/* @__PURE__ */ jsx14(
|
|
3318
|
+
View11,
|
|
3087
3319
|
{
|
|
3088
|
-
style:
|
|
3320
|
+
style: styles12.fill,
|
|
3089
3321
|
onStartShouldSetResponderCapture: twoFingers,
|
|
3090
3322
|
onMoveShouldSetResponderCapture: twoFingers,
|
|
3091
3323
|
onResponderTerminationRequest: () => false,
|
|
@@ -3097,10 +3329,10 @@ function TimeSeriesPanel({ panel, frames }) {
|
|
|
3097
3329
|
onResponderMove: onPinchMove,
|
|
3098
3330
|
onResponderRelease: () => onPinchEnd(true),
|
|
3099
3331
|
onResponderTerminate: () => onPinchEnd(false),
|
|
3100
|
-
children: /* @__PURE__ */
|
|
3101
|
-
|
|
3332
|
+
children: /* @__PURE__ */ jsxs12(
|
|
3333
|
+
View11,
|
|
3102
3334
|
{
|
|
3103
|
-
style:
|
|
3335
|
+
style: styles12.fill,
|
|
3104
3336
|
onLayout,
|
|
3105
3337
|
onStartShouldSetResponder: () => true,
|
|
3106
3338
|
onResponderGrant: (e) => {
|
|
@@ -3120,12 +3352,12 @@ function TimeSeriesPanel({ panel, frames }) {
|
|
|
3120
3352
|
setHoverX(null);
|
|
3121
3353
|
},
|
|
3122
3354
|
children: [
|
|
3123
|
-
size.width > 0 && /* @__PURE__ */
|
|
3124
|
-
ticks.map((t) => /* @__PURE__ */
|
|
3125
|
-
/* @__PURE__ */
|
|
3126
|
-
/* @__PURE__ */
|
|
3355
|
+
size.width > 0 && /* @__PURE__ */ jsxs12(Svg8, { width: size.width, height: size.height, children: [
|
|
3356
|
+
ticks.map((t) => /* @__PURE__ */ jsxs12(G, { children: [
|
|
3357
|
+
/* @__PURE__ */ jsx14(Line, { x1: PAD.left, x2: PAD.left + plotW, y1: y(t), y2: y(t), stroke: theme.grid, strokeWidth: 1 }),
|
|
3358
|
+
/* @__PURE__ */ jsx14(SvgText3, { x: PAD.left - 6, y: y(t) + 3, fontSize: 10, fill: theme.textMuted, textAnchor: "end", children: formatValue(t, { ...unitConfig, decimals: tickDecimals(ticks) }) })
|
|
3127
3359
|
] }, t)),
|
|
3128
|
-
xTicks.map((t) => /* @__PURE__ */
|
|
3360
|
+
xTicks.map((t) => /* @__PURE__ */ jsx14(
|
|
3129
3361
|
SvgText3,
|
|
3130
3362
|
{
|
|
3131
3363
|
x: x(t),
|
|
@@ -3137,65 +3369,65 @@ function TimeSeriesPanel({ panel, frames }) {
|
|
|
3137
3369
|
},
|
|
3138
3370
|
t
|
|
3139
3371
|
)),
|
|
3140
|
-
/* @__PURE__ */
|
|
3141
|
-
/* @__PURE__ */
|
|
3142
|
-
/* @__PURE__ */
|
|
3372
|
+
/* @__PURE__ */ jsx14(AxisTitles, { x: xTitle, y: yTitle, plot: { left: PAD.left, top: PAD.top, width: plotW, height: plotH }, height: size.height }),
|
|
3373
|
+
/* @__PURE__ */ jsx14(Defs, { children: /* @__PURE__ */ jsx14(ClipPath, { id: clipId, children: /* @__PURE__ */ jsx14(Rect, { x: PAD.left - 6, y: 0, width: plotW + 12, height: size.height }) }) }),
|
|
3374
|
+
/* @__PURE__ */ jsxs12(G, { clipPath: `url(#${clipId})`, children: [
|
|
3143
3375
|
barSeries.map(
|
|
3144
3376
|
(s, si) => s.times.map((t, i) => {
|
|
3145
3377
|
const v = s.values[i];
|
|
3146
3378
|
if (v == null || t < xFrom || t > xTo) return null;
|
|
3147
3379
|
const left = x(t) - groupW / 2 + si * (groupW / barSeries.length);
|
|
3148
|
-
return /* @__PURE__ */
|
|
3380
|
+
return /* @__PURE__ */ jsx14(Path8, { d: barPath(left, barW, y(Math.max(v, 0)), y(Math.min(v, 0)), v >= 0), fill: s.color }, `${s.key}-${i}`);
|
|
3149
3381
|
})
|
|
3150
3382
|
),
|
|
3151
3383
|
series.filter((s) => style(s) !== "bars").map((s) => {
|
|
3152
3384
|
const fill = (s.config.custom?.fillOpacity ?? 0) / 100;
|
|
3153
3385
|
const showPoints = style(s) === "points" || s.config.custom?.showPoints === "always" || s.config.custom?.showPoints !== "never" && s.times.length <= plotW / 14;
|
|
3154
3386
|
const segs = segments(s, x, y, s.config.custom?.lineInterpolation === "stepAfter");
|
|
3155
|
-
return /* @__PURE__ */
|
|
3156
|
-
fill > 0 && segs.map((seg, i) => /* @__PURE__ */
|
|
3157
|
-
style(s) !== "points" && segs.map((seg, i) => /* @__PURE__ */
|
|
3387
|
+
return /* @__PURE__ */ jsxs12(G, { children: [
|
|
3388
|
+
fill > 0 && segs.map((seg, i) => /* @__PURE__ */ jsx14(Path8, { d: `${seg.d}L${seg.lastX},${y(Math.max(yMin, 0))}L${seg.firstX},${y(Math.max(yMin, 0))}Z`, fill: s.color, opacity: fill }, `f${i}`)),
|
|
3389
|
+
style(s) !== "points" && segs.map((seg, i) => /* @__PURE__ */ jsx14(Path8, { d: seg.d, stroke: s.color, strokeWidth: s.config.custom?.lineWidth ?? 2, fill: "none", strokeLinejoin: "round", strokeLinecap: "round" }, `l${i}`)),
|
|
3158
3390
|
showPoints && s.times.map(
|
|
3159
|
-
(t, i) => s.values[i] == null ? null : /* @__PURE__ */
|
|
3391
|
+
(t, i) => s.values[i] == null ? null : /* @__PURE__ */ jsx14(Circle, { cx: x(t), cy: y(s.values[i]), r: 4, fill: s.color, stroke: theme.surface, strokeWidth: 2 }, i)
|
|
3160
3392
|
)
|
|
3161
3393
|
] }, s.key);
|
|
3162
3394
|
}),
|
|
3163
|
-
hover && /* @__PURE__ */
|
|
3164
|
-
/* @__PURE__ */
|
|
3395
|
+
hover && /* @__PURE__ */ jsxs12(G, { children: [
|
|
3396
|
+
/* @__PURE__ */ jsx14(Line, { x1: x(hover.time), x2: x(hover.time), y1: PAD.top, y2: PAD.top + plotH, stroke: theme.textMuted, strokeWidth: 1 }),
|
|
3165
3397
|
hover.rows.map(
|
|
3166
|
-
(r) => r.value == null ? null : /* @__PURE__ */
|
|
3398
|
+
(r) => r.value == null ? null : /* @__PURE__ */ jsx14(Circle, { cx: x(r.time), cy: y(r.value), r: 5, fill: r.color, stroke: theme.surface, strokeWidth: 2 }, r.key)
|
|
3167
3399
|
)
|
|
3168
3400
|
] })
|
|
3169
3401
|
] })
|
|
3170
3402
|
] }),
|
|
3171
|
-
xZoom && !preview && /* @__PURE__ */
|
|
3172
|
-
|
|
3403
|
+
xZoom && !preview && /* @__PURE__ */ jsx14(
|
|
3404
|
+
Pressable11,
|
|
3173
3405
|
{
|
|
3174
3406
|
onPress: () => setXZoom(null),
|
|
3175
3407
|
accessibilityRole: "button",
|
|
3176
3408
|
hitSlop: 8,
|
|
3177
|
-
style: ({ pressed }) => [
|
|
3178
|
-
children: /* @__PURE__ */
|
|
3409
|
+
style: ({ pressed }) => [styles12.reset, { backgroundColor: theme.surface, borderColor: theme.border }, pressed && { opacity: 0.7 }],
|
|
3410
|
+
children: /* @__PURE__ */ jsx14(Text12, { style: [styles12.resetText, { color: theme.accent }], children: "Reset zoom" })
|
|
3179
3411
|
}
|
|
3180
3412
|
),
|
|
3181
|
-
hover && /* @__PURE__ */
|
|
3182
|
-
|
|
3413
|
+
hover && /* @__PURE__ */ jsxs12(
|
|
3414
|
+
View11,
|
|
3183
3415
|
{
|
|
3184
3416
|
pointerEvents: isPinned ? "auto" : "none",
|
|
3185
3417
|
onStartShouldSetResponder: () => isPinned,
|
|
3186
3418
|
style: [
|
|
3187
|
-
|
|
3419
|
+
styles12.tooltip,
|
|
3188
3420
|
{ backgroundColor: theme.surface, borderColor: theme.border },
|
|
3189
3421
|
x(hover.time) > size.width / 2 ? { right: size.width - x(hover.time) + 8 } : { left: x(hover.time) + 8 }
|
|
3190
3422
|
],
|
|
3191
3423
|
children: [
|
|
3192
|
-
/* @__PURE__ */
|
|
3193
|
-
hover.rows.map((r) => /* @__PURE__ */
|
|
3194
|
-
/* @__PURE__ */
|
|
3195
|
-
/* @__PURE__ */
|
|
3196
|
-
/* @__PURE__ */
|
|
3424
|
+
/* @__PURE__ */ jsx14(Text12, { style: [styles12.tooltipTime, { color: theme.textMuted }], children: numericX ? formatValue(hover.time, xConfig) : formatTooltipTime(hover.time) }),
|
|
3425
|
+
hover.rows.map((r) => /* @__PURE__ */ jsxs12(View11, { style: styles12.tooltipRow, children: [
|
|
3426
|
+
/* @__PURE__ */ jsx14(View11, { style: [styles12.swatch, { backgroundColor: r.color }] }),
|
|
3427
|
+
/* @__PURE__ */ jsx14(Text12, { style: [styles12.tooltipName, { color: theme.textSecondary }], numberOfLines: 1, children: r.name }),
|
|
3428
|
+
/* @__PURE__ */ jsx14(Text12, { style: [styles12.tooltipValue, { color: theme.text }], children: formatValue(r.value, r.config) })
|
|
3197
3429
|
] }, r.key)),
|
|
3198
|
-
isPinned && /* @__PURE__ */
|
|
3430
|
+
isPinned && /* @__PURE__ */ jsx14(TooltipLinks, { links: hoverLinks, onOpen: (l) => openLinks([l]) })
|
|
3199
3431
|
]
|
|
3200
3432
|
}
|
|
3201
3433
|
)
|
|
@@ -3204,7 +3436,7 @@ function TimeSeriesPanel({ panel, frames }) {
|
|
|
3204
3436
|
)
|
|
3205
3437
|
}
|
|
3206
3438
|
),
|
|
3207
|
-
showLegend(panel, series.length) && /* @__PURE__ */
|
|
3439
|
+
showLegend(panel, series.length) && /* @__PURE__ */ jsx14(Legend, { items: series })
|
|
3208
3440
|
] });
|
|
3209
3441
|
}
|
|
3210
3442
|
function segments(s, x, y, step = false) {
|
|
@@ -3293,7 +3525,7 @@ function linkData(r, frames, xField) {
|
|
|
3293
3525
|
time: xField === void 0 ? r.time : void 0
|
|
3294
3526
|
};
|
|
3295
3527
|
}
|
|
3296
|
-
var
|
|
3528
|
+
var styles12 = StyleSheet12.create({
|
|
3297
3529
|
fill: { flex: 1 },
|
|
3298
3530
|
tooltip: {
|
|
3299
3531
|
position: "absolute",
|
|
@@ -3301,7 +3533,7 @@ var styles11 = StyleSheet11.create({
|
|
|
3301
3533
|
paddingHorizontal: 8,
|
|
3302
3534
|
paddingVertical: 6,
|
|
3303
3535
|
borderRadius: 6,
|
|
3304
|
-
borderWidth:
|
|
3536
|
+
borderWidth: StyleSheet12.hairlineWidth,
|
|
3305
3537
|
maxWidth: 220,
|
|
3306
3538
|
shadowColor: "#000",
|
|
3307
3539
|
shadowOpacity: 0.12,
|
|
@@ -3309,7 +3541,7 @@ var styles11 = StyleSheet11.create({
|
|
|
3309
3541
|
shadowOffset: { width: 0, height: 2 },
|
|
3310
3542
|
elevation: 3
|
|
3311
3543
|
},
|
|
3312
|
-
reset: { position: "absolute", top: 4, right: 8, paddingHorizontal: 8, paddingVertical: 3, borderRadius: 6, borderWidth:
|
|
3544
|
+
reset: { position: "absolute", top: 4, right: 8, paddingHorizontal: 8, paddingVertical: 3, borderRadius: 6, borderWidth: StyleSheet12.hairlineWidth },
|
|
3313
3545
|
resetText: { fontSize: 11, fontWeight: "600" },
|
|
3314
3546
|
tooltipTime: { fontSize: 11, marginBottom: 3 },
|
|
3315
3547
|
tooltipRow: { flexDirection: "row", alignItems: "center", gap: 6 },
|
|
@@ -3319,8 +3551,8 @@ var styles11 = StyleSheet11.create({
|
|
|
3319
3551
|
});
|
|
3320
3552
|
|
|
3321
3553
|
// src/ui/panels/XYChartPanel.tsx
|
|
3322
|
-
import { useId as useId2, useMemo as
|
|
3323
|
-
import { StyleSheet as
|
|
3554
|
+
import { useId as useId2, useMemo as useMemo8, useState as useState10 } from "react";
|
|
3555
|
+
import { StyleSheet as StyleSheet13, View as View12 } from "react-native";
|
|
3324
3556
|
import Svg9, { Circle as Circle2, G as G2, Line as Line2, Path as Path9, Text as SvgText4 } from "react-native-svg";
|
|
3325
3557
|
|
|
3326
3558
|
// src/ui/xychart.ts
|
|
@@ -3452,19 +3684,19 @@ function xyDomain(values, config) {
|
|
|
3452
3684
|
}
|
|
3453
3685
|
|
|
3454
3686
|
// src/ui/panels/XYChartPanel.tsx
|
|
3455
|
-
import { jsx as
|
|
3687
|
+
import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
3456
3688
|
var AXIS = { left: 44, bottom: 20 };
|
|
3457
3689
|
var EDGE = 8;
|
|
3458
3690
|
var HIT_PX2 = 32;
|
|
3459
3691
|
function XYChartPanel({ panel, frames }) {
|
|
3460
3692
|
const theme = useDashTheme();
|
|
3461
3693
|
const [size, onLayout] = useLayout();
|
|
3462
|
-
const [touch, setTouch] =
|
|
3463
|
-
const [touching, setTouching] =
|
|
3694
|
+
const [touch, setTouch] = useState10(null);
|
|
3695
|
+
const [touching, setTouching] = useState10(false);
|
|
3464
3696
|
const id = useId2();
|
|
3465
3697
|
const { pinned, setPinned } = useDashboard();
|
|
3466
3698
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
3467
|
-
const series =
|
|
3699
|
+
const series = useMemo8(() => xySeries(panel, frames, theme.scheme), [panel, frames, theme.scheme]);
|
|
3468
3700
|
const first = series[0];
|
|
3469
3701
|
const showX = first?.xConfig.custom?.axisPlacement !== "hidden";
|
|
3470
3702
|
const showY = first?.yConfig.custom?.axisPlacement !== "hidden";
|
|
@@ -3478,7 +3710,7 @@ function XYChartPanel({ panel, frames }) {
|
|
|
3478
3710
|
};
|
|
3479
3711
|
const plotW = Math.max(0, size.width - pad.left - pad.right);
|
|
3480
3712
|
const plotH = Math.max(0, size.height - pad.top - pad.bottom);
|
|
3481
|
-
const layout =
|
|
3713
|
+
const layout = useMemo8(() => {
|
|
3482
3714
|
if (!first) return null;
|
|
3483
3715
|
const [x0, x1] = xyDomain(series.map((s) => s.xs), first.xConfig);
|
|
3484
3716
|
const [y0, y1] = xyDomain(series.map((s) => s.ys), first.yConfig);
|
|
@@ -3487,7 +3719,7 @@ function XYChartPanel({ panel, frames }) {
|
|
|
3487
3719
|
const points = series.map((s) => ({ px: s.xs.map(x), py: s.ys.map(y) }));
|
|
3488
3720
|
return { x, y, x0, x1, y0, y1, points, paths: series.map((s, i) => drawSeries(s, points[i].px, points[i].py)) };
|
|
3489
3721
|
}, [series, first, pad.left, pad.top, plotW, plotH]);
|
|
3490
|
-
if (!first || !layout || series.every((s) => !s.rows.length)) return /* @__PURE__ */
|
|
3722
|
+
if (!first || !layout || series.every((s) => !s.rows.length)) return /* @__PURE__ */ jsx15(NoData, {});
|
|
3491
3723
|
const xTicks = showX ? axisTicks(layout.x0, layout.x1, plotW < 220 ? 2 : plotW < 400 ? 3 : 5) : [];
|
|
3492
3724
|
const yTicks = showY ? axisTicks(layout.y0, layout.y1, plotH < 100 ? 2 : 4) : [];
|
|
3493
3725
|
const gridX = first.xConfig.custom?.axisGridShow !== false;
|
|
@@ -3496,11 +3728,11 @@ function XYChartPanel({ panel, frames }) {
|
|
|
3496
3728
|
const hoverLinks = hover ? rowLinks(panel, hover.series.frame, hover.series.rows[hover.index], frames.length > 1, resolve) : [];
|
|
3497
3729
|
const isPinned = !!hover && pinned === id;
|
|
3498
3730
|
const legendItems = series.filter((s) => !s.yConfig.custom?.hideFrom?.legend);
|
|
3499
|
-
return /* @__PURE__ */
|
|
3500
|
-
/* @__PURE__ */
|
|
3501
|
-
|
|
3731
|
+
return /* @__PURE__ */ jsxs13(View12, { style: styles13.fill, children: [
|
|
3732
|
+
/* @__PURE__ */ jsxs13(
|
|
3733
|
+
View12,
|
|
3502
3734
|
{
|
|
3503
|
-
style:
|
|
3735
|
+
style: styles13.fill,
|
|
3504
3736
|
onLayout,
|
|
3505
3737
|
onStartShouldSetResponder: () => true,
|
|
3506
3738
|
onResponderGrant: (e) => {
|
|
@@ -3519,14 +3751,14 @@ function XYChartPanel({ panel, frames }) {
|
|
|
3519
3751
|
setTouch(null);
|
|
3520
3752
|
},
|
|
3521
3753
|
children: [
|
|
3522
|
-
size.width > 0 && /* @__PURE__ */
|
|
3523
|
-
yTicks.map((t) => /* @__PURE__ */
|
|
3524
|
-
gridY && /* @__PURE__ */
|
|
3525
|
-
/* @__PURE__ */
|
|
3754
|
+
size.width > 0 && /* @__PURE__ */ jsxs13(Svg9, { width: size.width, height: size.height, children: [
|
|
3755
|
+
yTicks.map((t) => /* @__PURE__ */ jsxs13(G2, { children: [
|
|
3756
|
+
gridY && /* @__PURE__ */ jsx15(Line2, { x1: pad.left, x2: pad.left + plotW, y1: layout.y(t), y2: layout.y(t), stroke: theme.grid, strokeWidth: 1 }),
|
|
3757
|
+
/* @__PURE__ */ jsx15(SvgText4, { x: pad.left - 6, y: layout.y(t) + 3, fontSize: 10, fill: theme.textMuted, textAnchor: "end", children: formatValue(t, { ...first.yConfig, decimals: first.yConfig.decimals ?? tickDecimals(yTicks) }) })
|
|
3526
3758
|
] }, `y${t}`)),
|
|
3527
|
-
xTicks.map((t) => /* @__PURE__ */
|
|
3528
|
-
gridX && /* @__PURE__ */
|
|
3529
|
-
/* @__PURE__ */
|
|
3759
|
+
xTicks.map((t) => /* @__PURE__ */ jsxs13(G2, { children: [
|
|
3760
|
+
gridX && /* @__PURE__ */ jsx15(Line2, { x1: layout.x(t), x2: layout.x(t), y1: pad.top, y2: pad.top + plotH, stroke: theme.grid, strokeWidth: 1 }),
|
|
3761
|
+
/* @__PURE__ */ jsx15(
|
|
3530
3762
|
SvgText4,
|
|
3531
3763
|
{
|
|
3532
3764
|
x: layout.x(t),
|
|
@@ -3538,12 +3770,12 @@ function XYChartPanel({ panel, frames }) {
|
|
|
3538
3770
|
}
|
|
3539
3771
|
)
|
|
3540
3772
|
] }, `x${t}`)),
|
|
3541
|
-
/* @__PURE__ */
|
|
3542
|
-
series.map((s, si) => /* @__PURE__ */
|
|
3543
|
-
layout.paths[si].line && /* @__PURE__ */
|
|
3544
|
-
layout.paths[si].dots.map(([color, d]) => /* @__PURE__ */
|
|
3773
|
+
/* @__PURE__ */ jsx15(AxisTitles, { x: xTitle, y: yTitle, plot: { left: pad.left, top: pad.top, width: plotW, height: plotH }, height: size.height }),
|
|
3774
|
+
series.map((s, si) => /* @__PURE__ */ jsxs13(G2, { children: [
|
|
3775
|
+
layout.paths[si].line && /* @__PURE__ */ jsx15(Path9, { d: layout.paths[si].line, stroke: s.color, strokeWidth: s.lineWidth, fill: "none", strokeLinejoin: "round" }),
|
|
3776
|
+
layout.paths[si].dots.map(([color, d]) => /* @__PURE__ */ jsx15(Path9, { d, fill: color }, color))
|
|
3545
3777
|
] }, s.key)),
|
|
3546
|
-
hover && /* @__PURE__ */
|
|
3778
|
+
hover && /* @__PURE__ */ jsx15(
|
|
3547
3779
|
Circle2,
|
|
3548
3780
|
{
|
|
3549
3781
|
cx: hover.px,
|
|
@@ -3555,7 +3787,7 @@ function XYChartPanel({ panel, frames }) {
|
|
|
3555
3787
|
}
|
|
3556
3788
|
)
|
|
3557
3789
|
] }),
|
|
3558
|
-
hover && /* @__PURE__ */
|
|
3790
|
+
hover && /* @__PURE__ */ jsx15(
|
|
3559
3791
|
RowTooltip,
|
|
3560
3792
|
{
|
|
3561
3793
|
at: { x: hover.px, y: hover.py },
|
|
@@ -3570,7 +3802,7 @@ function XYChartPanel({ panel, frames }) {
|
|
|
3570
3802
|
]
|
|
3571
3803
|
}
|
|
3572
3804
|
),
|
|
3573
|
-
showLegend(panel, legendItems.length) && /* @__PURE__ */
|
|
3805
|
+
showLegend(panel, legendItems.length) && /* @__PURE__ */ jsx15(Legend, { items: legendItems })
|
|
3574
3806
|
] });
|
|
3575
3807
|
}
|
|
3576
3808
|
function drawSeries(s, px, py) {
|
|
@@ -3604,7 +3836,7 @@ function nearestPoint(series, points, at) {
|
|
|
3604
3836
|
});
|
|
3605
3837
|
return best;
|
|
3606
3838
|
}
|
|
3607
|
-
var
|
|
3839
|
+
var styles13 = StyleSheet13.create({
|
|
3608
3840
|
fill: { flex: 1 }
|
|
3609
3841
|
});
|
|
3610
3842
|
|
|
@@ -3632,8 +3864,8 @@ function panelComponent(type) {
|
|
|
3632
3864
|
}
|
|
3633
3865
|
|
|
3634
3866
|
// src/ui/DashboardView.tsx
|
|
3635
|
-
import { jsx as
|
|
3636
|
-
var
|
|
3867
|
+
import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
3868
|
+
var GAP2 = 8;
|
|
3637
3869
|
var SIDE = 12;
|
|
3638
3870
|
var TITLE_H = 28;
|
|
3639
3871
|
var TABLET_WIDTH = 700;
|
|
@@ -3646,48 +3878,48 @@ function DashboardView({ mode = "auto", header, footer, refreshable }) {
|
|
|
3646
3878
|
const insets = useSafeAreaInsets4();
|
|
3647
3879
|
const width = (measured.width || window.width) - insets.left - insets.right;
|
|
3648
3880
|
const layoutMode = mode === "auto" ? width >= TABLET_WIDTH ? "grid" : "phone" : mode;
|
|
3649
|
-
const sections =
|
|
3881
|
+
const sections = useMemo9(
|
|
3650
3882
|
() => layoutDashboard(dashboard, layoutMode, { values: variables, info: variableInfo2 }),
|
|
3651
3883
|
[dashboard, layoutMode, variables, variableInfo2]
|
|
3652
3884
|
);
|
|
3653
|
-
const [toggled, setToggled] =
|
|
3885
|
+
const [toggled, setToggled] = useState11({});
|
|
3654
3886
|
const { seen, viewportH, onScroll, onViewportLayout, onSectionLayout } = useSeenSections(window.height);
|
|
3655
3887
|
const maxPanelH = Math.max(MIN_PANEL_H, viewportH - SIDE * 2);
|
|
3656
3888
|
const contentW = width - SIDE * 2;
|
|
3657
3889
|
const canRefresh = refreshable ?? dashboard.panels.some((p) => panelHasQueries(p) || p.panels?.some(panelHasQueries));
|
|
3658
|
-
return /* @__PURE__ */
|
|
3659
|
-
width > 0 && /* @__PURE__ */
|
|
3660
|
-
|
|
3890
|
+
return /* @__PURE__ */ jsxs14(View13, { style: [styles14.fill, { backgroundColor: theme.background }], onLayout, children: [
|
|
3891
|
+
width > 0 && /* @__PURE__ */ jsxs14(
|
|
3892
|
+
ScrollView6,
|
|
3661
3893
|
{
|
|
3662
3894
|
onScroll,
|
|
3663
3895
|
onScrollBeginDrag: () => setPinned(null),
|
|
3664
3896
|
onLayout: onViewportLayout,
|
|
3665
3897
|
scrollEventThrottle: 100,
|
|
3666
|
-
contentContainerStyle: [
|
|
3898
|
+
contentContainerStyle: [styles14.content, { paddingLeft: SIDE + insets.left, paddingRight: SIDE + insets.right }],
|
|
3667
3899
|
keyboardShouldPersistTaps: "handled",
|
|
3668
|
-
refreshControl: canRefresh ? /* @__PURE__ */
|
|
3900
|
+
refreshControl: canRefresh ? /* @__PURE__ */ jsx16(RefreshControl, { refreshing: false, onRefresh: refresh }) : void 0,
|
|
3669
3901
|
children: [
|
|
3670
3902
|
header,
|
|
3671
3903
|
sections.map((section) => {
|
|
3672
3904
|
const collapsed = toggled[section.key] ?? section.collapsed;
|
|
3673
|
-
return /* @__PURE__ */
|
|
3674
|
-
section.row && /* @__PURE__ */
|
|
3675
|
-
|
|
3905
|
+
return /* @__PURE__ */ jsxs14(View13, { style: styles14.section, onLayout: (e) => onSectionLayout(section.key, e), children: [
|
|
3906
|
+
section.row && /* @__PURE__ */ jsxs14(
|
|
3907
|
+
Pressable12,
|
|
3676
3908
|
{
|
|
3677
3909
|
onPress: () => setToggled((t) => ({ ...t, [section.key]: !collapsed })),
|
|
3678
|
-
style:
|
|
3910
|
+
style: styles14.rowHeader,
|
|
3679
3911
|
accessibilityRole: "button",
|
|
3680
3912
|
accessibilityState: { expanded: !collapsed },
|
|
3681
3913
|
children: [
|
|
3682
|
-
/* @__PURE__ */
|
|
3683
|
-
/* @__PURE__ */
|
|
3914
|
+
/* @__PURE__ */ jsx16(Text13, { style: [styles14.chevron, { color: theme.textMuted }], children: collapsed ? "\u25B8" : "\u25BE" }),
|
|
3915
|
+
/* @__PURE__ */ jsx16(Text13, { style: [styles14.rowTitle, { color: theme.text }], numberOfLines: 2, children: interpolate(section.row.title ?? "", { values: variables, info: variableInfo2, scoped: section.row.scopedVars, timezone: dashboard.timezone }) })
|
|
3684
3916
|
]
|
|
3685
3917
|
}
|
|
3686
3918
|
),
|
|
3687
|
-
!collapsed && layoutMode === "grid" && /* @__PURE__ */
|
|
3688
|
-
!collapsed && layoutMode === "phone" && section.rows.map((row, ri) => /* @__PURE__ */
|
|
3689
|
-
const w = (contentW +
|
|
3690
|
-
return /* @__PURE__ */
|
|
3919
|
+
!collapsed && layoutMode === "grid" && /* @__PURE__ */ jsx16(GridSection, { grid: section.grid, width: contentW, maxPanelH, deferred: !seen.has(section.key) }),
|
|
3920
|
+
!collapsed && layoutMode === "phone" && section.rows.map((row, ri) => /* @__PURE__ */ jsx16(View13, { style: styles14.row, children: row.cells.map((cell) => {
|
|
3921
|
+
const w = (contentW + GAP2) * (cell.span / GRID_COLUMNS) - GAP2;
|
|
3922
|
+
return /* @__PURE__ */ jsx16(PanelCard, { panel: cell.panel, width: w, height: Math.min(gridUnitsToPx(row.h), maxPanelH), deferred: !seen.has(section.key) }, cell.key);
|
|
3691
3923
|
}) }, ri))
|
|
3692
3924
|
] }, section.key);
|
|
3693
3925
|
})
|
|
@@ -3698,16 +3930,16 @@ function DashboardView({ mode = "auto", header, footer, refreshable }) {
|
|
|
3698
3930
|
] });
|
|
3699
3931
|
}
|
|
3700
3932
|
function GridSection({ grid, width, maxPanelH, deferred }) {
|
|
3701
|
-
const colW = (width +
|
|
3933
|
+
const colW = (width + GAP2) / GRID_COLUMNS;
|
|
3702
3934
|
const tallest = Math.max(0, ...grid.cells.map((c) => gridUnitsToPx(c.h)));
|
|
3703
3935
|
const scale = tallest > maxPanelH ? maxPanelH / tallest : 1;
|
|
3704
|
-
return /* @__PURE__ */
|
|
3936
|
+
return /* @__PURE__ */ jsx16(View13, { style: { height: gridUnitsToPx(grid.h) * scale }, children: grid.cells.map((cell) => /* @__PURE__ */ jsx16(View13, { style: [styles14.gridCell, { left: cell.x * colW, top: gridOffsetPx(cell.y) * scale }], children: /* @__PURE__ */ jsx16(PanelCard, { panel: cell.panel, width: cell.w * colW - GAP2, height: gridUnitsToPx(cell.h) * scale, deferred }) }, cell.key)) });
|
|
3705
3937
|
}
|
|
3706
3938
|
function useSeenSections(viewportHeight) {
|
|
3707
|
-
const [seen, setSeen] =
|
|
3708
|
-
const view =
|
|
3709
|
-
const [viewportH, setViewportH] =
|
|
3710
|
-
const positions =
|
|
3939
|
+
const [seen, setSeen] = useState11(/* @__PURE__ */ new Set());
|
|
3940
|
+
const view = useRef5({ y: 0, h: viewportHeight });
|
|
3941
|
+
const [viewportH, setViewportH] = useState11(viewportHeight);
|
|
3942
|
+
const positions = useRef5(/* @__PURE__ */ new Map());
|
|
3711
3943
|
const reveal = useCallback3(() => {
|
|
3712
3944
|
const { y, h } = view.current;
|
|
3713
3945
|
setSeen((prev) => {
|
|
@@ -3746,43 +3978,44 @@ function useSeenSections(viewportHeight) {
|
|
|
3746
3978
|
}
|
|
3747
3979
|
function PanelCard(props) {
|
|
3748
3980
|
const { panel, width, height } = props;
|
|
3749
|
-
return /* @__PURE__ */
|
|
3981
|
+
return /* @__PURE__ */ jsx16(RenderBoundary, { resetKeys: [panel, width, height], fallback: (error) => /* @__PURE__ */ jsx16(PanelError, { panel, width, height, error }), children: /* @__PURE__ */ jsx16(PanelCardContent, { ...props }) });
|
|
3750
3982
|
}
|
|
3751
3983
|
function PanelError({ panel, width, height, error }) {
|
|
3752
3984
|
const theme = useDashTheme();
|
|
3753
|
-
return /* @__PURE__ */
|
|
3754
|
-
!!panel.title && /* @__PURE__ */
|
|
3755
|
-
/* @__PURE__ */
|
|
3756
|
-
/* @__PURE__ */
|
|
3985
|
+
return /* @__PURE__ */ jsxs14(View13, { style: [styles14.card, { width, height, backgroundColor: theme.surface, borderColor: theme.danger }], accessibilityRole: "alert", children: [
|
|
3986
|
+
!!panel.title && /* @__PURE__ */ jsx16(Text13, { style: [styles14.title, styles14.errorTitle, { color: theme.text }], numberOfLines: 1, children: panel.title }),
|
|
3987
|
+
/* @__PURE__ */ jsx16(Text13, { style: [styles14.errorText, { color: theme.danger }], children: "This panel couldn\u2019t be shown." }),
|
|
3988
|
+
/* @__PURE__ */ jsx16(Text13, { style: [styles14.errorText, { color: theme.textMuted }], numberOfLines: 3, children: error.message })
|
|
3757
3989
|
] });
|
|
3758
3990
|
}
|
|
3759
3991
|
function PanelCardContent({ panel, width, height, deferred }) {
|
|
3760
3992
|
const theme = useDashTheme();
|
|
3761
3993
|
const { dashboard, variables, variableInfo: variableInfo2 } = useDashboard();
|
|
3762
3994
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
3763
|
-
const
|
|
3995
|
+
const group = isInputGroup(panel);
|
|
3996
|
+
const input = isInputPanel(panel) || group;
|
|
3764
3997
|
const form = useContext4(InputFormContext);
|
|
3765
|
-
const problem =
|
|
3998
|
+
const problem = group ? form?.group?.(panel)?.problem : isInputPanel(panel) ? form?.problem?.(panel.options.metric) : void 0;
|
|
3766
3999
|
const hasLinks = !!panel.links?.length;
|
|
3767
4000
|
const hasTitle = !!panel.title || hasLinks || !!problem;
|
|
3768
4001
|
const title = panel.title ? interpolate(panel.title, { values: variables, info: variableInfo2, scoped: panel.scopedVars, timezone: dashboard.timezone }) : "";
|
|
3769
|
-
return /* @__PURE__ */
|
|
3770
|
-
hasTitle && /* @__PURE__ */
|
|
3771
|
-
/* @__PURE__ */
|
|
3772
|
-
!!problem && /* @__PURE__ */
|
|
3773
|
-
hasLinks && /* @__PURE__ */
|
|
3774
|
-
|
|
4002
|
+
return /* @__PURE__ */ jsxs14(View13, { style: [styles14.card, { width, height, backgroundColor: theme.surface, borderColor: theme.border }], children: [
|
|
4003
|
+
hasTitle && /* @__PURE__ */ jsxs14(View13, { style: styles14.titleRow, children: [
|
|
4004
|
+
/* @__PURE__ */ jsx16(Text13, { style: [styles14.title, { color: theme.text }], numberOfLines: 1, children: title }),
|
|
4005
|
+
!!problem && /* @__PURE__ */ jsx16(Text13, { style: [styles14.problem, { color: theme.danger }], numberOfLines: 1, accessibilityRole: "alert", children: problem }),
|
|
4006
|
+
hasLinks && /* @__PURE__ */ jsx16(
|
|
4007
|
+
Pressable12,
|
|
3775
4008
|
{
|
|
3776
4009
|
onPress: () => openLinks(resolve(panel.links), title || void 0),
|
|
3777
4010
|
accessibilityRole: "button",
|
|
3778
4011
|
accessibilityLabel: panel.links.length === 1 ? panel.links[0].title || "Open link" : "Panel links",
|
|
3779
4012
|
hitSlop: 10,
|
|
3780
|
-
style: ({ pressed }) => [
|
|
3781
|
-
children: /* @__PURE__ */
|
|
4013
|
+
style: ({ pressed }) => [styles14.titleLink, pressed && { opacity: 0.6 }],
|
|
4014
|
+
children: /* @__PURE__ */ jsx16(LinkIcon, { color: theme.textMuted })
|
|
3782
4015
|
}
|
|
3783
4016
|
)
|
|
3784
4017
|
] }),
|
|
3785
|
-
/* @__PURE__ */
|
|
4018
|
+
/* @__PURE__ */ jsx16(View13, { style: styles14.body, children: deferred && !input ? null : input ? group ? /* @__PURE__ */ jsx16(InputGroupBody, { panel }) : /* @__PURE__ */ jsx16(InputPanelBody, { panel }) : /* @__PURE__ */ jsx16(DataPanelBody, { panel, width: width - 24, height: height - (hasTitle ? TITLE_H : 0) - 16 }) })
|
|
3786
4019
|
] });
|
|
3787
4020
|
}
|
|
3788
4021
|
function DataPanelBody({ panel, width, height }) {
|
|
@@ -3791,23 +4024,23 @@ function DataPanelBody({ panel, width, height }) {
|
|
|
3791
4024
|
const data = usePanelData(panel, width, needsData);
|
|
3792
4025
|
const Component2 = panelComponent(panel.type);
|
|
3793
4026
|
if (needsData && data.error) {
|
|
3794
|
-
return /* @__PURE__ */
|
|
4027
|
+
return /* @__PURE__ */ jsx16(View13, { style: styles14.center, children: /* @__PURE__ */ jsx16(Text13, { style: [styles14.error, { color: theme.danger }], numberOfLines: 4, children: data.error }) });
|
|
3795
4028
|
}
|
|
3796
4029
|
if (needsData && data.loading && !data.frames.length) {
|
|
3797
|
-
return /* @__PURE__ */
|
|
4030
|
+
return /* @__PURE__ */ jsx16(View13, { style: styles14.center, children: /* @__PURE__ */ jsx16(ActivityIndicator, { color: theme.textMuted }) });
|
|
3798
4031
|
}
|
|
3799
|
-
return /* @__PURE__ */
|
|
4032
|
+
return /* @__PURE__ */ jsx16(Component2, { panel, frames: data.frames, width, height });
|
|
3800
4033
|
}
|
|
3801
|
-
var
|
|
4034
|
+
var styles14 = StyleSheet14.create({
|
|
3802
4035
|
fill: { flex: 1 },
|
|
3803
|
-
content: { padding: SIDE, paddingBottom: 32, gap:
|
|
3804
|
-
section: { gap:
|
|
4036
|
+
content: { padding: SIDE, paddingBottom: 32, gap: GAP2 },
|
|
4037
|
+
section: { gap: GAP2 },
|
|
3805
4038
|
rowHeader: { flexDirection: "row", alignItems: "center", gap: 6, paddingVertical: 6 },
|
|
3806
4039
|
chevron: { fontSize: 14, width: 14 },
|
|
3807
4040
|
rowTitle: { fontSize: 15, fontWeight: "600" },
|
|
3808
|
-
row: { flexDirection: "row", gap:
|
|
4041
|
+
row: { flexDirection: "row", gap: GAP2 },
|
|
3809
4042
|
gridCell: { position: "absolute" },
|
|
3810
|
-
card: { borderRadius: 10, borderWidth:
|
|
4043
|
+
card: { borderRadius: 10, borderWidth: StyleSheet14.hairlineWidth, paddingHorizontal: 12, paddingVertical: 8, overflow: "hidden" },
|
|
3811
4044
|
titleRow: { flexDirection: "row", alignItems: "flex-start", gap: 8, height: TITLE_H - 8, marginBottom: 8 },
|
|
3812
4045
|
title: { flex: 1, fontSize: 13, fontWeight: "600" },
|
|
3813
4046
|
titleLink: { paddingTop: 1 },
|
|
@@ -3820,9 +4053,9 @@ var styles13 = StyleSheet13.create({
|
|
|
3820
4053
|
});
|
|
3821
4054
|
|
|
3822
4055
|
// src/ui/inputs/InputForm.tsx
|
|
3823
|
-
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as
|
|
3824
|
-
import { Pressable as
|
|
3825
|
-
import { jsx as
|
|
4056
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo10, useState as useState12 } from "react";
|
|
4057
|
+
import { Pressable as Pressable13, StyleSheet as StyleSheet15, Text as Text14, View as View14 } from "react-native";
|
|
4058
|
+
import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
3826
4059
|
var NO_CHOICES = {};
|
|
3827
4060
|
var NO_DEFAULTS = {};
|
|
3828
4061
|
function savedValues(panels, entries) {
|
|
@@ -3833,15 +4066,39 @@ function savedValues(panels, entries) {
|
|
|
3833
4066
|
}
|
|
3834
4067
|
return values;
|
|
3835
4068
|
}
|
|
4069
|
+
async function lastItems(store, group) {
|
|
4070
|
+
const metrics = groupFields(group).map((f) => f.options.metric);
|
|
4071
|
+
const latest = (await Promise.all(metrics.map((m) => store.latest(m)))).filter((e) => !!e).sort((a, b) => b.ts - a.ts)[0];
|
|
4072
|
+
if (!latest) return [];
|
|
4073
|
+
return entriesToItems(group, sameSave(latest, await store.list({ metrics, from: latest.ts, to: latest.ts })));
|
|
4074
|
+
}
|
|
4075
|
+
function freshItem(group, position, last) {
|
|
4076
|
+
const item = {};
|
|
4077
|
+
for (const f of groupFields(group)) {
|
|
4078
|
+
const d = f.options.default;
|
|
4079
|
+
const v = d === "last" ? last?.[position]?.[f.options.metric] : d;
|
|
4080
|
+
if (v !== void 0 && v !== null) item[f.options.metric] = v;
|
|
4081
|
+
}
|
|
4082
|
+
return item;
|
|
4083
|
+
}
|
|
4084
|
+
function baseItems(group, editing, last) {
|
|
4085
|
+
const start = group.options.start;
|
|
4086
|
+
const values = editing ? entriesToItems(group, editing) : start === "last" && last?.length ? last : Array.from({ length: typeof start === "number" ? Math.max(0, start) : 1 }, (_, i) => freshItem(group, i, last));
|
|
4087
|
+
return values.map((v, i) => ({ key: `b${i}`, values: v, edited: [] }));
|
|
4088
|
+
}
|
|
4089
|
+
var nextItemKey = 1;
|
|
3836
4090
|
function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, timestamp, defaults: given = NO_DEFAULTS, beforeSave, editing }) {
|
|
3837
4091
|
const theme = useDashTheme();
|
|
3838
|
-
const panels =
|
|
3839
|
-
const
|
|
3840
|
-
const
|
|
3841
|
-
const [
|
|
3842
|
-
const [
|
|
3843
|
-
const [
|
|
3844
|
-
const [
|
|
4092
|
+
const panels = useMemo10(() => plainInputPanels(dashboard), [dashboard]);
|
|
4093
|
+
const groups = useMemo10(() => inputGroups(dashboard), [dashboard]);
|
|
4094
|
+
const saved = useMemo10(() => editing ? savedValues(panels, editing) : NO_DEFAULTS, [panels, editing]);
|
|
4095
|
+
const [defaults, setDefaults] = useState12({});
|
|
4096
|
+
const [edits, setEdits] = useState12({});
|
|
4097
|
+
const [last, setLast] = useState12({});
|
|
4098
|
+
const [groupEdits, setGroupEdits] = useState12({});
|
|
4099
|
+
const [offsetMs, setOffsetMs] = useState12(0);
|
|
4100
|
+
const [status, setStatus] = useState12(null);
|
|
4101
|
+
const [checked, setChecked] = useState12(false);
|
|
3845
4102
|
useEffect4(() => {
|
|
3846
4103
|
let run = 0;
|
|
3847
4104
|
const load = async () => {
|
|
@@ -3852,7 +4109,15 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
3852
4109
|
if (d === "last") next[p.options.metric] = entryToInputValue(p, await store.latest(p.options.metric));
|
|
3853
4110
|
else if (d !== void 0) next[p.options.metric] = d;
|
|
3854
4111
|
}
|
|
3855
|
-
|
|
4112
|
+
const lastNext = {};
|
|
4113
|
+
for (const g of groups) {
|
|
4114
|
+
const wanted = g.options.start === "last" || groupFields(g).some((f) => f.options.default === "last");
|
|
4115
|
+
if (wanted) lastNext[groupKey(g)] = await lastItems(store, g);
|
|
4116
|
+
}
|
|
4117
|
+
if (mine === run) {
|
|
4118
|
+
setDefaults(next);
|
|
4119
|
+
setLast(lastNext);
|
|
4120
|
+
}
|
|
3856
4121
|
};
|
|
3857
4122
|
load();
|
|
3858
4123
|
const unsubscribe = store.subscribe(load);
|
|
@@ -3860,8 +4125,10 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
3860
4125
|
run = -1;
|
|
3861
4126
|
unsubscribe();
|
|
3862
4127
|
};
|
|
3863
|
-
}, [panels, store]);
|
|
3864
|
-
const
|
|
4128
|
+
}, [panels, groups, store]);
|
|
4129
|
+
const base = useMemo10(() => Object.fromEntries(groups.map((g) => [groupKey(g), baseItems(g, editing, last[groupKey(g)])])), [groups, editing, last]);
|
|
4130
|
+
const itemsOf = useCallback4((g) => groupEdits[groupKey(g)] ?? base[groupKey(g)] ?? [], [groupEdits, base]);
|
|
4131
|
+
const state = useMemo10(() => {
|
|
3865
4132
|
const value = (m) => m in edits ? edits[m] : m in saved ? saved[m] : m in given ? given[m] : defaults[m] ?? null;
|
|
3866
4133
|
return {
|
|
3867
4134
|
value,
|
|
@@ -3875,65 +4142,124 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
3875
4142
|
problem: (m) => {
|
|
3876
4143
|
const p = panels.find((x) => x.options.metric === m);
|
|
3877
4144
|
return p && (checked || m in edits) ? inputProblem(p, value(m)) : void 0;
|
|
3878
|
-
}
|
|
4145
|
+
},
|
|
4146
|
+
group: (g) => groupState(g, itemsOf(g), last[groupKey(g)], groupKey(g) in groupEdits, checked, (update) => {
|
|
4147
|
+
setStatus(null);
|
|
4148
|
+
setGroupEdits((all) => ({ ...all, [groupKey(g)]: update(all[groupKey(g)] ?? base[groupKey(g)] ?? []) }));
|
|
4149
|
+
})
|
|
3879
4150
|
};
|
|
3880
|
-
}, [edits, saved, defaults, given, store, choices, panels, checked]);
|
|
3881
|
-
const dirty = Object.keys(edits).length;
|
|
4151
|
+
}, [edits, saved, defaults, given, store, choices, panels, checked, itemsOf, last, groupEdits, base]);
|
|
4152
|
+
const dirty = Object.keys(edits).length + groups.reduce((n, g) => n + groupChanges(base[groupKey(g)] ?? [], groupEdits[groupKey(g)]), 0);
|
|
4153
|
+
const recordedGroups = useCallback4(
|
|
4154
|
+
() => groups.filter((g) => editing || groupKey(g) in groupEdits || groupFields(g).some((f) => f.options.record === "always")),
|
|
4155
|
+
[groups, editing, groupEdits]
|
|
4156
|
+
);
|
|
3882
4157
|
const save = useCallback4(async () => {
|
|
3883
4158
|
const problems = panels.flatMap((p) => {
|
|
3884
4159
|
const problem = inputProblem(p, state.value(p.options.metric));
|
|
3885
4160
|
return problem ? [`${p.title || p.options.metric}: ${problem.toLowerCase()}`] : [];
|
|
3886
4161
|
});
|
|
4162
|
+
for (const g of recordedGroups()) problems.push(...groupProblems(g, itemsOf(g).map((i) => i.values)));
|
|
3887
4163
|
if (problems.length) {
|
|
3888
4164
|
setChecked(true);
|
|
3889
4165
|
setStatus(problems.length === 1 ? `Can\u2019t save. ${problems[0]}` : `Can\u2019t save: ${problems.length} fields need fixing`);
|
|
3890
4166
|
return;
|
|
3891
4167
|
}
|
|
3892
4168
|
const ts = editing?.[0]?.ts ?? (header !== void 0 ? timestamp?.() ?? Date.now() : Date.now() + offsetMs);
|
|
3893
|
-
const
|
|
4169
|
+
const saveId = editing?.find((e) => e.save)?.save ?? newSaveId();
|
|
4170
|
+
const entries = [
|
|
4171
|
+
...panels.filter((p) => editing || p.options.metric in edits || p.options.record === "always").flatMap((p) => toEntries(p, state.value(p.options.metric), ts, { save: saveId })),
|
|
4172
|
+
...recordedGroups().flatMap((g) => groupToEntries(g, itemsOf(g).map((i) => i.values), ts, saveId))
|
|
4173
|
+
];
|
|
3894
4174
|
if (!entries.length) return;
|
|
3895
4175
|
const extra = beforeSave ? await beforeSave(ts) : [];
|
|
3896
4176
|
if (!extra) return;
|
|
3897
4177
|
const added = editing ? await replace(store, editing.map((e) => e.id), [...entries, ...extra]) : await store.add([...entries, ...extra]);
|
|
3898
4178
|
setEdits({});
|
|
4179
|
+
setGroupEdits({});
|
|
3899
4180
|
setChecked(false);
|
|
3900
4181
|
setOffsetMs(0);
|
|
3901
4182
|
setStatus(`Saved ${added.length} ${added.length === 1 ? "value" : "values"}`);
|
|
3902
4183
|
onSaved?.(added.length, added);
|
|
3903
|
-
}, [panels, edits, state, offsetMs, store, onSaved, header, timestamp, beforeSave, editing]);
|
|
3904
|
-
return /* @__PURE__ */
|
|
4184
|
+
}, [panels, edits, state, offsetMs, store, onSaved, header, timestamp, beforeSave, editing, recordedGroups, itemsOf]);
|
|
4185
|
+
return /* @__PURE__ */ jsx17(InputFormContext.Provider, { value: state, children: /* @__PURE__ */ jsx17(DashboardProvider, { dashboard, children: /* @__PURE__ */ jsx17(
|
|
3905
4186
|
DashboardView,
|
|
3906
4187
|
{
|
|
3907
|
-
header: header !== void 0 ? header : /* @__PURE__ */
|
|
3908
|
-
footer: /* @__PURE__ */
|
|
3909
|
-
/* @__PURE__ */
|
|
3910
|
-
dirty > 0 && /* @__PURE__ */
|
|
3911
|
-
|
|
4188
|
+
header: header !== void 0 ? header : /* @__PURE__ */ jsx17(TimestampPicker, { offsetMs, onChange: setOffsetMs }),
|
|
4189
|
+
footer: /* @__PURE__ */ jsxs15(View14, { style: [styles15.footer, { backgroundColor: theme.surface, borderTopColor: theme.border }], children: [
|
|
4190
|
+
/* @__PURE__ */ jsx17(Text14, { style: [styles15.status, { color: status?.startsWith("Can\u2019t") ? theme.danger : theme.textSecondary }], children: status ?? (dirty ? `${dirty} unsaved ${dirty === 1 ? "change" : "changes"}` : "Nothing to save") }),
|
|
4191
|
+
dirty > 0 && /* @__PURE__ */ jsx17(
|
|
4192
|
+
Pressable13,
|
|
3912
4193
|
{
|
|
3913
4194
|
onPress: () => {
|
|
3914
4195
|
setEdits({});
|
|
4196
|
+
setGroupEdits({});
|
|
3915
4197
|
setChecked(false);
|
|
3916
4198
|
setStatus(null);
|
|
3917
4199
|
},
|
|
3918
|
-
style:
|
|
4200
|
+
style: styles15.secondary,
|
|
3919
4201
|
accessibilityRole: "button",
|
|
3920
|
-
children: /* @__PURE__ */
|
|
4202
|
+
children: /* @__PURE__ */ jsx17(Text14, { style: { color: theme.textSecondary, fontWeight: "500" }, children: "Discard" })
|
|
3921
4203
|
}
|
|
3922
4204
|
),
|
|
3923
|
-
/* @__PURE__ */
|
|
3924
|
-
|
|
4205
|
+
/* @__PURE__ */ jsx17(
|
|
4206
|
+
Pressable13,
|
|
3925
4207
|
{
|
|
3926
4208
|
onPress: save,
|
|
3927
4209
|
disabled: !dirty,
|
|
3928
4210
|
accessibilityRole: "button",
|
|
3929
|
-
style: ({ pressed }) => [
|
|
3930
|
-
children: /* @__PURE__ */
|
|
4211
|
+
style: ({ pressed }) => [styles15.save, { backgroundColor: theme.accent, opacity: !dirty ? 0.4 : pressed ? 0.8 : 1 }],
|
|
4212
|
+
children: /* @__PURE__ */ jsx17(Text14, { style: styles15.saveText, children: "Save" })
|
|
3931
4213
|
}
|
|
3932
4214
|
)
|
|
3933
4215
|
] })
|
|
3934
4216
|
}
|
|
3935
4217
|
) }) });
|
|
3936
4218
|
}
|
|
4219
|
+
function groupChanges(base, items) {
|
|
4220
|
+
if (!items) return 0;
|
|
4221
|
+
const baseKeys = new Set(base.map((i) => i.key));
|
|
4222
|
+
const keys = new Set(items.map((i) => i.key));
|
|
4223
|
+
const edited = items.reduce((n, i) => n + (baseKeys.has(i.key) ? i.edited.length : 0), 0);
|
|
4224
|
+
const added = items.filter((i) => !baseKeys.has(i.key)).length;
|
|
4225
|
+
const removed = base.filter((i) => !keys.has(i.key)).length;
|
|
4226
|
+
const moved = edited + added + removed === 0 && items.some((i, n) => base[n]?.key !== i.key) ? 1 : 0;
|
|
4227
|
+
return edited + added + removed + moved;
|
|
4228
|
+
}
|
|
4229
|
+
function groupState(group, items, last, edited, showProblems, update) {
|
|
4230
|
+
const fields = groupFields(group);
|
|
4231
|
+
const { max } = group.options;
|
|
4232
|
+
const fresh = (position) => ({ key: `n${nextItemKey++}`, values: freshItem(group, position, last), edited: [] });
|
|
4233
|
+
const filled = items.filter((i) => !isEmptyItem(group, i.values)).length;
|
|
4234
|
+
const { min } = group.options;
|
|
4235
|
+
return {
|
|
4236
|
+
items: items.map((i) => ({ key: i.key, values: i.values, edited: i.edited })),
|
|
4237
|
+
canAdd: typeof max !== "number" || items.length < max,
|
|
4238
|
+
edited,
|
|
4239
|
+
problem: showProblems && typeof min === "number" && filled < min ? `At least ${min}` : void 0,
|
|
4240
|
+
add: () => update((all) => typeof max === "number" && all.length >= max ? all : [...all, fresh(all.length)]),
|
|
4241
|
+
duplicate: (index) => update(
|
|
4242
|
+
(all) => typeof max === "number" && all.length >= max ? all : [...all.slice(0, index + 1), { key: `n${nextItemKey++}`, values: { ...all[index].values }, edited: Object.keys(all[index].values) }, ...all.slice(index + 1)]
|
|
4243
|
+
),
|
|
4244
|
+
remove: (index) => update((all) => all.filter((_, i) => i !== index)),
|
|
4245
|
+
move: (index, by) => update((all) => {
|
|
4246
|
+
const to = index + by;
|
|
4247
|
+
if (to < 0 || to >= all.length) return all;
|
|
4248
|
+
const next = [...all];
|
|
4249
|
+
[next[index], next[to]] = [next[to], next[index]];
|
|
4250
|
+
return next;
|
|
4251
|
+
}),
|
|
4252
|
+
setValue: (index, metric, v) => update(
|
|
4253
|
+
(all) => all.map((item, i) => i === index ? { ...item, values: { ...item.values, [metric]: v }, edited: item.edited.includes(metric) ? item.edited : [...item.edited, metric] } : item)
|
|
4254
|
+
),
|
|
4255
|
+
fieldProblem: (index, metric) => {
|
|
4256
|
+
const item = items[index];
|
|
4257
|
+
const field = fields.find((f) => f.options.metric === metric);
|
|
4258
|
+
if (!item || !field || isEmptyItem(group, item.values)) return void 0;
|
|
4259
|
+
return showProblems || item.edited.includes(metric) ? inputProblem(field, item.values[metric] ?? null) : void 0;
|
|
4260
|
+
}
|
|
4261
|
+
};
|
|
4262
|
+
}
|
|
3937
4263
|
async function replace(store, ids, entries) {
|
|
3938
4264
|
if (store.replace) return store.replace(ids, entries);
|
|
3939
4265
|
for (const id of ids) await store.remove(id);
|
|
@@ -3942,33 +4268,33 @@ async function replace(store, ids, entries) {
|
|
|
3942
4268
|
var HOUR = 36e5;
|
|
3943
4269
|
function TimestampPicker({ offsetMs, onChange }) {
|
|
3944
4270
|
const theme = useDashTheme();
|
|
3945
|
-
const [now, setNow] =
|
|
4271
|
+
const [now, setNow] = useState12(() => Date.now());
|
|
3946
4272
|
useEffect4(() => {
|
|
3947
4273
|
const id = setInterval(() => setNow(Date.now()), 3e4);
|
|
3948
4274
|
return () => clearInterval(id);
|
|
3949
4275
|
}, []);
|
|
3950
4276
|
const when = new Date(now + offsetMs);
|
|
3951
4277
|
const step = (ms) => () => onChange(Math.min(0, offsetMs + ms));
|
|
3952
|
-
return /* @__PURE__ */
|
|
3953
|
-
/* @__PURE__ */
|
|
3954
|
-
/* @__PURE__ */
|
|
3955
|
-
/* @__PURE__ */
|
|
4278
|
+
return /* @__PURE__ */ jsxs15(View14, { style: [styles15.when, { backgroundColor: theme.surface, borderColor: theme.border }], children: [
|
|
4279
|
+
/* @__PURE__ */ jsxs15(View14, { style: { flex: 1 }, children: [
|
|
4280
|
+
/* @__PURE__ */ jsx17(Text14, { style: [styles15.whenLabel, { color: theme.textMuted }], children: "Recording for" }),
|
|
4281
|
+
/* @__PURE__ */ jsx17(Text14, { style: [styles15.whenValue, { color: theme.text }], children: offsetMs === 0 ? "Now" : when.toLocaleString(void 0, { weekday: "short", month: "short", day: "numeric", hour: "numeric", minute: "2-digit" }) })
|
|
3956
4282
|
] }),
|
|
3957
4283
|
[
|
|
3958
4284
|
["\u22121d", -24 * HOUR],
|
|
3959
4285
|
["\u22121h", -HOUR],
|
|
3960
4286
|
["+1h", HOUR]
|
|
3961
|
-
].map(([label, ms]) => /* @__PURE__ */
|
|
3962
|
-
offsetMs !== 0 && /* @__PURE__ */
|
|
4287
|
+
].map(([label, ms]) => /* @__PURE__ */ jsx17(Pressable13, { onPress: step(ms), style: [styles15.stepBtn, { borderColor: theme.border }], accessibilityRole: "button", children: /* @__PURE__ */ jsx17(Text14, { style: { color: theme.text, fontSize: 13 }, children: label }) }, label)),
|
|
4288
|
+
offsetMs !== 0 && /* @__PURE__ */ jsx17(Pressable13, { onPress: () => onChange(0), style: [styles15.stepBtn, { borderColor: theme.accent }], accessibilityRole: "button", children: /* @__PURE__ */ jsx17(Text14, { style: { color: theme.accent, fontSize: 13, fontWeight: "600" }, children: "Now" }) })
|
|
3963
4289
|
] });
|
|
3964
4290
|
}
|
|
3965
|
-
var
|
|
3966
|
-
footer: { flexDirection: "row", alignItems: "center", gap: 12, paddingHorizontal: 16, paddingVertical: 10, borderTopWidth:
|
|
4291
|
+
var styles15 = StyleSheet15.create({
|
|
4292
|
+
footer: { flexDirection: "row", alignItems: "center", gap: 12, paddingHorizontal: 16, paddingVertical: 10, borderTopWidth: StyleSheet15.hairlineWidth },
|
|
3967
4293
|
status: { flex: 1, fontSize: 13 },
|
|
3968
4294
|
secondary: { paddingHorizontal: 8, paddingVertical: 10 },
|
|
3969
4295
|
save: { paddingHorizontal: 22, paddingVertical: 10, borderRadius: 8 },
|
|
3970
4296
|
saveText: { color: "#fff", fontWeight: "600", fontSize: 15 },
|
|
3971
|
-
when: { flexDirection: "row", alignItems: "center", gap: 6, padding: 12, borderRadius: 10, borderWidth:
|
|
4297
|
+
when: { flexDirection: "row", alignItems: "center", gap: 6, padding: 12, borderRadius: 10, borderWidth: StyleSheet15.hairlineWidth },
|
|
3972
4298
|
whenLabel: { fontSize: 11 },
|
|
3973
4299
|
whenValue: { fontSize: 15, fontWeight: "600" },
|
|
3974
4300
|
stepBtn: { paddingHorizontal: 10, paddingVertical: 6, borderRadius: 6, borderWidth: 1 }
|
|
@@ -3990,10 +4316,12 @@ export {
|
|
|
3990
4316
|
DashboardView,
|
|
3991
4317
|
EDITABLE_VARIABLE_TYPES,
|
|
3992
4318
|
GRID_COLUMNS,
|
|
4319
|
+
GROUP_FIELD_TYPES,
|
|
3993
4320
|
GrafanaClient,
|
|
3994
4321
|
GrafanaDataSource,
|
|
3995
4322
|
GrafanaError,
|
|
3996
4323
|
HttpConfigFiles,
|
|
4324
|
+
INPUT_GROUP,
|
|
3997
4325
|
INPUT_OPTION_KEYS,
|
|
3998
4326
|
INPUT_TYPES,
|
|
3999
4327
|
InputForm,
|
|
@@ -4051,6 +4379,7 @@ export {
|
|
|
4051
4379
|
dropTarget,
|
|
4052
4380
|
duplicatePanel,
|
|
4053
4381
|
entriesSavedWith,
|
|
4382
|
+
entriesToItems,
|
|
4054
4383
|
entryToInputValue,
|
|
4055
4384
|
expandRow,
|
|
4056
4385
|
fetchBundle,
|
|
@@ -4069,8 +4398,13 @@ export {
|
|
|
4069
4398
|
getPath,
|
|
4070
4399
|
gridOffsetPx,
|
|
4071
4400
|
gridUnitsToPx,
|
|
4401
|
+
groupFields,
|
|
4402
|
+
groupKey,
|
|
4403
|
+
groupProblems,
|
|
4404
|
+
groupToEntries,
|
|
4072
4405
|
httpFetchJson,
|
|
4073
4406
|
initialVariableValues,
|
|
4407
|
+
inputGroups,
|
|
4074
4408
|
inputPanels,
|
|
4075
4409
|
inputProblem,
|
|
4076
4410
|
insertPanel,
|
|
@@ -4078,6 +4412,9 @@ export {
|
|
|
4078
4412
|
interpolateDeep,
|
|
4079
4413
|
isBundleResponse,
|
|
4080
4414
|
isEditableVariableType,
|
|
4415
|
+
isEmptyItem,
|
|
4416
|
+
isFormPanelType,
|
|
4417
|
+
isInputGroup,
|
|
4081
4418
|
isInputPanel,
|
|
4082
4419
|
isInputType,
|
|
4083
4420
|
isLocalDatasource,
|
|
@@ -4100,6 +4437,7 @@ export {
|
|
|
4100
4437
|
movePanel,
|
|
4101
4438
|
newDocument,
|
|
4102
4439
|
newPanel,
|
|
4440
|
+
newSaveId,
|
|
4103
4441
|
newVariable,
|
|
4104
4442
|
nextPanelId,
|
|
4105
4443
|
normalizeRef,
|
|
@@ -4126,6 +4464,7 @@ export {
|
|
|
4126
4464
|
parseTime,
|
|
4127
4465
|
pasteSnippet,
|
|
4128
4466
|
placePanel,
|
|
4467
|
+
plainInputPanels,
|
|
4129
4468
|
pointerToPath,
|
|
4130
4469
|
prepareDashboard,
|
|
4131
4470
|
previewPaste,
|
|
@@ -4153,6 +4492,7 @@ export {
|
|
|
4153
4492
|
resolveVariables,
|
|
4154
4493
|
revalidateBundle,
|
|
4155
4494
|
rowsToMappings,
|
|
4495
|
+
sameSave,
|
|
4156
4496
|
sampleEntries,
|
|
4157
4497
|
screenDocuments,
|
|
4158
4498
|
screenOfType,
|