2022-06-25 17:01:40 +03:00
|
|
|
<template>
|
|
|
|
<canvas ref="chartEl"></canvas>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2022-12-23 08:21:55 +02:00
|
|
|
import { watch, onMounted, onUnmounted, ref } from 'vue';
|
2022-06-25 17:01:40 +03:00
|
|
|
import {
|
|
|
|
Chart,
|
|
|
|
ArcElement,
|
|
|
|
LineElement,
|
|
|
|
BarElement,
|
|
|
|
PointElement,
|
|
|
|
BarController,
|
|
|
|
LineController,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
Legend,
|
|
|
|
Title,
|
|
|
|
Tooltip,
|
|
|
|
SubTitle,
|
|
|
|
Filler,
|
|
|
|
} 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-12-23 08:21:55 +02:00
|
|
|
import { chartVLine } from '@/scripts/chart-vline';
|
2022-12-28 06:42:30 +02:00
|
|
|
import { alpha } from '@/scripts/color';
|
2022-06-25 17:01:40 +03:00
|
|
|
|
|
|
|
Chart.register(
|
|
|
|
ArcElement,
|
|
|
|
LineElement,
|
|
|
|
BarElement,
|
|
|
|
PointElement,
|
|
|
|
BarController,
|
|
|
|
LineController,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
Legend,
|
|
|
|
Title,
|
|
|
|
Tooltip,
|
|
|
|
SubTitle,
|
|
|
|
Filler,
|
|
|
|
);
|
|
|
|
|
|
|
|
const props = defineProps<{
|
2022-12-23 08:21:55 +02:00
|
|
|
type: string;
|
2022-06-25 17:01:40 +03:00
|
|
|
}>();
|
|
|
|
|
|
|
|
const chartEl = ref<HTMLCanvasElement>(null);
|
|
|
|
|
|
|
|
const gridColor = defaultStore.state.darkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)';
|
|
|
|
|
|
|
|
// フォントカラー
|
|
|
|
Chart.defaults.color = getComputedStyle(document.documentElement).getPropertyValue('--fg');
|
|
|
|
|
|
|
|
const { handler: externalTooltipHandler } = useChartTooltip();
|
|
|
|
|
|
|
|
let chartInstance: Chart;
|
|
|
|
|
2022-12-23 08:21:55 +02:00
|
|
|
function setData(values) {
|
|
|
|
if (chartInstance == null) return;
|
|
|
|
for (const value of values) {
|
2022-06-25 17:01:40 +03:00
|
|
|
chartInstance.data.labels.push('');
|
2022-12-23 08:21:55 +02:00
|
|
|
chartInstance.data.datasets[0].data.push(value);
|
2022-06-26 07:28:47 +03:00
|
|
|
if (chartInstance.data.datasets[0].data.length > 100) {
|
2022-06-25 17:01:40 +03:00
|
|
|
chartInstance.data.labels.shift();
|
|
|
|
chartInstance.data.datasets[0].data.shift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chartInstance.update();
|
2022-12-23 08:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 > 100) {
|
|
|
|
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;
|
2022-06-25 17:01:40 +03:00
|
|
|
|
|
|
|
onMounted(() => {
|
2022-12-23 08:21:55 +02:00
|
|
|
const vLineColor = defaultStore.state.darkMode ? 'rgba(255, 255, 255, 0.2)' : 'rgba(0, 0, 0, 0.2)';
|
|
|
|
|
2022-06-25 17:01:40 +03:00
|
|
|
chartInstance = new Chart(chartEl.value, {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
labels: [],
|
|
|
|
datasets: [{
|
2022-12-23 08:21:55 +02:00
|
|
|
label: label,
|
2022-06-25 17:01:40 +03:00
|
|
|
pointRadius: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
borderWidth: 2,
|
|
|
|
borderJoinStyle: 'round',
|
2022-12-23 08:21:55 +02:00
|
|
|
borderColor: color,
|
2022-12-24 04:04:07 +02:00
|
|
|
backgroundColor: alpha(color, 0.2),
|
|
|
|
fill: true,
|
2022-06-25 17:01:40 +03:00
|
|
|
data: [],
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
options: {
|
2022-06-26 07:28:47 +03:00
|
|
|
aspectRatio: 2.5,
|
2022-06-25 17:01:40 +03:00
|
|
|
layout: {
|
|
|
|
padding: {
|
|
|
|
left: 0,
|
2022-06-28 04:42:54 +03:00
|
|
|
right: 0,
|
2022-06-25 17:01:40 +03:00
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
grid: {
|
|
|
|
display: false,
|
2022-12-23 08:21:55 +02:00
|
|
|
color: gridColor,
|
|
|
|
borderColor: 'rgb(0, 0, 0, 0)',
|
2022-06-25 17:01:40 +03:00
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: false,
|
|
|
|
maxTicksLimit: 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
min: 0,
|
|
|
|
grid: {
|
2022-12-23 08:21:55 +02:00
|
|
|
color: gridColor,
|
|
|
|
borderColor: 'rgb(0, 0, 0, 0)',
|
2022-06-25 17:01:40 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
interaction: {
|
|
|
|
intersect: false,
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
enabled: false,
|
|
|
|
mode: 'index',
|
|
|
|
animation: {
|
|
|
|
duration: 0,
|
|
|
|
},
|
|
|
|
external: externalTooltipHandler,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-23 08:21:55 +02:00
|
|
|
plugins: [chartVLine(vLineColor)],
|
2022-06-25 17:01:40 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-23 08:21:55 +02:00
|
|
|
defineExpose({
|
|
|
|
setData,
|
|
|
|
pushData,
|
2022-06-25 17:01:40 +03:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-27 11:29:39 +02:00
|
|
|
<style lang="scss" scoped>
|
2022-06-25 17:01:40 +03:00
|
|
|
|
|
|
|
</style>
|