2022-08-31 02:14:16 +02:00
|
|
|
<script>
|
|
|
|
|
import Chart from "svelte-frappe-charts";
|
2022-08-31 22:25:22 +02:00
|
|
|
|
2022-08-31 02:14:16 +02:00
|
|
|
export let widget;
|
|
|
|
|
|
2022-08-31 22:25:22 +02:00
|
|
|
let axisOptions = { xAxisMode: "tick", xIsSeries: true };
|
|
|
|
|
let lineOptions;
|
|
|
|
|
|
|
|
|
|
if (widget.pointRadius == "0") {
|
|
|
|
|
lineOptions = { regionFill: 1, hideDots: 1, spline: 1 };
|
|
|
|
|
} else {
|
|
|
|
|
lineOptions = { regionFill: 1, dotSize: 3, spline: 1 };
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 23:46:43 +02:00
|
|
|
let collectingDataArray = [];
|
|
|
|
|
let prevSatus = [];
|
2022-08-31 22:25:22 +02:00
|
|
|
|
2022-08-31 23:46:43 +02:00
|
|
|
//необходимые по умолчанию значения из за тупости библиотеки
|
|
|
|
|
let labels = [0, 0];
|
|
|
|
|
let values = [0, 0];
|
2022-08-31 02:14:16 +02:00
|
|
|
|
|
|
|
|
let datachart = {
|
|
|
|
|
labels: labels,
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
2022-08-31 22:25:22 +02:00
|
|
|
name: widget.descr,
|
2022-08-31 02:14:16 +02:00
|
|
|
values: values,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-31 23:46:43 +02:00
|
|
|
$: widget.status, collectDataToArr();
|
2022-08-31 02:14:16 +02:00
|
|
|
|
2022-08-31 23:46:43 +02:00
|
|
|
function collectDataToArr() {
|
2022-09-08 23:35:58 +02:00
|
|
|
if (widget.status && Array.isArray(widget.status)) {
|
|
|
|
|
//отсекаем лишние события изменения переменной widget
|
|
|
|
|
if (prevSatus !== widget.status) {
|
|
|
|
|
console.log("[i]", "collecting chart data to array, topic:", widget.topic);
|
|
|
|
|
let incomingDataArr = widget.status;
|
2022-08-31 23:46:43 +02:00
|
|
|
|
2022-09-08 23:35:58 +02:00
|
|
|
console.log("[i]", "array:", incomingDataArr);
|
2022-09-01 12:51:17 +02:00
|
|
|
|
2022-09-08 23:35:58 +02:00
|
|
|
collectingDataArray = [...collectingDataArray, ...incomingDataArr];
|
2022-08-31 23:46:43 +02:00
|
|
|
|
2022-09-08 23:35:58 +02:00
|
|
|
for (let i = 0; i < collectingDataArray.length; i++) {
|
|
|
|
|
labels[i] = getHHMM(collectingDataArray[i].x);
|
|
|
|
|
values[i] = [collectingDataArray[i].y1];
|
2022-09-01 12:51:17 +02:00
|
|
|
}
|
2022-09-08 23:35:58 +02:00
|
|
|
|
|
|
|
|
datachart = {
|
|
|
|
|
labels: labels,
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
name: widget.descr,
|
|
|
|
|
values: values,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
prevSatus = widget.status;
|
|
|
|
|
datachart = datachart;
|
2022-09-01 01:56:23 +02:00
|
|
|
}
|
2022-09-08 23:35:58 +02:00
|
|
|
} else {
|
|
|
|
|
console.log("[i]", "skipping event, topic:", widget.topic);
|
2022-08-31 02:14:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 22:25:22 +02:00
|
|
|
function getHHMM(timestamp) {
|
|
|
|
|
var date = new Date(timestamp * 1000);
|
|
|
|
|
return ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2);
|
2022-08-31 02:14:16 +02:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2022-09-10 02:59:03 +02:00
|
|
|
<div class="text-center">
|
|
|
|
|
<!-- svelte-ignore a11y-label-has-associated-control -->
|
|
|
|
|
<label class="inline-block italic align-top text-center text-gray-500 txt-sz">{!widget.descr ? "" : widget.descr}</label>
|
|
|
|
|
</div>
|
|
|
|
|
<Chart class="h-24" data={datachart} type="line" lineOptions={lineOptions} axisOptions={axisOptions} />
|