Commit 85984e428e4ffcdc5be1b18337a8ba7a9e9f8a85
1 parent
81579257
Exists in
master
design: improve the margins and publish the new plot
Showing
2 changed files
with
36 additions
and
15 deletions
Show diff stats
flaskr/static/js/plots/sorted_emissions_inequality.js
1 | 1 | function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
2 | 2 | |
3 | 3 | // set the dimensions and margins of the graph |
4 | - let margin = {top: 30, right: 10, bottom: 62, left: 72}, | |
4 | + let margin = {top: 50, right: 30, bottom: 80, left: 75}, | |
5 | 5 | width = 600 - margin.left - margin.right, |
6 | 6 | height = 700 - margin.top - margin.bottom; |
7 | 7 | |
... | ... | @@ -78,7 +78,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
78 | 78 | |
79 | 79 | } |
80 | 80 | |
81 | - function setupCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip) { | |
81 | + function refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip) { | |
82 | 82 | const x = d3.pointer(event)[0]; |
83 | 83 | const y = d3.pointer(event)[1]; |
84 | 84 | // var y = d3.event.pageY - document.getElementById(<id-of-your-svg>).getBoundingClientRect().y + 10 |
... | ... | @@ -109,19 +109,26 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
109 | 109 | let sliceCollision = getSliceCollision(xInGraph, yInGraph, barSettings); |
110 | 110 | // console.log(sliceCollision); |
111 | 111 | if (sliceCollision) { |
112 | - | |
113 | 112 | if (sliceCollision.isXDriving) { |
114 | 113 | vertical.style("left", x + "px"); |
115 | 114 | horizontal.style("top", yScale(sliceCollision.otherAxisLevel) + margin.top + "px"); |
116 | 115 | |
117 | - tooltip.text(Math.round(xInGraph) + "% of participants emitted " + Math.round(sliceCollision.otherAxisLevel) + "% of CO\u2082eq"); | |
116 | + tooltip.text( | |
117 | + Math.round(xInGraph) + | |
118 | + "% of ๐ attendees emitted " + | |
119 | + Math.round(sliceCollision.otherAxisLevel) + | |
120 | + "% of CO\u2082 equivalent" | |
121 | + ); | |
118 | 122 | } else { |
119 | 123 | horizontal.style("top", y + "px"); |
120 | 124 | vertical.style("left", xScale(sliceCollision.otherAxisLevel) + margin.left + "px"); |
121 | 125 | |
122 | - // noinspection JSSuspiciousNameCombination o.O | |
123 | - tooltip.text(Math.round(100.0 - sliceCollision.otherAxisLevel) + "% of participants emitted " + Math.round(100.0 - yInGraph) + "% of CO\u2082eq"); | |
124 | - // tooltip.text(sliceCollision.otherAxisLevel + " " + yInGraph); | |
126 | + tooltip.text( | |
127 | + Math.round(100.0 - sliceCollision.otherAxisLevel) + | |
128 | + "% of ๐ attendees emitted " + | |
129 | + Math.round(100.0 - yInGraph) + | |
130 | + "% of CO\u2082 equivalent" | |
131 | + ); | |
125 | 132 | } |
126 | 133 | } |
127 | 134 | |
... | ... | @@ -160,7 +167,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
160 | 167 | |
161 | 168 | let tooltip = d3.select(containerSelector) |
162 | 169 | .append("div") |
163 | - .attr("class", "no-pointer-events") | |
170 | + .attr("class", "no-pointer-events plot-tooltip") | |
164 | 171 | .style("display", "none") |
165 | 172 | .style("position", "absolute") |
166 | 173 | .style("z-index", "20") |
... | ... | @@ -175,10 +182,10 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
175 | 182 | |
176 | 183 | d3.select(containerSelector) |
177 | 184 | .on("mousemove", function (event) { |
178 | - setupCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); | |
185 | + refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); | |
179 | 186 | }) |
180 | 187 | .on("mouseover", function (event) { |
181 | - setupCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); | |
188 | + refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); | |
182 | 189 | }); |
183 | 190 | } |
184 | 191 | |
... | ... | @@ -232,7 +239,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
232 | 239 | } |
233 | 240 | return 0; |
234 | 241 | }); |
235 | - console.log(data); | |
242 | + // console.log(data); | |
236 | 243 | let dataIndex = 0; |
237 | 244 | data.forEach((datum, index) => { |
238 | 245 | let trainAttendee = parseInt(datum["train trips_amount"]); |
... | ... | @@ -255,8 +262,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
255 | 262 | //Title |
256 | 263 | svg.append("text") |
257 | 264 | .attr("transform", |
258 | - "translate(" + (70 + margin.left) + ", -12)") | |
259 | - .style("text-anchor", "middle") | |
265 | + "translate(" + (0) + ", -15)") | |
260 | 266 | .style("font-weight", "bold") |
261 | 267 | .style("font-size", "130%") |
262 | 268 | .text("Sorted carbon emissions"); |
... | ... | @@ -291,7 +297,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
291 | 297 | |
292 | 298 | svg.append("text") |
293 | 299 | .attr("transform", "rotate(-90)") |
294 | - .attr("y", 0 - margin.left) | |
300 | + .attr("y", 0 - 4*margin.left/5) | |
295 | 301 | .attr("x", 0 - (height / 2)) |
296 | 302 | .attr("dy", "1em") |
297 | 303 | .style("text-anchor", "middle") | ... | ... |
flaskr/templates/estimation.html
... | ... | @@ -122,6 +122,16 @@ |
122 | 122 | {% endif %} |
123 | 123 | {#############################################################################} |
124 | 124 | |
125 | +{# SORTED EMISSIONS INEQUALITY ##########################################} | |
126 | +{# That plot makes no sense with our many to many data. #} | |
127 | +{% if not estimation.is_many_to_many() %} | |
128 | +<div class="row"> | |
129 | + <div id="sorted_emissions_inequality" class="plot-container"></div> | |
130 | +</div> | |
131 | +<hr> | |
132 | +{% endif %} | |
133 | +{#############################################################################} | |
134 | + | |
125 | 135 | {% endif %}{# not estimation.has_failed() #} |
126 | 136 | |
127 | 137 | |
... | ... | @@ -244,11 +254,12 @@ |
244 | 254 | <script src="/static/js/vendor/d3-geo-projection.v2.min.js"></script> |
245 | 255 | <script src="/static/js/plots/utils.js"></script> |
246 | 256 | <script src="/static/js/plots/emissions-per-distance.js"></script> |
257 | +<script src="/static/js/plots/sorted_emissions_inequality.js"></script> | |
247 | 258 | <script src="/static/js/plots/travel-legs-worldmap.js"></script> |
248 | 259 | |
249 | 260 | <script type="text/javascript"> |
250 | 261 | |
251 | -var plots_config = { | |
262 | +const plots_config = { | |
252 | 263 | 'cities_count': {{ estimation_output.cities | length }} |
253 | 264 | }; |
254 | 265 | |
... | ... | @@ -257,6 +268,10 @@ draw_emissions_per_distance( |
257 | 268 | "#emissions_per_distance_histogram", |
258 | 269 | "/estimation/{{ estimation.public_id }}.csv" |
259 | 270 | ); |
271 | +draw_sorted_emissions_inequality( | |
272 | + "#sorted_emissions_inequality", | |
273 | + "/estimation/{{ estimation.public_id }}.csv" | |
274 | +); | |
260 | 275 | {% endif %} |
261 | 276 | |
262 | 277 | ... | ... |