From a2a08db21db789a59cb9aa99b84527ab6e303284 Mon Sep 17 00:00:00 2001 From: Goutte Date: Sun, 17 Dec 2017 08:24:13 +0100 Subject: [PATCH] Make sure targets are hidden from the orbits plots when there is no orbit data for the observed interval. --- config.yml | 13 +++++-------- web/static/js/swapp.js | 46 +++++++++++++++++++++++++++++++--------------- web/static/js/swapp.ls | 38 ++++++++++++++++++++++++++------------ 3 files changed, 62 insertions(+), 35 deletions(-) diff --git a/config.yml b/config.yml index 2718a8e..4c4d4e0 100644 --- a/config.yml +++ b/config.yml @@ -89,7 +89,11 @@ inputs: #Exomars exomars_cruise_all #Rosetta ros_orb_cruise -# `slug` is used internally, and should match \[a-z0-9]+\ (NO dashes !) +# To add a new target, you must : +# 1. Configure it here +# 2. Create the two related images in `web/static/img/target/` +# +# `slug` is used internally, and should match \[a-z0-9]+\ (NO dashes /!\) # `name` is displayed in the time series (should be short) # `title` appears on mouse hover, and can be longer # `locked` is for sources that are "coming soon" @@ -303,10 +307,3 @@ targets: #Mars tao_mars_sw 1990-01-01T01:00 2017-02-19T00:00 #Jupiter tao_jup_sw 1990-01-01T01:00 2017-02-19T00:00 #Saturn tao_sat_sw 1990-01-01T01:30 2017-02-19T00:00 - -#models: -# jupiter: -# name: Jupiter -# model: tao_jup_sw -# started_at: "1990-01-01T01:30:00" -# stopped_at: "2017-02-19T00:00:00" diff --git a/web/static/js/swapp.js b/web/static/js/swapp.js index 5773dae..2ecc0a9 100644 --- a/web/static/js/swapp.js +++ b/web/static/js/swapp.js @@ -141,7 +141,7 @@ }); this.targets[target_slug].active = true; if ((ref$ = this.orbits) != null) { - ref$.showOrbiter(target_slug); + ref$.enableTarget(target_slug); } return this; }; @@ -154,7 +154,7 @@ }); this.targets[target_slug].active = false; if ((ref$ = this.orbits) != null) { - ref$.hideOrbiter(target_slug); + ref$.disableTarget(target_slug); } return this; }; @@ -267,7 +267,6 @@ case 'invalid': console.error("Failed loading CSV data of " + target.name + "."); targetButton.addClass('error'); - this$.is_invalid = true; break; case 'empty': msg = "No data for " + target.name + "\n during interval from \n" + started_at + " to " + stopped_at + "."; @@ -419,9 +418,8 @@ }); this.orbits.resizeDomain(started_at, stopped_at); } else { - this.is_invalid = false; 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?"); + console.warn("This might take a good 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); } @@ -761,9 +759,6 @@ this.options = options != null ? options : {}; - this.init(); - } - Orbits.prototype.init = function(){ console.log("Initializing plot of orbits…"); this.margin = { top: 30, @@ -799,8 +794,8 @@ this.sun = this.plotWrapper.append("svg:image").attr('xlink:href', this.options.sun.img).attr('width', '32px').attr('height', '32px'); this.sun.append('svg:title').text("Sun"); $(this.svg.node()).hide(); - return this.resize(); - }; + this.resize(); + } Orbits.prototype.initOrbiter = function(slug, config, data){ var orbit_ellipse, orbiter, orbit_line, orbit_section, this$ = this; this.data[slug] = data; @@ -833,13 +828,28 @@ return Math.max(Math.abs(d.x), Math.abs(d.y)); }); $(this.svg.node()).show(); - this.resize(true); + if (config.active) { + this.enableTarget(slug); + } else { + this.disableTarget(slug); + } return this; }; + Orbits.prototype.enableTarget = function(slug){ + this.orbiters[slug].enabled = true; + return this.showOrbiter(slug); + }; + Orbits.prototype.disableTarget = function(slug){ + this.orbiters[slug].enabled = false; + return this.hideOrbiter(slug); + }; Orbits.prototype.showOrbiter = function(slug){ if (!this.data[slug].length) { return; } + if (!this.orbiters[slug].enabled) { + return; + } this.orbiters[slug].hidden = false; this.orbitersElements[slug].orbiter.style("display", null); this.orbitersElements[slug].orbit_ellipse.style("display", null); @@ -979,33 +989,39 @@ return this; }; Orbits.prototype.resizeDomain = function(started_at, stopped_at){ - var slug, ref$, config, el, data; + var slug, ref$, config, el, data, results$ = []; for (slug in ref$ = this.orbiters) { config = ref$[slug]; el = this.orbitersElements[slug]; data = this.data[slug].filter(fn$); if (!data.length) { - return; + this.hideOrbiter(slug); + continue; } el['orbit_section'].datum(data); el['orbit_section'].attr('d', el['orbit_line']); + results$.push(this.showOrbiter(slug)); } + return results$; function fn$(d){ var ref$; return started_at <= (ref$ = d.t) && ref$ <= stopped_at; } }; Orbits.prototype.resetZoom = function(){ - var slug, ref$, config, el; + var slug, ref$, config, el, results$ = []; for (slug in ref$ = this.orbiters) { config = ref$[slug]; el = this.orbitersElements[slug]; if (!this.data[slug].length) { - return; + this.hideOrbiter(slug); + continue; } el['orbit_section'].datum(this.data[slug]); el['orbit_section'].attr('d', el['orbit_line']); + results$.push(this.showOrbiter(slug)); } + return results$; }; return Orbits; }()); diff --git a/web/static/js/swapp.ls b/web/static/js/swapp.ls index 121b3db..f0c7071 100644 --- a/web/static/js/swapp.ls +++ b/web/static/js/swapp.ls @@ -129,13 +129,13 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE enableTarget: (target_slug) -> @time_series.forEach((ts) ~> ts.show() if ts.target.slug == target_slug && @parameters[ts.parameter].active) @targets[target_slug].active = true - @orbits?.showOrbiter target_slug + @orbits?.enableTarget target_slug this disableTarget: (target_slug) -> @time_series.forEach((ts) -> ts.hide() if ts.target.slug == target_slug) @targets[target_slug].active = false - @orbits?.hideOrbiter target_slug + @orbits?.disableTarget target_slug this resize: -> @@ -223,7 +223,7 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE # But when we re-generate it a second time, usually it's okay. # alert("There was an error with #{target.name}.\nPlease retry in a few moments.") targetButton.addClass('error') - @is_invalid = true +# @is_invalid = true break case 'empty' msg = "No data for #{target.name}\n during interval from \n#{started_at} to #{stopped_at}." @@ -321,10 +321,9 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE @time_series.forEach((ts) -> if ts.visible then ts.zoomIn(started_at, stopped_at)) @orbits.resizeDomain started_at, stopped_at else - @is_invalid = false +# @is_invalid = false 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 + console.warn "This might take a good while… Why not see what else we're up to on http://cdpp.eu while you're waiting?" @clearPlots() @loadAndCreatePlots(started_at, stopped_at) @@ -694,9 +693,7 @@ export class Orbits """ (@container, @options = {}) -> - @init() - init: -> console.log "Initializing plot of orbits…" # In the variable names below, x and y are the usual ones. @@ -791,12 +788,24 @@ export class Orbits $(@svg.node()).show(); - @resize(true) + if config.active + @enableTarget slug + else + @disableTarget slug this + enableTarget: (slug) -> + @orbiters[slug].enabled = true + @showOrbiter slug + + disableTarget: (slug) -> + @orbiters[slug].enabled = false + @hideOrbiter slug + showOrbiter: (slug) -> if not @data[slug].length then return + if not @orbiters[slug].enabled then return @orbiters[slug].hidden = false @orbitersElements[slug].orbiter.style("display", null) @orbitersElements[slug].orbit_ellipse.style("display", null) @@ -930,14 +939,19 @@ export class Orbits for slug, config of @orbiters el = @orbitersElements[slug] data = @data[slug].filter (d) -> started_at <= d.t <= stopped_at - if not data.length then return + if not data.length + @hideOrbiter(slug) + continue el['orbit_section'].datum(data) el['orbit_section'].attr('d', el['orbit_line']) + @showOrbiter(slug) resetZoom: -> for slug, config of @orbiters el = @orbitersElements[slug] - if not @data[slug].length then return + if not @data[slug].length + @hideOrbiter(slug) + continue el['orbit_section'].datum(@data[slug]) el['orbit_section'].attr('d', el['orbit_line']) - + @showOrbiter(slug) -- libgit2 0.21.2