refactor queue chart to composition API
This commit is contained in:
parent
307bfaf220
commit
dca0db770e
|
@ -2,8 +2,8 @@
|
||||||
<canvas ref="chartEl"></canvas>
|
<canvas ref="chartEl"></canvas>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent, onMounted, onUnmounted, ref } from 'vue';
|
import { onMounted, onUnmounted, ref } from 'vue';
|
||||||
import {
|
import {
|
||||||
Chart,
|
Chart,
|
||||||
ArcElement,
|
ArcElement,
|
||||||
|
@ -42,26 +42,19 @@ Chart.register(
|
||||||
Filler,
|
Filler,
|
||||||
);
|
);
|
||||||
|
|
||||||
export default defineComponent({
|
const props = defineProps<{
|
||||||
props: {
|
domain: string,
|
||||||
domain: {
|
connection: any,
|
||||||
type: String,
|
}>();
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
connection: {
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
setup(props) {
|
const chartEl = ref<HTMLCanvasElement>(null);
|
||||||
const chartEl = ref<HTMLCanvasElement>(null);
|
|
||||||
|
|
||||||
const gridColor = defaultStore.state.darkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)';
|
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');
|
Chart.defaults.color = getComputedStyle(document.documentElement).getPropertyValue('--fg');
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const chartInstance = new Chart(chartEl.value, {
|
const chartInstance = new Chart(chartEl.value, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
|
@ -134,91 +127,3 @@ export default defineComponent({
|
||||||
stack: 'queue',
|
stack: 'queue',
|
||||||
stackWeight: 2,
|
stackWeight: 2,
|
||||||
grid: {
|
grid: {
|
||||||
color: gridColor,
|
|
||||||
borderColor: '#1f1d2e',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
y2: {
|
|
||||||
min: 0,
|
|
||||||
offset: true,
|
|
||||||
stack: 'queue',
|
|
||||||
stackWeight: 1,
|
|
||||||
grid: {
|
|
||||||
color: gridColor,
|
|
||||||
borderColor: '#1f1d2e',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
interaction: {
|
|
||||||
intersect: false,
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
legend: {
|
|
||||||
position: 'bottom',
|
|
||||||
labels: {
|
|
||||||
boxWidth: 16,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
mode: 'index',
|
|
||||||
animation: {
|
|
||||||
duration: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const onStats = (stats) => {
|
|
||||||
chartInstance.data.labels.push('');
|
|
||||||
chartInstance.data.datasets[0].data.push(stats[props.domain].activeSincePrevTick);
|
|
||||||
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);
|
|
||||||
if (chartInstance.data.datasets[0].data.length > 200) {
|
|
||||||
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()) {
|
|
||||||
chartInstance.data.labels.push('');
|
|
||||||
chartInstance.data.datasets[0].data.push(stats[props.domain].activeSincePrevTick);
|
|
||||||
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);
|
|
||||||
if (chartInstance.data.datasets[0].data.length > 200) {
|
|
||||||
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();
|
|
||||||
};
|
|
||||||
|
|
||||||
props.connection.on('stats', onStats);
|
|
||||||
props.connection.on('statsLog', onStatsLog);
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
props.connection.off('stats', onStats);
|
|
||||||
props.connection.off('statsLog', onStatsLog);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
chartEl,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
Loading…
Reference in New Issue