Skip to content

Commit 686f7ca

Browse files
committed
Fixed Liverange
1 parent 5e99d94 commit 686f7ca

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var container = document.getElementById('pryvGraphs');
33
var monitor;
44

55
var pullSerieFrequencyMs = 100;
6+
var pullSerieFrequencyMsIfEmpty = 1000;
67

78

89
/**
@@ -133,10 +134,18 @@ var traces = {}; // Container for "traces" .. lines
133134
var presets = {};
134135
var plots = {}; // Index that keeps a link tracekey => plot
135136

136-
function getDateString(timestamp) {
137+
function getDate(timestamp) {
137138
return new Date(timestamp);
138139
}
139140

141+
142+
function getDateString(timestamp) {
143+
var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
144+
var localISOTime = (new Date(timestamp - tzoffset)).toISOString().slice(0, -1);
145+
return localISOTime.substring(0, 10) + ' ' + localISOTime.substring(11);
146+
}
147+
148+
140149
/**
141150
* Initialize a Trace
142151
*/
@@ -324,7 +333,7 @@ function updatePlot(events) {
324333
if (! isHF) { // Standard event
325334
if (traces[traceKey].gaps) {
326335
if ((event.time - traces[traceKey].last) > traces[traceKey].gaps * 1000) {
327-
traces[traceKey].trace.x.push(getDateString(traces[traceKey].last + 1));
336+
traces[traceKey].trace.x.push(getDate(traces[traceKey].last + 1));
328337
traces[traceKey].trace.y.push(null);
329338
}
330339
}
@@ -345,6 +354,7 @@ function updatePlot(events) {
345354
console.log("pulling serie on", traces[traceKey].activeHF.id);
346355
fetchSerie(traces[traceKey].activeHF, traces[traceKey].last, function (err, res) {
347356

357+
var nextPullIn = pullSerieFrequencyMsIfEmpty;
348358

349359
if (res.points && res.points.length > 0) {
350360
var l = res.points.length;
@@ -357,13 +367,13 @@ function updatePlot(events) {
357367
}
358368

359369

360-
361-
console.log("received" + res.points.length);
370+
nextPullIn = pullSerieFrequencyMs;
371+
console.log('received' + res.points.length);
362372

363373
}
364374

365375
initOrRedraw(traceKey);
366-
setTimeout(traces[traceKey].pull, pullSerieFrequencyMs);
376+
setTimeout(traces[traceKey].pull, nextPullIn);
367377
});
368378

369379

@@ -399,8 +409,8 @@ function addValueToTrace(traceKey, time, timeLT, value) {
399409
lastX = timeLT;
400410
}
401411

402-
console.log(time - traces[traceKey].last, value, getDateString(timeLT));
403-
traces[traceKey].trace.x.push(getDateString(timeLT));
412+
//console.log(time - traces[traceKey].last, value, getDateString(timeLT));
413+
traces[traceKey].trace.x.push(getDate(timeLT));
404414
traces[traceKey].trace.y.push(value);
405415
traces[traceKey].last = time;
406416

0 commit comments

Comments
 (0)