Commit 03452084e45f51e656a5cba778fc291e94f9756b
1 parent
4bbc0e4a
Exists in
master
and in
2 other branches
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 | 361 | } |
362 | 362 | |
363 | 363 | createTimeSeries(target, data) { |
364 | - const this$ = this; | |
364 | + const app = this; | |
365 | 365 | this.configuration['parameters'].forEach(parameter => { |
366 | 366 | let container; |
367 | 367 | let id; |
368 | 368 | let title; |
369 | - container = this$.configuration['time_series_container']; | |
369 | + container = app.configuration['time_series_container']; | |
370 | 370 | id = parameter['id']; |
371 | 371 | title = parameter['title']; |
372 | 372 | if (!(id in data)) { |
... | ... | @@ -374,33 +374,36 @@ |
374 | 374 | } |
375 | 375 | console.log(target['name'], id, data[id]); |
376 | 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 | 384 | ts.options['onMouseOver'] = () => true; |
385 | 385 | ts.options['onMouseOut'] = () => { |
386 | - this$.time_series.forEach(ts2 => ts2.hideCursor()); | |
386 | + app.time_series.forEach(ts2 => ts2.hideCursor()); | |
387 | 387 | return true; |
388 | 388 | }; |
389 | 389 | ts.options['onMouseMove'] = t => { |
390 | 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 | 393 | ref$.moveToDate(t); |
394 | 394 | } |
395 | 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 | 401 | return true; |
400 | - }; | |
402 | + }).bind(ts); | |
403 | + | |
401 | 404 | return ts.options['onDblClick'] = () => { |
402 | 405 | let ref$; |
403 | - this$.resetZoom(); | |
406 | + app.resetZoom(); | |
404 | 407 | if ((ref$ = $("#zoom_controls_help")) != null) { |
405 | 408 | ref$.remove(); |
406 | 409 | } |
... | ... | @@ -474,14 +477,11 @@ |
474 | 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 | 481 | let ref$; |
479 | 482 | let max_stopped_at; |
480 | 483 | let formatted_started_at; |
481 | 484 | let formatted_stopped_at; |
482 | - let tsv; | |
483 | - let tsv_cursor; | |
484 | - let tsv_length; | |
485 | 485 | let zoomedOnVisible; |
486 | 486 | if (stopped_at < started_at) { |
487 | 487 | ref$ = [stopped_at, started_at], started_at = ref$[0], stopped_at = ref$[1]; |
... | ... | @@ -501,8 +501,10 @@ |
501 | 501 | if ((this.started_at <= started_at && started_at <= this.stopped_at) && |
502 | 502 | (this.started_at <= stopped_at && stopped_at <= this.stopped_at)) { |
503 | 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 | 508 | zoomedOnVisible = new Promise((resolve, reject) => { |
507 | 509 | let tsv_zoom_on_next; |
508 | 510 | tsv_zoom_on_next = i => { |
... | ... | @@ -511,7 +513,7 @@ |
511 | 513 | resolve(); |
512 | 514 | return; |
513 | 515 | } |
514 | - ts = tsv[i]; | |
516 | + ts = tsv[(i+starting_ts_key)%tsv_length]; | |
515 | 517 | ts.zoomIn(started_at, stopped_at) |
516 | 518 | .then(() => tsv_zoom_on_next(i + 1)); |
517 | 519 | }; |
... | ... | @@ -535,10 +537,7 @@ |
535 | 537 | } |
536 | 538 | |
537 | 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 | 541 | return this; |
543 | 542 | } |
544 | 543 | |
... | ... | @@ -805,13 +804,13 @@ |
805 | 804 | } |
806 | 805 | |
807 | 806 | onBrushEnd() { |
808 | - let s; | |
809 | - let minmax; | |
810 | - s = d3.event.selection; | |
807 | + let s = d3.event.selection; | |
811 | 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 | 810 | this.brush.call(this.brushFunction.move, null); |
814 | 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 | 814 | return this.options.onBrushEnd(minmax[0], minmax[1]); |
816 | 815 | } else { |
817 | 816 | return this.zoomIn(minmax[0], minmax[1]); |
... | ... | @@ -843,12 +842,6 @@ |
843 | 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 | 845 | applyZoom() { |
853 | 846 | let duration; |
854 | 847 | let t; |
... | ... | @@ -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 | 1321 | Orbits.prototype.bisectDate = d3.bisector(d => d.t).left; | ... | ... |
web/view/home.html.jinja2
... | ... | @@ -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 | 807 | var connector = new samp.Connector("Sender"); |
808 | - connector.onHubAvailability(onHubAvailability, 5000); | |
808 | + connector.onHubAvailability(onHubAvailability, 7000); | |
809 | 809 | window.onunload = function () { |
810 | 810 | connector.unregister(); |
811 | 811 | }; |
... | ... | @@ -817,7 +817,7 @@ jQuery().ready(function($){ |
817 | 817 | // pitfall : connector.connection is ALWAYS undefined here |
818 | 818 | if ( ! isConnected) { // so we use a bool flag instead |
819 | 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 | 821 | return; |
822 | 822 | } |
823 | 823 | var name = sw.buildSampName(); | ... | ... |