Commit 03452084e45f51e656a5cba778fc291e94f9756b

Authored by Goutte
1 parent 4bbc0e4a

Make time series' resizing more fluid.

Showing 2 changed files with 49 additions and 56 deletions   Show diff stats
web/static/js/main.js
@@ -361,12 +361,12 @@ @@ -361,12 +361,12 @@
361 } 361 }
362 362
363 createTimeSeries(target, data) { 363 createTimeSeries(target, data) {
364 - const this$ = this; 364 + const app = this;
365 this.configuration['parameters'].forEach(parameter => { 365 this.configuration['parameters'].forEach(parameter => {
366 let container; 366 let container;
367 let id; 367 let id;
368 let title; 368 let title;
369 - container = this$.configuration['time_series_container']; 369 + container = app.configuration['time_series_container'];
370 id = parameter['id']; 370 id = parameter['id'];
371 title = parameter['title']; 371 title = parameter['title'];
372 if (!(id in data)) { 372 if (!(id in data)) {
@@ -374,33 +374,36 @@ @@ -374,33 +374,36 @@
374 } 374 }
375 console.log(target['name'], id, data[id]); 375 console.log(target['name'], id, data[id]);
376 if (data[id].length) { 376 if (data[id].length) {
377 - return this$.time_series.push(new TimeSeries(id, title, target, data[id], this$.parameters[id].active, container, {  
378 - 'started_at': this$.started_at,  
379 - 'stopped_at': this$.stopped_at 377 + return app.time_series.push(new TimeSeries(id, title, target, data[id], app.parameters[id].active, container, {
  378 + 'started_at': app.started_at,
  379 + 'stopped_at': app.stopped_at
380 })); 380 }));
381 } 381 }
382 }); 382 });
383 - this.time_series.forEach(ts => { 383 + this.time_series.forEach((ts, tsk) => {
384 ts.options['onMouseOver'] = () => true; 384 ts.options['onMouseOver'] = () => true;
385 ts.options['onMouseOut'] = () => { 385 ts.options['onMouseOut'] = () => {
386 - this$.time_series.forEach(ts2 => ts2.hideCursor()); 386 + app.time_series.forEach(ts2 => ts2.hideCursor());
387 return true; 387 return true;
388 }; 388 };
389 ts.options['onMouseMove'] = t => { 389 ts.options['onMouseMove'] = t => {
390 let ref$; 390 let ref$;
391 - this$.time_series.forEach(ts2 => ts2.moveCursor(t));  
392 - if ((ref$ = this$.orbits) != null) { 391 + app.time_series.forEach(ts2 => ts2.moveCursor(t));
  392 + if ((ref$ = app.orbits) != null) {
393 ref$.moveToDate(t); 393 ref$.moveToDate(t);
394 } 394 }
395 return true; 395 return true;
396 }; 396 };
397 - ts.options['onBrushEnd'] = (sta, sto) => {  
398 - this$.resizeDomain(moment(sta), moment(sto)); 397 +
  398 + ts.options['onBrushEnd'] = ((sta, sto) => {
  399 + //console.debug('Why is this true? bind() WTF', this === app);
  400 + app.resizeDomain(moment(sta), moment(sto), ts);
399 return true; 401 return true;
400 - }; 402 + }).bind(ts);
  403 +
401 return ts.options['onDblClick'] = () => { 404 return ts.options['onDblClick'] = () => {
402 let ref$; 405 let ref$;
403 - this$.resetZoom(); 406 + app.resetZoom();
404 if ((ref$ = $("#zoom_controls_help")) != null) { 407 if ((ref$ = $("#zoom_controls_help")) != null) {
405 ref$.remove(); 408 ref$.remove();
406 } 409 }
@@ -474,14 +477,11 @@ @@ -474,14 +477,11 @@
474 return [this.started_at, this.stopped_at]; 477 return [this.started_at, this.stopped_at];
475 } 478 }
476 479
477 - resizeDomain(started_at, stopped_at) { 480 + resizeDomain(started_at, stopped_at, starting_ts) {
478 let ref$; 481 let ref$;
479 let max_stopped_at; 482 let max_stopped_at;
480 let formatted_started_at; 483 let formatted_started_at;
481 let formatted_stopped_at; 484 let formatted_stopped_at;
482 - let tsv;  
483 - let tsv_cursor;  
484 - let tsv_length;  
485 let zoomedOnVisible; 485 let zoomedOnVisible;
486 if (stopped_at < started_at) { 486 if (stopped_at < started_at) {
487 ref$ = [stopped_at, started_at], started_at = ref$[0], stopped_at = ref$[1]; 487 ref$ = [stopped_at, started_at], started_at = ref$[0], stopped_at = ref$[1];
@@ -501,8 +501,10 @@ @@ -501,8 +501,10 @@
501 if ((this.started_at <= started_at && started_at <= this.stopped_at) && 501 if ((this.started_at <= started_at && started_at <= this.stopped_at) &&
502 (this.started_at <= stopped_at && stopped_at <= this.stopped_at)) { 502 (this.started_at <= stopped_at && stopped_at <= this.stopped_at)) {
503 console.info(`Resizing the temporal domain from ${formatted_started_at} to ${formatted_stopped_at} without fetching new dataโ€ฆ`); 503 console.info(`Resizing the temporal domain from ${formatted_started_at} to ${formatted_stopped_at} without fetching new dataโ€ฆ`);
504 - tsv = this.time_series.filter(ts => ts.visible);  
505 - tsv_length = tsv.length; 504 + let tsv = this.time_series.filter(ts => ts.visible);
  505 + let tsv_length = tsv.length;
  506 + let starting_ts_key = tsv.indexOf(starting_ts);
  507 + if (starting_ts_key === -1) starting_ts_key = 0;
506 zoomedOnVisible = new Promise((resolve, reject) => { 508 zoomedOnVisible = new Promise((resolve, reject) => {
507 let tsv_zoom_on_next; 509 let tsv_zoom_on_next;
508 tsv_zoom_on_next = i => { 510 tsv_zoom_on_next = i => {
@@ -511,7 +513,7 @@ @@ -511,7 +513,7 @@
511 resolve(); 513 resolve();
512 return; 514 return;
513 } 515 }
514 - ts = tsv[i]; 516 + ts = tsv[(i+starting_ts_key)%tsv_length];
515 ts.zoomIn(started_at, stopped_at) 517 ts.zoomIn(started_at, stopped_at)
516 .then(() => tsv_zoom_on_next(i + 1)); 518 .then(() => tsv_zoom_on_next(i + 1));
517 }; 519 };
@@ -535,10 +537,7 @@ @@ -535,10 +537,7 @@
535 } 537 }
536 538
537 resetZoom() { 539 resetZoom() {
538 - this.time_series.forEach(ts => ts.resetZoom());  
539 - this.orbits.resetZoom();  
540 - this.setStartAndStop(this.started_at, this.stopped_at);  
541 - 540 + this.resizeDomain(this.started_at, this.stopped_at);
542 return this; 541 return this;
543 } 542 }
544 543
@@ -805,13 +804,13 @@ @@ -805,13 +804,13 @@
805 } 804 }
806 805
807 onBrushEnd() { 806 onBrushEnd() {
808 - let s;  
809 - let minmax;  
810 - s = d3.event.selection; 807 + let s = d3.event.selection;
811 if (s) { 808 if (s) {
812 - minmax = [s[0], s[1]].map(this.xScale.invert, this.xScale); 809 + let minmax = [s[0], s[1]].map(this.xScale.invert, this.xScale);
813 this.brush.call(this.brushFunction.move, null); 810 this.brush.call(this.brushFunction.move, null);
814 if (this.options.onBrushEnd != null) { 811 if (this.options.onBrushEnd != null) {
  812 + // same, the 'this' is still the old one
  813 + // return this.options.onBrushEnd.apply(this, [minmax[0], minmax[1]]);
815 return this.options.onBrushEnd(minmax[0], minmax[1]); 814 return this.options.onBrushEnd(minmax[0], minmax[1]);
816 } else { 815 } else {
817 return this.zoomIn(minmax[0], minmax[1]); 816 return this.zoomIn(minmax[0], minmax[1]);
@@ -843,12 +842,6 @@ @@ -843,12 +842,6 @@
843 return this.applyZoom(); 842 return this.applyZoom();
844 } 843 }
845 844
846 - resetZoom() {  
847 - this.xScale.domain(this.xDataExtent);  
848 - this.yScale.domain(this.yDataExtent);  
849 - return this.applyZoom();  
850 - }  
851 -  
852 applyZoom() { 845 applyZoom() {
853 let duration; 846 let duration;
854 let t; 847 let t;
@@ -1304,25 +1297,25 @@ @@ -1304,25 +1297,25 @@
1304 } 1297 }
1305 } 1298 }
1306 1299
1307 - resetZoom() {  
1308 - let slug;  
1309 - let ref$;  
1310 - let config;  
1311 - let el;  
1312 - const results$ = [];  
1313 - for (slug in ref$ = this.orbiters) {  
1314 - config = ref$[slug];  
1315 - el = this.orbitersElements[slug];  
1316 - if (!this.data[slug].length) {  
1317 - this.hideOrbiter(slug);  
1318 - continue;  
1319 - }  
1320 - el['orbit_section'].datum(this.data[slug]);  
1321 - el['orbit_section'].attr('d', el['orbit_line']);  
1322 - results$.push(this.showOrbiter(slug));  
1323 - }  
1324 - return results$;  
1325 - } 1300 + // resetZoom() {
  1301 + // let slug;
  1302 + // let ref$;
  1303 + // let config;
  1304 + // let el;
  1305 + // const results$ = [];
  1306 + // for (slug in ref$ = this.orbiters) {
  1307 + // config = ref$[slug];
  1308 + // el = this.orbitersElements[slug];
  1309 + // if (!this.data[slug].length) {
  1310 + // this.hideOrbiter(slug);
  1311 + // continue;
  1312 + // }
  1313 + // el['orbit_section'].datum(this.data[slug]);
  1314 + // el['orbit_section'].attr('d', el['orbit_line']);
  1315 + // results$.push(this.showOrbiter(slug));
  1316 + // }
  1317 + // return results$;
  1318 + // }
1326 } 1319 }
1327 1320
1328 Orbits.prototype.bisectDate = d3.bisector(d => d.t).left; 1321 Orbits.prototype.bisectDate = d3.bisector(d => d.t).left;
web/view/home.html.jinja2
@@ -803,9 +803,9 @@ jQuery().ready(function($){ @@ -803,9 +803,9 @@ jQuery().ready(function($){
803 }); 803 });
804 }; 804 };
805 805
806 - // Update the document about the presence of any SAMP hub every 10 sec. 806 + // Update the document about the presence of any SAMP hub every 7 sec.
807 var connector = new samp.Connector("Sender"); 807 var connector = new samp.Connector("Sender");
808 - connector.onHubAvailability(onHubAvailability, 5000); 808 + connector.onHubAvailability(onHubAvailability, 7000);
809 window.onunload = function () { 809 window.onunload = function () {
810 connector.unregister(); 810 connector.unregister();
811 }; 811 };
@@ -817,7 +817,7 @@ jQuery().ready(function($){ @@ -817,7 +817,7 @@ jQuery().ready(function($){
817 // pitfall : connector.connection is ALWAYS undefined here 817 // pitfall : connector.connection is ALWAYS undefined here
818 if ( ! isConnected) { // so we use a bool flag instead 818 if ( ! isConnected) { // so we use a bool flag instead
819 alert("We do not detect any connected SAMP hub.\n" + 819 alert("We do not detect any connected SAMP hub.\n" +
820 - "Wait some more, or try refreshing this page?"); 820 + "Wait some more, or try refreshing this page?");
821 return; 821 return;
822 } 822 }
823 var name = sw.buildSampName(); 823 var name = sw.buildSampName();