Skip to content

Commit e312c2e

Browse files
added comments and organized code
1 parent d7ecc0a commit e312c2e

3 files changed

Lines changed: 84 additions & 87 deletions

File tree

js/widgets/main_plot.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ $(function() {
295295
this.update_legend()
296296
},
297297

298-
plot_composite: function(xmin, xmax, sense, anti, scale, color, secondary_color, i, opacity, smoothing, bp_shift, hide, hide_sense=false , hide_anti=false, baseline=0) {
298+
plot_composite: function(xmin, xmax, sense, anti, scale, color, secondary_color, i, opacity, smoothing, bp_shift, hide, hide_sense=false, hide_anti=false, baseline=0) {
299299
// Set composite visibility
300300
let composite = this._elements.composites[i]
301301
.classed("plotted", !hide)
@@ -323,7 +323,7 @@ $(function() {
323323
{new_xdomain, new_occupancy: smoothed_occupancy} = sliding_window(shifted_xdomain, combined_occupancy, smoothing),
324324
// Truncate x domain to x axis limits
325325
truncated_xdomain = new_xdomain.filter(x => x >= this.xmin && x <= this.xmax),
326-
// Truncate occupancy and scale by scale factor, adding baseline
326+
// Truncate occupancy and scale by scale factor, adding baseline value
327327
scaled_occupancy = smoothed_occupancy.filter((_, j) => new_xdomain[j] >= this.xmin && new_xdomain[j] <= this.xmax)
328328
.map(d => ((value = d * scale + baseline) > 0)? value: 0);
329329

@@ -407,18 +407,17 @@ $(function() {
407407
scaled_anti = smoothed_anti.filter((_, j) => new_xdomain[j] - bp_shift >= this.xmin
408408
&& new_xdomain[j] - bp_shift <= this.xmax).map(d => (value = d * scale + baseline) > 0? value: 0);
409409

410+
//Create sense path and gradient if not hidden
410411
let sense_path = "";
411412
if (!hide_sense){
412413
sense_path = "M" + truncated_sense_domain.map((d, j) => this.xscale(d) + " " + this.yscale(scaled_sense[j])).join("L");
413-
414414
composite.select(".composite-gradient-top")
415415
.selectAll("stop")
416416
.data([0, 1])
417417
.join("stop")
418418
.attr("offset", d => d)
419419
.attr("stop-color", color)
420420
.attr("stop-opacity", d => (1 - d) * opacity);
421-
// Redraw composite fill
422421
composite.select(".composite-fill-top")
423422
.attr("points", truncated_sense_domain.map((d, j) => this.xscale(d) + "," + this.yscale(scaled_sense[j])).join(" ")
424423
+ " " + this.xscale(truncated_sense_domain[truncated_sense_domain.length - 1]) + "," + this.yscale(0)
@@ -433,6 +432,7 @@ $(function() {
433432
.attr("stop-opacity", d => 0);
434433
}
435434

435+
//Create anti path and gradient if not hidden
436436
let anti_path = "";
437437
if (!hide_anti){
438438
anti_path = "M" + truncated_anti_domain.map((d, j) => this.xscale(d) + " " + this.yscale(-scaled_anti[j])).join("L");
@@ -459,7 +459,7 @@ $(function() {
459459
.attr("stop-opacity", d => (1 - d) * 0);
460460
}
461461

462-
// Redraw composite trace
462+
// Redraw composite trace for visible strands
463463
if (this.color_trace) {
464464
composite.select(".white-line")
465465
.style("display", "none")

js/widgets/settings_table.js

Lines changed: 79 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ $(function() {
208208
// Add event listeners
209209
let row = d3.select(this.element.context)
210210

211+
//Create table for each row of the settings table
211212
options_table = row.append("table")
212213
.attr("draggable", true)
213214
.classed("added-table", true)
@@ -221,7 +222,7 @@ $(function() {
221222
$(row.node()).settings_row("direct_drop_event", e)
222223
}),
223224

224-
// Add sliders and buttons
225+
// Add sliders and buttons to first row
225226
primary_row = options_table.append("tr")
226227
.classed("settings-row", true);
227228
drag_col = primary_row.append("td")
@@ -296,8 +297,7 @@ $(function() {
296297
.on("change", function() {$(row.node()).settings_row("change_secondary_color", this.value)});
297298
};
298299

299-
300-
//creates a new slider for the scale input
300+
//Creates elements for scale column right-to-left
301301
scale_col.append("input")
302302
.attr("type", "range")
303303
.classed("scale-slider", true)
@@ -317,11 +317,9 @@ $(function() {
317317
.on("mouseup", function() {$(row.node()).settings_row("toggle_draggable", true)})
318318
.on("mouseleave", function() {$(row.node()).settings_row("toggle_draggable", true)});
319319

320-
// Add scale input
321320
scale_col.append("label")
322321
.text("Scale:");
323322

324-
325323
// Add opacity input
326324
opacity_col.append("label")
327325
.text("Opacity:");
@@ -447,32 +445,31 @@ $(function() {
447445
.style("float", "right")
448446
.on("click", function() {$(row.node()).settings_row("toggle_second_row")});
449447

450-
let more_options = options_table.append("tr")
448+
//Creates second row for additional options
449+
let secondary_row = options_table.append("tr")
451450
.classed("settings-row", true)
452451
.classed("second-row", true)
453452
.style("margin-right", "0px")
454453
.style("display", "none");
455454

456-
col_one = more_options.append("td"),
457-
baseline_col = more_options.append("td")
458-
.classed("baseline-col", true)
459-
.classed("slider-col", true)
460-
.attr("colspan", "3"),
461-
col_four = more_options.append("td"),
462-
col_five = more_options.append("td"),
463-
hide_strand_col = more_options.append("td")
464-
.classed("hide-strand-col", true)
465-
.attr("colspan", "3")
466-
.style("white-space", "nowrap"),
467-
col_seven = more_options.append("td")
468-
.style("width", "30%")
469-
.style("white-space", "normal"),
470-
reset_col = more_options.append("td")
471-
.classed("reset-col", true);
472-
473-
//creates a new slider for the scale input
455+
//Adds options to secondary row, with cells for features which may be added in the future
456+
secondary_row.append("td"),
457+
baseline_col = secondary_row.append("td")
458+
.classed("baseline-col", true)
459+
.classed("slider-col", true)
460+
.attr("colspan", "3"),
461+
secondary_row.append("td"),
462+
secondary_row.append("td"),
463+
hide_strand_col = secondary_row.append("td")
464+
.classed("hide-strand-col", true)
465+
.attr("colspan", "3")
466+
.style("white-space", "nowrap"),
467+
secondary_row.append("td")
468+
reset_col = secondary_row.append("td")
469+
.classed("reset-col", true);
470+
471+
//Creates elements for baseline col, right-to-left
474472
baseline_col.append("input")
475-
.style("float", "right")
476473
.attr("type", "range")
477474
.classed("shift-slider", true)
478475
.attr("value", 50)
@@ -495,9 +492,11 @@ $(function() {
495492
.text("Shift occupancy:")
496493
.style("float", "right");
497494

495+
//Creates hide-strand input
498496
forward = hide_strand_col.append("div")
499497
.attr("title", "forward")
500498
.style("float", "left")
499+
.style("margin-left", "10%")
501500
.style("margin-right", "15px")
502501
forward.append("label")
503502
.text("Show forward:")
@@ -509,9 +508,6 @@ $(function() {
509508
.on("input", function() {
510509
self.toggle_forward(!d3.select(this).property("checked"));
511510
})
512-
513-
514-
515511
reverse = hide_strand_col.append("div")
516512
.attr("title", "reverse")
517513
reverse.append("label")
@@ -526,6 +522,7 @@ $(function() {
526522
self.toggle_reverse(!d3.select(this).property("checked"));
527523
})
528524

525+
//Add reset button
529526
reset_col.append("input")
530527
.attr("type", "button")
531528
.attr("value", "Reset")
@@ -534,55 +531,6 @@ $(function() {
534531
.on("click", function() {$(row.node()).settings_row("reset")});
535532
},
536533

537-
disable_direction_checkboxes: function(disable, plot=true){
538-
this.hide_forward = disable;
539-
this.hide_reverse = disable;
540-
if (disable){
541-
d3.select(this.element.context).selectAll("input.direction_checkbox")
542-
.attr("disabled", true)
543-
.property('checked', false);
544-
d3.select(this.element.context).selectAll("td.hide-strand-col")
545-
.style("opacity", ".5");
546-
} else {
547-
d3.select(this.element.context).selectAll("input.direction_checkbox")
548-
.attr("disabled", null)
549-
.property('checked', true);
550-
d3.select(this.element.context).selectAll("td.hide-strand-col")
551-
.style("opacity", "1");
552-
}
553-
if (plot){
554-
this.plot_composite();
555-
}
556-
},
557-
558-
toggle_forward: function(hide){
559-
this.hide_forward = hide;
560-
d3.select(this.element.context).select("input.forward_checkbox").property("checked", !hide);
561-
this.plot_composite();
562-
},
563-
564-
toggle_reverse: function(hide){
565-
this.hide_reverse = hide;
566-
d3.select(this.element.context).select("div.forward input").property("checked", !hide);
567-
this.plot_composite()
568-
},
569-
570-
change_baseline: function(new_baseline, plot=true){
571-
if (isNaN(new_baseline)) {
572-
d3.select(this.element.context).select("td.baseline-col input.setting-text").node().value = this.baseline;
573-
d3.select(this.element.context).select("td.baseline-col input.shift-slider").node().value = (this.baseline) * $("#main-plot").main_plot("export").ymax + 50;
574-
575-
} else {
576-
new_baseline = new_baseline !== "" ? parseFloat(new_baseline) : 0;
577-
this.baseline = new_baseline;
578-
d3.select(this.element.context).select("td.baseline-col input.setting-text").node().value = (new_baseline > 0? "+": "") + Math.round(new_baseline * 100) / 100;
579-
d3.select(this.element.context).select("td.baseline-col input.shift-slider").node().value = (new_baseline) * $("#main-plot").main_plot("export").ymax + 50;
580-
if (plot) {
581-
this.plot_composite()
582-
}
583-
}
584-
},
585-
586534
// Remove the row
587535
_destroy: function() {
588536
d3.select(this.element.context).remove()
@@ -745,6 +693,7 @@ $(function() {
745693
this.options.name = new_name;
746694
$("#main-plot").main_plot("change_name", this.options.idx, new_name);
747695

696+
//Manually adjust width of name divs
748697
let largestWidth = 0;
749698
d3.selectAll('.name-col').each(function() {
750699
let box = d3.select(this);
@@ -865,6 +814,59 @@ $(function() {
865814
}
866815
},
867816

817+
//Disables direction checkboxes if composite is hidden
818+
disable_direction_checkboxes: function(disable, plot=true){
819+
this.hide_forward = disable;
820+
this.hide_reverse = disable;
821+
if (disable){
822+
d3.select(this.element.context).selectAll("input.direction_checkbox")
823+
.attr("disabled", true)
824+
.property('checked', false);
825+
d3.select(this.element.context).selectAll("td.hide-strand-col")
826+
.style("opacity", ".5");
827+
} else {
828+
d3.select(this.element.context).selectAll("input.direction_checkbox")
829+
.attr("disabled", null)
830+
.property('checked', true);
831+
d3.select(this.element.context).selectAll("td.hide-strand-col")
832+
.style("opacity", "1");
833+
}
834+
if (plot){
835+
this.plot_composite();
836+
}
837+
},
838+
839+
//Hides forward strand
840+
toggle_forward: function(hide){
841+
this.hide_forward = hide;
842+
d3.select(this.element.context).select("input.forward_checkbox").property("checked", !hide);
843+
this.plot_composite();
844+
},
845+
846+
//Hides reverse strand
847+
toggle_reverse: function(hide){
848+
this.hide_reverse = hide;
849+
d3.select(this.element.context).select("div.forward input").property("checked", !hide);
850+
this.plot_composite()
851+
},
852+
853+
//Changes baseline occupancy, adjusting slider for plot scale
854+
change_baseline: function(new_baseline, plot=true){
855+
if (isNaN(new_baseline)) {
856+
d3.select(this.element.context).select("td.baseline-col input.setting-text").node().value = this.baseline;
857+
d3.select(this.element.context).select("td.baseline-col input.shift-slider").node().value = (this.baseline) * $("#main-plot").main_plot("export").ymax + 50;
858+
859+
} else {
860+
new_baseline = new_baseline !== "" ? parseFloat(new_baseline) : 0;
861+
this.baseline = new_baseline;
862+
d3.select(this.element.context).select("td.baseline-col input.setting-text").node().value = (new_baseline > 0? "+": "") + Math.round(new_baseline * 100) / 100;
863+
d3.select(this.element.context).select("td.baseline-col input.shift-slider").node().value = (new_baseline) * $("#main-plot").main_plot("export").ymax + 50;
864+
if (plot) {
865+
this.plot_composite()
866+
}
867+
}
868+
},
869+
868870
add_id: function(id) {
869871
this.options.ids.push(id);
870872
let id_list = d3.select(this.element.context).select(".id-col .id-list"),

style.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,8 @@ td.remove-row {
142142
white-space: nowrap;
143143
}
144144

145-
#settings-table .added-table label {
146-
cursor: grab;
147-
}
148-
149145
.mouse-highlight {
150146
border: 3px solid #8888FF;
151-
position: relative;
152147
}
153148

154149
.drag-highlight {

0 commit comments

Comments
 (0)