-
Notifications
You must be signed in to change notification settings - Fork 0
/
charts.js
136 lines (130 loc) · 5 KB
/
charts.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// charts.js
let powerChart, leverTravelChart, scatterChart;
function createCharts(powerDifferences, leverTravelDifferences, mcToCaliperRatios, leverageRatios, originalMcToCaliperRatio, originalOverallLeverageRatio) {
createPowerChart(powerDifferences);
createLeverTravelChart(leverTravelDifferences);
createScatterChart(mcToCaliperRatios, leverageRatios, originalMcToCaliperRatio, originalOverallLeverageRatio);
}
function createPowerChart(powerDifferences) {
const ctx = document.getElementById('powerChart').getContext('2d');
if (powerChart) powerChart.destroy();
powerChart = new Chart(ctx, {
type: 'bar',
data: {
labels: presetConfigurations.map(config => config.name),
datasets: [{
label: 'Power Difference (%)',
data: powerDifferences,
backgroundColor: 'rgba(75, 192, 192, 0.6)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
}
function createLeverTravelChart(leverTravelDifferences) {
const ctx = document.getElementById('leverTravelChart').getContext('2d');
if (leverTravelChart) leverTravelChart.destroy();
leverTravelChart = new Chart(ctx, {
type: 'bar',
data: {
labels: presetConfigurations.map(config => config.name),
datasets: [{
label: 'Lever Travel Difference (%)',
data: leverTravelDifferences,
backgroundColor: 'rgba(255, 99, 132, 0.6)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
}
function createScatterChart(mcToCaliperRatios, leverageRatios, originalMcToCaliperRatio, originalOverallLeverageRatio) {
const ctx = document.getElementById('scatterChart').getContext('2d');
if (scatterChart) scatterChart.destroy();
scatterChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: [{
label: 'Configurazioni',
data: mcToCaliperRatios.map((ratio, index) => ({
x: ratio,
y: leverageRatios[index]
})),
backgroundColor: 'rgba(75, 192, 192, 0.6)',
borderColor: 'rgba(75, 192, 192, 1)',
pointRadius: 6,
pointHoverRadius: 8
}, {
label: 'Originale',
data: [{ x: originalMcToCaliperRatio, y: originalOverallLeverageRatio }],
backgroundColor: 'rgba(255, 99, 132, 1)',
borderColor: 'rgba(255, 99, 132, 1)',
pointRadius: 8,
pointHoverRadius: 10
}]
},
options: {
responsive: true,
scales: {
x: {
title: {
display: true,
text: 'MC-to-Caliper Ratio - Amplificazione idraulica'
}
},
y: {
title: {
display: true,
text: 'Leverage Ratio - Amplificazione totale'
}
}
},
plugins: {
tooltip: {
callbacks: {
label: function(context) {
const index = context.dataIndex;
return context.dataset.label === 'Originale' ?
`Originale: (MC-to-Caliper Ratio: ${context.parsed.x.toFixed(3)}, Leverage Ratio: ${context.parsed.y.toFixed(2)})` :
`${presetConfigurations[index].name}: (MC-to-Caliper Ratio: ${context.parsed.x.toFixed(3)}, Leverage Ratio: ${context.parsed.y.toFixed(2)})`;
}
}
},
datalabels: {
align: 'end',
anchor: 'end',
backgroundColor: 'rgba(0, 0, 0, 0.7)',
borderRadius: 4,
color: 'white',
font: {
size: 10
},
formatter: function(value, context) {
return context.dataset.label === 'Originale' ?
`Originale` : `${presetConfigurations[context.dataIndex].name}`;
}
}
}
}
});
}
// Export the functions if using modules
// Uncomment the following line if you're using ES6 modules
// export { createCharts };