Blame view

web/view/home.html.jinja2 12.9 KB
9390ec89   Goutte   Initial experimen...
1
2
3
4
{% extends 'layout.html.jinja2' %}
{% set menu_section = 'home' %}
{% block title %}Home{% endblock %}

4900d232   Goutte   Add the time inte...
5
6
7
{# This is the main template file, along with the layout. #}
{# The engine is Jinja2, close to Twig (yet not as good) #}

9390ec89   Goutte   Initial experimen...
8
9
{% block content %}

4cf497e0   Goutte   Make the targets ...
10
11
12
13
14
{% macro target_button(target) -%}
    <img width="64px" height="64px"
         src="{{ static('img/target/'~target.slug~'_128.png') }}"
         title="{{ target.title }}"
         alt="{{ target.name }}"
93ee5563   Goutte   Add a loading ani...
15
         class="target {{ target.slug }} {{ 'locked' if target.locked else 'active' }}"
4cf497e0   Goutte   Make the targets ...
16
17
18
19
         data-target-slug="{{ target.slug }}"
    >
{%- endmacro %}

23110c4a   Goutte   Add icons to the ...
20
{% macro icon(name) %}<i class="fa fa-{{ name }}" aria-hidden="true"></i>{% endmacro %}
9c0c4509   Goutte   Add a loader to t...
21
22
23
24
25
26
27
28
29
30

<div id="plots_loader">
  <p class="loader-text">Loading Heliopropa&hellip;<br>This might take a while.</p>
  <div id="plots_loader_img1" class="img"></div>
  <div id="plots_loader_img2" class="img"></div>
  <div id="plots_loader_img3" class="img"></div>
  <div id="plots_loader_img4" class="img"></div>
  <div id="plots_loader_img5" class="img"></div>
</div>

f6ed8d85   Goutte   Rework layout as ...
31
32
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer">

f6ed8d85   Goutte   Rework layout as ...
33
  <div class="mdl-layout__drawer">
23110c4a   Goutte   Add icons to the ...
34
    <span class="mdl-layout-title" title="Two years maximum.">{{ icon('calendar') }} Time Interval</span>
1754789b   Goutte   Decorate and clea...
35
36
37
38
39
    <form id="form_time_interval" action="#">
      <div class="mdl-textfield mdl-js-textfield">
      <input type="date" id="started_at" name="started_at" title="The date of the beginning of the interval to observe." class="mdl-textfield__input">
      <input type="date" id="stopped_at" name="stopped_at" title="The date of the end of the interval to observe. (exclusive)" class="mdl-textfield__input">
      </div>
23110c4a   Goutte   Add icons to the ...
40
      <input type="submit" id="apply_new_interval" value="Load new interval" title="Two years maximum. This may take a while." class="mdl-button mdl-js-button mdl-js-ripple-effect">
1754789b   Goutte   Decorate and clea...
41
42
43
44
    </form>

    <br>
    <hr class="clear">
4900d232   Goutte   Add the time inte...
45

23110c4a   Goutte   Add icons to the ...
46
    <span class="mdl-layout-title">{{ icon('eercast') }} Planets</span>
f6ed8d85   Goutte   Rework layout as ...
47

4900d232   Goutte   Add the time inte...
48
    <section class="targets-filters">
4cf497e0   Goutte   Make the targets ...
49
50
{% for target in planets %}
      {{ target_button(target) }}
a79c5268   Goutte   Add probes and co...
51
{% endfor %}
c42fea3a   Goutte   Rework the CSS wi...
52
    </section>
a79c5268   Goutte   Add probes and co...
53
54
55
56

    <br>
    <hr class="clear">

23110c4a   Goutte   Add icons to the ...
57
    <span class="mdl-layout-title">{{ icon('rocket') }} Probes &amp; Comets</span>
a79c5268   Goutte   Add probes and co...
58

4900d232   Goutte   Add the time inte...
59
    <section class="targets-filters">
4cf497e0   Goutte   Make the targets ...
60
61
{% for target in probes %}
      {{ target_button(target) }}
a79c5268   Goutte   Add probes and co...
62
{% endfor %}
4cf497e0   Goutte   Make the targets ...
63
64
{% for target in comets %}
      {{ target_button(target) }}
a79c5268   Goutte   Add probes and co...
65
66
67
{% endfor %}
    </section>

b550c2b0   Goutte   Rework the home s...
68
    <br>
c42fea3a   Goutte   Rework the CSS wi...
69
    <hr class="clear">
b550c2b0   Goutte   Rework the home s...
70

23110c4a   Goutte   Add icons to the ...
71
    <span class="mdl-layout-title">{{ icon('flask') }} Parameters</span>
b550c2b0   Goutte   Rework the home s...
72
73

    <nav id="parameters" class="mdl-navigation">
8cb213b9   Goutte   Clean up, and pre...
74
      {# todo: generate this from config #}
b7fe650c   Goutte   Misc bundle of ol...
75
76
77
78
79
      <a class="mdl-navigation__link parameter active" data-ts-slug="pdyn" href="#">Dynamic Pressure</a>
      <a class="mdl-navigation__link parameter" data-ts-slug="magn" href="#">B Tangential</a>
      <a class="mdl-navigation__link parameter" data-ts-slug="vlen" href="#">Velocity</a>
      <a class="mdl-navigation__link parameter" data-ts-slug="temp" href="#">Temperature</a>
      <a class="mdl-navigation__link parameter" data-ts-slug="dens" href="#">Density</a>
08569a6b   Goutte   Add a zooming bru...
80
      <a class="mdl-navigation__link parameter" data-ts-slug="angl" href="#">Angle Target-Sun-Earth</a>
b550c2b0   Goutte   Rework the home s...
81
82
    </nav>

a4a9ef03   Goutte   Cache generated C...
83
84
    <div class="mdl-layout-spacer"></div>

c42fea3a   Goutte   Rework the CSS wi...
85
  </div>
b7fe650c   Goutte   Misc bundle of ol...
86
  <main id="plots_wrapper" class="mdl-layout__content">
9390ec89   Goutte   Initial experimen...
87

b550c2b0   Goutte   Rework the home s...
88
89
90
    <div class="mdl-grid">
      <div class="mdl-cell mdl-cell--4-col">
        <section id="orbits"></section>
6b149919   Goutte   Add a Download bu...
91
92
93
94
        <button id="download" class="mdl-button mdl-button--raised mdl-button--primary"
                title="Download the CSV raw data for each target in a tarball.">
          Download
        </button>
b550c2b0   Goutte   Rework the home s...
95
96
      </div>
      <div class="mdl-cell mdl-cell--8-col">
9c0c4509   Goutte   Add a loader to t...
97
98
99
        <section id="time_series">
          <p id="zoom_controls_help" class="help mdl-cell--8-col">Drag to zoom in, double click to zoom out.</p>
        </section>
b550c2b0   Goutte   Rework the home s...
100
101
102
      </div>
    </div>

f6ed8d85   Goutte   Rework layout as ...
103
104
  </main>
</div>
9390ec89   Goutte   Initial experimen...
105
106
107
{% endblock %}


7d6dee0f   Goutte   Continue refacto ...
108

9390ec89   Goutte   Initial experimen...
109
110
{% block styles %}
  <style>
c42fea3a   Goutte   Rework the CSS wi...
111
    html, body {
f6ed8d85   Goutte   Rework layout as ...
112
113
{#      background-color: #322e3f;#}
{#      color: #e3e3e3;#}
c42fea3a   Goutte   Rework the CSS wi...
114
    }
23110c4a   Goutte   Add icons to the ...
115
116
117
118
119
    .mdl-layout__drawer > .mdl-layout-title {
      padding-left: 30px;
    }


9c0c4509   Goutte   Add a loader to t...
120
121
122
123
    #plots_wrapper {
{#      position: relative;#}
    }
    #plots_loader {
6b149919   Goutte   Add a Download bu...
124
      position: fixed;
9c0c4509   Goutte   Add a loader to t...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
      top: 0; left: 0; bottom: 0; right: 0;
      height: 100%;
      width: 100%;
      background-color: #fff;
      z-index: 1000;
    }

    #plots_loader .loader-text {
      width: 200px;
      height: 30px;
      position: absolute;
      top: -240px; left: -32px; bottom: 0; right: 0;
      margin: auto;
      text-align: center;
      font-size: 1.0em;
      font-style: italic;
      color: darkgrey;
    }

    #plots_loader .img {
      width: 100px;
      height: 100px;
      border-radius: 100%;
      position: absolute;
      border: 1px solid #6978ff;
      animation: up 1s;
      animation-iteration-count: infinite;
      transition: 2s;
      border-bottom: none;
      border-right: none;
      animation-timing-function: linear;
      margin-left: -70px;
      margin-top: -70px;
      left: 50%;
      top: 50%;
    }

    @keyframes up {
      from {
        transform: rotate(0deg);
      }
      50% {
        transform: rotate(180deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }

    #plots_loader #plots_loader_img2 {
      width: 90px;
      height: 90px;
      left: 50.35%;
      top: 50.7%;
      animation-delay: .2s;
    }

    #plots_loader #plots_loader_img3 {
      width: 80px;
      height: 80px;
      left: 50.70%;
      top: 51.4%;
      animation-delay: .4s;
    }

    #plots_loader #plots_loader_img4 {
      width: 70px;
      height: 70px;
      left: 51.05%;
      top: 52.1%;
      animation-delay: .6s;
    }

    #plots_loader #plots_loader_img5 {
      width: 60px;
      height: 60px;
      left: 51.40%;
      top: 52.8%;
      animation-delay: .8s;
    }

6b149919   Goutte   Add a Download bu...
206
207
208
209
210
    #download {
      display: block;
      margin: 3em auto;
    }

9c0c4509   Goutte   Add a loader to t...
211
212
213
214
215
216
217
218
219
220
221
    #time_series .help {
      position: absolute;
      text-align: center;
      font-size: 0.9em;
      font-style: italic;
      color: darkgrey;
      display: none;
    }
    #time_series:hover .help {
      display: block;
    }
18f38374   Goutte   Crisp edges for a...
222
223
    .axis path, .axis line {
      fill: none;
f6ed8d85   Goutte   Rework layout as ...
224
{#      stroke: #f4f4f4;#}
18f38374   Goutte   Crisp edges for a...
225
226
227
      shape-rendering: crispEdges;
      stroke-width: 1px;
    }
c42fea3a   Goutte   Rework the CSS wi...
228
    svg text {
f6ed8d85   Goutte   Rework layout as ...
229
{#      fill: #f4f4f4;#}
c42fea3a   Goutte   Rework the CSS wi...
230
    }
08569a6b   Goutte   Add a zooming bru...
231
232
233
    #time_series svg .brush .selection {
      fill: #efa02c;
      fill-opacity: 0.382;
908b4423   Goutte   Bump to a newer j...
234
    }
9390ec89   Goutte   Initial experimen...
235
236
237
238
239
    path.line {
      fill: none;
      stroke: steelblue;
      stroke-width: 1px;
    }
81c9b2e8   Goutte   Add the values to...
240
    circle.cursor-circle {
b550c2b0   Goutte   Rework the home s...
241
242
243
244
245
246
247
248
      fill: black;
      stroke: rgba(20, 20, 20, 0.48);
    }
    text.cursor-text {
{#      font-family: 'Ubuntu', 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva', 'Verdana', sans-serif;#}
{#      font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;#}
      font-family: "Ubuntu Mono", 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;
      text-align: right;
81c9b2e8   Goutte   Add the values to...
249
250
251
    }
    text.cursor-text-shadow {
      stroke: white;
b550c2b0   Goutte   Rework the home s...
252
253
      stroke-width: 5px;
      opacity: 0.777
81c9b2e8   Goutte   Add the values to...
254
    }
c42fea3a   Goutte   Rework the CSS wi...
255
    path.orbit.orbit_section {
2d2af24b   Goutte   Add a basic orbit...
256
257
      fill: none;
      stroke: steelblue;
c42fea3a   Goutte   Rework the CSS wi...
258
259
260
261
262
263
264
265
      stroke-width: 3px;
    }
    ellipse.orbit.orbit_ellipse {
      fill: none;
      stroke: #a3a3a3;
      stroke-width: 1px;
      stroke-dasharray: 5px;
    }
1754789b   Goutte   Decorate and clea...
266
267
268
269
270
271
272
273
274
    #form_time_interval {
      padding-left: 30px;
    }
    #form_time_interval .mdl-textfield {
      padding-top: 0;
    }
    #started_at, #stopped_at {
      width: 85%;
    }
4900d232   Goutte   Add the time inte...
275
    .targets-filters {
a79c5268   Goutte   Add probes and co...
276
277
      padding-left: 17px;
    }
4900d232   Goutte   Add the time inte...
278
    .targets-filters .target {
c42fea3a   Goutte   Rework the CSS wi...
279
      float: left;
4cf497e0   Goutte   Make the targets ...
280
      cursor: pointer;
c42fea3a   Goutte   Rework the CSS wi...
281
    }
4900d232   Goutte   Add the time inte...
282
    .targets-filters .target:not(.active) {
c42fea3a   Goutte   Rework the CSS wi...
283
284
285
286
287
288
      -webkit-filter: grayscale(100%);
         -moz-filter: grayscale(100%);
           -o-filter: grayscale(100%);
          -ms-filter: grayscale(100%);
              filter: grayscale(100%);
    }
4900d232   Goutte   Add the time inte...
289
    .targets-filters .target.locked {
4cf497e0   Goutte   Make the targets ...
290
291
      cursor: not-allowed;
    }
4900d232   Goutte   Add the time inte...
292
    .targets-filters .target.loading {
93ee5563   Goutte   Add a loading ani...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
        -webkit-animation-name: spin;
        -webkit-animation-duration: 4000ms;
        -webkit-animation-iteration-count: infinite;
        -webkit-animation-timing-function: linear;
        -moz-animation-name: spin;
        -moz-animation-duration: 4000ms;
        -moz-animation-iteration-count: infinite;
        -moz-animation-timing-function: linear;
        -ms-animation-name: spin;
        -ms-animation-duration: 4000ms;
        -ms-animation-iteration-count: infinite;
        -ms-animation-timing-function: linear;
        animation-name: spin;
        animation-duration: 4000ms;
        animation-iteration-count: infinite;
        animation-timing-function: linear;
    }
c42fea3a   Goutte   Rework the CSS wi...
310

23110c4a   Goutte   Add icons to the ...
311
{#    #orbits {#}
f6ed8d85   Goutte   Rework layout as ...
312
313
314
{#      background-image: url('{{ static('img/orbitals_background.png') }}');#}
{#      background-repeat: repeat;#}
{#      background-size: 42%;#}
23110c4a   Goutte   Add icons to the ...
315
{#    }#}
6f9a3852   Goutte   Hide time series ...
316
317
318
319
320
321
322

    #parameters .parameter {
      outline: 0;
    }
    #parameters .parameter.active {
      background-color: #c8d3e1;
    }
4cf497e0   Goutte   Make the targets ...
323
324
325
  #time_series svg {
    cursor: crosshair;
  }
9390ec89   Goutte   Initial experimen...
326
327
328
329
  </style>
{% endblock %}


7d6dee0f   Goutte   Continue refacto ...
330

9390ec89   Goutte   Initial experimen...
331
{% block scripts_footer %}
f7a10f28   Goutte   Make our custom m...
332
<script type="application/javascript" src="{{ static('js/vendor/d3-custom.js') }}"></script>
a4a9ef03   Goutte   Cache generated C...
333
<script type="application/javascript" src="{{ static('js/vendor/moment.min.js') }}"></script>
438929a4   Goutte   Rewrite the orbit...
334
<script type="application/javascript" src="{{ static('js/swapp.js') }}"></script>
9390ec89   Goutte   Initial experimen...
335
336
<script type="application/javascript">

ae0aa7d2   Goutte   Add an x axis lab...
337
338
339
var configuration = {
  time_series_container: '#time_series',
  orbits_container: '#orbits',
f75faf5f   Goutte   WIP
340
  api : {
6b149919   Goutte   Add a Download bu...
341
342
      'data_for_interval': "{{ request.url_root }}<target>_<started_at>_<stopped_at>.csv",
      'download': "{{ request.url_root }}<targets>_<started_at>_<stopped_at>.tar.gz"
f75faf5f   Goutte   WIP
343
  },
8bd715ad   Goutte   Use a pixel art i...
344
345
346
  sun: {
    img: '{{ static('img/sun_128.png') }}'
  },
b60e7acd   Goutte   Rename "source" i...
347
  targets : {
d9453685   Goutte   Clean up.
348
{% for target in targets if not target.locked %}
a21f81d9   Goutte   Enable Venus and ...
349
350
351
352
    {% if not loop.first %},{% endif %}
    '{{ target.slug }}': {
      slug: '{{ target.slug }}',
      name: '{{ target.name }}',
ae0aa7d2   Goutte   Add an x axis lab...
353
      active: true,
a21f81d9   Goutte   Enable Venus and ...
354
355
      orbit: { a: {{ target.orbit.semimajor }}, b: {{ target.orbit.semiminor }} },
      img: '{{ static('img/target/'~target.slug~'_128.png') }}'
ae0aa7d2   Goutte   Add an x axis lab...
356
    }
a21f81d9   Goutte   Enable Venus and ...
357
{% endfor %}
aba70d3a   Goutte   Refactor time ser...
358
  },
8cb213b9   Goutte   Clean up, and pre...
359
360
{# todo @Nicolas Define -somehow- error margins of each parameter ? #}
{# todo: generate this from config #}
aba70d3a   Goutte   Refactor time ser...
361
362
363
  parameters : [
    {
      id: 'pdyn',
4cf497e0   Goutte   Make the targets ...
364
      title: "Dyn. Pressure (nPa)",
b7fe650c   Goutte   Misc bundle of ol...
365
      active: true,
f75faf5f   Goutte   WIP
366
      unit: "nPa"
aba70d3a   Goutte   Refactor time ser...
367
368
369
    },
    {
      id: 'magn',
f75faf5f   Goutte   WIP
370
      title: "Magnetism (nT)",
b7fe650c   Goutte   Misc bundle of ol...
371
      active: false,
f75faf5f   Goutte   WIP
372
      unit: "nT"
aba70d3a   Goutte   Refactor time ser...
373
374
375
    },
    {
      id: 'vlen',
f75faf5f   Goutte   WIP
376
      title: "Velocity (km/s)",
b7fe650c   Goutte   Misc bundle of ol...
377
      active: false,
f75faf5f   Goutte   WIP
378
      unit: "km/s"
aba70d3a   Goutte   Refactor time ser...
379
380
381
    },
    {
      id: 'temp',
f75faf5f   Goutte   WIP
382
      title: "Temperature (K)",
b7fe650c   Goutte   Misc bundle of ol...
383
      active: false,
f75faf5f   Goutte   WIP
384
      unit: "K"
aba70d3a   Goutte   Refactor time ser...
385
386
387
    },
    {
      id: 'dens',
f75faf5f   Goutte   WIP
388
      title: "Density N (cm⁻³)",
b7fe650c   Goutte   Misc bundle of ol...
389
      active: false,
f75faf5f   Goutte   WIP
390
      unit: "cm⁻³"
aba70d3a   Goutte   Refactor time ser...
391
392
393
    },
    {
      id: 'angl',
08569a6b   Goutte   Add a zooming bru...
394
      title: "Angle T-S-E (deg)",
b7fe650c   Goutte   Misc bundle of ol...
395
      active: false,
f75faf5f   Goutte   WIP
396
      unit: "deg"
aba70d3a   Goutte   Refactor time ser...
397
398
    }
  ]
438929a4   Goutte   Rewrite the orbit...
399
};
9390ec89   Goutte   Initial experimen...
400

06a3a1f1   Goutte   Continue bug hunt...
401
var sw;
9390ec89   Goutte   Initial experimen...
402
jQuery().ready(function($){
a975b380   Goutte   Clean up.
403
  // Space Weather app itself, handling data downloads and plot draws.
06a3a1f1   Goutte   Continue bug hunt...
404
  sw = new SpaceWeather(configuration);
fe3132dd   Goutte   Refactor even more.
405
  sw.init();
ae0aa7d2   Goutte   Add an x axis lab...
406

a975b380   Goutte   Clean up.
407
408
409
410
411
412
413
414
  // User Interface (except plots' interactivity, such as mouse hovers)
  var parameters = $('#parameters');
  var isLastParameterEnabled = function(parameter_id) {
    var s = 0;
    parameters.find('.parameter[data-ts-slug]').each(function(i,p) {
      if ($(p).hasClass('active')) s++;
    });
    return s < 2;
6f9a3852   Goutte   Hide time series ...
415
  };
4cf497e0   Goutte   Make the targets ...
416
417
  var isLastTargetEnabled = function(target_slug) {
    var s = 0;
4900d232   Goutte   Add the time inte...
418
    $(".targets-filters .target:not(.locked)").each(function(i,p) {
9c0c4509   Goutte   Add a loader to t...
419
      if ($(p).hasClass('active') && ! $(p).hasClass('loading')) s++;
4cf497e0   Goutte   Make the targets ...
420
421
422
    });
    return s < 2;
  };
a975b380   Goutte   Clean up.
423
  parameters.find(".parameter").click(function(e){
b7fe650c   Goutte   Misc bundle of ol...
424
425
426
427
    var switch_on = ! $(this).hasClass('active');
    var parameter_slug = $(this).attr('data-ts-slug');
    if (switch_on) {
      sw.enableParameter(parameter_slug);
a975b380   Goutte   Clean up.
428
429
      $(this).addClass('active');
    } else if ( ! isLastParameterEnabled(parameter_slug)) {
b7fe650c   Goutte   Misc bundle of ol...
430
      sw.disableParameter(parameter_slug);
a975b380   Goutte   Clean up.
431
      $(this).removeClass('active');
b7fe650c   Goutte   Misc bundle of ol...
432
    }
6f9a3852   Goutte   Hide time series ...
433
434
    return false;
  });
4900d232   Goutte   Add the time inte...
435
  $(".targets-filters .target:not(.locked)").on("click", function(e){
9c0c4509   Goutte   Add a loader to t...
436
    if ($(this).hasClass('loading')) return false;
4cf497e0   Goutte   Make the targets ...
437
438
439
    var switch_on = ! $(this).hasClass('active');
    var target_slug = $(this).attr('data-target-slug');
    if (switch_on) {
6bb225d6   Goutte   Link the time ser...
440
      sw.enableTarget(target_slug);
4cf497e0   Goutte   Make the targets ...
441
442
      $(this).addClass('active');
    } else if ( ! isLastTargetEnabled(target_slug)) {
6bb225d6   Goutte   Link the time ser...
443
      sw.disableTarget(target_slug);
4cf497e0   Goutte   Make the targets ...
444
445
446
447
      $(this).removeClass('active');
    }
    return false;
  });
243cd8a4   Goutte   Timestamp party c...
448
449
450
451
452
  $('#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;
6b149919   Goutte   Add a Download bu...
453
454
455
456
457
458
459
  });
  $('#download').on("click", function(e){
    var url = sw.buildDownloadUrl();
    $.ajax({
      type: 'GET',
      url: url,
      processData: false,
5f63c83b   Goutte   Lint.
460
      success: function (data) { window.location = url; },
6b149919   Goutte   Add a Download bu...
461
462
463
464
465
466
467
      error: function (xhr) {
        console.error('Cannot download.', xhr);
        alert("Our apologies, there was an error while downloading.");
      }
    });
    return false;
  });
6f9a3852   Goutte   Hide time series ...
468

9390ec89   Goutte   Initial experimen...
469
470
});
</script>
9390ec89   Goutte   Initial experimen...
471
{% endblock %}