|
25 | 25 | var data = {}; |
26 | 26 | var elementData = []; |
27 | 27 | var nViews = views.length; |
28 | | - var nElements = 1*(views[nViews-1]["elements"][views[nViews-1]["elements"].length-1]["index"])+1; |
| 28 | + var nElements = 1*(views[nViews - 1].elements[views[nViews - 1].elements.length - 1].index)+1; |
29 | 29 |
|
30 | 30 | var measuring = true; |
31 | 31 | var countDown = 0; |
|
205 | 205 | } |
206 | 206 |
|
207 | 207 | function composeVarStr(name, partial, partialComponent) { |
208 | | - var namePart = encodeURIComponent(name); |
209 | | - if (partial == "full") |
210 | | - return namePart + "=full"; |
211 | | - if (partial == "partial" || partial == "partialXYZ") { |
212 | | - if ((!forceFull) && data.hasOwnProperty(partialComponent) && data[partialComponent]["data"].length > 0 && data.hasOwnProperty(name) && data[name]["data"].length > 0) { |
213 | | - if (partialComponent == name) |
214 | | - return namePart + "=" + data[partialComponent]["data"][data[partialComponent]["data"].length-1]; |
215 | | - else { |
216 | | - var minLength = Math.min(data[partialComponent]["data"].length, data[name]["data"].length); |
217 | | - return namePart + "=" + encodeURIComponent(data[partialComponent]["data"][minLength-1] + "|" + partialComponent); |
| 208 | + var value; // empty (one sample) by default |
| 209 | + if (partial == "full") { |
| 210 | + value = "full"; |
| 211 | + } else if (partial == "partial" || partial == "partialXYZ") { |
| 212 | + value = "full"; // fallback to full |
| 213 | + if (!forceFull && data.hasOwnProperty(partialComponent) && data.hasOwnProperty(name)) { |
| 214 | + var length = Math.min(data[partialComponent].data.length, data[name].data.length); |
| 215 | + if (length > 0) { |
| 216 | + value = data[partialComponent].data[length - 1]; |
| 217 | + if (partialComponent !== name) |
| 218 | + value += encodeURIComponent("|" + partialComponent); |
218 | 219 | } |
219 | | - } else |
220 | | - return namePart + "=full"; |
| 220 | + } |
221 | 221 | } |
222 | | - return namePart; |
| 222 | + return encodeURIComponent(name) + (value ? '=' + value : ''); |
223 | 223 | } |
224 | 224 |
|
225 | 225 | function updateUsedVarStr() { |
226 | | - var usedVars = []; |
227 | | - var modePriority = []; |
228 | | - views[currentView]["elements"].forEach(function(ve) { |
| 226 | + var vars = {}; |
| 227 | + var priorities = {}; |
| 228 | + views[currentView].elements.forEach(function(ve) { |
229 | 229 | if (ve.hasOwnProperty("dataInput")) { |
230 | | - for (var index = 0; index < ve["dataInput"].length; index++) { |
231 | | - if (ve["dataInput"][index] == null) |
| 230 | + let dataInput = ve.dataInput; |
| 231 | + let updateMode = ve.updateMode; |
| 232 | + for (var i = 0; i < dataInput.length; i++) { |
| 233 | + if (dataInput[i] == null) |
232 | 234 | continue; |
233 | | - let varStr = ve["dataInput"][index]; |
234 | | - let varKey = "buffer:" + varStr; |
235 | | - if (ve["updateMode"] == "single" || ve["updateMode"] == "input") { |
236 | | - if (modePriority[varKey] >= 1) |
237 | | - continue; |
238 | | - usedVars[varKey] = composeVarStr(varStr, "single"); |
239 | | - modePriority[varKey] = 1; |
240 | | - } else if (ve["updateMode"] == "partial") { |
241 | | - if (modePriority[varKey] >= 2) |
242 | | - continue; |
243 | | - var dependentVar = ((ve["dataInput"].length > index + 1) && (index % 2 == 0)) ? ve["dataInput"][index+1] : ve["dataInput"][index]; |
244 | | - usedVars[varKey] = composeVarStr(varStr, "partial", dependentVar); |
245 | | - modePriority[varKey] = 2; |
246 | | - } else if (ve["updateMode"] == "partialXYZ") { |
247 | | - if (modePriority[varKey] >= 3) |
248 | | - continue; |
249 | | - var dependentVar = ve["dataInput"][Math.floor(index / 3)]; |
250 | | - usedVars[varKey] = composeVarStr(varStr, "partialXYZ", dependentVar); |
251 | | - modePriority[varKey] = 3; |
252 | | - } else if (ve["updateMode"] == "full") { |
253 | | - if (modePriority[varKey] >= 4) |
254 | | - continue; |
255 | | - usedVars[varKey] = composeVarStr(varStr, "full"); |
256 | | - modePriority[varKey] = 4; |
| 235 | + let name = dataInput[i]; |
| 236 | + let key = "buffer:" + name; |
| 237 | + let priority = priorities[key] || 0; |
| 238 | + if (priority < 1 && (updateMode == "single" || updateMode == "input")) { |
| 239 | + vars[key] = composeVarStr(name, "single"); |
| 240 | + priorities[key] = 1; |
| 241 | + } else if (priority < 2 && updateMode == "partial") { |
| 242 | + var dependentVar = ((dataInput.length > i + 1) && (i % 2 == 0)) ? dataInput[i + 1] : dataInput[i]; |
| 243 | + vars[key] = composeVarStr(name, "partial", dependentVar); |
| 244 | + priorities[key] = 2; |
| 245 | + } else if (priority < 3 && updateMode == "partialXYZ") { |
| 246 | + var dependentVar = dataInput[Math.floor(i / 3)]; |
| 247 | + vars[key] = composeVarStr(name, "partialXYZ", dependentVar); |
| 248 | + priorities[key] = 3; |
| 249 | + } else if (priority < 4 && updateMode == "full") { |
| 250 | + vars[key] = composeVarStr(name, "full"); |
| 251 | + priorities[key] = 4; |
257 | 252 | } |
258 | 253 | } |
259 | 254 | } |
260 | 255 | }); |
261 | 256 |
|
262 | 257 | usedVarStr = ""; |
263 | | - for (var usedVar in usedVars) { |
| 258 | + for (var v in vars) { |
264 | 259 | if (usedVarStr != "") |
265 | 260 | usedVarStr += "&"; |
266 | | - usedVarStr += usedVars[usedVar]; |
| 261 | + usedVarStr += vars[v]; |
267 | 262 | } |
268 | 263 | forceFull = false; |
269 | 264 | } |
|
280 | 275 | function updateData() { |
281 | 276 | updateUsedVarStr(); |
282 | 277 | ajax("get?" + usedVarStr, |
283 | | - function( jsonData ) { |
284 | | - for (var index in jsonData["buffer"]) { |
285 | | - if (jsonData["buffer"][index]["updateMode"] == "partial" && data.hasOwnProperty(index) && data[index]["data"].length > 0) { |
286 | | - if (jsonData["buffer"][index]["buffer"].length == 0) { |
287 | | - data[index]["changed"] = false; |
| 278 | + function(response) { |
| 279 | + for (var name in response.buffer) { |
| 280 | + let buffer = response.buffer[name]; |
| 281 | + let existing = data[name]; |
| 282 | + if (buffer.updateMode == "partial" && existing && existing.data.length > 0) { |
| 283 | + if (buffer.buffer.length == 0) { |
| 284 | + existing.changed = false; |
288 | 285 | continue; |
289 | 286 | } |
290 | | - data[index]["data"] = data[index]["data"].concat(nullToNaN(jsonData["buffer"][index]["buffer"])); |
291 | | - if (jsonData["buffer"][index]["size"] > 0) |
292 | | - data[index]["data"].splice(0, data[index]["data"].length - jsonData["buffer"][index]["size"]); |
293 | | - data[index]["changed"] = true; |
| 287 | + existing.data = existing.data.concat(nullToNaN(buffer.buffer)); |
| 288 | + if (buffer.size > 0) |
| 289 | + existing.data.splice(0, existing.data.length - buffer.size); |
| 290 | + existing.changed = true; |
294 | 291 | } else { |
295 | | - data[index] = {}; |
296 | | - data[index]["data"] = nullToNaN(jsonData["buffer"][index]["buffer"]); |
297 | | - data[index]["changed"] = true; |
| 292 | + data[name] = { |
| 293 | + data: nullToNaN(buffer.buffer), |
| 294 | + changed: true |
| 295 | + }; |
298 | 296 | } |
299 | 297 | } |
300 | 298 | updateViews(); |
301 | | - updateMeasuring(jsonData["status"]); |
| 299 | + updateMeasuring(response.status); |
302 | 300 | errorNode.style.display = "none"; |
303 | 301 | }, |
304 | 302 | function() { |
|
307 | 305 | forceFull = true; |
308 | 306 | }, |
309 | 307 | function() { |
310 | | - if (measuring) |
311 | | - setTimeout(updateData, 30); |
312 | | - else |
313 | | - setTimeout(updateData, 250); |
| 308 | + setTimeout(updateData, measuring ? 30 : 250); |
314 | 309 | }, |
315 | 310 | 10000 |
316 | 311 | ); |
|
327 | 322 | if (fatalStop) |
328 | 323 | return; |
329 | 324 |
|
330 | | - if (measuring != s["measuring"]) |
| 325 | + if (measuring != s.measuring) |
331 | 326 | forceFull = true; |
332 | 327 | if (sessionID == "") |
333 | | - sessionID = s["session"]; |
334 | | - else if (sessionID != s["session"]) { |
| 328 | + sessionID = s.session; |
| 329 | + else if (sessionID != s.session) { |
335 | 330 | fatalStop = true; |
336 | 331 | askSessionReload(); |
337 | 332 | } |
338 | | - measuring = s["measuring"]; |
339 | | - timedRun = s["timedRun"]; |
340 | | - countDown = s["countDown"]; |
341 | | - if (measuring) |
342 | | - header.classList.add("active"); |
343 | | - else |
344 | | - header.classList.remove("active"); |
345 | | - if (countDown != 0) |
346 | | - header.classList.add("countdown"); |
347 | | - else |
348 | | - header.classList.remove("countdown"); |
| 333 | + measuring = s.measuring; |
| 334 | + timedRun = s.timedRun; |
| 335 | + countDown = s.countDown; |
| 336 | + header.classList.toggle("active", measuring); |
| 337 | + header.classList.toggle("countdown", countDown != 0); |
349 | 338 | if (countDown != 0) { |
350 | 339 | document.getElementById("countdown").textContent = Math.ceil(countDown/1000) + "s"; |
351 | 340 | } else { |
|
359 | 348 | } |
360 | 349 |
|
361 | 350 | function updateViews() { |
362 | | - views[currentView]["elements"].forEach(function(ve) { |
| 351 | + views[currentView].elements.forEach(function(ve) { |
363 | 352 | if (ve.hasOwnProperty("dataInputFunction")) |
364 | | - ve["dataInputFunction"](data); |
365 | | - ve["dataCompleteFunction"](); |
| 353 | + ve.dataInputFunction(data); |
| 354 | + ve.dataCompleteFunction(); |
366 | 355 | }); |
367 | 356 | } |
368 | 357 |
|
|
371 | 360 | for (i = 0; i < nElements; i++) |
372 | 361 | elementData[i] = {}; |
373 | 362 |
|
374 | | - views[currentView]["elements"].forEach(function(ve) { |
375 | | - viewsNode.innerHTML += ("<div class=\"elementBlock\">" + ve["html"] + "</div>"); |
| 363 | + views[currentView].elements.forEach(function(ve) { |
| 364 | + viewsNode.innerHTML += ("<div class=\"elementBlock\">" + ve.html + "</div>"); |
376 | 365 | }); |
377 | 366 | adjustColors(); |
378 | 367 | forceFull = true; |
|
386 | 375 |
|
387 | 376 | var liElements = viewSelector.getElementsByTagName("li"); |
388 | 377 | for (var i = 0; i < liElements.length; i++) { |
389 | | - var el = liElements[i]; |
390 | | - if (i == currentView) |
391 | | - el.classList.add("active"); |
392 | | - else |
393 | | - el.classList.remove("active"); |
394 | | - }; |
| 378 | + liElements[i].classList.toggle("active", i == currentView); |
| 379 | + } |
395 | 380 | recreateViews(); |
396 | 381 | } |
397 | 382 |
|
|
441 | 426 |
|
442 | 427 | var elements = document.getElementsByClassName("exclusive"); |
443 | 428 | for (var i = 0; i < elements.length; i++) { |
444 | | - var elem = elements[i]; |
445 | | - elem.classList.remove("exclusive"); |
446 | | - }; |
| 429 | + elements[i].classList.remove("exclusive"); |
| 430 | + } |
447 | 431 | } |
448 | 432 |
|
449 | 433 | function toggleExclusive(i) { |
|
454 | 438 | setExclusive(i); |
455 | 439 | } |
456 | 440 |
|
457 | | - function zoomLarger(e) { |
| 441 | + function zoom(e, factor) { |
458 | 442 | leaveExclusive(); |
459 | | - if (scaleFactor < 3) |
460 | | - scaleFactor *= 1.2; |
| 443 | + scaleFactor = factor; |
461 | 444 | saveSetting("scaleFactor", scaleFactor); |
462 | 445 | body.style.fontSize = (100*scaleFactor)+"%"; |
463 | 446 | e.stopPropagation(); |
464 | 447 | recreateViews(); |
465 | 448 | } |
466 | 449 |
|
| 450 | + function zoomLarger(e) { |
| 451 | + if (scaleFactor < 3) |
| 452 | + zoom(e, scaleFactor * 1.2); |
| 453 | + } |
| 454 | + |
467 | 455 | function zoomSmaller(e) { |
468 | | - leaveExclusive(); |
469 | 456 | if (scaleFactor > 0.5) |
470 | | - scaleFactor /= 1.2; |
471 | | - saveSetting("scaleFactor", scaleFactor); |
472 | | - body.style.fontSize = (100*scaleFactor)+"%"; |
473 | | - e.stopPropagation(); |
474 | | - recreateViews(); |
| 457 | + zoom(e, scaleFactor / 1.2); |
475 | 458 | } |
476 | 459 |
|
477 | 460 | function zoomDefault(e) { |
478 | | - leaveExclusive(); |
479 | | - scaleFactor = 1.0; |
480 | | - saveSetting("scaleFactor", scaleFactor); |
481 | | - body.style.fontSize = (100*scaleFactor)+"%"; |
482 | | - e.stopPropagation(); |
483 | | - recreateViews(); |
| 461 | + zoom(e, 1.0); |
484 | 462 | } |
485 | 463 |
|
486 | 464 | function toggleBrightMode(e) { |
|
0 commit comments