2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
2024-02-13 15:50:11 +00:00
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
2023-07-27 05:31:52 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-06-25 14:01:40 +00:00
|
|
|
<template>
|
|
|
|
<canvas ref="chartEl"></canvas>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-02-16 14:09:41 +00:00
|
|
|
import { onMounted, shallowRef } from 'vue';
|
2023-01-02 01:18:47 +00:00
|
|
|
import { Chart } from 'chart.js';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { useChartTooltip } from '@/scripts/use-chart-tooltip.js';
|
|
|
|
import { chartVLine } from '@/scripts/chart-vline.js';
|
|
|
|
import { alpha } from '@/scripts/color.js';
|
|
|
|
import { initChart } from '@/scripts/init-chart.js';
|
2022-06-25 14:01:40 +00:00
|
|
|
|
2023-01-02 01:18:47 +00:00
|
|
|
initChart();
|
2022-06-25 14:01:40 +00:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
type: string;
|
|
|
|
}>();
|
|
|
|
|
2023-01-03 01:12:37 +00:00
|
|
|
const chartEl = shallowRef<HTMLCanvasElement>(null);
|
2022-06-25 14:01:40 +00:00
|
|
|
|
|
|
|
const { handler: externalTooltipHandler } = useChartTooltip();
|
|
|
|
|
|
|
|
let chartInstance: Chart;
|
|
|
|
|
|
|
|
function setData(values) {
|
|
|
|
if (chartInstance == null) return;
|
|
|
|
for (const value of values) {
|
|
|
|
chartInstance.data.labels.push('');
|
|
|
|
chartInstance.data.datasets[0].data.push(value);
|
|
|
|
if (chartInstance.data.datasets[0].data.length > 200) {
|
|
|
|
chartInstance.data.labels.shift();
|
|
|
|
chartInstance.data.datasets[0].data.shift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chartInstance.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
function pushData(value) {
|
|
|
|
if (chartInstance == null) return;
|
|
|
|
chartInstance.data.labels.push('');
|
|
|
|
chartInstance.data.datasets[0].data.push(value);
|
|
|
|
if (chartInstance.data.datasets[0].data.length > 200) {
|
|
|
|
chartInstance.data.labels.shift();
|
|
|
|
chartInstance.data.datasets[0].data.shift();
|
|
|
|
}
|
|
|
|
chartInstance.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
const label =
|
|
|
|
props.type === 'process' ? 'Process' :
|
|
|
|
props.type === 'active' ? 'Active' :
|
|
|
|
props.type === 'delayed' ? 'Delayed' :
|
|
|
|
props.type === 'waiting' ? 'Waiting' :
|
|
|
|
'?' as never;
|
|
|
|
|
|
|
|
const color =
|
|
|
|
props.type === 'process' ? '#00E396' :
|
|
|
|
props.type === 'active' ? '#00BCD4' :
|
|
|
|
props.type === 'delayed' ? '#E53935' :
|
|
|
|
props.type === 'waiting' ? '#FFB300' :
|
|
|
|
'?' as never;
|
|
|
|
|
|
|
|
onMounted(() => {
|
2022-12-23 06:21:55 +00:00
|
|
|
const vLineColor = defaultStore.state.darkMode ? 'rgba(255, 255, 255, 0.2)' : 'rgba(0, 0, 0, 0.2)';
|
|
|
|
|
2022-06-25 14:01:40 +00:00
|
|
|
chartInstance = new Chart(chartEl.value, {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
labels: [],
|
|
|
|
datasets: [{
|
|
|
|
label: label,
|
|
|
|
pointRadius: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
borderWidth: 2,
|
|
|
|
borderJoinStyle: 'round',
|
|
|
|
borderColor: color,
|
2022-12-24 02:04:07 +00:00
|
|
|
backgroundColor: alpha(color, 0.2),
|
|
|
|
fill: true,
|
2022-06-25 14:01:40 +00:00
|
|
|
data: [],
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
aspectRatio: 2.5,
|
|
|
|
layout: {
|
|
|
|
padding: {
|
|
|
|
left: 0,
|
2022-06-28 01:42:54 +00:00
|
|
|
right: 0,
|
2022-06-25 14:01:40 +00:00
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
grid: {
|
|
|
|
display: true,
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false,
|
|
|
|
maxTicksLimit: 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
min: 0,
|
|
|
|
grid: {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
interaction: {
|
|
|
|
intersect: false,
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
enabled: false,
|
|
|
|
mode: 'index',
|
|
|
|
animation: {
|
|
|
|
duration: 0,
|
|
|
|
},
|
|
|
|
external: externalTooltipHandler,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-23 06:21:55 +00:00
|
|
|
plugins: [chartVLine(vLineColor)],
|
2022-06-25 14:01:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
setData,
|
|
|
|
pushData,
|
|
|
|
});
|
|
|
|
</script>
|