Skip to content

Commit 5d72bba

Browse files
fixed tooltip positioning
appended an svg to body.
1 parent 21217a2 commit 5d72bba

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ <h4>Composite metadata</h4>
111111
</div>
112112
<div class="col-8">
113113
<div class="row" style="display:flex; align-items:center;">
114-
<div style="max-width:calc(100% - 270px);">
114+
<div style="max-width:calc(100% - 270px);" id="main-plot-div">
115115
<svg id="main-plot" baseProfile="full" version="1.1" xmlns="http://www.w3.org/2000/svg" font-family="Helvetica" style="height: 50vh; max-width: 100%; overflow: hide;"></svg>
116116
<script src="js/sliding_window.js"></script>
117117
<script src="js/widgets/main_plot.js"></script>

js/events/plot_tabs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ $(function() {
1111
})
1212
d3.select("#nucleosome-slider-tab").on("click", function() {
1313
showPane("nucleosome-slider-options", this);
14+
$("#main-plot").main_plot("toggle_tooltip", false);
15+
$("#nucleosome-slider").nucleosome_slider("update_all");
1416
})
1517

1618
function showPane(id, tab){

js/widgets/main_plot.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ $(function() {
155155
.attr("transform", "translate(" + (this.width - this.margins.right + 25) + " " + this.margins.top + ")");
156156

157157
// Create tooltip
158-
this._elements.tooltip = main_plot.append("g")
158+
this._elements.tooltip = d3.select("body").append("svg")
159159
.attr("id", "composite-plot-tooltip");
160160

161161
main_plot.append("g")
@@ -171,7 +171,7 @@ $(function() {
171171
$("#main-plot").main_plot("move_tooltip", e)
172172
});
173173
main_plot.on("mouseleave", function() {
174-
$("#main-plot").main_plot("hide_tooltip")
174+
// $("#main-plot").main_plot("hide_tooltip")
175175
});
176176
},
177177

@@ -763,6 +763,7 @@ $(function() {
763763
},
764764

765765
move_tooltip: function(ev) {
766+
let self = this;
766767
if (this.enable_tooltip) {
767768
// Get data for all composites that are plotted and have files loaded
768769
let data = $("#settings-table").settings_table("export").filter(d => d.files_loaded > 0 && !d.hide),
@@ -780,7 +781,11 @@ $(function() {
780781
// Move tooltip to mouse position
781782
this._elements.tooltip
782783
.style("display", null)
783-
.attr("transform", "translate(" + this.xscale(mouse_x_scaled) + " " + mouse_y + ")");
784+
.style("position", "absolute")
785+
.style("top", ev.clientY)
786+
.style("left", ev.clientX)
787+
.style("pointer-events", "none");
788+
// .attr("transform", "translate(" + this.xscale(mouse_x_scaled) + " " + mouse_y + ")");
784789

785790
// Create tooltip border and text
786791
let tooltip_border = this._elements.tooltip.selectAll("path")
@@ -807,9 +812,12 @@ $(function() {
807812
: parseFloat(d.sense[mouse_x_scaled - d.xmin].toPrecision(2)) + "; " + parseFloat(d.anti[mouse_x_scaled - d.xmin].toPrecision(2))));
808813
// Get bounding box of text
809814
let {y, width: w, height: h} = tooltip_text.node().getBBox();
810-
tooltip_text.attr("transform", "translate(" + (-w / 2) + " " + (15 - y) + ")");
815+
tooltip_text.attr("transform", "translate(" + 2 + " " + (15 - y) + ")");
811816
// Update tooltip border
812-
tooltip_border.attr("d", "M" + (-w / 2 - 10) + ",5H-5l5,-5l5,5H" + (w / 2 + 10) + "v" + (h + 20) + "h-" + (w + 20) + "z")
817+
tooltip_border.attr("d", "M" + (w + 4) + " 5 H " + (w + 20) / 2 + " l -5 -5 l-5 5 H 0 V " + (h + 20) + " H " + (w + 4) + " z")
818+
this._elements.tooltip
819+
.style("top", ev.clientY)
820+
.style("left", ev.clientX - ((w + 8) / 2));
813821
} else {
814822
this._elements.tooltip.style("display", "none")
815823
}

js/widgets/reference_axes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ $(function() {
2323

2424
this.main_plot = $("#main-plot").main_plot("instance");
2525

26-
d3.select("body").on("mousemove", function(e) {
26+
d3.select("#main-plot-div").on("mousemove", function(e) {
2727
self.drag_plot_element(e);
2828
});
29-
d3.select("body").on("mouseup", function() {
29+
d3.select("#main-plot-div").on("mouseup", function() {
3030
self.end_dragging();
3131
});
3232

0 commit comments

Comments
 (0)