-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
137 lines (115 loc) · 3.8 KB
/
index.html
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
137
<!doctype html>
<html>
<head>
<title>Needlecraft</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
<script src="https://www.chartjs.org/samples/latest/utils.js"></script>
<script src="data.js"></script>
<style>
canvas {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>
<body>
<script>
var needleCount = rawData[0].length;
var needles = [];
for (var i = 0; i < needleCount; i++) {
var needle = {
label: rawData[0][i],
data: []
};
for (var x = 1; x < 14; x++) {
needle.data.push(Number(rawData[x][i]));
}
needles.push(needle);
}
var nextFreeColor = 0;
var fillingColors = [
window.chartColors.green,
window.chartColors.orange,
window.chartColors.yellow,
window.chartColors.purple
];
var currentNeedleIndex = -1;
window.needleSelection = [];
function load_next_needle(direction){
currentNeedleIndex+=direction;
if(currentNeedleIndex >= needles.length){
currentNeedleIndex = needles.length-1;
}
if(currentNeedleIndex <= 0){
currentNeedleIndex = 0;
}
nextFreeColor = 0;
window.needleSelection.splice(0,window.needleSelection.length);
var needle_A = needles[2];
var needle_B = needles[currentNeedleIndex];
var needle_C = needles[9];
needle_A.backgroundColor = window.chartColors.blue;
needle_B.backgroundColor = window.chartColors.red;
needle_C.backgroundColor = window.chartColors.green;
window.needleSelection.push(needle_A);
window.needleSelection.push(needle_C);
window.needleSelection.push(needle_B);
window.myBar.update();
drawNeedleSelect();
}
</script>
alles wird gut :-) ...irgendwann...
<div style="width: 75%">
<canvas id="canvas"></canvas>
</div>
<button id="prevNeedle">prev needle</button>
<button id="nextNeedle">next needle</button>
direct selection
<select id="allNeedlesSelect"></select>
<p> </p>
<script>
var barChartData = {
labels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'],
datasets: window.needleSelection
};
window.onload = function() {
var ctx = document.getElementById('canvas').getContext('2d');
window.myBar = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
responsive: true,
title: {
display: true,
text: 'Nadelsuche GT6'
},
tooltips: {
mode: 'index',
intersect: true
}
}
});
load_next_needle(1); // init
};
function drawNeedleSelect(){
allNeedlesSelect.innerHTML = "";
for(var i = 0; i < needles.length; i++){
var option = document.createElement("option");
option.value = i;
option.innerHTML = needles[i].label;
if(i == currentNeedleIndex){
option.selected = "selected";
}
allNeedlesSelect.appendChild(option);
}
}
document.getElementById('nextNeedle').addEventListener('click', function(){ load_next_needle(1) });
document.getElementById('prevNeedle').addEventListener('click', function(){ load_next_needle(-1) });
document.getElementById('allNeedlesSelect').addEventListener('change', function(){
currentNeedleIndex = allNeedlesSelect.selectedIndex;
load_next_needle(0);
});
</script>
</body>
</html>