Skip to content

Commit 97fb6b5

Browse files
authored
Merge pull request #28 from CEGRcode/dev
Merge dev branch
2 parents 1786cf5 + e7e72d2 commit 97fb6b5

3 files changed

Lines changed: 37 additions & 3 deletions

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: 27 additions & 3 deletions
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
},
@@ -706,10 +712,18 @@ $(function() {
706712
a.dispatchEvent(e)
707713
},
708714

715+
toggle_svg_button: function() {
716+
let disable = this._elements.main_plot.selectAll("foreignObject").size() > 0;
717+
d3.select("#download-svg-button")
718+
.property("disabled", disable)
719+
.attr("title", disable ? "Cannot download SVG while labels are being edited" : null)
720+
},
721+
709722
export: function() {
710723
return {title: this.title, xlabel: this.xlabel, ylabel: this.ylabel, opacity: this.opacity,
711724
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}
725+
ymax: this.ymax, combined: this.combined, locked: this.locked, color_trace: this.color_trace,
726+
show_legend: this.show_legend}
713727
},
714728

715729
import: function(data) {
@@ -752,6 +766,11 @@ $(function() {
752766
if ("color_trace" in data) {
753767
this.toggle_color_trace(data.color_trace);
754768
d3.select("#color-trace-checkbox").property("checked", data.color_trace)
769+
};
770+
771+
if ("show_legend") {
772+
this.toggle_legend(data.show_legend);
773+
d3.select("#show-legend-checkbox").property("checked", data.show_legend)
755774
}
756775
},
757776

@@ -826,7 +845,10 @@ $(function() {
826845

827846
this.foreign_object.select("input")
828847
.on("keypress", function(e) {$(label_group.node()).editable_svg_text("enter_input", e)})
829-
.node().focus()
848+
.attr("title", "Press enter to submit")
849+
.node().focus();
850+
851+
$("#main-plot").main_plot("toggle_svg_button")
830852
},
831853

832854
enter_input: function(ev) {
@@ -837,7 +859,9 @@ $(function() {
837859
this.change_label(ev.target.value)
838860
} else {
839861
this.text_label.style("display", null)
840-
}
862+
};
863+
864+
$("#main-plot").main_plot("toggle_svg_button")
841865
}
842866
},
843867

0 commit comments

Comments
 (0)