From 7b5642aef428cd0ec598497637ddbe162dfa5f9c Mon Sep 17 00:00:00 2001 From: Goutte Date: Tue, 26 Sep 2017 15:03:33 +0200 Subject: [PATCH] Normalize time interval for time series. --- CHANGELOG.md | 3 +-- web/static/js/swapp.js | 24 +++++++++++++++--------- web/static/js/swapp.ls | 19 +++++++++++-------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f069a4f..e64088a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,9 @@ - [ ] Set the log level to _error_ in production (see `web/run.py`) - [ ] CRON statements to call the cache cleanup and warmup - [ ] Cache warmup (generate for today's default interval) `/cache/warmup` -- [ ] Normalize time interval for time series - [ ] Give the future data another color - [ ] Sort times series by closeness to the sun - [ ] Generate a CDF file (not NetCDF) -- [ ] Move the link to the source in the footer An heliospheric propagation 1D MHD model for solar wind prediction at planets, probes and comets. @@ -18,6 +16,7 @@ An heliospheric propagation 1D MHD model for solar wind prediction at planets, p ## 1.0.0-rc4 +- [x] Normalize time interval for time series - [x] Make the footer images clickable - [x] Highlight the visits counter - [x] Use a default interval up to 3 weeks in the future diff --git a/web/static/js/swapp.js b/web/static/js/swapp.js index a2c0e61..d79da60 100644 --- a/web/static/js/swapp.js +++ b/web/static/js/swapp.js @@ -299,7 +299,10 @@ if (!(id in data)) { console.error("No data for id '" + id + "'.", data); } - return this$.time_series.push(new TimeSeries(id, title, target, data[id], this$.parameters[id].active, container)); + return this$.time_series.push(new TimeSeries(id, title, target, data[id], this$.parameters[id].active, container, { + 'started_at': this$.started_at, + 'stopped_at': this$.stopped_at + })); }); this.time_series.forEach(function(ts){ ts.options['onMouseOver'] = function(){ @@ -445,6 +448,7 @@ this.parameter = parameter; this.title = title; this.target = target; + this.data = data; this.visible = visible; this.container = container; this.options = options != null @@ -455,24 +459,26 @@ this.onMouseOut = bind$(this, 'onMouseOut', prototype); this.onMouseOver = bind$(this, 'onMouseOver', prototype); this.onMouseMove = bind$(this, 'onMouseMove', prototype); - this.setData(data); this.init(); } TimeSeries.prototype.toString = function(){ return this.title + " of " + this.target.name; }; - TimeSeries.prototype.setData = function(data){ - this.data = data; + TimeSeries.prototype.init = function(){ + var formatMillisecond, formatSecond, formatMinute, formatHour, formatDay, formatWeek, formatMonth, formatYear, multiFormat, clipId, dx, this$ = this; + console.info("Initializing plot of " + this + "…"); this.xDataExtent = d3.extent(this.data, function(d){ return d.x; }); - return this.yDataExtent = d3.extent(this.data, function(d){ + this.yDataExtent = d3.extent(this.data, function(d){ return d.y; }); - }; - TimeSeries.prototype.init = function(){ - var formatMillisecond, formatSecond, formatMinute, formatHour, formatDay, formatWeek, formatMonth, formatYear, multiFormat, clipId, dx, this$ = this; - console.info("Initializing plot of " + this + "…"); + if (this.options['started_at']) { + this.xDataExtent[0] = this.options['started_at']; + } + if (this.options['stopped_at']) { + this.xDataExtent[1] = this.options['stopped_at']; + } this.margin = { top: 30, right: 20, diff --git a/web/static/js/swapp.ls b/web/static/js/swapp.ls index 4c26cd6..2bca06d 100644 --- a/web/static/js/swapp.ls +++ b/web/static/js/swapp.ls @@ -251,7 +251,10 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE id = parameter['id'] ; title = parameter['title'] if id not of data then console.error("No data for id '#{id}'.", data) @time_series.push(new TimeSeries( - id, title, target, data[id], @parameters[id].active, container + id, title, target, data[id], @parameters[id].active, container, { + 'started_at': @started_at, + 'stopped_at': @stopped_at, + } )) ) @time_series.forEach((ts) ~> # returning true may be faster @@ -347,24 +350,24 @@ export class TimeSeries # Time in x-axis # Data in y-axis - (@parameter, @title, @target, data, @visible, @container, @options = {}) -> + (@parameter, @title, @target, @data, @visible, @container, @options = {}) -> # parameter : slug of the parameter to observe, like btan or pdyn # title : string, more descriptive, shown on the left of the Y axis # target : target object, like described in configuration # data : list of {x: , y: } - @setData(data) @init() toString: -> "#{@title} of #{@target.name}" - setData: (data) -> - @data = data # and pre-compute extents for performance when zooming - @xDataExtent = d3.extent(@data, (d) -> d.x) - @yDataExtent = d3.extent(@data, (d) -> d.y) - init: -> console.info "Initializing plot of #{@}…" + # pre-compute extents for performance when zooming + @xDataExtent = d3.extent(@data, (d) -> d.x) + @yDataExtent = d3.extent(@data, (d) -> d.y) + if @options['started_at'] then @xDataExtent[0] = @options['started_at'] + if @options['stopped_at'] then @xDataExtent[1] = @options['stopped_at'] + @margin = { top: 30, right: 20, -- libgit2 0.21.2