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 | function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | 1 | function draw_sorted_emissions_inequality(containerSelector, csvUrl) { |
2 | 2 | ||
3 | // set the dimensions and margins of the graph | 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 | width = 600 - margin.left - margin.right, | 5 | width = 600 - margin.left - margin.right, |
6 | height = 700 - margin.top - margin.bottom; | 6 | height = 700 - margin.top - margin.bottom; |
7 | 7 | ||
@@ -78,7 +78,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -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 | const x = d3.pointer(event)[0]; | 82 | const x = d3.pointer(event)[0]; |
83 | const y = d3.pointer(event)[1]; | 83 | const y = d3.pointer(event)[1]; |
84 | // var y = d3.event.pageY - document.getElementById(<id-of-your-svg>).getBoundingClientRect().y + 10 | 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,19 +109,26 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
109 | let sliceCollision = getSliceCollision(xInGraph, yInGraph, barSettings); | 109 | let sliceCollision = getSliceCollision(xInGraph, yInGraph, barSettings); |
110 | // console.log(sliceCollision); | 110 | // console.log(sliceCollision); |
111 | if (sliceCollision) { | 111 | if (sliceCollision) { |
112 | - | ||
113 | if (sliceCollision.isXDriving) { | 112 | if (sliceCollision.isXDriving) { |
114 | vertical.style("left", x + "px"); | 113 | vertical.style("left", x + "px"); |
115 | horizontal.style("top", yScale(sliceCollision.otherAxisLevel) + margin.top + "px"); | 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 | } else { | 122 | } else { |
119 | horizontal.style("top", y + "px"); | 123 | horizontal.style("top", y + "px"); |
120 | vertical.style("left", xScale(sliceCollision.otherAxisLevel) + margin.left + "px"); | 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,7 +167,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
160 | 167 | ||
161 | let tooltip = d3.select(containerSelector) | 168 | let tooltip = d3.select(containerSelector) |
162 | .append("div") | 169 | .append("div") |
163 | - .attr("class", "no-pointer-events") | 170 | + .attr("class", "no-pointer-events plot-tooltip") |
164 | .style("display", "none") | 171 | .style("display", "none") |
165 | .style("position", "absolute") | 172 | .style("position", "absolute") |
166 | .style("z-index", "20") | 173 | .style("z-index", "20") |
@@ -175,10 +182,10 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -175,10 +182,10 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
175 | 182 | ||
176 | d3.select(containerSelector) | 183 | d3.select(containerSelector) |
177 | .on("mousemove", function (event) { | 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 | .on("mouseover", function (event) { | 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,7 +239,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
232 | } | 239 | } |
233 | return 0; | 240 | return 0; |
234 | }); | 241 | }); |
235 | - console.log(data); | 242 | + // console.log(data); |
236 | let dataIndex = 0; | 243 | let dataIndex = 0; |
237 | data.forEach((datum, index) => { | 244 | data.forEach((datum, index) => { |
238 | let trainAttendee = parseInt(datum["train trips_amount"]); | 245 | let trainAttendee = parseInt(datum["train trips_amount"]); |
@@ -255,8 +262,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -255,8 +262,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
255 | //Title | 262 | //Title |
256 | svg.append("text") | 263 | svg.append("text") |
257 | .attr("transform", | 264 | .attr("transform", |
258 | - "translate(" + (70 + margin.left) + ", -12)") | ||
259 | - .style("text-anchor", "middle") | 265 | + "translate(" + (0) + ", -15)") |
260 | .style("font-weight", "bold") | 266 | .style("font-weight", "bold") |
261 | .style("font-size", "130%") | 267 | .style("font-size", "130%") |
262 | .text("Sorted carbon emissions"); | 268 | .text("Sorted carbon emissions"); |
@@ -291,7 +297,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -291,7 +297,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
291 | 297 | ||
292 | svg.append("text") | 298 | svg.append("text") |
293 | .attr("transform", "rotate(-90)") | 299 | .attr("transform", "rotate(-90)") |
294 | - .attr("y", 0 - margin.left) | 300 | + .attr("y", 0 - 4*margin.left/5) |
295 | .attr("x", 0 - (height / 2)) | 301 | .attr("x", 0 - (height / 2)) |
296 | .attr("dy", "1em") | 302 | .attr("dy", "1em") |
297 | .style("text-anchor", "middle") | 303 | .style("text-anchor", "middle") |
flaskr/templates/estimation.html
@@ -122,6 +122,16 @@ | @@ -122,6 +122,16 @@ | ||
122 | {% endif %} | 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 | {% endif %}{# not estimation.has_failed() #} | 135 | {% endif %}{# not estimation.has_failed() #} |
126 | 136 | ||
127 | 137 | ||
@@ -244,11 +254,12 @@ | @@ -244,11 +254,12 @@ | ||
244 | <script src="/static/js/vendor/d3-geo-projection.v2.min.js"></script> | 254 | <script src="/static/js/vendor/d3-geo-projection.v2.min.js"></script> |
245 | <script src="/static/js/plots/utils.js"></script> | 255 | <script src="/static/js/plots/utils.js"></script> |
246 | <script src="/static/js/plots/emissions-per-distance.js"></script> | 256 | <script src="/static/js/plots/emissions-per-distance.js"></script> |
257 | +<script src="/static/js/plots/sorted_emissions_inequality.js"></script> | ||
247 | <script src="/static/js/plots/travel-legs-worldmap.js"></script> | 258 | <script src="/static/js/plots/travel-legs-worldmap.js"></script> |
248 | 259 | ||
249 | <script type="text/javascript"> | 260 | <script type="text/javascript"> |
250 | 261 | ||
251 | -var plots_config = { | 262 | +const plots_config = { |
252 | 'cities_count': {{ estimation_output.cities | length }} | 263 | 'cities_count': {{ estimation_output.cities | length }} |
253 | }; | 264 | }; |
254 | 265 | ||
@@ -257,6 +268,10 @@ draw_emissions_per_distance( | @@ -257,6 +268,10 @@ draw_emissions_per_distance( | ||
257 | "#emissions_per_distance_histogram", | 268 | "#emissions_per_distance_histogram", |
258 | "/estimation/{{ estimation.public_id }}.csv" | 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 | {% endif %} | 275 | {% endif %} |
261 | 276 | ||
262 | 277 |