Api call from component itself and linting.
This commit is contained in:
@@ -5,13 +5,17 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { chartWinsByColor } from "@/api";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
methods: {
|
||||||
|
fetchWinsByColor() {
|
||||||
|
return fetch("/api/history/by-color").then(resp => resp.json());
|
||||||
|
}
|
||||||
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
let canvas = this.$refs["win-chart"].getContext("2d");
|
let canvas = this.$refs["win-chart"].getContext("2d");
|
||||||
|
|
||||||
let response = await chartWinsByColor();
|
let response = await this.fetchWinsByColor();
|
||||||
|
const { colors } = response;
|
||||||
let labels = ["Vunnet"];
|
let labels = ["Vunnet"];
|
||||||
let blue = {
|
let blue = {
|
||||||
label: "Blå",
|
label: "Blå",
|
||||||
@@ -42,23 +46,26 @@ export default {
|
|||||||
data: []
|
data: []
|
||||||
};
|
};
|
||||||
|
|
||||||
blue.data.push(response.blue.win);
|
const findColorWinners = (colorSelect, colors) => {
|
||||||
yellow.data.push(response.yellow.win);
|
return colors.filter(color => color.color == colorSelect)[0].count;
|
||||||
red.data.push(response.red.win);
|
};
|
||||||
green.data.push(response.green.win);
|
|
||||||
|
const blueWinCount = findColorWinners("blue", colors);
|
||||||
|
const redWinCount = findColorWinners("red", colors);
|
||||||
|
const greenWinCount = findColorWinners("green", colors);
|
||||||
|
const yellowWinCount = findColorWinners("yellow", colors);
|
||||||
|
|
||||||
|
blue.data.push(blueWinCount);
|
||||||
|
red.data.push(redWinCount);
|
||||||
|
green.data.push(greenWinCount);
|
||||||
|
yellow.data.push(yellowWinCount);
|
||||||
|
|
||||||
let highestNumber = 0;
|
let highestNumber = 0;
|
||||||
if (response.blue.win > highestNumber) {
|
[blueWinCount, redWinCount, greenWinCount, greenWinCount].forEach(winCount => {
|
||||||
highestNumber = response.blue.win;
|
if (winCount > highestNumber) {
|
||||||
}
|
highestNumber = winCount;
|
||||||
if (response.red.win > highestNumber) {
|
}
|
||||||
highestNumber = response.red.win;
|
});
|
||||||
}
|
|
||||||
if (response.green.win > highestNumber) {
|
|
||||||
highestNumber = response.green.win;
|
|
||||||
}
|
|
||||||
if (response.yellow.win > highestNumber) {
|
|
||||||
highestNumber = response.yellow.win;
|
|
||||||
}
|
|
||||||
|
|
||||||
let datasets = [blue, yellow, green, red];
|
let datasets = [blue, yellow, green, red];
|
||||||
let chartdata = {
|
let chartdata = {
|
||||||
@@ -102,8 +109,6 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import "../styles/media-queries.scss";
|
|
||||||
|
|
||||||
.chart {
|
.chart {
|
||||||
height: 40vh;
|
height: 40vh;
|
||||||
max-height: 500px;
|
max-height: 500px;
|
||||||
|
|||||||
Reference in New Issue
Block a user