Skip to content

Commit b86f174

Browse files
committed
plot co2e and energy in one plot with two axis
1 parent 2df5664 commit b86f174

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

plugins/nf-co2footprint/src/resources/CO2FootprintReportTemplate.html

+2-23
Original file line numberDiff line numberDiff line change
@@ -235,40 +235,19 @@ <h3 class="mt-5">Total CO<sub>2</sub>e footprint measures</h3>
235235
<div class="container">
236236
<h2 id="resources" style="padding-top: 80px;">CO2e Footprint Measures</h2>
237237

238-
<h4>CO2e</h4>
238+
<h4>CO2e - Energy consumption</h4>
239239
<ul class="nav nav-tabs" id="co2eplot_tabs" role="tablist">
240240
<li class="nav-item">
241241
<a class="nav-link active" id="co2eplot_tablink" data-toggle="tab" href="#co2eplot_tabpanel" role="tab" aria-controls="co2eplot_tabpanel" aria-expanded="false">
242-
Raw Emissions
242+
Raw Emissions - Consumption
243243
</a>
244244
</li>
245245
</ul>
246246
<div class="tab-content" id="co2eplot_tabcontent">
247247
<div class="tab-pane fade show active" id="co2eplot_tabpanel" role="tabpanel">
248248
<div id="co2eplot"></div>
249249
</div>
250-
<div class="tab-pane fade" id="pctco2eplot_tabpanel" role="tabpanel">
251-
<div id="pctco2eplot"></div>
252-
</div>
253-
</div>
254-
255-
<h4>Energy consumption</h4>
256-
<ul class="nav nav-tabs" id="energyplot_tabs" role="tablist">
257-
<li class="nav-item">
258-
<a class="nav-link active" id="energyplot_tablink" data-toggle="tab" href="#energyplot_tabpanel" role="tab" aria-controls="energyplot_tabpanel" aria-expanded="false">
259-
Raw Consumption
260-
</a>
261-
</li>
262-
</ul>
263-
<div class="tab-content" id="energyplot_tabcontent">
264-
<div class="tab-pane fade show active" id="energyplot_tabpanel" role="tabpanel">
265-
<div id="energyplot"></div>
266-
</div>
267-
<div class="tab-pane fade" id="pctenergyplot_tabpanel" role="tabpanel">
268-
<div id="pctenergyplot"></div>
269-
</div>
270250
</div>
271-
</div>
272251

273252

274253
<div class="container">

plugins/nf-co2footprint/src/resources/assets/CO2FootprintReportTemplate.js

+32-14
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,56 @@ $(function() {
7272
if( !window.data_byprocess.hasOwnProperty(pname) )
7373
continue;
7474
var smry = window.data_byprocess[pname];
75-
co2e_data.push({y: norm_units(smry.co2e), name: pname, type:'box', boxmean: true, boxpoints: false});
76-
energy_data.push({y: norm_units(smry.energy), name: pname, type:'box', boxmean: true, boxpoints: false});
75+
co2e_data.push({x:pname, y: norm_units(smry.co2e), name: pname, type:'box', boxmean: true, boxpoints: false});
76+
energy_data.push({x:pname, y: norm_units(smry.energy), name: pname, type:'box', boxmean: true, boxpoints: false});
7777
}
7878

7979
// Decide yaxis tickformat
80+
var max_co2e = 0;
8081
co2e_data.forEach(function (p) {
81-
max = 0;
82+
max_co2e = 0;
8283
if (p != null) {
8384
if (Array.isArray(p.y)) {
84-
max = Math.max(max, ...p.y);
85+
max_co2e = Math.max(max_co2e, ...p.y);
8586
} else {
86-
max = Math.max(max, p.y);
87+
max_co2e = Math.max(max_co2e, p.y);
8788
}
88-
8989
}
9090
});
91-
var co2e_tickformat = (max <= 4) ? ('.2f') : ('.3s');
91+
var co2e_tickformat = (max_co2e <= 4) ? ('.2f') : ('.3s');
9292
energy_data.forEach(function (p) {
93-
max = 0;
93+
max_energy = 0;
9494
if (p != null) {
9595
if (Array.isArray(p.y)) {
96-
max = Math.max(max, ...p.y);
96+
max_energy = Math.max(max_energy, ...p.y);
9797
} else {
98-
max = Math.max(max, p.y);
98+
max_energy = Math.max(max_energy, p.y);
9999
}
100100
}
101101
});
102-
var energy_tickformat = (max <= 4) ? ('.2f') : ('.3s');
102+
var energy_tickformat = (max_energy <= 4) ? ('.2f') : ('.3s');
103103

104-
105-
Plotly.newPlot('co2eplot', co2e_data, { title: 'CO2e emission', yaxis: {title: 'CO2e emission (g)', tickformat: co2e_tickformat, rangemode: 'tozero'} });
106-
Plotly.newPlot('energyplot', energy_data, { title: 'Energy consumption', yaxis: {title: 'Energy consumption (Wh)', tickformat: energy_tickformat, rangemode: 'tozero'} });
104+
var layout = {
105+
title: 'CO2e emission & energy consumption',
106+
xaxis: {domain: [0.3, 0.7]},
107+
yaxis: {title: 'CO2e emission (g)',
108+
tickformat: co2e_tickformat,
109+
range: [0, max_co2e + 1]
110+
},
111+
yaxis2: {
112+
title: 'Energy consumption (Wh)',
113+
tickformat: energy_tickformat,
114+
range: [0, max_energy + 1],
115+
overlaying: 'y',
116+
side: 'left',
117+
anchor: 'free',
118+
position: 0.15
119+
}
120+
};
121+
122+
var data = co2e_data;
123+
data.push({yaxis:'y2'});
124+
Plotly.newPlot('co2eplot', data, layout);
107125

108126
// Convert to readable units
109127
function readable_units(value, unit_index) {

0 commit comments

Comments
 (0)