-
Notifications
You must be signed in to change notification settings - Fork 1
/
viewer_functions.js
245 lines (190 loc) · 7.26 KB
/
viewer_functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
viewer.fn = {};
//// Warning about bad options
viewer.fn.warn_about_arcs_show = function () {
if (
global.html.val.tree_layout === global.html.id.tree_layout_rectangular ||
global.html.val.tree_layout === global.html.id.tree_layout_radial
) {
alert(global.warnings.arcs_show);
jq(global.html.id.arcs_show).prop("checked", false);
global.html.val.arcs_show = false;
}
};
viewer.fn.warn_about_bars_axis_show = function () {
if (
global.html.val.tree_layout === global.html.id.tree_layout_radial
) {
alert(global.warnings.bars_axis_show);
jq(global.html.id.bars_axis_show).prop("checked", false);
global.html.val.bars_axis_show = false;
}
};
//// Reseting options
viewer.fn.reset_tree_format_opts_to_defaults = function () {
// Tree options
jq(global.html.id.tree_width).val(viewer.defaults.radial.width);
jq(global.html.id.tree_height).prop("disabled", true).val(viewer.defaults.radial.height);
jq(global.html.id.tree_padding).val(viewer.defaults.tree_padding);
jq(global.html.id.tree_rotation).val(viewer.defaults.tree_rotation);
jq(global.html.id.tree_layout).val(global.html.id.tree_layout_radial);
jq(global.html.id.tree_branch_style).val(global.html.id.tree_branch_style_normal);
jq(global.html.id.tree_sorting).val(global.html.id.tree_sorting_forward);
check(global.html.id.biologically_rooted);
};
viewer.fn.reset_scale_bar_opts_to_defaults = function () {
// Scale bar options
jq(global.html.id.scale_bar_show)
.prop("checked", viewer.defaults.scale_bar_show_is_checked);
jq(global.html.id.scale_bar_autosize)
.prop("checked", viewer.defaults.scale_bar_autosize_is_checked);
jq(global.html.id.scale_bar_length)
.val(viewer.defaults.scale_bar_length)
.prop("disabled", viewer.defaults.scale_bar_length_is_disabled);
jq(global.html.id.scale_bar_offset_weight)
.val(viewer.defaults.scale_bar_offset_weight);
};
viewer.fn.reset_label_opts_to_defaults = function () {
uncheck(global.html.id.inner_labels_show);
jq(global.html.id.inner_labels_size).val(viewer.defaults.inner_labels_size);
jq(global.html.id.leaf_labels_show)
.prop("checked", viewer.defaults.leaf_labels_show);
jq(global.html.id.leaf_labels_align)
.prop("checked", viewer.defaults.leaf_labels_align);
jq(global.html.id.leaf_labels_size).val(viewer.defaults.leaf_labels_size);
jq(global.html.id.leaf_labels_padding).val(viewer.defaults.leaf_labels_padding);
// not checked, not disabled
sync_align_buttons_and_vals(false, false);
jq(global.html.id.leaf_labels_color).val(viewer.defaults.leaf_labels_color);
jq(global.html.id.leaf_labels_font).val(viewer.defaults.leaf_labels_font);
jq(global.html.id.inner_labels_color).val(viewer.defaults.inner_labels_color);
jq(global.html.id.inner_labels_font).val(viewer.defaults.inner_labels_font);
};
viewer.fn.reset_dot_opts_to_defaults = function () {
// Inner dot options
jq(global.html.id.inner_dots_show).val(viewer.defaults.inner_dots_show);
jq(global.html.id.inner_dots_size).val(viewer.defaults.inner_dots_size);
jq(global.html.id.inner_dots_cutoff_filled).val(viewer.defaults.inner_dots_cutoff_filled);
jq(global.html.id.inner_dots_cutoff_unfilled).val(viewer.defaults.inner_dots_cutoff_unfilled);
// Leaf dot options
uncheck(global.html.id.leaf_dots_show);
jq(global.html.id.leaf_dots_size).val(viewer.defaults.leaf_dots_size);
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);
};
viewer.fn.reset_bar_opts_to_defaults = function () {
// Bar options
jq(global.html.id.bars_show).prop("checked", viewer.defaults.bars_show);
jq(global.html.id.bars_axis_show).prop("checked", viewer.defaults.bars_axis_show);
jq(global.html.id.bars_color).val(viewer.defaults.bars_color);
jq(global.html.id.bars_height).val(viewer.defaults.bars_height);
jq(global.html.id.bars_width).val(viewer.defaults.bars_width);
jq(global.html.id.bars_padding).val(viewer.defaults.bars_padding);
};
viewer.fn.reset_arc_opts_to_defaults = function () {
// arc options
jq(global.html.id.arcs_show).prop("checked", viewer.defaults.arcs_show);
jq(global.html.id.arcs_padding).val(viewer.defaults.arcs_padding);
jq(global.html.id.arcs_height).val(viewer.defaults.arcs_height);
jq(global.html.id.arcs_cap_radius).val(viewer.defaults.arcs_cap_radius);
};
viewer.fn.reset_branch_opts_to_defaults = function () {
// Branch options
jq(global.html.id.branches_color).val(viewer.defaults.branches_color);
jq(global.html.id.branches_width).val(viewer.defaults.branches_width);
};
viewer.fn.reset_viewer_opts_to_defaults = function () {
// Viewer options
jq(global.html.id.viewer_size_fixed).prop("checked", viewer.defaults.viewer_size_fixed);
};
// Currently, these are all the defaults for the radial tree.
viewer.fn.reset_all_to_defaults = function () {
EXTRA_NAME_WARNINGS = false;
// The set_options_by_metadata function will change the value of the *_options_present vars, but if you change the mapping file to a new one, these don't appear to get changed back.
// Set these to null as this function is called when clicking the submit or reset buttons. Either of which will re-set these anyway. But doing this avoids some weird bugs where the mapping file is still hanging around after hitting reset. See https://github.com/mooreryan/iroki_web/issues/32.
tree_input = null;
mapping_input = null;
// name2md = null;
viewer.fn.reset_tree_format_opts_to_defaults();
viewer.fn.reset_scale_bar_opts_to_defaults();
viewer.fn.reset_label_opts_to_defaults();
viewer.fn.reset_dot_opts_to_defaults();
viewer.fn.reset_bar_opts_to_defaults();
viewer.fn.reset_arc_opts_to_defaults();
viewer.fn.reset_branch_opts_to_defaults();
viewer.fn.reset_viewer_opts_to_defaults();
};
//// Random utils
function ary_mean(ary) {
var num_elems = ary.length;
var total = 0;
ary.map(function (d) {
total += d;
});
return total / num_elems;
}
function flatten(ary) {
function flatten_iter(ary) {
for (var i = 0; i < ary.length; ++i) {
var val = ary[i];
if (Array.isArray(val)) {
flatten_iter(val);
}
else {
flat_ary.push(val);
}
}
}
var flat_ary = [];
flatten_iter(ary);
return flat_ary;
}
function ary_min_max(ary) {
var min = null;
var max = null;
ary.forEach(function (val) {
if (!max || val > max) {
max = val;
}
if (!min || val < min) {
min = val;
}
});
return { min: min, max: max };
}
//// Tiny javascript element helpers
function set_value_of(id, val) {
var elem = document.getElementById(id);
elem.value = val;
}
//// Tiny jquery helpers (lots of things depend on these)
function jq(id) {
return $("#" + id);
}
function disable(id) {
return jq(id).prop("disabled", true);
}
function undisable(id) {
return jq(id).prop("disabled", false);
}
function check(id) {
$("#" + id).prop("checked", true);
}
function uncheck(id) {
$("#" + id).prop("checked", false);
}
function is_checked(id) {
return jq(id).prop("checked");
}
//// Boolean type functions for checking nodes of a parsed tree
function is_root(d) {
return d.depth === 0;
}
function is_leaf(d) {
return d.value === 1;
}
function is_inner(d) {
return !is_leaf(d);
}
function is_root_node(d) {
return d.depth === 1;
}