diff --git a/package-lock.json b/package-lock.json index b05624a..56fc935 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.1.0", "dependencies": { "chart.js": "^4.2.1", + "chartjs-plugin-annotation": "^2.2.1", "core-js": "^3.8.3", "vue": "^3.2.13", "vue-chartjs": "^5.2.0", @@ -4376,6 +4377,14 @@ "pnpm": "^7.0.0" } }, + "node_modules/chartjs-plugin-annotation": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/chartjs-plugin-annotation/-/chartjs-plugin-annotation-2.2.1.tgz", + "integrity": "sha512-RL9UtrFr2SXd7C47zD0MZqn6ZLgrcRt3ySC6cYal2amBdANcYB1QcwFXcpKWAYnO4SGJYRok7P5rKDDNgJMA/w==", + "peerDependencies": { + "chart.js": ">=3.7.0" + } + }, "node_modules/chokidar": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", diff --git a/package.json b/package.json index b2c7d4b..f42025f 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ }, "dependencies": { "chart.js": "^4.2.1", + "chartjs-plugin-annotation": "^2.2.1", "core-js": "^3.8.3", "vue": "^3.2.13", "vue-chartjs": "^5.2.0", diff --git a/src/components/PlayerChart.vue b/src/components/PlayerChart.vue index 71f6874..b227f23 100644 --- a/src/components/PlayerChart.vue +++ b/src/components/PlayerChart.vue @@ -1,6 +1,6 @@ @@ -13,11 +13,12 @@ import { Tooltip, Legend } from 'chart.js' +import annotationPlugin from 'chartjs-plugin-annotation' import { Scatter } from 'vue-chartjs' import { defineComponent } from 'vue' -ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Legend) +ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Legend, annotationPlugin) export default defineComponent({ name: 'PlayerChart', @@ -46,16 +47,9 @@ export default defineComponent({ chartData.datasets[0].labels = Object.keys(this.$props.players) chartData.datasets[0].data = Object.values(this.$props.players).map((e:any) => ({ x: e.deaths, y: e.kills })) return chartData - } - }, - /* watch: { - players: function (newval: any, oldval: any): void { - - } - }, */ - data () { - return { - options: { + }, + chartOptions () { + const options = { responsive: true, plugins: { tooltip: { @@ -71,9 +65,48 @@ export default defineComponent({ return label } } + }, + annotation: {} + } + } + if (!this.$props.players) { + return options + } + const maxX = Math.max(...Object.values(this.$props.players).map(e => e.deaths)) + const maxY = Math.max(...Object.values(this.$props.players).map(e => e.kills)) + let endX, endY + if (maxY > maxX) { + endX = maxX + endY = (maxX / maxY) * maxY + } else { + endY = maxY + endX = (maxY / maxX) * maxX + } + options.plugins.annotation = { + annotations: { + line: { + type: 'line', + yMin: 0, + xMin: 0, + yMax: endY, + xMax: endX, + borderWidth: 2, + borderColor: 'black', + borderDash: [1, 5] } } } + return options + } + }, + /* watch: { + players: function (newval: any, oldval: any): void { + + } + }, */ + data () { + return { + } } }) diff --git a/src/views/PlayerView.vue b/src/views/PlayerView.vue index 21fcd89..799d781 100644 --- a/src/views/PlayerView.vue +++ b/src/views/PlayerView.vue @@ -1,7 +1,11 @@