home.html.jinja2
5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
{% extends 'layout.html.jinja2' %}
{% set menu_section = 'home' %}
{% block title %}Home{% endblock %}
{% block content %}
<h2>Overview</h2>
<p>
TODO
</p>
<section id="orbits"></section>
<section id="time_series"></section>
{% endblock %}
{% block styles %}
<style>
.axis path, .axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
stroke-width: 1px;
}
path.line {
fill: none;
stroke: steelblue;
stroke-width: 1px;
}
path.orbit {
fill: none;
stroke: steelblue;
stroke-width: 2px;
}
</style>
{% endblock %}
{% block scripts_footer %}
<script type="application/javascript" src="{{ static('js/d3.min.js') }}"></script>
<script type="application/javascript">
var swApp = (function (window, d3, $) {
var $time_series = $("#time_series");
var $orbits = $("#orbits");
var plotTimeSeries = function(data, options) {
console.log("Init time series with data", data, options);
var xScale, yScale, xAxis, yAxis;
var line;
var svg, plotWrapper, path;
var width, height;
var margin = {
top: 30,
right: 20,
bottom: 30,
left: 60
};
// INIT SCALES
xScale = d3.scaleTime().domain(d3.extent(data, function (d) {
return d.x;
}));
yScale = d3.scaleLinear().domain(d3.extent(data, function (d) {
return d.y;
}));
// INIT AXISES
xAxis = d3.axisBottom()
.ticks(7, ",f")
.tickFormat(d3.timeFormat("%Y-%m-%d"));
yAxis = d3.axisLeft()
.ticks(10);
// INIT LINE
line = d3.line()
.x(function (d) { return xScale(d.x) })
.y(function (d) { return yScale(d.y) });
// INIT SVG
svg = d3.select('#time_series').append('svg');
plotWrapper = svg.append('g');
path = plotWrapper.append('path')
.datum(data)
.classed('line', true);
plotWrapper.append('g')
.classed('x axis', true);
plotWrapper.append('g')
.classed('y axis', true);
width = $time_series.width() - margin.left - margin.right;
height = .618 * width;
xScale.range([0, width]);
yScale.range([height, 0]);
svg.attr('width', width + margin.right + margin.left)
.attr('height', height + margin.top + margin.bottom);
plotWrapper.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
path.attr('d', line);
xAxis.scale(xScale);
yAxis.scale(yScale);
if (width < 600) { xAxis.ticks(3); }
svg.select('.x.axis')
.attr('transform', 'translate(0,' + height + ')')
.call(xAxis);
svg.select('.y.axis')
.call(yAxis);
};
var plotOrbits = function(data, options) {
console.log("Init orbits with data", data, options);
var xScale, yScale, xAxis, yAxis;
var line;
var svg, plotWrapper, path, sun;
var width, height;
var margin = {
top: 30,
right: 20,
bottom: 30,
left: 60
};
// INIT SCALES
var extremum = 1.11 * d3.max(data, function (d) {
return Math.max(Math.abs(d.x), Math.abs(d.y));
});
xScale = d3.scaleLinear().domain([-1 * extremum, extremum]);
yScale = d3.scaleLinear().domain([-1 * extremum, extremum]);
xAxis = d3.axisBottom().ticks(10);
yAxis = d3.axisLeft().ticks(10);
// INIT LINE
line = d3.line()
.x(function (d) { return xScale(d.x) })
.y(function (d) { return yScale(d.y) });
// INIT SVG
svg = d3.select('#orbits').append('svg');
plotWrapper = svg.append('g');
// Sun
sun = plotWrapper.append("svg:circle");
sun.append('svg:title').text("Sol");
// Orbit
path = plotWrapper.append('path')
.datum(data)
.classed('orbit', true);
plotWrapper.append('g').classed('x axis', true);
plotWrapper.append('g').classed('y axis', true);
width = $orbits.width() - margin.left - margin.right;
height = width * 1.0;
xScale.range([0, width]);
yScale.range([height, 0]);
svg.attr('width', width + margin.right + margin.left)
.attr('height', height + margin.top + margin.bottom);
plotWrapper.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
path.attr('d', line);
sun.attr("cx", width / 2).attr("cy", height / 2).attr("r", 17).style("fill", "yellow");
xAxis.scale(xScale);
yAxis.scale(yScale);
//if (width < 600) { xAxis.ticks(3); }
svg.select('.x.axis')
.attr('transform', 'translate(0,' + height + ')')
.call(xAxis);
svg.select('.y.axis')
.call(yAxis);
};
return {
plotTimeSeries: plotTimeSeries,
plotOrbits: plotOrbits
};
})(window, d3, jQuery);
jQuery().ready(function($){
d3.csv("{{ url_for('get_csv') }}", function(csv){
var timeFormat = d3.timeParse('%Y-%m-%dT%H:%M:%S%Z');
var data = {'pdyn': [], 'magn': []};
csv.forEach(function (d) {
data['pdyn'].push({x: timeFormat(d['time']), y: parseFloat(d['pdyn'])});
data['magn'].push({x: timeFormat(d['time']), y: parseFloat(d['magn'])});
});
swApp.plotTimeSeries(data['pdyn'], {});
swApp.plotTimeSeries(data['magn'], {});
});
d3.csv("{{ url_for('get_astral_coordinates_csv') }}", function(csv){
var data = [];
csv.forEach(function (d) {
data.push({x: parseFloat(d['x_hci']), y: parseFloat(d['y_hci'])});
});
swApp.plotOrbits(data, {});
});
});
</script>
{% endblock %}