Commit b4abddb75e4b70fdd3b1c5c719f8b092ab23c18a

Authored by Goutte
1 parent 391d581c

Fix a small issue with the time series' cursors that has been bugging me for too long.

Showing 2 changed files with 11 additions and 7 deletions   Show diff stats
web/static/js/swapp.js
... ... @@ -313,9 +313,6 @@
313 313 });
314 314 this.time_series.forEach(function(ts){
315 315 ts.options['onMouseOver'] = function(){
316   - this$.time_series.forEach(function(ts2){
317   - return ts2.showCursor();
318   - });
319 316 return true;
320 317 };
321 318 ts.options['onMouseOut'] = function(){
... ... @@ -732,7 +729,8 @@
732 729 i = this.bisectDate(this.data, x0, 1);
733 730 d0 = this.data[i - 1];
734 731 d1 = this.data[i];
735   - if (!(d1 && d0)) {
  732 + if (!d1 || !d0) {
  733 + this.hideCursor();
736 734 return;
737 735 }
738 736 d = x0 - d0.x > d1.x - x0 ? d1 : d0;
... ... @@ -749,6 +747,7 @@
749 747 this.cursorValueShadow.attr("transform", transform).text(d.y).attr('text-anchor', mirrored ? 'end' : 'start').attr("dx", dx);
750 748 this.cursorDate.attr("transform", transform).text(this.timeFormat(d.x)).attr('text-anchor', mirrored ? 'end' : 'start').attr("dx", dx);
751 749 this.cursorDateShadow.attr("transform", transform).text(this.timeFormat(d.x)).attr('text-anchor', mirrored ? 'end' : 'start').attr("dx", dx);
  750 + this.showCursor();
752 751 return this;
753 752 };
754 753 return TimeSeries;
... ...
web/static/js/swapp.ls
... ... @@ -260,9 +260,10 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE
260 260 }
261 261 ))
262 262 )
263   - @time_series.forEach((ts) ~> # returning true may be faster
  263 + # Let's override all time series' input handlers to link them together
  264 + @time_series.forEach((ts) ~> # returning true may be faster, how to bench?
264 265 ts.options['onMouseOver'] = ~>
265   - @time_series.forEach((ts2) -> ts2.showCursor()) ; true
  266 + true # let's do nothing, we'll show the cursor during moveCursor()
266 267 ts.options['onMouseOut'] = ~>
267 268 @time_series.forEach((ts2) -> ts2.hideCursor()) ; true
268 269 ts.options['onMouseMove'] = (t) ~>
... ... @@ -651,7 +652,10 @@ export class TimeSeries
651 652 i = @bisectDate(@data, x0, 1)
652 653 d0 = @data[i - 1]
653 654 d1 = @data[i]
654   - return unless d1 and d0
  655 + if (not d1) or (not d0)
  656 + @hideCursor()
  657 + return
  658 +
655 659 d = if x0 - d0.x > d1.x - x0 then d1 else d0
656 660 xx = @xScale(d.x)
657 661 yy = @yScale(d.y)
... ... @@ -675,6 +679,7 @@ export class TimeSeries
675 679 @cursorDateShadow.attr("transform", transform).text(@timeFormat(d.x))
676 680 .attr('text-anchor', if mirrored then 'end' else 'start')
677 681 .attr("dx", dx)
  682 + @showCursor()
678 683  
679 684 this
680 685  
... ...