Skip to content

Commit 3cdb6c2

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

File tree

2 files changed

+37
-55
lines changed

2 files changed

+37
-55
lines changed

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

+1-23
Original file line numberDiff line numberDiff line change
@@ -235,40 +235,18 @@ <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>
239238
<ul class="nav nav-tabs" id="co2eplot_tabs" role="tablist">
240239
<li class="nav-item">
241240
<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
241+
Raw values
243242
</a>
244243
</li>
245244
</ul>
246245
<div class="tab-content" id="co2eplot_tabcontent">
247246
<div class="tab-pane fade show active" id="co2eplot_tabpanel" role="tabpanel">
248247
<div id="co2eplot"></div>
249248
</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>
270249
</div>
271-
</div>
272250

273251

274252
<div class="container">

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

+36-32
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,48 @@ $(function() {
6666
}
6767

6868
// Plot histograms of resource usage
69-
var co2e_data = [];
70-
var energy_data = [];
69+
var data = [];
7170
for(var pname in window.data_byprocess){
7271
if( !window.data_byprocess.hasOwnProperty(pname) )
7372
continue;
7473
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});
74+
data.push({x:pname, y: norm_units(smry.co2e), name: pname, legendgroup: pname, type:'box', boxmean: true, boxpoints: false});
75+
data.push({x:pname, y: norm_units(smry.energy), name: pname, legendgroup: pname, yaxis: 'y2', type:'box', boxmean: true, boxpoints: false});
7776
}
78-
79-
// Decide yaxis tickformat
80-
co2e_data.forEach(function (p) {
81-
max = 0;
82-
if (p != null) {
83-
if (Array.isArray(p.y)) {
84-
max = Math.max(max, ...p.y);
85-
} else {
86-
max = Math.max(max, p.y);
87-
}
88-
89-
}
90-
});
91-
var co2e_tickformat = (max <= 4) ? ('.2f') : ('.3s');
92-
energy_data.forEach(function (p) {
93-
max = 0;
94-
if (p != null) {
95-
if (Array.isArray(p.y)) {
96-
max = Math.max(max, ...p.y);
97-
} else {
98-
max = Math.max(max, p.y);
99-
}
100-
}
101-
});
102-
var energy_tickformat = (max <= 4) ? ('.2f') : ('.3s');
10377

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'} });
78+
var layout = {
79+
title: 'CO2 emission & energy consumption',
80+
xaxis: {domain: [0.2, 1]},
81+
yaxis: {title: 'CO2e emission (g)',
82+
rangemode: 'tozero',
83+
tickformatstops: [{
84+
"dtickrange": [null, 4],
85+
"value": ".2f"
86+
},
87+
{
88+
"dtickrange": [4, null],
89+
"value": ".3s"
90+
}]
91+
},
92+
yaxis2: {title: 'Energy consumption (Wh)',
93+
rangemode: 'tozero',
94+
gridcolor: 'rgba(0, 0, 0, 0)', // transparent grid lines
95+
overlaying: 'y',
96+
side: 'left',
97+
anchor: 'free',
98+
position: 0.1,
99+
tickformatstops: [{
100+
"dtickrange": [null, 4],
101+
"value": ".2f"
102+
},
103+
{
104+
"dtickrange": [4, null],
105+
"value": ".3s"
106+
}]
107+
},
108+
};
109+
110+
Plotly.newPlot('co2eplot', data, layout);
107111

108112
// Convert to readable units
109113
function readable_units(value, unit_index) {

0 commit comments

Comments
 (0)