From 243cd8a4c2a49b4281de7979ef908cd2cd3cff5c Mon Sep 17 00:00:00 2001 From: Goutte Date: Fri, 14 Jul 2017 03:30:35 +0200 Subject: [PATCH] Timestamp party commit 😁 WOOOOOOOOOOO 1500000000 --- web/static/js/swapp.js | 72 +++++++++++++++++++++++++++++++++++++++++++++--------------------------- web/static/js/swapp.ls | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- web/view/home.html.jinja2 | 7 ++++++- 3 files changed, 101 insertions(+), 55 deletions(-) diff --git a/web/static/js/swapp.js b/web/static/js/swapp.js index e369a88..0adf8ae 100644 --- a/web/static/js/swapp.js +++ b/web/static/js/swapp.js @@ -16,8 +16,9 @@ out$.SpaceWeather = SpaceWeather = (function(){ "The main app, instanciated from an inline script.\nIt defaults to an interval starting a year ago, and ending in seven days.\n(both at midnight)"; SpaceWeather.displayName = 'SpaceWeather'; - var API_TIME_FORMAT, timeSeries, prototype = SpaceWeather.prototype, constructor = SpaceWeather; + var API_TIME_FORMAT, INPUT_TIME_FORMAT, prototype = SpaceWeather.prototype, constructor = SpaceWeather; API_TIME_FORMAT = "YYYY-MM-DDTHH:mm:ss"; + INPUT_TIME_FORMAT = "YYYY-MM-DD"; function SpaceWeather(configuration){ var configs, res$, k, this$ = this; this.configuration = configuration; @@ -35,6 +36,7 @@ this.configuration['parameters'].forEach(function(p){ return this$.parameters[p['id']] = p; }); + this.timeSeries = []; } SpaceWeather.prototype.init = function(){ "This is called by the inline bootstrap javascript code.\nThis ain't in the constructor because it might return a Promise later on.\n(for the loader, for example)"; @@ -45,6 +47,7 @@ started_at = this.started_at.format(API_TIME_FORMAT); stopped_at = this.stopped_at.format(API_TIME_FORMAT); console.info("Setting time interval from " + started_at + " to " + stopped_at + "…"); + this.setStartAndStop(this.started_at, this.stopped_at); this.loadAndCreatePlots(started_at, stopped_at); return window.addEventListener('resize', function(){ return this$.resize(); @@ -64,7 +67,7 @@ }; SpaceWeather.prototype.enableTarget = function(target_slug){ var this$ = this; - timeSeries.forEach(function(ts){ + this.timeSeries.forEach(function(ts){ if (ts.target.slug === target_slug && this$.parameters[ts.parameter].active) { return ts.show(); } @@ -73,7 +76,7 @@ return this; }; SpaceWeather.prototype.disableTarget = function(target_slug){ - timeSeries.forEach(function(ts){ + this.timeSeries.forEach(function(ts){ if (ts.target.slug === target_slug) { return ts.hide(); } @@ -86,7 +89,7 @@ if ((ref$ = this.orbits) != null) { ref$.resize(); } - return timeSeries.forEach(function(ts){ + return this.timeSeries.forEach(function(ts){ return ts.resize(); }); }; @@ -136,8 +139,11 @@ }); }; SpaceWeather.prototype.loadAndCreatePlots = function(started_at, stopped_at){ + "started_at: moment(.js) object\nstopped_at: moment(.js) object"; var active_targets, res$, k, this$ = this; this.showLoader(); + started_at = started_at.format(API_TIME_FORMAT); + stopped_at = stopped_at.format(API_TIME_FORMAT); res$ = []; for (k in this.targets) { if (this.targets[k].active) { @@ -162,16 +168,14 @@ }); }; SpaceWeather.prototype.clearPlots = function(){ - var timeSeries; this.orbits.clear(); - timeSeries.forEach(function(ts){ + this.timeSeries.forEach(function(ts){ return ts.clear(); }); this.orbits = null; - timeSeries = []; + this.timeSeries = []; return this; }; - timeSeries = []; SpaceWeather.prototype.createTimeSeries = function(target, data){ var this$ = this; this.configuration['parameters'].forEach(function(parameter){ @@ -182,24 +186,24 @@ if (!(id in data)) { console.error("No data for id '" + id + "'.", data); } - return timeSeries.push(new TimeSeries(id, title, target, data[id], this$.parameters[id].active, container)); + return this$.timeSeries.push(new TimeSeries(id, title, target, data[id], this$.parameters[id].active, container)); }); - return timeSeries.forEach(function(ts){ + this.timeSeries.forEach(function(ts){ ts.options['onMouseOver'] = function(){ - timeSeries.forEach(function(ts2){ + this$.timeSeries.forEach(function(ts2){ return ts2.showCursor(); }); return true; }; ts.options['onMouseOut'] = function(){ - timeSeries.forEach(function(ts2){ + this$.timeSeries.forEach(function(ts2){ return ts2.hideCursor(); }); return true; }; ts.options['onMouseMove'] = function(t){ var ref$; - timeSeries.forEach(function(ts2){ + this$.timeSeries.forEach(function(ts2){ return ts2.moveCursor(t); }); if ((ref$ = this$.orbits) != null) { @@ -208,7 +212,7 @@ return true; }; ts.options['onBrushEnd'] = function(sta, sto){ - this$.resizeDomain(sta, sto); + this$.resizeDomain(moment(sta), moment(sto)); return true; }; return ts.options['onDblClick'] = function(){ @@ -220,6 +224,7 @@ return true; }; }); + return this.timeSeries; }; SpaceWeather.prototype.enableParameter = function(parameter_slug){ var this$ = this; @@ -227,7 +232,7 @@ console.error("Unknown parameter " + parameter_slug + "."); } this.parameters[parameter_slug].active = true; - timeSeries.forEach(function(ts){ + this.timeSeries.forEach(function(ts){ if (ts.parameter === parameter_slug && this$.targets[ts.target.slug].active) { return ts.show(); } @@ -239,7 +244,7 @@ console.error("Unknown parameter " + parameter_slug + "."); } this.parameters[parameter_slug].active = false; - timeSeries.forEach(function(ts){ + this.timeSeries.forEach(function(ts){ if (ts.parameter === parameter_slug) { return ts.hide(); } @@ -253,7 +258,7 @@ return [this.started_at, this.stopped_at]; }; SpaceWeather.prototype.resizeDomain = function(started_at, stopped_at){ - var tmp; + var tmp, formatted_started_at, formatted_stopped_at; if (stopped_at < started_at) { tmp = started_at; started_at = stopped_at; @@ -263,31 +268,44 @@ console.warn("Please provide distinct start and stop dates."); return; } - this.current_started_at = started_at; - this.current_stopped_at = stopped_at; + this.setStartAndStop(started_at, stopped_at); + formatted_started_at = started_at.format(); + formatted_stopped_at = stopped_at.format(); if ((this.started_at <= started_at && started_at <= this.stopped_at) && (this.started_at <= stopped_at && stopped_at <= this.stopped_at)) { - console.info("Resizing the temporal domain from " + started_at + " to " + stopped_at + " without fetching new data…"); - timeSeries.forEach(function(ts){ + console.info("Resizing the temporal domain from " + formatted_started_at + " to " + formatted_stopped_at + " without fetching new data…"); + this.timeSeries.forEach(function(ts){ if (!ts.visible) { return ts.zoomIn(started_at, stopped_at); } }); - timeSeries.forEach(function(ts){ + this.timeSeries.forEach(function(ts){ if (ts.visible) { return ts.zoomIn(started_at, stopped_at); } }); this.orbits.resizeDomain(started_at, stopped_at); - return; + } else { + console.info("Resizing the temporal domain from " + formatted_started_at + " to " + formatted_stopped_at + " and fetching new data…"); + console.warn("This might take a while… Why not see what else we're up to on http://cdpp.eu while you're waiting?"); + this.clearPlots(); + this.loadAndCreatePlots(started_at, stopped_at); } - this.clearPlots(); - return this.loadAndCreatePlots(started_at, stopped_at); + return this; }; SpaceWeather.prototype.resetZoom = function(){ - timeSeries.forEach(function(ts){ + this.timeSeries.forEach(function(ts){ return ts.resetZoom(); }); - return this.orbits.resetZoom(); + this.orbits.resetZoom(); + this.setStartAndStop(this.started_at, this.stopped_at); + return this; + }; + SpaceWeather.prototype.setStartAndStop = function(started_at, stopped_at){ + this.current_started_at = started_at; + this.current_stopped_at = stopped_at; + $("#started_at").val(started_at.format(INPUT_TIME_FORMAT)); + $("#stopped_at").val(stopped_at.format(INPUT_TIME_FORMAT)); + return this; }; return SpaceWeather; }()); diff --git a/web/static/js/swapp.ls b/web/static/js/swapp.ls index fed6da5..80b6c42 100644 --- a/web/static/js/swapp.ls +++ b/web/static/js/swapp.ls @@ -36,6 +36,7 @@ export class SpaceWeather """ API_TIME_FORMAT = "YYYY-MM-DDTHH:mm:ss" + INPUT_TIME_FORMAT = "YYYY-MM-DD" (@configuration) -> console.info """ @@ -62,6 +63,7 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE @configuration['parameters'].forEach((p) ~> @parameters[p['id']] = p ) + @timeSeries = [] init: -> """ @@ -77,7 +79,9 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE started_at = @started_at.format(API_TIME_FORMAT) stopped_at = @stopped_at.format(API_TIME_FORMAT) console.info "Setting time interval from #{started_at} to #{stopped_at}…" + @setStartAndStop(@started_at, @stopped_at) @loadAndCreatePlots(started_at, stopped_at) + window.addEventListener 'resize', ~> @resize() buildDataUrlForTarget: (target_slug, started_at, stopped_at) -> @@ -97,18 +101,18 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE # this enableTarget: (target_slug) -> - timeSeries.forEach((ts) ~> ts.show() if ts.target.slug == target_slug && @parameters[ts.parameter].active) + @timeSeries.forEach((ts) ~> ts.show() if ts.target.slug == target_slug && @parameters[ts.parameter].active) @targets[target_slug].active = true this disableTarget: (target_slug) -> - timeSeries.forEach((ts) -> ts.hide() if ts.target.slug == target_slug) + @timeSeries.forEach((ts) -> ts.hide() if ts.target.slug == target_slug) @targets[target_slug].active = false this resize: -> @orbits?.resize(); - timeSeries.forEach((ts) -> ts.resize()) + @timeSeries.forEach((ts) -> ts.resize()) showLoader: -> $("\#plots_loader").show(); @@ -121,6 +125,7 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE Load the data as CSV for the specified target and interval, and return it in a Promise. """ + sw = this new Promise((resolve, reject) -> url = sw.buildDataUrlForTarget(target_slug, started_at, stopped_at) @@ -144,7 +149,13 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE ) loadAndCreatePlots: (started_at, stopped_at) -> + """ + started_at: moment(.js) object + stopped_at: moment(.js) object + """ @showLoader() + started_at = started_at.format(API_TIME_FORMAT) + stopped_at = stopped_at.format(API_TIME_FORMAT) active_targets = [@targets[k] for k of @targets when @targets[k].active] active_targets.forEach((target) ~> console.info "Loading CSV data of #{target.name}…" @@ -164,45 +175,45 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE clearPlots: -> @orbits.clear() - timeSeries.forEach((ts) -> ts.clear()) + @timeSeries.forEach((ts) -> ts.clear()) @orbits = null - timeSeries = [] # do we de-reference all existing TimeSeries ? #memleak? + @timeSeries = [] # do we de-reference everything ? listeners ? #memleak? this - timeSeries = [] # deprecated (was for scoping) ; use @property with ~> createTimeSeries: (target, data) -> @configuration['parameters'].forEach((parameter) ~> container = @configuration['time_series_container'] id = parameter['id'] ; title = parameter['title'] if id not of data then console.error("No data for id '#{id}'.", data) - timeSeries.push(new TimeSeries( + @timeSeries.push(new TimeSeries( id, title, target, data[id], @parameters[id].active, container )) ) - timeSeries.forEach((ts) ~> # returning true may be faster - ts.options['onMouseOver'] = -> - timeSeries.forEach((ts2) -> ts2.showCursor()) ; true - ts.options['onMouseOut'] = -> - timeSeries.forEach((ts2) -> ts2.hideCursor()) ; true + @timeSeries.forEach((ts) ~> # returning true may be faster + ts.options['onMouseOver'] = ~> + @timeSeries.forEach((ts2) -> ts2.showCursor()) ; true + ts.options['onMouseOut'] = ~> + @timeSeries.forEach((ts2) -> ts2.hideCursor()) ; true ts.options['onMouseMove'] = (t) ~> - timeSeries.forEach((ts2) -> ts2.moveCursor(t)) + @timeSeries.forEach((ts2) -> ts2.moveCursor(t)) @orbits?.moveToDate(t) ; true ts.options['onBrushEnd'] = (sta, sto) ~> - @resizeDomain(sta, sto) ; true + @resizeDomain(moment(sta), moment(sto)) ; true ts.options['onDblClick'] = ~> @resetZoom() ; $("\#zoom_controls_help")?.remove() ; true ) + @timeSeries enableParameter: (parameter_slug) -> if parameter_slug not of @parameters then console.error("Unknown parameter #{parameter_slug}.") @parameters[parameter_slug].active = true - timeSeries.forEach((ts) ~> ts.show() if ts.parameter == parameter_slug && @targets[ts.target.slug].active) + @timeSeries.forEach((ts) ~> ts.show() if ts.parameter == parameter_slug && @targets[ts.target.slug].active) this disableParameter: (parameter_slug) -> if parameter_slug not of @parameters then console.error("Unknown parameter #{parameter_slug}.") @parameters[parameter_slug].active = false - timeSeries.forEach((ts) -> ts.hide() if ts.parameter == parameter_slug) + @timeSeries.forEach((ts) -> ts.hide() if ts.parameter == parameter_slug) this getDomain: -> @@ -220,27 +231,39 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE console.warn "Please provide distinct start and stop dates." return - @current_started_at = started_at - @current_stopped_at = stopped_at + @setStartAndStop(started_at, stopped_at) + formatted_started_at = started_at.format() + formatted_stopped_at = stopped_at.format() if (@started_at <= started_at <= @stopped_at) and (@started_at <= stopped_at <= @stopped_at) then - console.info "Resizing the temporal domain from #{started_at} to #{stopped_at} without fetching new data…" + console.info "Resizing the temporal domain from #{formatted_started_at} to #{formatted_stopped_at} without fetching new data…" # We first resize the hidden time series and only afterwards we resize # the visible ones, for a smoother transition. - timeSeries.forEach((ts) -> if not ts.visible then ts.zoomIn(started_at, stopped_at)) - timeSeries.forEach((ts) -> if ts.visible then ts.zoomIn(started_at, stopped_at)) + @timeSeries.forEach((ts) -> if not ts.visible then ts.zoomIn(started_at, stopped_at)) + @timeSeries.forEach((ts) -> if ts.visible then ts.zoomIn(started_at, stopped_at)) @orbits.resizeDomain started_at, stopped_at - return - - # fetch new data and remake the plots - @clearPlots() - @loadAndCreatePlots(started_at, stopped_at) + else + console.info "Resizing the temporal domain from #{formatted_started_at} to #{formatted_stopped_at} and fetching new data…" + console.warn "This might take a while… Why not see what else we're up to on http://cdpp.eu while you're waiting?" + # fetch new data and remake the plots + @clearPlots() + @loadAndCreatePlots(started_at, stopped_at) + this resetZoom: -> - timeSeries.forEach((ts) -> ts.resetZoom()) + @timeSeries.forEach((ts) -> ts.resetZoom()) @orbits.resetZoom() + @setStartAndStop(@started_at, @stopped_at) + this + + setStartAndStop: (started_at, stopped_at) -> + @current_started_at = started_at + @current_stopped_at = stopped_at + $("\#started_at").val(started_at.format(INPUT_TIME_FORMAT)) + $("\#stopped_at").val(stopped_at.format(INPUT_TIME_FORMAT)) + this diff --git a/web/view/home.html.jinja2 b/web/view/home.html.jinja2 index 490ba88..0095429 100755 --- a/web/view/home.html.jinja2 +++ b/web/view/home.html.jinja2 @@ -425,7 +425,12 @@ jQuery().ready(function($){ } return false; }); - + $('#apply_new_interval').on("click", function(e){ + var started_at = moment($("#started_at").val()); + var stopped_at = moment($("#stopped_at").val()); + sw.resizeDomain(started_at, stopped_at); + return false; + }) }); -- libgit2 0.21.2