Skip to content

Commit 61558b4

Browse files
committed
Added show legend checkbox
1 parent 09f3e41 commit 61558b4

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ <h4>Composite metadata</h4>
140140
<input id="tooltip-checkbox" type="checkbox" checked>
141141
<script src="js/events/tooltip_checkbox.js"></script>
142142
</div>
143+
<div>
144+
<label for="show-legend-checkbox">Show legend</label>
145+
<input id="show-legend-checkbox" type="checkbox" checked>
146+
<script src="js/events/show_legend_checkbox.js"></script>
147+
</div>
143148
<div>
144149
<input type="button" id="download-svg-button" value="Download as SVG">
145150
<script src="js/events/download_svg_button.js"></script>

js/events/show_legend_checkbox.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$(function() {
2+
$('#show-legend-checkbox').change(function() {
3+
$("#main-plot").main_plot("toggle_legend", this.checked)
4+
})
5+
})

js/widgets/main_plot.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $(function() {
1919
color_trace: false,
2020
locked: false,
2121
enable_tooltip: true,
22+
show_legend: true,
2223

2324
_elements: {
2425
main_plot: null,
@@ -497,6 +498,11 @@ $(function() {
497498
.style("display", d => d[1])
498499
},
499500

501+
toggle_legend: function(show) {
502+
this.show_legend = show;
503+
this._elements.legend.style("display", show ? null : "none")
504+
},
505+
500506
change_label: function(label, text) {
501507
this[label] = text
502508
},
@@ -709,7 +715,8 @@ $(function() {
709715
export: function() {
710716
return {title: this.title, xlabel: this.xlabel, ylabel: this.ylabel, opacity: this.opacity,
711717
smoothing: this.smoothing, bp_shift: this.bp_shift, xmin: this.xmin, xmax: this.xmax,
712-
ymax: this.ymax, combined: this.combined, locked: this.locked, color_trace: this.color_trace}
718+
ymax: this.ymax, combined: this.combined, locked: this.locked, color_trace: this.color_trace,
719+
show_legend: this.show_legend}
713720
},
714721

715722
import: function(data) {
@@ -752,6 +759,11 @@ $(function() {
752759
if ("color_trace" in data) {
753760
this.toggle_color_trace(data.color_trace);
754761
d3.select("#color-trace-checkbox").property("checked", data.color_trace)
762+
};
763+
764+
if ("show_legend") {
765+
this.toggle_legend(data.show_legend);
766+
d3.select("#show-legend-checkbox").property("checked", data.show_legend)
755767
}
756768
},
757769

0 commit comments

Comments
 (0)