forked from omsi6/omsi6.github.io
-
Notifications
You must be signed in to change notification settings - Fork 31
/
statsgraph.js
93 lines (92 loc) · 3.49 KB
/
statsgraph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const statGraph = {
initalized: false,
init() {
if (this.initalized) return;
const statChartCtx = document.getElementById("statChartCtx");
const dataset = this.getGraphDatasets();
const statLabels = [];
$(statList).each((_index, stat) => {
statLabels.push(_txt(`stats>${stat}>short_form`));
});
this.graphObject = new Chart(statChartCtx, {
type: "radar",
options: {
plugins: {
tooltip: {
callbacks: {
label(context) {
// format raw value as a reasonable percentage
let formattedValue = context.raw;
if (formattedValue > 99.99999999) formattedValue = formattedValue.toPrecision(12);
else if (formattedValue > 99.999999) formattedValue = formattedValue.toPrecision(10);
else if (formattedValue > 99.9999) formattedValue = formattedValue.toPrecision(8);
else if (formattedValue > 99.99) formattedValue = formattedValue.toPrecision(6);
else if (formattedValue === 0) formattedValue = 0;
else formattedValue = formattedValue.toPrecision(4);
return `${context.dataset.label}: ${formattedValue}%`;
}
}
}
},
elements: {
line: {
tension: 0,
borderWidth: 4
},
point: {
radius: 5,
hoverRadius: 6,
hitRadius: 1
}
},
scales: {
r: {
suggestedMin: 0,
suggestedMax: 20,
ticks: {
showLabelBackdrop: false,
maxTicksLimit: 6,
stepSize: 10,
precision: 0,
z: 1
},
},
},
},
data: {
labels: statLabels,
datasets: dataset,
}
});
this.initalized = true;
},
graphObject: null,
getGraphDatasets() {
const dataset = [
{
label: _txt("stats>tooltip>mana_cost_reduction"),
data: [],
fill: true,
backgroundColor: "rgba(157, 103, 205, 0.2)",
borderColor: "rgb(157, 103, 205)",
pointBackgroundColor: "rgb(157, 103, 205)",
pointBorderColor: "#fff",
pointHoverBackgroundColor: "#fff",
pointHoverBorderColor: "rgb(157, 103, 205)",
}
];
for (let i = 0; i < statList.length; i++) {
dataset[0].data.push((1 - (1 / (1 + getLevel(statList[i]) * 0.01))) * 100);
}
return dataset;
},
update() {
const newDatasets = this.getGraphDatasets();
this.graphObject.data.datasets.forEach((dataset, index) => {
dataset.data = newDatasets[index].data;
});
this.graphObject.update();
view.updateStatGraphNeeded = false;
}
};
let radarModifier;