Commit a2a08db21db789a59cb9aa99b84527ab6e303284

Authored by Goutte
1 parent b4abddb7

Make sure targets are hidden from the orbits plots when there is no orbit data f…

…or the observed interval.
config.yml
... ... @@ -89,7 +89,11 @@ inputs:
89 89 #Exomars exomars_cruise_all
90 90 #Rosetta ros_orb_cruise
91 91  
92   -# `slug` is used internally, and should match \[a-z0-9]+\ (NO dashes !)
  92 +# To add a new target, you must :
  93 +# 1. Configure it here
  94 +# 2. Create the two related images in `web/static/img/target/`
  95 +#
  96 +# `slug` is used internally, and should match \[a-z0-9]+\ (NO dashes /!\)
93 97 # `name` is displayed in the time series (should be short)
94 98 # `title` appears on mouse hover, and can be longer
95 99 # `locked` is for sources that are "coming soon"
... ... @@ -303,10 +307,3 @@ targets:
303 307 #Mars tao_mars_sw 1990-01-01T01:00 2017-02-19T00:00
304 308 #Jupiter tao_jup_sw 1990-01-01T01:00 2017-02-19T00:00
305 309 #Saturn tao_sat_sw 1990-01-01T01:30 2017-02-19T00:00
306   -
307   -#models:
308   -# jupiter:
309   -# name: Jupiter
310   -# model: tao_jup_sw
311   -# started_at: "1990-01-01T01:30:00"
312   -# stopped_at: "2017-02-19T00:00:00"
... ...
web/static/js/swapp.js
... ... @@ -141,7 +141,7 @@
141 141 });
142 142 this.targets[target_slug].active = true;
143 143 if ((ref$ = this.orbits) != null) {
144   - ref$.showOrbiter(target_slug);
  144 + ref$.enableTarget(target_slug);
145 145 }
146 146 return this;
147 147 };
... ... @@ -154,7 +154,7 @@
154 154 });
155 155 this.targets[target_slug].active = false;
156 156 if ((ref$ = this.orbits) != null) {
157   - ref$.hideOrbiter(target_slug);
  157 + ref$.disableTarget(target_slug);
158 158 }
159 159 return this;
160 160 };
... ... @@ -267,7 +267,6 @@
267 267 case 'invalid':
268 268 console.error("Failed loading CSV data of " + target.name + ".");
269 269 targetButton.addClass('error');
270   - this$.is_invalid = true;
271 270 break;
272 271 case 'empty':
273 272 msg = "No data for " + target.name + "\n during interval from \n" + started_at + " to " + stopped_at + ".";
... ... @@ -419,9 +418,8 @@
419 418 });
420 419 this.orbits.resizeDomain(started_at, stopped_at);
421 420 } else {
422   - this.is_invalid = false;
423 421 console.info("Resizing the temporal domain from " + formatted_started_at + " to " + formatted_stopped_at + " and fetching new data…");
424   - console.warn("This might take a while… Why not see what else we're up to on http://cdpp.eu while you're waiting?");
  422 + 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?");
425 423 this.clearPlots();
426 424 this.loadAndCreatePlots(started_at, stopped_at);
427 425 }
... ... @@ -761,9 +759,6 @@
761 759 this.options = options != null
762 760 ? options
763 761 : {};
764   - this.init();
765   - }
766   - Orbits.prototype.init = function(){
767 762 console.log("Initializing plot of orbits…");
768 763 this.margin = {
769 764 top: 30,
... ... @@ -799,8 +794,8 @@
799 794 this.sun = this.plotWrapper.append("svg:image").attr('xlink:href', this.options.sun.img).attr('width', '32px').attr('height', '32px');
800 795 this.sun.append('svg:title').text("Sun");
801 796 $(this.svg.node()).hide();
802   - return this.resize();
803   - };
  797 + this.resize();
  798 + }
804 799 Orbits.prototype.initOrbiter = function(slug, config, data){
805 800 var orbit_ellipse, orbiter, orbit_line, orbit_section, this$ = this;
806 801 this.data[slug] = data;
... ... @@ -833,13 +828,28 @@
833 828 return Math.max(Math.abs(d.x), Math.abs(d.y));
834 829 });
835 830 $(this.svg.node()).show();
836   - this.resize(true);
  831 + if (config.active) {
  832 + this.enableTarget(slug);
  833 + } else {
  834 + this.disableTarget(slug);
  835 + }
837 836 return this;
838 837 };
  838 + Orbits.prototype.enableTarget = function(slug){
  839 + this.orbiters[slug].enabled = true;
  840 + return this.showOrbiter(slug);
  841 + };
  842 + Orbits.prototype.disableTarget = function(slug){
  843 + this.orbiters[slug].enabled = false;
  844 + return this.hideOrbiter(slug);
  845 + };
839 846 Orbits.prototype.showOrbiter = function(slug){
840 847 if (!this.data[slug].length) {
841 848 return;
842 849 }
  850 + if (!this.orbiters[slug].enabled) {
  851 + return;
  852 + }
843 853 this.orbiters[slug].hidden = false;
844 854 this.orbitersElements[slug].orbiter.style("display", null);
845 855 this.orbitersElements[slug].orbit_ellipse.style("display", null);
... ... @@ -979,33 +989,39 @@
979 989 return this;
980 990 };
981 991 Orbits.prototype.resizeDomain = function(started_at, stopped_at){
982   - var slug, ref$, config, el, data;
  992 + var slug, ref$, config, el, data, results$ = [];
983 993 for (slug in ref$ = this.orbiters) {
984 994 config = ref$[slug];
985 995 el = this.orbitersElements[slug];
986 996 data = this.data[slug].filter(fn$);
987 997 if (!data.length) {
988   - return;
  998 + this.hideOrbiter(slug);
  999 + continue;
989 1000 }
990 1001 el['orbit_section'].datum(data);
991 1002 el['orbit_section'].attr('d', el['orbit_line']);
  1003 + results$.push(this.showOrbiter(slug));
992 1004 }
  1005 + return results$;
993 1006 function fn$(d){
994 1007 var ref$;
995 1008 return started_at <= (ref$ = d.t) && ref$ <= stopped_at;
996 1009 }
997 1010 };
998 1011 Orbits.prototype.resetZoom = function(){
999   - var slug, ref$, config, el;
  1012 + var slug, ref$, config, el, results$ = [];
1000 1013 for (slug in ref$ = this.orbiters) {
1001 1014 config = ref$[slug];
1002 1015 el = this.orbitersElements[slug];
1003 1016 if (!this.data[slug].length) {
1004   - return;
  1017 + this.hideOrbiter(slug);
  1018 + continue;
1005 1019 }
1006 1020 el['orbit_section'].datum(this.data[slug]);
1007 1021 el['orbit_section'].attr('d', el['orbit_line']);
  1022 + results$.push(this.showOrbiter(slug));
1008 1023 }
  1024 + return results$;
1009 1025 };
1010 1026 return Orbits;
1011 1027 }());
... ...
web/static/js/swapp.ls
... ... @@ -129,13 +129,13 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE
129 129 enableTarget: (target_slug) ->
130 130 @time_series.forEach((ts) ~> ts.show() if ts.target.slug == target_slug && @parameters[ts.parameter].active)
131 131 @targets[target_slug].active = true
132   - @orbits?.showOrbiter target_slug
  132 + @orbits?.enableTarget target_slug
133 133 this
134 134  
135 135 disableTarget: (target_slug) ->
136 136 @time_series.forEach((ts) -> ts.hide() if ts.target.slug == target_slug)
137 137 @targets[target_slug].active = false
138   - @orbits?.hideOrbiter target_slug
  138 + @orbits?.disableTarget target_slug
139 139 this
140 140  
141 141 resize: ->
... ... @@ -223,7 +223,7 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE
223 223 # But when we re-generate it a second time, usually it's okay.
224 224 # alert("There was an error with #{target.name}.\nPlease retry in a few moments.")
225 225 targetButton.addClass('error')
226   - @is_invalid = true
  226 +# @is_invalid = true
227 227 break
228 228 case 'empty'
229 229 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
321 321 @time_series.forEach((ts) -> if ts.visible then ts.zoomIn(started_at, stopped_at))
322 322 @orbits.resizeDomain started_at, stopped_at
323 323 else
324   - @is_invalid = false
  324 +# @is_invalid = false
325 325 console.info "Resizing the temporal domain from #{formatted_started_at} to #{formatted_stopped_at} and fetching new data…"
326   - console.warn "This might take a while… Why not see what else we're up to on http://cdpp.eu while you're waiting?"
327   - # fetch new data and remake the plots
  326 + 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?"
328 327 @clearPlots()
329 328 @loadAndCreatePlots(started_at, stopped_at)
330 329  
... ... @@ -694,9 +693,7 @@ export class Orbits
694 693 """
695 694  
696 695 (@container, @options = {}) ->
697   - @init()
698 696  
699   - init: ->
700 697 console.log "Initializing plot of orbits…"
701 698  
702 699 # In the variable names below, x and y are the usual ones.
... ... @@ -791,12 +788,24 @@ export class Orbits
791 788  
792 789 $(@svg.node()).show();
793 790  
794   - @resize(true)
  791 + if config.active
  792 + @enableTarget slug
  793 + else
  794 + @disableTarget slug
795 795  
796 796 this
797 797  
  798 + enableTarget: (slug) ->
  799 + @orbiters[slug].enabled = true
  800 + @showOrbiter slug
  801 +
  802 + disableTarget: (slug) ->
  803 + @orbiters[slug].enabled = false
  804 + @hideOrbiter slug
  805 +
798 806 showOrbiter: (slug) ->
799 807 if not @data[slug].length then return
  808 + if not @orbiters[slug].enabled then return
800 809 @orbiters[slug].hidden = false
801 810 @orbitersElements[slug].orbiter.style("display", null)
802 811 @orbitersElements[slug].orbit_ellipse.style("display", null)
... ... @@ -930,14 +939,19 @@ export class Orbits
930 939 for slug, config of @orbiters
931 940 el = @orbitersElements[slug]
932 941 data = @data[slug].filter (d) -> started_at <= d.t <= stopped_at
933   - if not data.length then return
  942 + if not data.length
  943 + @hideOrbiter(slug)
  944 + continue
934 945 el['orbit_section'].datum(data)
935 946 el['orbit_section'].attr('d', el['orbit_line'])
  947 + @showOrbiter(slug)
936 948  
937 949 resetZoom: ->
938 950 for slug, config of @orbiters
939 951 el = @orbitersElements[slug]
940   - if not @data[slug].length then return
  952 + if not @data[slug].length
  953 + @hideOrbiter(slug)
  954 + continue
941 955 el['orbit_section'].datum(@data[slug])
942 956 el['orbit_section'].attr('d', el['orbit_line'])
943   -
  957 + @showOrbiter(slug)
... ...