Skip to content

Commit

Permalink
Issue332 html plot (#333)
Browse files Browse the repository at this point in the history
* Use model path for plot title

* Fix error axes issue

Also: specify plotly version, improve tick labels format and add x axis to error plot in case of only 1 group of variables to plot.
  • Loading branch information
AntoineGautier authored Feb 20, 2020
1 parent f224db3 commit a106e44
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions buildingspy/templates/datatable.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
$('#myTable3').on('click', '.myClass', function () {
var tr = $(this).closest('tr');
var row_idx = table3.row(tr).index();
var model = table3.cell(row_idx, 0).data();
var variables = table3.cell(row_idx, 1).data();
var file = table3.cell(row_idx, 3).data();
var dirs = table3.cell(row_idx, 4).data();
Expand Down Expand Up @@ -288,14 +289,13 @@
if (navail_vars.length > 0) { title = title.concat('<br />No available results for: ').concat(navail_vars.join(', ')); }
var new_data = data.replace('$DICT_VAR_INFO', JSON.stringify(dict_var_info));
new_data = new_data.replace('$PAGE_TITLE', title);
new_data = new_data.replace('$TITLE', title);
new_data = new_data.replace('$TITLE', model);
new_data = new_data.replace('$HEIGHT', height + '%');
new_data = new_data.replace('$ERR_PLOT_HEIGHT', err_plot_height);
var strWindowFeatures = "menubar=yes, location=yes, resizable=yes, scrollbars=yes, status=yes";
var win = window.open('', '_blank', strWindowFeatures);
win.document.write(new_data);
win.document.close(); // necessary for the scripts on the page to be executed
// win.document.title = file;
} else { alert(warnings.join('\n')); }
});
});
Expand Down
28 changes: 25 additions & 3 deletions buildingspy/templates/plot.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<title>$PAGE_TITLE</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdn.plot.ly/plotly-1.52.0.min.js"></script>
<script src="https://d3js.org/d3-queue.v3.min.js"></script>
</head>

Expand Down Expand Up @@ -69,6 +69,20 @@
var error_y_axis_title = 'error [unit of variable]';
var gen_y_axis_title = 'variable';
var gen_x_axis_title = 'time [s]';
var tickformatstops = [
{
'dtickrange': [0, 0.1],
'value': '.2e',
},
{
'dtickrange': [0.1, 1000],
'value': '.1f',
},
{
'dtickrange': [1000, null],
'value': '.2e',
},
];
// Dummy traces for legend only.
traces.push(
{
Expand Down Expand Up @@ -126,16 +140,17 @@
layout['yaxis' + axis_error_idx] = {
domain: [1 - err_plot_height, 1],
ticks: 'inside',
tickformatstops: tickformatstops,
showline: true,
zeroline: true,
title: error_y_axis_title,
};
layout['xaxis' + axis_error_idx] = {
showline: false,
zeroline: false,
tickformatstops: tickformatstops,
showticklabels: false,
anchor: 'y' + axis_error_idx,
matches: 'x' + (nb_groups + 1)
};
// ref & test domains
var divHeight = parseFloat(document.getElementById('myDiv').style.height).toFixed(2);
Expand Down Expand Up @@ -200,6 +215,7 @@
showline: true,
zeroline: false,
title: gen_y_axis_title,
tickformatstops: tickformatstops,
};
layout['xaxis' + axis_data_idx] = {
ticks: 'inside',
Expand All @@ -208,13 +224,19 @@
mirror: 'ticks',
zeroline: false,
anchor: 'y' + axis_data_idx,
matches: 'x' + (axis_data_idx - 1)
matches: 'x',
tickformatstops: tickformatstops,
};
});
});
layout['xaxis2']['showticklabels'] = true;
if (nb_groups > 1) {
layout['xaxis2']['side'] = 'top';
} else { // Only onr group: no axis mirroring but add x axis to error plot.
layout['xaxis2']['mirror'] = false;
layout['yaxis2']['mirror'] = false;
layout['xaxis1']['showline'] = true;
layout['xaxis1']['showticklabels'] = true;
}
layout['xaxis' + (nb_groups + 1)]['showticklabels'] = true;
layout['xaxis' + (nb_groups + 1)]['title'] = gen_x_axis_title;
Expand Down

0 comments on commit a106e44

Please sign in to comment.