@nubitio/dashboard 0.11.3 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AreaChartWidgetView-BBp9C1bD.mjs +111 -0
- package/dist/AreaChartWidgetView-CmHmNCUh.cjs +112 -0
- package/dist/ChartTooltip-C0m3o4tP.cjs +70 -0
- package/dist/ChartTooltip-DQbTw6D2.mjs +37 -0
- package/dist/LineChartWidgetView-_HlG1ODm.cjs +90 -0
- package/dist/LineChartWidgetView-gNlby0Gq.mjs +89 -0
- package/dist/chartPalette-BmJoPzOC.cjs +90 -0
- package/dist/chartPalette-VDQwLcM-.mjs +67 -0
- package/dist/index.cjs +32 -297
- package/dist/index.mjs +15 -280
- package/package.json +9 -4
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { i as formatDashboardValue, n as resolveArray, t as DEFAULT_CHART_COLORS } from "./chartPalette-VDQwLcM-.mjs";
|
|
2
|
+
import { t as ChartTooltip } from "./ChartTooltip-DQbTw6D2.mjs";
|
|
3
|
+
import { StatCard } from "@nubitio/ui";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import * as recharts from "recharts";
|
|
6
|
+
//#region packages/dashboard/dashboard/widgets/AreaChartWidgetView.tsx
|
|
7
|
+
const Area = recharts.Area;
|
|
8
|
+
const AreaChart = recharts.AreaChart;
|
|
9
|
+
const CartesianGrid = recharts.CartesianGrid;
|
|
10
|
+
const Legend = recharts.Legend;
|
|
11
|
+
const ResponsiveContainer = recharts.ResponsiveContainer;
|
|
12
|
+
const Tooltip = recharts.Tooltip;
|
|
13
|
+
const XAxis = recharts.XAxis;
|
|
14
|
+
const YAxis = recharts.YAxis;
|
|
15
|
+
function AreaChartWidgetView({ widget, data, loading }) {
|
|
16
|
+
const rows = resolveArray(data, widget.dataPath);
|
|
17
|
+
const height = widget.height ?? 240;
|
|
18
|
+
return /* @__PURE__ */ jsx(StatCard, {
|
|
19
|
+
title: widget.title,
|
|
20
|
+
headerExtra: widget.subtitle ? /* @__PURE__ */ jsx("span", {
|
|
21
|
+
className: "nb-dashboard-widget__subtitle",
|
|
22
|
+
children: widget.subtitle
|
|
23
|
+
}) : void 0,
|
|
24
|
+
menuVisible: widget.menuVisible,
|
|
25
|
+
isLoading: loading,
|
|
26
|
+
className: "nb-dashboard-chart-card",
|
|
27
|
+
children: rows.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
28
|
+
className: "nb-dashboard-chart-empty",
|
|
29
|
+
children: "No data"
|
|
30
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
31
|
+
style: { height },
|
|
32
|
+
children: /* @__PURE__ */ jsx(ResponsiveContainer, {
|
|
33
|
+
width: "100%",
|
|
34
|
+
height: "100%",
|
|
35
|
+
children: /* @__PURE__ */ jsxs(AreaChart, {
|
|
36
|
+
data: rows,
|
|
37
|
+
margin: {
|
|
38
|
+
top: 4,
|
|
39
|
+
right: 8,
|
|
40
|
+
bottom: 0,
|
|
41
|
+
left: 0
|
|
42
|
+
},
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsx("defs", { children: widget.series.map((series, index) => {
|
|
45
|
+
const color = series.color ?? DEFAULT_CHART_COLORS[index % DEFAULT_CHART_COLORS.length];
|
|
46
|
+
return /* @__PURE__ */ jsxs("linearGradient", {
|
|
47
|
+
id: `nb-area-${widget.id}-${series.key}`,
|
|
48
|
+
x1: "0",
|
|
49
|
+
y1: "0",
|
|
50
|
+
x2: "0",
|
|
51
|
+
y2: "1",
|
|
52
|
+
children: [/* @__PURE__ */ jsx("stop", {
|
|
53
|
+
offset: "5%",
|
|
54
|
+
stopColor: color,
|
|
55
|
+
stopOpacity: .35
|
|
56
|
+
}), /* @__PURE__ */ jsx("stop", {
|
|
57
|
+
offset: "95%",
|
|
58
|
+
stopColor: color,
|
|
59
|
+
stopOpacity: .02
|
|
60
|
+
})]
|
|
61
|
+
}, series.key);
|
|
62
|
+
}) }),
|
|
63
|
+
widget.showGrid !== false && /* @__PURE__ */ jsx(CartesianGrid, {
|
|
64
|
+
strokeDasharray: "3 3",
|
|
65
|
+
stroke: "var(--border-color)",
|
|
66
|
+
vertical: false
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx(XAxis, {
|
|
69
|
+
dataKey: widget.xKey,
|
|
70
|
+
tick: {
|
|
71
|
+
fontSize: 11,
|
|
72
|
+
fill: "var(--text-tertiary)"
|
|
73
|
+
},
|
|
74
|
+
axisLine: { stroke: "var(--border-color)" },
|
|
75
|
+
tickLine: false
|
|
76
|
+
}),
|
|
77
|
+
/* @__PURE__ */ jsx(YAxis, {
|
|
78
|
+
tick: {
|
|
79
|
+
fontSize: 11,
|
|
80
|
+
fill: "var(--text-tertiary)"
|
|
81
|
+
},
|
|
82
|
+
axisLine: false,
|
|
83
|
+
tickLine: false,
|
|
84
|
+
width: 48,
|
|
85
|
+
tickFormatter: (v) => formatDashboardValue(v, widget.valueFormat)
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltip, {
|
|
88
|
+
labelFormat: widget.valueFormat,
|
|
89
|
+
series: widget.series
|
|
90
|
+
}) }),
|
|
91
|
+
widget.showLegend && /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 12 } }),
|
|
92
|
+
widget.series.map((series, index) => {
|
|
93
|
+
const color = series.color ?? DEFAULT_CHART_COLORS[index % DEFAULT_CHART_COLORS.length];
|
|
94
|
+
return /* @__PURE__ */ jsx(Area, {
|
|
95
|
+
type: "monotone",
|
|
96
|
+
dataKey: series.key,
|
|
97
|
+
name: series.label ?? series.key,
|
|
98
|
+
stroke: color,
|
|
99
|
+
strokeWidth: 2,
|
|
100
|
+
fill: `url(#nb-area-${widget.id}-${series.key})`,
|
|
101
|
+
stackId: widget.stacked ? "stack" : void 0
|
|
102
|
+
}, series.key);
|
|
103
|
+
})
|
|
104
|
+
]
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { AreaChartWidgetView };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const require_ChartTooltip = require("./ChartTooltip-C0m3o4tP.cjs");
|
|
2
|
+
const require_chartPalette = require("./chartPalette-BmJoPzOC.cjs");
|
|
3
|
+
let _nubitio_ui = require("@nubitio/ui");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
let recharts = require("recharts");
|
|
6
|
+
recharts = require_ChartTooltip.__toESM(recharts);
|
|
7
|
+
//#region packages/dashboard/dashboard/widgets/AreaChartWidgetView.tsx
|
|
8
|
+
const Area = recharts.Area;
|
|
9
|
+
const AreaChart = recharts.AreaChart;
|
|
10
|
+
const CartesianGrid = recharts.CartesianGrid;
|
|
11
|
+
const Legend = recharts.Legend;
|
|
12
|
+
const ResponsiveContainer = recharts.ResponsiveContainer;
|
|
13
|
+
const Tooltip = recharts.Tooltip;
|
|
14
|
+
const XAxis = recharts.XAxis;
|
|
15
|
+
const YAxis = recharts.YAxis;
|
|
16
|
+
function AreaChartWidgetView({ widget, data, loading }) {
|
|
17
|
+
const rows = require_chartPalette.resolveArray(data, widget.dataPath);
|
|
18
|
+
const height = widget.height ?? 240;
|
|
19
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nubitio_ui.StatCard, {
|
|
20
|
+
title: widget.title,
|
|
21
|
+
headerExtra: widget.subtitle ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
22
|
+
className: "nb-dashboard-widget__subtitle",
|
|
23
|
+
children: widget.subtitle
|
|
24
|
+
}) : void 0,
|
|
25
|
+
menuVisible: widget.menuVisible,
|
|
26
|
+
isLoading: loading,
|
|
27
|
+
className: "nb-dashboard-chart-card",
|
|
28
|
+
children: rows.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
29
|
+
className: "nb-dashboard-chart-empty",
|
|
30
|
+
children: "No data"
|
|
31
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
32
|
+
style: { height },
|
|
33
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResponsiveContainer, {
|
|
34
|
+
width: "100%",
|
|
35
|
+
height: "100%",
|
|
36
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(AreaChart, {
|
|
37
|
+
data: rows,
|
|
38
|
+
margin: {
|
|
39
|
+
top: 4,
|
|
40
|
+
right: 8,
|
|
41
|
+
bottom: 0,
|
|
42
|
+
left: 0
|
|
43
|
+
},
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("defs", { children: widget.series.map((series, index) => {
|
|
46
|
+
const color = series.color ?? require_chartPalette.DEFAULT_CHART_COLORS[index % require_chartPalette.DEFAULT_CHART_COLORS.length];
|
|
47
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
|
|
48
|
+
id: `nb-area-${widget.id}-${series.key}`,
|
|
49
|
+
x1: "0",
|
|
50
|
+
y1: "0",
|
|
51
|
+
x2: "0",
|
|
52
|
+
y2: "1",
|
|
53
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
|
|
54
|
+
offset: "5%",
|
|
55
|
+
stopColor: color,
|
|
56
|
+
stopOpacity: .35
|
|
57
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
|
|
58
|
+
offset: "95%",
|
|
59
|
+
stopColor: color,
|
|
60
|
+
stopOpacity: .02
|
|
61
|
+
})]
|
|
62
|
+
}, series.key);
|
|
63
|
+
}) }),
|
|
64
|
+
widget.showGrid !== false && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CartesianGrid, {
|
|
65
|
+
strokeDasharray: "3 3",
|
|
66
|
+
stroke: "var(--border-color)",
|
|
67
|
+
vertical: false
|
|
68
|
+
}),
|
|
69
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(XAxis, {
|
|
70
|
+
dataKey: widget.xKey,
|
|
71
|
+
tick: {
|
|
72
|
+
fontSize: 11,
|
|
73
|
+
fill: "var(--text-tertiary)"
|
|
74
|
+
},
|
|
75
|
+
axisLine: { stroke: "var(--border-color)" },
|
|
76
|
+
tickLine: false
|
|
77
|
+
}),
|
|
78
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(YAxis, {
|
|
79
|
+
tick: {
|
|
80
|
+
fontSize: 11,
|
|
81
|
+
fill: "var(--text-tertiary)"
|
|
82
|
+
},
|
|
83
|
+
axisLine: false,
|
|
84
|
+
tickLine: false,
|
|
85
|
+
width: 48,
|
|
86
|
+
tickFormatter: (v) => require_chartPalette.formatDashboardValue(v, widget.valueFormat)
|
|
87
|
+
}),
|
|
88
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tooltip, { content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChartTooltip.ChartTooltip, {
|
|
89
|
+
labelFormat: widget.valueFormat,
|
|
90
|
+
series: widget.series
|
|
91
|
+
}) }),
|
|
92
|
+
widget.showLegend && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Legend, { wrapperStyle: { fontSize: 12 } }),
|
|
93
|
+
widget.series.map((series, index) => {
|
|
94
|
+
const color = series.color ?? require_chartPalette.DEFAULT_CHART_COLORS[index % require_chartPalette.DEFAULT_CHART_COLORS.length];
|
|
95
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Area, {
|
|
96
|
+
type: "monotone",
|
|
97
|
+
dataKey: series.key,
|
|
98
|
+
name: series.label ?? series.key,
|
|
99
|
+
stroke: color,
|
|
100
|
+
strokeWidth: 2,
|
|
101
|
+
fill: `url(#nb-area-${widget.id}-${series.key})`,
|
|
102
|
+
stackId: widget.stacked ? "stack" : void 0
|
|
103
|
+
}, series.key);
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
exports.AreaChartWidgetView = AreaChartWidgetView;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
const require_chartPalette = require("./chartPalette-BmJoPzOC.cjs");
|
|
24
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
//#region packages/dashboard/dashboard/widgets/ChartTooltip.tsx
|
|
26
|
+
function ChartTooltip({ active, label, payload, labelFormat, series }) {
|
|
27
|
+
if (!active || !payload?.length) return null;
|
|
28
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
29
|
+
className: "nb-dashboard-chart-tooltip",
|
|
30
|
+
children: [label !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
31
|
+
className: "nb-dashboard-chart-tooltip__label",
|
|
32
|
+
children: label
|
|
33
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
34
|
+
className: "nb-dashboard-chart-tooltip__items",
|
|
35
|
+
children: payload.map((item) => {
|
|
36
|
+
const seriesConfig = series?.find((s) => s.key === item.dataKey);
|
|
37
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
38
|
+
className: "nb-dashboard-chart-tooltip__item",
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
41
|
+
className: "nb-dashboard-chart-tooltip__swatch",
|
|
42
|
+
style: { background: item.color }
|
|
43
|
+
}),
|
|
44
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
45
|
+
className: "nb-dashboard-chart-tooltip__name",
|
|
46
|
+
children: item.name
|
|
47
|
+
}),
|
|
48
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
49
|
+
className: "nb-dashboard-chart-tooltip__value",
|
|
50
|
+
children: require_chartPalette.formatDashboardValue(item.value, seriesConfig?.valueFormat ?? labelFormat)
|
|
51
|
+
})
|
|
52
|
+
]
|
|
53
|
+
}, String(item.dataKey));
|
|
54
|
+
})
|
|
55
|
+
})]
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
Object.defineProperty(exports, "ChartTooltip", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function() {
|
|
62
|
+
return ChartTooltip;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(exports, "__toESM", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function() {
|
|
68
|
+
return __toESM;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { i as formatDashboardValue } from "./chartPalette-VDQwLcM-.mjs";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region packages/dashboard/dashboard/widgets/ChartTooltip.tsx
|
|
4
|
+
function ChartTooltip({ active, label, payload, labelFormat, series }) {
|
|
5
|
+
if (!active || !payload?.length) return null;
|
|
6
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
7
|
+
className: "nb-dashboard-chart-tooltip",
|
|
8
|
+
children: [label !== void 0 && /* @__PURE__ */ jsx("div", {
|
|
9
|
+
className: "nb-dashboard-chart-tooltip__label",
|
|
10
|
+
children: label
|
|
11
|
+
}), /* @__PURE__ */ jsx("ul", {
|
|
12
|
+
className: "nb-dashboard-chart-tooltip__items",
|
|
13
|
+
children: payload.map((item) => {
|
|
14
|
+
const seriesConfig = series?.find((s) => s.key === item.dataKey);
|
|
15
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
16
|
+
className: "nb-dashboard-chart-tooltip__item",
|
|
17
|
+
children: [
|
|
18
|
+
/* @__PURE__ */ jsx("span", {
|
|
19
|
+
className: "nb-dashboard-chart-tooltip__swatch",
|
|
20
|
+
style: { background: item.color }
|
|
21
|
+
}),
|
|
22
|
+
/* @__PURE__ */ jsx("span", {
|
|
23
|
+
className: "nb-dashboard-chart-tooltip__name",
|
|
24
|
+
children: item.name
|
|
25
|
+
}),
|
|
26
|
+
/* @__PURE__ */ jsx("span", {
|
|
27
|
+
className: "nb-dashboard-chart-tooltip__value",
|
|
28
|
+
children: formatDashboardValue(item.value, seriesConfig?.valueFormat ?? labelFormat)
|
|
29
|
+
})
|
|
30
|
+
]
|
|
31
|
+
}, String(item.dataKey));
|
|
32
|
+
})
|
|
33
|
+
})]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { ChartTooltip as t };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const require_ChartTooltip = require("./ChartTooltip-C0m3o4tP.cjs");
|
|
2
|
+
const require_chartPalette = require("./chartPalette-BmJoPzOC.cjs");
|
|
3
|
+
let _nubitio_ui = require("@nubitio/ui");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
let recharts = require("recharts");
|
|
6
|
+
recharts = require_ChartTooltip.__toESM(recharts);
|
|
7
|
+
//#region packages/dashboard/dashboard/widgets/LineChartWidgetView.tsx
|
|
8
|
+
const CartesianGrid = recharts.CartesianGrid;
|
|
9
|
+
const Legend = recharts.Legend;
|
|
10
|
+
const Line = recharts.Line;
|
|
11
|
+
const LineChart = recharts.LineChart;
|
|
12
|
+
const ResponsiveContainer = recharts.ResponsiveContainer;
|
|
13
|
+
const Tooltip = recharts.Tooltip;
|
|
14
|
+
const XAxis = recharts.XAxis;
|
|
15
|
+
const YAxis = recharts.YAxis;
|
|
16
|
+
function LineChartWidgetView({ widget, data, loading }) {
|
|
17
|
+
const rows = require_chartPalette.resolveArray(data, widget.dataPath);
|
|
18
|
+
const height = widget.height ?? 240;
|
|
19
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nubitio_ui.StatCard, {
|
|
20
|
+
title: widget.title,
|
|
21
|
+
headerExtra: widget.subtitle ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
22
|
+
className: "nb-dashboard-widget__subtitle",
|
|
23
|
+
children: widget.subtitle
|
|
24
|
+
}) : void 0,
|
|
25
|
+
menuVisible: widget.menuVisible,
|
|
26
|
+
isLoading: loading,
|
|
27
|
+
className: "nb-dashboard-chart-card",
|
|
28
|
+
children: rows.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
29
|
+
className: "nb-dashboard-chart-empty",
|
|
30
|
+
children: "No data"
|
|
31
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
32
|
+
style: { height },
|
|
33
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResponsiveContainer, {
|
|
34
|
+
width: "100%",
|
|
35
|
+
height: "100%",
|
|
36
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(LineChart, {
|
|
37
|
+
data: rows,
|
|
38
|
+
margin: {
|
|
39
|
+
top: 4,
|
|
40
|
+
right: 8,
|
|
41
|
+
bottom: 0,
|
|
42
|
+
left: 0
|
|
43
|
+
},
|
|
44
|
+
children: [
|
|
45
|
+
widget.showGrid !== false && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CartesianGrid, {
|
|
46
|
+
strokeDasharray: "3 3",
|
|
47
|
+
stroke: "var(--border-color)",
|
|
48
|
+
vertical: false
|
|
49
|
+
}),
|
|
50
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(XAxis, {
|
|
51
|
+
dataKey: widget.xKey,
|
|
52
|
+
tick: {
|
|
53
|
+
fontSize: 11,
|
|
54
|
+
fill: "var(--text-tertiary)"
|
|
55
|
+
},
|
|
56
|
+
axisLine: { stroke: "var(--border-color)" },
|
|
57
|
+
tickLine: false
|
|
58
|
+
}),
|
|
59
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(YAxis, {
|
|
60
|
+
tick: {
|
|
61
|
+
fontSize: 11,
|
|
62
|
+
fill: "var(--text-tertiary)"
|
|
63
|
+
},
|
|
64
|
+
axisLine: false,
|
|
65
|
+
tickLine: false,
|
|
66
|
+
width: 48,
|
|
67
|
+
tickFormatter: (v) => require_chartPalette.formatDashboardValue(v, widget.valueFormat)
|
|
68
|
+
}),
|
|
69
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tooltip, { content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChartTooltip.ChartTooltip, {
|
|
70
|
+
labelFormat: widget.valueFormat,
|
|
71
|
+
series: widget.series
|
|
72
|
+
}) }),
|
|
73
|
+
widget.showLegend && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Legend, { wrapperStyle: { fontSize: 12 } }),
|
|
74
|
+
widget.series.map((series, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Line, {
|
|
75
|
+
type: widget.curved === false ? "linear" : "monotone",
|
|
76
|
+
dataKey: series.key,
|
|
77
|
+
name: series.label ?? series.key,
|
|
78
|
+
stroke: series.color ?? require_chartPalette.DEFAULT_CHART_COLORS[index % require_chartPalette.DEFAULT_CHART_COLORS.length],
|
|
79
|
+
strokeWidth: 2,
|
|
80
|
+
dot: false,
|
|
81
|
+
activeDot: { r: 4 }
|
|
82
|
+
}, series.key))
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
exports.LineChartWidgetView = LineChartWidgetView;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { i as formatDashboardValue, n as resolveArray, t as DEFAULT_CHART_COLORS } from "./chartPalette-VDQwLcM-.mjs";
|
|
2
|
+
import { t as ChartTooltip } from "./ChartTooltip-DQbTw6D2.mjs";
|
|
3
|
+
import { StatCard } from "@nubitio/ui";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import * as recharts from "recharts";
|
|
6
|
+
//#region packages/dashboard/dashboard/widgets/LineChartWidgetView.tsx
|
|
7
|
+
const CartesianGrid = recharts.CartesianGrid;
|
|
8
|
+
const Legend = recharts.Legend;
|
|
9
|
+
const Line = recharts.Line;
|
|
10
|
+
const LineChart = recharts.LineChart;
|
|
11
|
+
const ResponsiveContainer = recharts.ResponsiveContainer;
|
|
12
|
+
const Tooltip = recharts.Tooltip;
|
|
13
|
+
const XAxis = recharts.XAxis;
|
|
14
|
+
const YAxis = recharts.YAxis;
|
|
15
|
+
function LineChartWidgetView({ widget, data, loading }) {
|
|
16
|
+
const rows = resolveArray(data, widget.dataPath);
|
|
17
|
+
const height = widget.height ?? 240;
|
|
18
|
+
return /* @__PURE__ */ jsx(StatCard, {
|
|
19
|
+
title: widget.title,
|
|
20
|
+
headerExtra: widget.subtitle ? /* @__PURE__ */ jsx("span", {
|
|
21
|
+
className: "nb-dashboard-widget__subtitle",
|
|
22
|
+
children: widget.subtitle
|
|
23
|
+
}) : void 0,
|
|
24
|
+
menuVisible: widget.menuVisible,
|
|
25
|
+
isLoading: loading,
|
|
26
|
+
className: "nb-dashboard-chart-card",
|
|
27
|
+
children: rows.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
28
|
+
className: "nb-dashboard-chart-empty",
|
|
29
|
+
children: "No data"
|
|
30
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
31
|
+
style: { height },
|
|
32
|
+
children: /* @__PURE__ */ jsx(ResponsiveContainer, {
|
|
33
|
+
width: "100%",
|
|
34
|
+
height: "100%",
|
|
35
|
+
children: /* @__PURE__ */ jsxs(LineChart, {
|
|
36
|
+
data: rows,
|
|
37
|
+
margin: {
|
|
38
|
+
top: 4,
|
|
39
|
+
right: 8,
|
|
40
|
+
bottom: 0,
|
|
41
|
+
left: 0
|
|
42
|
+
},
|
|
43
|
+
children: [
|
|
44
|
+
widget.showGrid !== false && /* @__PURE__ */ jsx(CartesianGrid, {
|
|
45
|
+
strokeDasharray: "3 3",
|
|
46
|
+
stroke: "var(--border-color)",
|
|
47
|
+
vertical: false
|
|
48
|
+
}),
|
|
49
|
+
/* @__PURE__ */ jsx(XAxis, {
|
|
50
|
+
dataKey: widget.xKey,
|
|
51
|
+
tick: {
|
|
52
|
+
fontSize: 11,
|
|
53
|
+
fill: "var(--text-tertiary)"
|
|
54
|
+
},
|
|
55
|
+
axisLine: { stroke: "var(--border-color)" },
|
|
56
|
+
tickLine: false
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsx(YAxis, {
|
|
59
|
+
tick: {
|
|
60
|
+
fontSize: 11,
|
|
61
|
+
fill: "var(--text-tertiary)"
|
|
62
|
+
},
|
|
63
|
+
axisLine: false,
|
|
64
|
+
tickLine: false,
|
|
65
|
+
width: 48,
|
|
66
|
+
tickFormatter: (v) => formatDashboardValue(v, widget.valueFormat)
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltip, {
|
|
69
|
+
labelFormat: widget.valueFormat,
|
|
70
|
+
series: widget.series
|
|
71
|
+
}) }),
|
|
72
|
+
widget.showLegend && /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 12 } }),
|
|
73
|
+
widget.series.map((series, index) => /* @__PURE__ */ jsx(Line, {
|
|
74
|
+
type: widget.curved === false ? "linear" : "monotone",
|
|
75
|
+
dataKey: series.key,
|
|
76
|
+
name: series.label ?? series.key,
|
|
77
|
+
stroke: series.color ?? DEFAULT_CHART_COLORS[index % DEFAULT_CHART_COLORS.length],
|
|
78
|
+
strokeWidth: 2,
|
|
79
|
+
dot: false,
|
|
80
|
+
activeDot: { r: 4 }
|
|
81
|
+
}, series.key))
|
|
82
|
+
]
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { LineChartWidgetView };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
let _nubitio_core = require("@nubitio/core");
|
|
2
|
+
//#region packages/dashboard/dashboard/formatValue.ts
|
|
3
|
+
function formatDashboardValue(value, format = "text") {
|
|
4
|
+
if (value === null || value === void 0) return "—";
|
|
5
|
+
if (format === "text") return String(value);
|
|
6
|
+
if (format === "date" || format === "datetime") {
|
|
7
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
8
|
+
if (Number.isNaN(date.getTime())) return String(value);
|
|
9
|
+
return new Intl.DateTimeFormat((0, _nubitio_core.getCoreLocale)(), {
|
|
10
|
+
dateStyle: format === "date" ? "medium" : void 0,
|
|
11
|
+
timeStyle: format === "datetime" ? "short" : void 0
|
|
12
|
+
}).format(date);
|
|
13
|
+
}
|
|
14
|
+
const numeric = typeof value === "number" ? value : Number(value);
|
|
15
|
+
if (!Number.isFinite(numeric)) return String(value);
|
|
16
|
+
const baseOptions = {
|
|
17
|
+
minimumFractionDigits: format === "currency" ? 2 : void 0,
|
|
18
|
+
maximumFractionDigits: format === "currency" ? 2 : void 0
|
|
19
|
+
};
|
|
20
|
+
if (format === "currency") {
|
|
21
|
+
const currency = (0, _nubitio_core.getCoreCurrency)();
|
|
22
|
+
if (!currency) return new Intl.NumberFormat((0, _nubitio_core.getCoreLocale)(), baseOptions).format(numeric);
|
|
23
|
+
return new Intl.NumberFormat((0, _nubitio_core.getCoreLocale)(), {
|
|
24
|
+
...baseOptions,
|
|
25
|
+
style: "currency",
|
|
26
|
+
currency,
|
|
27
|
+
currencyDisplay: "narrowSymbol"
|
|
28
|
+
}).format(numeric);
|
|
29
|
+
}
|
|
30
|
+
if (format === "percent") {
|
|
31
|
+
const normalized = Math.abs(numeric) <= 1 ? numeric : numeric / 100;
|
|
32
|
+
return new Intl.NumberFormat((0, _nubitio_core.getCoreLocale)(), {
|
|
33
|
+
style: "percent",
|
|
34
|
+
minimumFractionDigits: 1,
|
|
35
|
+
maximumFractionDigits: 1
|
|
36
|
+
}).format(normalized);
|
|
37
|
+
}
|
|
38
|
+
return new Intl.NumberFormat((0, _nubitio_core.getCoreLocale)()).format(numeric);
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region packages/dashboard/dashboard/resolvePath.ts
|
|
42
|
+
function resolvePath(source, path) {
|
|
43
|
+
if (path === void 0 || path === "") return source;
|
|
44
|
+
if (source === null || source === void 0) return void 0;
|
|
45
|
+
return path.split(".").reduce((current, segment) => {
|
|
46
|
+
if (current === null || current === void 0) return void 0;
|
|
47
|
+
if (typeof current !== "object") return void 0;
|
|
48
|
+
return current[segment];
|
|
49
|
+
}, source);
|
|
50
|
+
}
|
|
51
|
+
function resolveArray(source, path) {
|
|
52
|
+
const value = resolvePath(source, path);
|
|
53
|
+
if (!Array.isArray(value)) return [];
|
|
54
|
+
return value.filter((item) => item !== null && typeof item === "object");
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region packages/dashboard/dashboard/chartPalette.ts
|
|
58
|
+
const DEFAULT_CHART_COLORS = [
|
|
59
|
+
"var(--accent-color)",
|
|
60
|
+
"var(--success-color)",
|
|
61
|
+
"var(--warning-color)",
|
|
62
|
+
"var(--info-color)",
|
|
63
|
+
"#6b4fc8",
|
|
64
|
+
"#c2410c"
|
|
65
|
+
];
|
|
66
|
+
//#endregion
|
|
67
|
+
Object.defineProperty(exports, "DEFAULT_CHART_COLORS", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function() {
|
|
70
|
+
return DEFAULT_CHART_COLORS;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "formatDashboardValue", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function() {
|
|
76
|
+
return formatDashboardValue;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "resolveArray", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function() {
|
|
82
|
+
return resolveArray;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "resolvePath", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function() {
|
|
88
|
+
return resolvePath;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getCoreCurrency, getCoreLocale } from "@nubitio/core";
|
|
2
|
+
//#region packages/dashboard/dashboard/formatValue.ts
|
|
3
|
+
function formatDashboardValue(value, format = "text") {
|
|
4
|
+
if (value === null || value === void 0) return "—";
|
|
5
|
+
if (format === "text") return String(value);
|
|
6
|
+
if (format === "date" || format === "datetime") {
|
|
7
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
8
|
+
if (Number.isNaN(date.getTime())) return String(value);
|
|
9
|
+
return new Intl.DateTimeFormat(getCoreLocale(), {
|
|
10
|
+
dateStyle: format === "date" ? "medium" : void 0,
|
|
11
|
+
timeStyle: format === "datetime" ? "short" : void 0
|
|
12
|
+
}).format(date);
|
|
13
|
+
}
|
|
14
|
+
const numeric = typeof value === "number" ? value : Number(value);
|
|
15
|
+
if (!Number.isFinite(numeric)) return String(value);
|
|
16
|
+
const baseOptions = {
|
|
17
|
+
minimumFractionDigits: format === "currency" ? 2 : void 0,
|
|
18
|
+
maximumFractionDigits: format === "currency" ? 2 : void 0
|
|
19
|
+
};
|
|
20
|
+
if (format === "currency") {
|
|
21
|
+
const currency = getCoreCurrency();
|
|
22
|
+
if (!currency) return new Intl.NumberFormat(getCoreLocale(), baseOptions).format(numeric);
|
|
23
|
+
return new Intl.NumberFormat(getCoreLocale(), {
|
|
24
|
+
...baseOptions,
|
|
25
|
+
style: "currency",
|
|
26
|
+
currency,
|
|
27
|
+
currencyDisplay: "narrowSymbol"
|
|
28
|
+
}).format(numeric);
|
|
29
|
+
}
|
|
30
|
+
if (format === "percent") {
|
|
31
|
+
const normalized = Math.abs(numeric) <= 1 ? numeric : numeric / 100;
|
|
32
|
+
return new Intl.NumberFormat(getCoreLocale(), {
|
|
33
|
+
style: "percent",
|
|
34
|
+
minimumFractionDigits: 1,
|
|
35
|
+
maximumFractionDigits: 1
|
|
36
|
+
}).format(normalized);
|
|
37
|
+
}
|
|
38
|
+
return new Intl.NumberFormat(getCoreLocale()).format(numeric);
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region packages/dashboard/dashboard/resolvePath.ts
|
|
42
|
+
function resolvePath(source, path) {
|
|
43
|
+
if (path === void 0 || path === "") return source;
|
|
44
|
+
if (source === null || source === void 0) return void 0;
|
|
45
|
+
return path.split(".").reduce((current, segment) => {
|
|
46
|
+
if (current === null || current === void 0) return void 0;
|
|
47
|
+
if (typeof current !== "object") return void 0;
|
|
48
|
+
return current[segment];
|
|
49
|
+
}, source);
|
|
50
|
+
}
|
|
51
|
+
function resolveArray(source, path) {
|
|
52
|
+
const value = resolvePath(source, path);
|
|
53
|
+
if (!Array.isArray(value)) return [];
|
|
54
|
+
return value.filter((item) => item !== null && typeof item === "object");
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region packages/dashboard/dashboard/chartPalette.ts
|
|
58
|
+
const DEFAULT_CHART_COLORS = [
|
|
59
|
+
"var(--accent-color)",
|
|
60
|
+
"var(--success-color)",
|
|
61
|
+
"var(--warning-color)",
|
|
62
|
+
"var(--info-color)",
|
|
63
|
+
"#6b4fc8",
|
|
64
|
+
"#c2410c"
|
|
65
|
+
];
|
|
66
|
+
//#endregion
|
|
67
|
+
export { formatDashboardValue as i, resolveArray as n, resolvePath as r, DEFAULT_CHART_COLORS as t };
|