Skip to content

Commit

Permalink
Add test and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mooreryan committed Feb 28, 2019
1 parent 1cd96de commit 4d9186f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 26 deletions.
7 changes: 7 additions & 0 deletions app/assets/javascripts/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ global.html.id.inner_dots_cutoff_filled = "bootstrap-cutoff-filled-dot";
global.html.id.inner_dots_color = "inner-dot-color";
global.html.id.inner_dots_size = "inner-dot-size";

// Leaf dots
global.html.id.leaf_dots_show = "show-leaf-dots";
global.html.id.leaf_dots_align = "align-leaf-dots";
global.html.id.leaf_dots_color = "leaf-dot-color";
global.html.id.leaf_dots_size = "leaf-dot-size";


global.ZERO_REPLACEMENT_VAL = 1e-5;
53 changes: 28 additions & 25 deletions app/assets/javascripts/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ var viewer = {
}
};

// This will be passed to all things that could be aligned (leaf labels, dots, bars, etc)
viewer.defaults.tip_decorations_align = false;

viewer.defaults.inner_labels_size = 12;
viewer.defaults.inner_labels_color = "#000000";
viewer.defaults.inner_labels_font = "Helvetica";
Expand All @@ -57,7 +60,7 @@ viewer.defaults.leaf_labels_size = 16;
viewer.defaults.leaf_labels_padding = 0;
viewer.defaults.leaf_labels_padding_min = 0;
viewer.defaults.leaf_labels_padding_max = 10000;
viewer.defaults.leaf_labels_align = false;
viewer.defaults.leaf_labels_align = viewer.defaults.tip_decorations_align;
viewer.defaults.leaf_labels_rotation = 0;
viewer.defaults.leaf_labels_color = "#000000";
viewer.defaults.leaf_labels_font = "Helvetica";
Expand All @@ -69,6 +72,12 @@ viewer.defaults.inner_dots_cutoff_filled = 0.75;
viewer.defaults.inner_dots_color = "#000000";
viewer.defaults.inner_dots_size = 5;

// Leaf dots defaults
viewer.defaults.leaf_dots_show = false;
viewer.defaults.leaf_dots_align = viewer.defaults.tip_decorations_align;
viewer.defaults.leaf_dots_color = "#000000";
viewer.defaults.leaf_dots_size = 5;

var MAPPING_CHANGED, TREE_CHANGED;

var OPTIONS_DIV;
Expand Down Expand Up @@ -273,15 +282,9 @@ var ID_BAR_SHOW = "show-bars",
var ID_BAR_SHOW_START_AXIS = "show-bar-start-axis",
VAL_BAR_SHOW_START_AXIS;

var
ID_LEAF_DOT_SIZE = "leaf-dot-size";

var ID_LEAF_DOT_COLOR = "leaf-dot-color",
VAL_LEAF_DOT_COLOR,
var VAL_LEAF_DOT_COLOR,
VAL_INNER_DOT_COLOR;

var ID_LEAF_DOT_ALIGN = "align-leaf-dots";

var VAL_BIOLOGICALLY_ROOTED;

var ID_SHOW_INNER_DOTS = "show-inner-dots",
Expand Down Expand Up @@ -329,7 +332,7 @@ var md_cat_name2id = {
"leaf_label_font": null,
"leaf_label_size": global.html.id.leaf_labels_size,
"leaf_dot_color": null,
"leaf_dot_size": ID_LEAF_DOT_SIZE,
"leaf_dot_size": global.html.id.leaf_dots_size,
"new_name": null,
"branch_width": "branch-width",
"branch_color": null
Expand Down Expand Up @@ -1062,7 +1065,7 @@ function lalala(tree_input_param, mapping_input_param) {
utils__set_status_msg_to_done();
}, TIMEOUT);
});
listener("show-leaf-dots", "change", function () {
listener(global.html.id.leaf_dots_show, "change", function () {
utils__set_status_msg_to_rendering();

setTimeout(function () {
Expand All @@ -1076,25 +1079,25 @@ function lalala(tree_input_param, mapping_input_param) {
utils__set_status_msg_to_done();
}, TIMEOUT);
});
listener(ID_LEAF_DOT_ALIGN, "change", function () {
listener(global.html.id.leaf_dots_align, "change", function () {
utils__set_status_msg_to_rendering();

setTimeout(function () {
// First sync all the align buttons.
sync_align_buttons_and_vals(is_checked(ID_LEAF_DOT_ALIGN), false);
sync_align_buttons_and_vals(is_checked(global.html.id.leaf_dots_align), false);

leaf_label_align_listener_actions();
}, TIMEOUT);
});
listener(ID_LEAF_DOT_SIZE, "change", function () {
listener(global.html.id.leaf_dots_size, "change", function () {
utils__set_status_msg_to_rendering();

setTimeout(function () {
update_and_draw(draw_leaf_dots);
utils__set_status_msg_to_done();
}, TIMEOUT);
});
listener(ID_LEAF_DOT_COLOR, "change", function () {
listener(global.html.id.leaf_dots_color, "change", function () {
utils__set_status_msg_to_rendering();

setTimeout(function () {
Expand Down Expand Up @@ -1363,7 +1366,7 @@ function lalala(tree_input_param, mapping_input_param) {
DEFAULT_BRANCH_COLOR = document.getElementById("branch-color").value;
DEFAULT_BRANCH_WIDTH = parseInt(document.getElementById("branch-width").value);

VAL_LEAF_DOT_COLOR = jq(ID_LEAF_DOT_COLOR).val();
VAL_LEAF_DOT_COLOR = jq(global.html.id.leaf_dots_color).val();
VAL_INNER_DOT_COLOR = jq(global.html.id.inner_dots_color).val();


Expand Down Expand Up @@ -1409,9 +1412,9 @@ function lalala(tree_input_param, mapping_input_param) {
// Dots
VAL_SHOW_INNER_DOTS = jq(global.html.id.inner_dots_show).val();
SHOW_INNER_DOTS = document.getElementById(global.html.id.inner_dots_show).checked;
SHOW_LEAF_DOTS = document.getElementById("show-leaf-dots").checked;
SHOW_LEAF_DOTS = document.getElementById(global.html.id.leaf_dots_show).checked;
INNER_DOT_SIZE = parseInt(document.getElementById(global.html.id.inner_dots_size).value);
LEAF_DOT_SIZE = parseInt(document.getElementById(ID_LEAF_DOT_SIZE).value);
LEAF_DOT_SIZE = parseInt(document.getElementById(global.html.id.leaf_dots_size).value);

switch (VAL_SHOW_INNER_DOTS) {
case global.html.id.inner_dots_show_none:
Expand All @@ -1438,10 +1441,10 @@ function lalala(tree_input_param, mapping_input_param) {
}

if (SHOW_LEAF_DOTS) {
undisable(ID_LEAF_DOT_SIZE);
undisable(global.html.id.leaf_dots_size);
}
else {
disable(ID_LEAF_DOT_SIZE);
disable(global.html.id.leaf_dots_size);
}


Expand Down Expand Up @@ -3132,7 +3135,7 @@ function set_options_by_metadata() {

// Show leaf dots if leaf dot options are present
if (leaf_dot_options_present) {
check("show-leaf-dots");
check(global.html.id.leaf_dots_show);
}

// Show leaf labels if leaf label options are present.
Expand Down Expand Up @@ -3408,10 +3411,10 @@ function reset_all_to_defaults() {
jq(global.html.id.inner_dots_cutoff_unfilled).val(viewer.defaults.inner_dots_cutoff_unfilled);

// Leaf dot options
uncheck("show-leaf-dots");
$("#leaf-dot-size").val(5);
uncheck(global.html.id.leaf_dots_show);
jq(global.html.id.leaf_dots_size).val(viewer.defaults.leaf_dots_size);

jq(ID_LEAF_DOT_COLOR).val("#000000");
jq(global.html.id.leaf_dots_color).val(viewer.defaults.leaf_dots_color);
jq(global.html.id.inner_dots_color).val(viewer.defaults.inner_dots_color);

// Bar options
Expand Down Expand Up @@ -3764,11 +3767,11 @@ function set_and_validate_bootstrap_cutoff_input() {
// Also makes sure that the option is disabled or not.
var sync_align_buttons_and_vals = function (checked, disabled) {
jq(global.html.id.leaf_labels_align).prop("checked", checked);
jq(ID_LEAF_DOT_ALIGN).prop("checked", checked);
jq(global.html.id.leaf_dots_align).prop("checked", checked);
jq(ID_BAR_ALIGN).prop("checked", checked);

jq(global.html.id.leaf_labels_align).prop("disabled", disabled);
jq(ID_LEAF_DOT_ALIGN).prop("disabled", disabled);
jq(global.html.id.leaf_dots_align).prop("disabled", disabled);
jq(ID_BAR_ALIGN).prop("disabled", disabled);

// Make sure the val variable is also set so that everything is sync'd.
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_options_panel.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
input id="leaf-dot-color" type="color" value="#000000"
.small-12.medium-12.large-6.columns
label for="leaf-dot-size" Leaf dot size
input id="leaf-dot-size" type="range" min="2" max="8" value="5" class="slider width-100"
input id="leaf-dot-size" type="range" min="2" max="8" class="slider width-100"

li class="accordion-item" data-accordion-item=""
a href="#" class="accordion-title" Bar options
Expand Down
28 changes: 28 additions & 0 deletions spec/javascripts/viewer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,35 @@ describe("viewer", function () {
).to.equal(viewer.defaults.inner_dots_size);
});
});

describe("leaf dot options", function () {
it("sets show leaf dots default", function () {
expect(
$("#" + global.html.id.leaf_dots_show).prop("checked")
).to.eq(viewer.defaults.leaf_dots_show);
});

it("sets align leaf dots default", function () {
expect(
$("#" + global.html.id.leaf_dots_align).prop("checked")
).to.eq(viewer.defaults.leaf_dots_align);
});

it("sets leaf dot color default", function () {
expect(
$("#" + global.html.id.leaf_dots_color).val()
).to.equal(viewer.defaults.leaf_dots_color);
});

it("sets leaf dot size default", function () {
expect(
parseFloat($("#" + global.html.id.leaf_dots_size).val())
).to.equal(viewer.defaults.leaf_dots_size);
});
});
});

describe("bar options"); // START HERE
});
});
});
Expand Down

0 comments on commit 4d9186f

Please sign in to comment.