Skip to content

Commit

Permalink
Add a 'hide-legend' graph option
Browse files Browse the repository at this point in the history
Legends of graphs with many lines can take up too much space,
this simple button will hide the graph legend on demand.
  • Loading branch information
Alphare committed Apr 6, 2019
1 parent 25c6ba2 commit 7338c8b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions asv/www/graphdisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ $(document).ready(function() {
var select_reference = false;
/* The reference value */
var reference = 1.0;
/* Whether to hide the legend */
var hide_legend = false;
/* Is even commit spacing being used? */
var even_spacing = false;
var even_spacing_revisions = [];
Expand Down Expand Up @@ -257,6 +259,12 @@ $(document).ready(function() {
$('#even-spacing').removeClass('active');
update_state_url({'x-axis-scale': date_scale ? ['date'] : []});
});

$('#hide-legend').on('click', function(evt) {
hide_legend = !hide_legend;

update_state_url({'hide-legend': hide_legend ? [true] : []});
});

tooltip = $("<div></div>");
tooltip.appendTo("body");
Expand Down Expand Up @@ -1178,6 +1186,7 @@ $(document).ready(function() {
mode: "x"
},
legend: {
show: !hide_legend,
position: "nw",
labelFormatter: function(label, series) {
// Ensure HTML escaping
Expand Down Expand Up @@ -1384,6 +1393,18 @@ $(document).ready(function() {
}
delete params['x-axis-scale'];
}

var hide_legend_button = $('#hide-legend')
if (params['hide-legend']) {
if (params['hide-legend'][0] === 'true') {
hide_legend_button.addClass('active');
hide_legend = true;
}
delete params['hide-legend'];
}
else {
hide_legend_button.removeClass('active');
}

if (Object.keys(params).length > 0) {
state_selection = params;
Expand Down
5 changes: 5 additions & 0 deletions asv/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@
title="Space commits by commit date along the x-axis">
date scale
</a>
<a id="hide-legend" class="btn btn-default btn-xs" role="button"
data-toggle="tooltip" data-placement="right"
title="Hide legend in the graph">
hide legend
</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 7338c8b

Please sign in to comment.