forked from rodrigocfd/string-tension-calc
/
main.js
61 lines (56 loc) · 1.47 KB
/
main.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
/**
* String Tension Calculator
* @author Rodrigo Cesar de Freitas Dias
* @license MIT
* @see https://github.com/rodrigocfd/string-tension-calc
*/
$(document).ready(() => {
$('[name=unit]').on('change', ev => {
let unit = $(ev.currentTarget).val();
for (let sset of StringSet.getAllSets('#setsArea')) {
sset.setUnit(unit);
}
updatePlot();
});
$('#newStringSet').focus().on('click', () => {
let newSet = new StringSet();
newSet.getBlock().insertBefore('#newStringSet')
.hide().fadeIn(200);
newSet.onTensionChange(updatePlot);
$('[name=unit]:checked').trigger('change');
});
});
function updatePlot() {
let tensionSeries = [];
StringSet.getAllSets('#setsArea').forEach((setArea, i) => {
setArea.setColor(COLORS[i % COLORS.length]);
let series = {
color: COLORS[i % COLORS.length],
points: {radius: 6},
data: []
};
setArea.getTensions().forEach((tension, j) => {
if ($('[name=unit]:checked').val() === 'kg') tension *= .453592;
series.data.push([j, tension]);
});
tensionSeries.push(series);
});
if (tensionSeries.length) {
let xTicks = [];
['1st','2nd','3rd','4th','5th','6th','7th','8th'].forEach((ciph, i) => {
xTicks.push([i, ciph]);
});
$('#plotArea').hide().fadeIn(200);
$.plot('#plotArea', tensionSeries, {
grid: {
borderColor: '#999',
borderWidth: 1
},
lines: {show: true, lineWidth: 2},
points: {show: true, lineWidth: 3},
xaxis: {ticks: xTicks}
});
} else {
$('#plotArea').fadeOut(200);
}
}