|
|
@@ -5,87 +5,112 @@
|
|
|
<template>
|
|
|
<div class="wrapper">
|
|
|
<select v-model="selectedMember">
|
|
|
- <option v-for="(member, index) in Object.keys(cluster.members)" :key="index">{{ member }}</option>
|
|
|
+ <option
|
|
|
+ v-for="(member, index) in Object.keys(cluster.members)"
|
|
|
+ :key="index"
|
|
|
+ >
|
|
|
+ {{ member }}
|
|
|
+ </option>
|
|
|
</select>
|
|
|
- <RadarChart :chartData="chartData" :options="options" class="chart"></RadarChart>
|
|
|
+ <RadarChart
|
|
|
+ :chartData="chartData"
|
|
|
+ :options="options"
|
|
|
+ class="chart"
|
|
|
+ ></RadarChart>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import {defineComponent, ref, watch} from "vue";
|
|
|
-import {RadarChart} from "vue-chart-3"
|
|
|
-import {Chart, registerables} from 'chart.js';
|
|
|
-import ChartDataLabels from 'chartjs-plugin-datalabels';
|
|
|
+import { defineComponent, ref, watch } from "vue";
|
|
|
+import { RadarChart } from "vue-chart-3";
|
|
|
+import { Chart, registerables } from "chart.js";
|
|
|
+import ChartDataLabels from "chartjs-plugin-datalabels";
|
|
|
|
|
|
Chart.register(...registerables);
|
|
|
Chart.register(ChartDataLabels);
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: "ClusterRadarChart",
|
|
|
- components: {RadarChart},
|
|
|
+ components: { RadarChart },
|
|
|
props: {
|
|
|
- cluster: {}
|
|
|
+ cluster: {},
|
|
|
},
|
|
|
setup(props) {
|
|
|
- const selectedMember = ref("")
|
|
|
+ const selectedMember = ref(Object.keys(props.cluster.members)[0]);
|
|
|
|
|
|
const createLabelsFor = (member) => {
|
|
|
- let matchedWith = []
|
|
|
- props.cluster.members[member].forEach(m => matchedWith.push(m.matchedWith))
|
|
|
- return matchedWith
|
|
|
- }
|
|
|
+ let matchedWith = [];
|
|
|
+ props.cluster.members[member].forEach((m) =>
|
|
|
+ matchedWith.push(m.matchedWith)
|
|
|
+ );
|
|
|
+ return matchedWith;
|
|
|
+ };
|
|
|
const createDataSetFor = (member) => {
|
|
|
- let data = []
|
|
|
- props.cluster.members[member].forEach(m => data.push(m.percentage))
|
|
|
- return data
|
|
|
- }
|
|
|
+ let data = [];
|
|
|
+ props.cluster.members[member].forEach((m) =>
|
|
|
+ data.push(roundToTwoDecimals(m.percentage))
|
|
|
+ );
|
|
|
+ return data;
|
|
|
+ };
|
|
|
+ const roundToTwoDecimals = (number) =>
|
|
|
+ Math.round((number + Number.EPSILON) * 100) / 100;
|
|
|
|
|
|
const chartStyle = {
|
|
|
fill: true,
|
|
|
- backgroundColor: 'rgba(149, 168, 241, 0.5)',
|
|
|
- borderColor: 'rgba(149, 168, 241, 1)',
|
|
|
- pointBackgroundColor: 'rgba(149, 168, 241, 1)',
|
|
|
- pointBorderColor: '#fff',
|
|
|
- pointHoverBackgroundColor: '#fff',
|
|
|
- pointHoverBorderColor: 'rgb(255, 99, 132)'
|
|
|
- }
|
|
|
+ backgroundColor: "rgba(149, 168, 241, 0.5)",
|
|
|
+ borderColor: "rgba(149, 168, 241, 1)",
|
|
|
+ pointBackgroundColor: "rgba(149, 168, 241, 1)",
|
|
|
+ pointBorderColor: "#fff",
|
|
|
+ pointHoverBackgroundColor: "#fff",
|
|
|
+ pointHoverBorderColor: "rgb(255, 99, 132)",
|
|
|
+ };
|
|
|
|
|
|
const chartData = ref({
|
|
|
labels: createLabelsFor(Object.keys(props.cluster.members)[0]),
|
|
|
- datasets: [{
|
|
|
- ...chartStyle,
|
|
|
- label: Object.keys(props.cluster.members)[0],
|
|
|
- data: createDataSetFor(Object.keys(props.cluster.members)[0])
|
|
|
- }]
|
|
|
- })
|
|
|
+ datasets: [
|
|
|
+ {
|
|
|
+ ...chartStyle,
|
|
|
+ label: Object.keys(props.cluster.members)[0],
|
|
|
+ data: createDataSetFor(Object.keys(props.cluster.members)[0]),
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
|
|
|
const options = ref({
|
|
|
+ legend: {
|
|
|
+ display: false,
|
|
|
+ },
|
|
|
scales: {
|
|
|
r: {
|
|
|
suggestedMin: 50,
|
|
|
- suggestedMax: 100
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
+ suggestedMax: 100,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ });
|
|
|
|
|
|
- watch(() => selectedMember.value, (val) => {
|
|
|
- chartData.value = {
|
|
|
- labels: createLabelsFor(val),
|
|
|
- datasets: [{
|
|
|
- ...chartStyle,
|
|
|
- label: val,
|
|
|
- data: createDataSetFor(val),
|
|
|
- }]
|
|
|
+ watch(
|
|
|
+ () => selectedMember.value,
|
|
|
+ (val) => {
|
|
|
+ chartData.value = {
|
|
|
+ labels: createLabelsFor(val),
|
|
|
+ datasets: [
|
|
|
+ {
|
|
|
+ ...chartStyle,
|
|
|
+ label: val,
|
|
|
+ data: createDataSetFor(val),
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ };
|
|
|
}
|
|
|
- })
|
|
|
+ );
|
|
|
|
|
|
return {
|
|
|
selectedMember,
|
|
|
chartData,
|
|
|
- options
|
|
|
- }
|
|
|
- }
|
|
|
-})
|
|
|
+ options,
|
|
|
+ };
|
|
|
+ },
|
|
|
+});
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
@@ -93,10 +118,9 @@ export default defineComponent({
|
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
|
flex-wrap: nowrap;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
.chart {
|
|
|
height: 50vw;
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|