Skip to content

Commit f22fdcb

Browse files
increased scale of tool tip
and removed unused files
1 parent 5d72bba commit f22fdcb

7 files changed

Lines changed: 58 additions & 72 deletions

File tree

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ <h4>Composite metadata</h4>
207207
<circle r="15" cx="15" cy="15" fill="grey" />
208208
<path d="m 15 2 l 0 26 M 2 15 l 26 0" stroke-width="4" stroke="white" />
209209
</svg>
210+
<div>
211+
<label for="keep-reference-lines" id="keep-reference-lable">Keep reference lines on plot</label>
212+
<input type="checkbox" id="keep-reference-lines" style="margin-top: 15px;">
213+
</div>
210214
<script src="js/widgets/reference_axes.js"></script>
211215
</div>
212216
</div>

js/events/enable_nucleosome_button.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

js/events/import_json_button.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ $(function() {
5151
if (data.preset) {
5252
$("#settings-dropdown").settings_dropdown("set_value", data.preset)
5353
}
54-
$("#enable-nucleosome-button").prop("disabled", false);
5554
};
5655
reader.readAsText(file)
5756
})

js/events/plot_tabs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ $(function() {
66
d3.select("#reference-axes-tab").on("click", function() {
77
showPane("reference-axes-pane", this);
88
$("#main-plot").main_plot("toggle_tooltip", false);
9-
d3.select("#reference-axes-layer").attr("display", "block")
109
$("#reference-axes-pane").reference_axes("plot_lines");
1110
})
1211
d3.select("#nucleosome-slider-tab").on("click", function() {
@@ -40,5 +39,10 @@ $(function() {
4039
.selectAll("*")
4140
.remove();
4241
}
42+
if (d3.select("#keep-reference-lines").property("checked") == false){
43+
d3.select("#reference-axes-layer")
44+
.selectAll("*")
45+
.remove();
46+
}
4347
}
4448
})

js/widgets/main_plot.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ $(function() {
156156

157157
// Create tooltip
158158
this._elements.tooltip = d3.select("body").append("svg")
159+
.style("scale", "1.4")
159160
.attr("id", "composite-plot-tooltip");
160161

161162
main_plot.append("g")
@@ -173,6 +174,8 @@ $(function() {
173174
main_plot.on("mouseleave", function() {
174175
// $("#main-plot").main_plot("hide_tooltip")
175176
});
177+
178+
this.enable_tooltip = true;
176179
},
177180

178181
_destroy: function() {
@@ -816,8 +819,8 @@ $(function() {
816819
// Update tooltip border
817820
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")
818821
this._elements.tooltip
819-
.style("top", ev.clientY)
820-
.style("left", ev.clientX - ((w + 8) / 2));
822+
.style("top", ev.clientY + 0.7 * h)
823+
.style("left", ev.clientX - ((w + 8) / 2) * 0.57)
821824
} else {
822825
this._elements.tooltip.style("display", "none")
823826
}

js/widgets/nucleosome_slider.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ $(function() {
221221
let y = this.plot_points.get(parseInt(x));
222222
d3.select("#coord-svg-layer").append("circle")
223223
.attr("id", "projection-" + i)
224-
.attr("cx", x + "px")
224+
.attr("cx", (x + 1.5) + "px")
225225
.attr("cy", y + "px")
226226
.style("fill", "rgb(255, 252, 97)");
227227
i += 1;
@@ -230,11 +230,11 @@ $(function() {
230230
i = 0;
231231
for (var coord of this.mark_coords) {
232232
if (coord != "" && !isNaN(coord)) {
233-
let x = this.main_plot.xscale(parseInt(coord));
233+
let x = this.main_plot.xscale(parseInt(coord) + parseInt(this.start_coord));
234234
let y = this.plot_points.get(parseInt(x));
235235
d3.select("#coord-svg-layer").append("circle")
236236
.attr("id", "mark-" + i)
237-
.attr("cx", x + "px")
237+
.attr("cx", (x + 1.5) + "px")
238238
.attr("cy", y + "px")
239239
.style("fill", "rgb(205, 233, 255)");
240240
i += 1;

js/widgets/reference_axes.js

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $(function() {
77
styles: {
88
dashed : "5,5",
99
solid : "0",
10-
dotted : "2,1"
10+
dotted : "2,1",
1111
}
1212
},
1313

@@ -20,23 +20,24 @@ $(function() {
2020
this.x_table = d3.select("#x-axis-lines");
2121
this.selected_element = null;
2222
this.offset = { x: 0, y: 0 };
23-
2423
this.main_plot = $("#main-plot").main_plot("instance");
2524

25+
//Attach drag event handlers
2626
d3.select("#main-plot-div").on("mousemove", function(e) {
2727
self.drag_plot_element(e);
2828
});
2929
d3.select("#main-plot-div").on("mouseup", function() {
3030
self.end_dragging();
3131
});
32-
3332
this.y_table.append("tbody");
3433
this.x_table.append("tbody");
35-
console.log(this._elements.styles.dashed);
3634
this.add_row(0, "#FF0000", this._elements.styles.dashed, this.y_table);
3735
this.add_row(0, "#FF0000", this._elements.styles.dashed, this.x_table);
38-
d3.select("#reference-axes-layer").attr("display", "none");
3936

37+
//Hide axes until tab is selected
38+
d3.select("#reference-axes-layer")
39+
.selectAll("*")
40+
.remove();
4041
this.attach_event_handlers();
4142
},
4243

@@ -50,21 +51,24 @@ $(function() {
5051
},
5152

5253
start_dragging: function(e, element) {
53-
//Update plot stats and assign selected element
54+
//Assign selected element
5455
this.selected_element = element;
5556
this.offset = this.get_mouse_pos(e);
5657
},
5758

5859
drag_plot_element: function(e){
5960
self = this;
61+
//If element is being dragged
6062
if (self.selected_element){
6163
var mousePos = this.get_mouse_pos(e);
6264
if (this.selected_element.getAttribute("class").includes("x-reference")){
6365
var currentX = parseFloat(this.selected_element.getAttribute("x1"));
66+
//Check that line is still on plot
6467
if (this.main_plot.margins.left < currentX && currentX < this.main_plot.width - this.main_plot.margins.right){
6568
var newX = currentX + (mousePos.x - this.offset.x);
6669
this.selected_element.setAttribute("x1", newX + "px");
6770
this.selected_element.setAttribute("x2", newX + "px");
71+
//Find the corresponding element in the array and update coordinate
6872
var array = this._elements.x_lines.find(x => {
6973
if (x !== undefined) {
7074
return x.number === parseInt(self.selected_element.getAttribute("number"));
@@ -73,13 +77,13 @@ $(function() {
7377
array.coordinate = parseInt(this.main_plot.xscale.invert(newX));
7478
}
7579
} else if (this.selected_element.getAttribute("class").includes("y-reference")) {
76-
console.log(this._elements.y_lines);
77-
7880
var currentY = parseFloat(this.selected_element.getAttribute("y2"));
81+
//Check that line is still on plot
7982
if(currentY > this.main_plot.margins.top && currentY < this.main_plot.height - this.main_plot.margins.bottom){
8083
var newY = currentY + (mousePos.y - this.offset.y);
8184
this.selected_element.setAttribute("y1", newY + "px");
8285
this.selected_element.setAttribute("y2", newY + "px");
86+
//Find the corresponding element in the array and update coordinate
8387
var array = this._elements.y_lines.find(y => {
8488
if (y !== undefined) {
8589
return y.number === parseInt(self.selected_element.getAttribute("number"));
@@ -88,6 +92,7 @@ $(function() {
8892
array.coordinate = this.main_plot.yscale.invert(Math.abs(newY)).toFixed(2);
8993
}
9094
}
95+
//Update offset, tables, and add numbers to plot
9196
this.offset = this.get_mouse_pos(e);
9297
this.update_tables();
9398
this.add_plot_numbers();
@@ -101,6 +106,7 @@ $(function() {
101106

102107
attach_event_handlers: function() {
103108
let self = this;
109+
//Add default rows
104110
this.y_plus.on("click", function(){
105111
self.add_row(0, "#FF0000", self._elements.styles.dashed, self.y_table);
106112
})
@@ -109,21 +115,25 @@ $(function() {
109115
})
110116
},
111117

118+
//Adds a row to x or y table and plots line
112119
add_row: function(coord, col, style, table) {
113120
let self = this;
114121
let lines;
115-
122+
//Use proper array
116123
if (table == this.y_table) {
117124
lines = this._elements.y_lines;
118125
} else {
119126
lines = this._elements.x_lines;
120127
}
121128
num_rows = table.selectAll("tr").size();
129+
//Limited to 4 rows so that style selectors are positioned properly
122130
if (num_rows <= 3) {
131+
//Assign array values
123132
let row_number = lines.length;
124133
lines.push({ coordinate: coord, color: col, style: style, number: row_number });
125134
let row = table.append("tr")
126135
.attr("number", row_number);
136+
//Append text input
127137
row.append("td")
128138
.style("width", "30%")
129139
.append("input")
@@ -135,6 +145,7 @@ $(function() {
135145
lines[row_number].coordinate = parseFloat(this.value);
136146
self.plot_lines();
137147
});
148+
//Append color input
138149
row.append("td")
139150
.style("width", "30%")
140151
.append("input")
@@ -144,6 +155,7 @@ $(function() {
144155
lines[row_number].color = this.value;
145156
self.plot_lines();
146157
});
158+
//Append style column with given style parameter
147159
style_col = row.append("td")
148160
.style("width", "30%");
149161
style_div = style_col.append("div")
@@ -169,6 +181,7 @@ $(function() {
169181
.attr("stroke-width", "1.5px")
170182
.attr("fill", "none")
171183
.attr("id", "diagonal-line");
184+
//Append style selector with all styles
172185
let style_selector = style_div.append("div")
173186
.classed("style-selector", true);
174187
for (let s in self._elements.styles) {
@@ -206,6 +219,7 @@ $(function() {
206219
style_svg.on("click", function(){
207220
style_selector.style("display", "block");
208221
});
222+
//Append remove button
209223
remove = row.append("td")
210224
.style("width", "10%")
211225
.append("svg")
@@ -237,11 +251,10 @@ $(function() {
237251
self.x_plus.style("display", "block");
238252
}
239253
}
240-
console.log(number_rows);
241254
self.plot_lines();
242255
});
256+
//If there are more than 4 rows, hide new row button
243257
if (num_rows >= 3) {
244-
console.log(num_rows);
245258
if (lines == self._elements.y_lines){
246259
self.y_plus.style("display", "none");
247260
} else if (lines === self._elements.x_lines){
@@ -254,8 +267,10 @@ $(function() {
254267

255268

256269
plot_lines:function(){
270+
//Remove old lines
257271
d3.select("#reference-axes-layer").selectAll("*").remove();
258272
let self = this;
273+
//Add x-axis lines to plot with drag event handlers and labels
259274
for (let line of self._elements.x_lines) {
260275
if (line != null && !isNaN(line.coordinate)) {
261276
plotted_line = d3.select("#reference-axes-layer").append("line")
@@ -272,15 +287,9 @@ $(function() {
272287
self.selected_element = this;
273288
self.start_dragging(e, d3.select(this).node());
274289
});
275-
d3.select("#reference-axes-layer").append("text")
276-
.attr("x", self.main_plot.xscale(line.coordinate) - 4)
277-
.attr("y", self.main_plot.yscale(self.main_plot.ymin) + 8)
278-
.style("text-align", "middle")
279-
.style("fill", line.color)
280-
.attr("font-size", "8px")
281-
.text(line.coordinate);
282290
}
283291
}
292+
//Add y-axis lines to plot with event handlers and labels
284293
for (let line of self._elements.y_lines) {
285294
if (line != null && !isNaN(line.coordinate)){
286295
plotted_line = d3.select("#reference-axes-layer").append("line")
@@ -297,21 +306,16 @@ $(function() {
297306
self.selected_element = this;
298307
self.start_dragging(e, d3.select(this).node());
299308
});
300-
d3.select("#reference-axes-layer").append("text")
301-
.attr("x", self.main_plot.xscale(self.main_plot.xmax) + 5)
302-
.attr("y", self.main_plot.yscale(line.coordinate) + 4)
303-
.style("text-align", "middle")
304-
.style("fill", line.color)
305-
.attr("font-size", "8px")
306-
.text(line.coordinate);
307309
}
308310
}
309-
//Fix the rest of the nucleosome slider to not save variables
311+
this.add_plot_numbers();
310312
},
311313

312314
add_plot_numbers: function(){
315+
self = this;
316+
//Adds coord labels to x-axis lines
313317
d3.select("#reference-axes-layer").selectAll("text").remove();
314-
for (var line of self._elements.x_lines) {
318+
for (let line of self._elements.x_lines) {
315319
if (line !== undefined){
316320
d3.select("#reference-axes-layer").append("text")
317321
.attr("x", self.main_plot.xscale(line.coordinate) - 4)
@@ -322,7 +326,8 @@ $(function() {
322326
.text(line.coordinate);
323327
}
324328
}
325-
for (var line of self._elements.y_lines) {
329+
//Adds occupancy labels to y-axis lines
330+
for (let line of self._elements.y_lines) {
326331
if (line !== undefined){
327332
d3.select("#reference-axes-layer").append("text")
328333
.attr("x", self.main_plot.xscale(self.main_plot.xmax) + 5)
@@ -336,28 +341,28 @@ $(function() {
336341
},
337342

338343
update_tables:function(){
344+
//Updates tables based on line's position on plot
339345
for (var line of this._elements.x_lines) {
340346
if (line !== undefined){
341-
row =this.x_table.selectAll("tr").filter(function() {return parseInt(d3.select(this).attr("number")) == parseInt(line.number);});
347+
row = this.x_table.selectAll("tr").filter(function() {return parseInt(d3.select(this).attr("number")) == parseInt(line.number);});
342348
row.select(".coord_input").attr("value", line.coordinate);
343349
}
344350
}
345351
for (var line of this._elements.y_lines) {
346352
if (line !== undefined){
347-
row =this.y_table.selectAll("tr").filter(function() {return parseInt(d3.select(this).attr("number")) == parseInt(line.number);});
353+
row = this.y_table.selectAll("tr").filter(function() {return parseInt(d3.select(this).attr("number")) == parseInt(line.number);});
348354
row.select(".coord_input").attr("value", line.coordinate);
349355
}
350356
}
351357
},
352358

353359
update_all:function(){
354-
this.plot_lines();
355-
this.update_tables();
356-
this.add_plot_numbers();
360+
if (d3.select("#keep-reference-lines").property("checked") || d3.select("#reference-axes-tab").classed("selected-tab")){
361+
this.plot_lines();
362+
this.update_tables();
363+
this.add_plot_numbers();
364+
}
357365
}
358366
});
359-
360-
361-
362367
$("#reference-axes-pane").reference_axes();
363368
})

0 commit comments

Comments
 (0)