2022-06-25 16:01:40 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<canvas ref="chartEl"></canvas>
|
2022-06-25 16:01:40 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { defineComponent, onMounted, onUnmounted, ref } from "vue";
|
2022-06-25 16:01:40 +02:00
|
|
|
import {
|
|
|
|
Chart,
|
|
|
|
ArcElement,
|
|
|
|
LineElement,
|
|
|
|
BarElement,
|
|
|
|
PointElement,
|
|
|
|
BarController,
|
|
|
|
LineController,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
Legend,
|
|
|
|
Title,
|
|
|
|
Tooltip,
|
|
|
|
SubTitle,
|
|
|
|
Filler,
|
2023-04-08 02:01:42 +02:00
|
|
|
} from "chart.js";
|
|
|
|
import number from "@/filters/number";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { defaultStore } from "@/store";
|
|
|
|
import { useChartTooltip } from "@/scripts/use-chart-tooltip";
|
2022-06-25 16:01:40 +02:00
|
|
|
|
|
|
|
Chart.register(
|
|
|
|
ArcElement,
|
|
|
|
LineElement,
|
|
|
|
BarElement,
|
|
|
|
PointElement,
|
|
|
|
BarController,
|
|
|
|
LineController,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
Legend,
|
|
|
|
Title,
|
|
|
|
Tooltip,
|
|
|
|
SubTitle,
|
2023-04-08 02:01:42 +02:00
|
|
|
Filler
|
2022-06-25 16:01:40 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
domain: string;
|
|
|
|
connection: any;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const alpha = (hex, a) => {
|
|
|
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)!;
|
|
|
|
const r = parseInt(result[1], 16);
|
|
|
|
const g = parseInt(result[2], 16);
|
|
|
|
const b = parseInt(result[3], 16);
|
|
|
|
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
|
|
};
|
|
|
|
|
|
|
|
const chartEl = ref<HTMLCanvasElement>(null);
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const gridColor = defaultStore.state.darkMode
|
|
|
|
? "rgba(255, 255, 255, 0.1)"
|
|
|
|
: "rgba(0, 0, 0, 0.1)";
|
2022-06-25 16:01:40 +02:00
|
|
|
|
|
|
|
// フォントカラー
|
2023-04-08 02:01:42 +02:00
|
|
|
Chart.defaults.color = getComputedStyle(
|
|
|
|
document.documentElement
|
|
|
|
).getPropertyValue("--fg");
|
2022-06-25 16:01:40 +02:00
|
|
|
|
|
|
|
const { handler: externalTooltipHandler } = useChartTooltip();
|
|
|
|
|
|
|
|
let chartInstance: Chart;
|
|
|
|
|
|
|
|
const onStats = (stats) => {
|
2023-04-08 02:01:42 +02:00
|
|
|
chartInstance.data.labels.push("");
|
|
|
|
chartInstance.data.datasets[0].data.push(
|
|
|
|
stats[props.domain].activeSincePrevTick
|
|
|
|
);
|
2022-06-25 16:01:40 +02:00
|
|
|
chartInstance.data.datasets[1].data.push(stats[props.domain].active);
|
|
|
|
chartInstance.data.datasets[2].data.push(stats[props.domain].waiting);
|
|
|
|
chartInstance.data.datasets[3].data.push(stats[props.domain].delayed);
|
2022-06-26 06:28:47 +02:00
|
|
|
if (chartInstance.data.datasets[0].data.length > 100) {
|
2022-06-25 16:01:40 +02:00
|
|
|
chartInstance.data.labels.shift();
|
|
|
|
chartInstance.data.datasets[0].data.shift();
|
|
|
|
chartInstance.data.datasets[1].data.shift();
|
|
|
|
chartInstance.data.datasets[2].data.shift();
|
|
|
|
chartInstance.data.datasets[3].data.shift();
|
|
|
|
}
|
|
|
|
chartInstance.update();
|
|
|
|
};
|
|
|
|
|
|
|
|
const onStatsLog = (statsLog) => {
|
|
|
|
for (const stats of [...statsLog].reverse()) {
|
2023-04-08 02:01:42 +02:00
|
|
|
chartInstance.data.labels.push("");
|
|
|
|
chartInstance.data.datasets[0].data.push(
|
|
|
|
stats[props.domain].activeSincePrevTick
|
|
|
|
);
|
2022-06-25 16:01:40 +02:00
|
|
|
chartInstance.data.datasets[1].data.push(stats[props.domain].active);
|
|
|
|
chartInstance.data.datasets[2].data.push(stats[props.domain].waiting);
|
|
|
|
chartInstance.data.datasets[3].data.push(stats[props.domain].delayed);
|
2022-06-26 06:28:47 +02:00
|
|
|
if (chartInstance.data.datasets[0].data.length > 100) {
|
2022-06-25 16:01:40 +02:00
|
|
|
chartInstance.data.labels.shift();
|
|
|
|
chartInstance.data.datasets[0].data.shift();
|
|
|
|
chartInstance.data.datasets[1].data.shift();
|
|
|
|
chartInstance.data.datasets[2].data.shift();
|
|
|
|
chartInstance.data.datasets[3].data.shift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chartInstance.update();
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
chartInstance = new Chart(chartEl.value, {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "line",
|
2022-06-25 16:01:40 +02:00
|
|
|
data: {
|
|
|
|
labels: [],
|
2023-04-08 02:01:42 +02:00
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: "Process",
|
|
|
|
pointRadius: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
borderWidth: 2,
|
|
|
|
borderJoinStyle: "round",
|
|
|
|
borderColor: "#9ccfd8",
|
|
|
|
backgroundColor: alpha("#9ccfd8", 0.1),
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Active",
|
|
|
|
pointRadius: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
borderWidth: 2,
|
|
|
|
borderJoinStyle: "round",
|
|
|
|
borderColor: "#31748f",
|
|
|
|
backgroundColor: alpha("#31748f", 0.1),
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Waiting",
|
|
|
|
pointRadius: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
borderWidth: 2,
|
|
|
|
borderJoinStyle: "round",
|
|
|
|
borderColor: "#f6c177",
|
|
|
|
backgroundColor: alpha("#f6c177", 0.1),
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Delayed",
|
|
|
|
pointRadius: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
borderWidth: 2,
|
|
|
|
borderJoinStyle: "round",
|
|
|
|
borderColor: "#eb6f92",
|
|
|
|
borderDash: [5, 5],
|
|
|
|
fill: false,
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
],
|
2022-06-25 16:01:40 +02:00
|
|
|
},
|
|
|
|
options: {
|
2022-06-26 06:28:47 +02:00
|
|
|
aspectRatio: 2.5,
|
2022-06-25 16:01:40 +02:00
|
|
|
layout: {
|
|
|
|
padding: {
|
|
|
|
left: 0,
|
2022-06-28 03:42:54 +02:00
|
|
|
right: 0,
|
2022-06-25 16:01:40 +02:00
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
x: {
|
2022-06-26 06:28:47 +02:00
|
|
|
display: false,
|
2022-06-25 16:01:40 +02:00
|
|
|
grid: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false,
|
|
|
|
maxTicksLimit: 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
y: {
|
2022-06-26 06:28:47 +02:00
|
|
|
display: false,
|
2022-06-25 16:01:40 +02:00
|
|
|
min: 0,
|
|
|
|
grid: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
interaction: {
|
|
|
|
intersect: false,
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
enabled: false,
|
2023-04-08 02:01:42 +02:00
|
|
|
mode: "index",
|
2022-06-25 16:01:40 +02:00
|
|
|
animation: {
|
|
|
|
duration: 0,
|
|
|
|
},
|
|
|
|
external: externalTooltipHandler,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
props.connection.on("stats", onStats);
|
|
|
|
props.connection.on("statsLog", onStatsLog);
|
2022-06-25 16:01:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
2023-04-08 02:01:42 +02:00
|
|
|
props.connection.off("stats", onStats);
|
|
|
|
props.connection.off("statsLog", onStatsLog);
|
2022-06-25 16:01:40 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<style lang="scss" scoped></style>
|