@microbiome-informatics/genome-properties-viewer 0.0.0-stage → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,734 @@
1
+ import GenomePropertiesHierarchy from "./gp-hierarchy";
2
+ import GenomePropertiesTaxonomy from "./gp-taxonomy";
3
+ import ZoomPanel from "./zoomer";
4
+ import TaxonomySortButton from "./gp-taxonomy-sorter";
5
+ import GenomePropertiesController from "./gp-controller";
6
+ import { updateStepToggler, updateSteps } from "./gp-steps";
7
+ import "regenerator-runtime/runtime";
8
+
9
+ import {
10
+ drawScrollXBar,
11
+ // drawScrollYBar,
12
+ transformByScroll,
13
+ updateScrollBars,
14
+ } from "./gp-scroller";
15
+ import {
16
+ createGradient,
17
+ drawMasks,
18
+ updateMasks,
19
+ drawDragArea,
20
+ } from "./gp-ui-utils";
21
+
22
+ import {
23
+ FileGetter,
24
+ preloadSpecies,
25
+ enableSpeciesFromPreLoaded,
26
+ loadGenomePropertiesFile,
27
+ loadGenomePropertiesText,
28
+ removeGenomePropertiesFile,
29
+ } from "./gp-uploader";
30
+
31
+ import { filterByLegend, filterByHierarchy, filterByText } from "./gp-filters";
32
+
33
+ import {
34
+ drawTotalPerOrganismPanel,
35
+ updateTotalPerOrganismPanel,
36
+ drawRowTotalPanel,
37
+ updateRowTotalPanel,
38
+ refreshGPTotals,
39
+ } from "./gp-totals";
40
+
41
+ import GPModal from "./modal";
42
+
43
+ import * as d3 from "./d3";
44
+
45
+ export default class GenomePropertiesViewer {
46
+ constructor({
47
+ width = null,
48
+ height = null,
49
+ element_selector = "body",
50
+ cell_side = 20,
51
+ total_panel_height = cell_side,
52
+ server = "https://raw.githubusercontent.com/rdfinn/genome-properties/master/flatfiles/gp_assignments/SUMMARY_FILE_{}.gp",
53
+ server_tax = "https://raw.githubusercontent.com/rdfinn/genome-properties/master/flatfiles/taxonomy.json",
54
+ hierarchy_path = "../test-files/hierarchy.json",
55
+ model_species_path = "../test-files/JSON_MERGED",
56
+ whitelist_path = null,
57
+ controller_element_selector = "#gp-selector",
58
+ legends_element_selector = ".gp-legends",
59
+ gp_text_filter_selector = "#gp-filter",
60
+ gp_label_selector = "#gp_label",
61
+ tax_label_selector = "#tax_label",
62
+ tax_search_selector = "#tax-search",
63
+ template_link_to_GP_page = "https://wwwdev.ebi.ac.uk/interpro/genomeproperties/#{}",
64
+ gp_server = "http://wwwdev.ebi.ac.uk/interpro/genomeproperties/cgi-bin/test.pl",
65
+ dimensions = {
66
+ tree: { width: 160 },
67
+ labels: { width: 220 },
68
+ total: { short_side: cell_side },
69
+ step_expander: { short_side: cell_side },
70
+ scroller: { short_side: 12 },
71
+ },
72
+ }) {
73
+ this.destroyed = false;
74
+ this.data = {};
75
+ this.preloaded = {};
76
+ this.organisms = [];
77
+ this.organism_names = {};
78
+ this.organism_totals = {};
79
+ this.filter_text = "";
80
+ this.whitelist = null;
81
+ this.fixedHeight = height !== null;
82
+ this.propsOrder = null;
83
+
84
+ this.modal = new GPModal(element_selector);
85
+
86
+ this.fileGetter = new FileGetter({
87
+ element: ".gp-modal-content",
88
+ viewer: this,
89
+ });
90
+ if (width === null) {
91
+ const rect = d3.select(element_selector).node().getBoundingClientRect();
92
+ width = rect.width;
93
+ }
94
+
95
+ if (!this.fixedHeight) {
96
+ let rect = d3.select(element_selector).node().getBoundingClientRect();
97
+ if (rect.height < 1) {
98
+ d3.select(element_selector).style("flex", "1");
99
+ rect = d3.select(element_selector).node().getBoundingClientRect();
100
+ }
101
+ height = rect.height;
102
+ }
103
+
104
+ this.options = {
105
+ width,
106
+ height,
107
+ element_selector,
108
+ cell_side,
109
+ server,
110
+ gp_server,
111
+ server_tax,
112
+ total_panel_height,
113
+ hierarchy_path,
114
+ template_link_to_GP_page,
115
+ dimensions,
116
+ };
117
+ this.column_total_width = cell_side;
118
+ this.x = d3.scaleBand().range([0, cell_side]);
119
+ this.y = d3.scaleLinear().range([0, cell_side]);
120
+ this.gp_values = ["YES", "PARTIAL", "NO"];
121
+ this.c = {
122
+ YES: "rgb(49, 130, 189)",
123
+ PARTIAL: "rgb(107, 174, 214)",
124
+ NO: "rgb(210,210,210)",
125
+ };
126
+ this.current_order = null;
127
+
128
+ if (whitelist_path) {
129
+ fetch(whitelist_path)
130
+ .then((response) => {
131
+ if (!response.ok)
132
+ throw new Error(`${response.status} ${response.statusText}`);
133
+ return response.json;
134
+ })
135
+ .then((data) => {
136
+ this.whitelist = data;
137
+ });
138
+ }
139
+ this.svg = d3
140
+ .select(element_selector)
141
+ .append("svg")
142
+ .attr("xmlns:xlink", "http://www.w3.org/1999/xlink")
143
+ .attr("class", "gp-viewer")
144
+ .attr("tabindex", "0")
145
+ .attr("width", width)
146
+ .attr("height", height)
147
+ .on("wheel", (event) => {
148
+ if (this?.props?.length) {
149
+ event.stopPropagation();
150
+ this.moveScroll({ dx: -event.deltaX, dy: -event.deltaY });
151
+ }
152
+ });
153
+
154
+ this.mainGroup = this.svg.append("g");
155
+
156
+ d3.select(element_selector)
157
+ .on("keydown", (event) => {
158
+ this.step = this.step || 1;
159
+ switch (event.key) {
160
+ case "ArrowUp":
161
+ this.moveScroll({ dy: this.options.cell_side * this.step });
162
+ break;
163
+ case "ArrowDown":
164
+ this.moveScroll({ dy: -this.options.cell_side * this.step });
165
+ break;
166
+ case "ArrowLeft":
167
+ this.moveScroll({ dx: this.options.cell_side * this.step });
168
+ break;
169
+ case "ArrowRight":
170
+ this.moveScroll({ dx: -this.options.cell_side * this.step });
171
+ break;
172
+ default:
173
+ break;
174
+ }
175
+ this.step += 0.5;
176
+ })
177
+ .on("keyup", () => {
178
+ this.step = 1;
179
+ });
180
+ this.mainGroup.x = 0;
181
+ this.mainGroup.y = 0;
182
+ createGradient(this);
183
+
184
+ this.gp_taxonomy = new GenomePropertiesTaxonomy({
185
+ path: server_tax,
186
+ x: 0,
187
+ y: 20,
188
+ height: this.options.dimensions.tree.width,
189
+ width: Math.max(
190
+ cell_side,
191
+ width -
192
+ this.options.dimensions.labels.width -
193
+ this.options.dimensions.total.short_side
194
+ ),
195
+ })
196
+ .on("changeOrder", (order) => {
197
+ this.current_order = order;
198
+ this.order_organisms_current_order();
199
+ })
200
+ .on("spaciesRequested", (taxId) => {
201
+ // loadGenomePropertiesFile(this, taxId);
202
+ enableSpeciesFromPreLoaded(this, taxId);
203
+ })
204
+ .on("multipleSpaciesRequested", (taxa) => {
205
+ for (const taxId of taxa) {
206
+ enableSpeciesFromPreLoaded(this, taxId, false, false);
207
+ }
208
+ this.update_viewer(500);
209
+ })
210
+ .on("removeSpacies", (event, taxId) => {
211
+ event.stopPropagation();
212
+ removeGenomePropertiesFile(this, taxId);
213
+ })
214
+ .on("changeWidth", (h) => {
215
+ this.options.dimensions.tree.width = Math.max(80, h);
216
+ this.gp_taxonomy.height = this.options.dimensions.tree.width;
217
+ this.update_viewer();
218
+ });
219
+
220
+ this.gp_hierarchy = new GenomePropertiesHierarchy()
221
+ // .load_hierarchy_from_path(this.options.hierarchy_path)
222
+ .on("siwtchChanged", () => {
223
+ this.mainGroup.y = 0;
224
+ this.update_viewer(500);
225
+ updateTotalPerOrganismPanel(this);
226
+ });
227
+ this.sorter = new TaxonomySortButton({
228
+ container: this.mainGroup,
229
+ x: 0,
230
+ y: 0,
231
+ function_sort: (mode) => this.gp_taxonomy.sortBy(mode),
232
+ });
233
+ this.buttonHeight = 25;
234
+ this.zoomer = new ZoomPanel({
235
+ x: 0,
236
+ y: this.buttonHeight,
237
+ domain: [20, 200],
238
+ container: this.mainGroup,
239
+ function_plus: () => (this.cell_side = this.options.cell_side + 10),
240
+ function_less: () => (this.cell_side = this.options.cell_side - 10),
241
+ function_slide: (event) => {
242
+ const newY = Math.max(
243
+ this.zoomer.slider(this.zoomer.domain[1]),
244
+ Math.min(event.y, this.zoomer.slider(this.zoomer.domain[0]))
245
+ );
246
+ this.cell_side = Math.round(this.zoomer.slider.invert(newY));
247
+ },
248
+ });
249
+
250
+ // this.legends_filter = { YES: "", NO: "", PARTIAL: "" };
251
+ this.gp_label_type = "name";
252
+
253
+ this.controller = new GenomePropertiesController({
254
+ gp_element_selector: controller_element_selector,
255
+ legends_element_selector,
256
+ gp_text_filter_selector,
257
+ gp_label_selector,
258
+ tax_label_selector,
259
+ tax_search_selector,
260
+ gp_viewer: this,
261
+ gp_taxonomy: this.gp_taxonomy,
262
+ hierarchy_contorller: this.gp_hierarchy,
263
+ }).on("legendFilterChanged", (filters) => {
264
+ this.legend_filters = filters;
265
+ this.update_viewer();
266
+ });
267
+ this.gp_taxonomy.on("taxonomyLoaded", () =>
268
+ this.controller.loadSearchOptions()
269
+ );
270
+
271
+ this.current_scroll = { x: 0, y: 0 };
272
+ this.draw_heatmap_panel();
273
+ drawMasks(this);
274
+ this.draw_labels_panel();
275
+ drawRowTotalPanel(this);
276
+ this.gp_taxonomy.draw_tree_panel(this.mainGroup, this.treeClipId);
277
+ this.zoomer.draw_panel();
278
+ this.sorter.draw();
279
+ drawTotalPerOrganismPanel(this);
280
+ drawScrollXBar(this);
281
+ drawDragArea(this);
282
+ updateMasks(this);
283
+ this._onResize = () => this.refresh_size();
284
+ window.addEventListener("resize", this._onResize);
285
+
286
+ this.fileGetter.getJSON(server_tax).then((data) => {
287
+ if (this.destroyed) return;
288
+ this.gp_taxonomy.load_taxonomy_obj(data);
289
+ this.update_viewer();
290
+ });
291
+ this.fileGetter.getJSON(hierarchy_path).then((data) => {
292
+ if (this.destroyed) return;
293
+ this.gp_hierarchy.load_hierarchy_from_data(data);
294
+ this.fileGetter.getJSON(model_species_path).then((dataSpecies) => {
295
+ if (this.destroyed) return;
296
+ preloadSpecies(this, dataSpecies);
297
+ });
298
+ });
299
+ }
300
+
301
+ destroy() {
302
+ this.destroyed = true;
303
+ if (this._onResize) {
304
+ window.removeEventListener("resize", this._onResize);
305
+ }
306
+ if (this.fileGetter && this.fileGetter.destroy) {
307
+ this.fileGetter.destroy();
308
+ }
309
+ if (this.controller && this.controller.destroy) {
310
+ this.controller.destroy();
311
+ }
312
+ d3.select(this.options.element_selector).selectAll("*").remove();
313
+ }
314
+
315
+ get labelWidth() {
316
+ return this.options.dimensions.labels.width;
317
+ }
318
+
319
+ get treeHeight() {
320
+ if (this.gp_taxonomy && !this.gp_taxonomy.show_tree) {
321
+ return Math.max(70, this.options.cell_side * 3);
322
+ }
323
+ return this.options.dimensions.tree.width;
324
+ }
325
+
326
+ get heatmapLeft() {
327
+ return this.labelWidth;
328
+ }
329
+
330
+ get dataWidth() {
331
+ return (this.organisms?.length || 0) * this.options.cell_side;
332
+ }
333
+
334
+ get dataOffsetX() {
335
+ return Math.max(0, this.heatmapWidth() - this.dataWidth);
336
+ }
337
+
338
+ get heatmapAnchor() {
339
+ return this.heatmapLeft + this.dataOffsetX;
340
+ }
341
+
342
+ get heatmapTop() {
343
+ return this.treeHeight;
344
+ }
345
+
346
+ heatmapWidth() {
347
+ return Math.max(
348
+ this.options.cell_side,
349
+ this.options.width -
350
+ this.labelWidth -
351
+ this.options.dimensions.total.short_side -
352
+ this.options.dimensions.scroller.short_side
353
+ );
354
+ }
355
+
356
+ heatmapHeight() {
357
+ return Math.max(
358
+ this.options.cell_side,
359
+ this.options.height -
360
+ this.treeHeight -
361
+ this.options.dimensions.total.short_side -
362
+ this.options.dimensions.scroller.short_side
363
+ );
364
+ }
365
+
366
+ refresh_size() {
367
+ const rect = d3
368
+ .select(this.options.element_selector)
369
+ .node()
370
+ .getBoundingClientRect();
371
+ this.options.width = rect.width;
372
+ if (!this.fixedHeight) this.options.height = rect.height;
373
+ d3.select(this.options.element_selector)
374
+ .select("svg")
375
+ .attr("width", rect.width)
376
+ .attr("height", this.options.height);
377
+ this.update_viewer();
378
+ }
379
+
380
+ set cell_side(value) {
381
+ const p = this.options.cell_side;
382
+ this.options.cell_side = Math.max(20, Math.min(200, value));
383
+ if (p !== this.options.cell_side) {
384
+ const ratio = this.options.cell_side / p;
385
+ this.current_scroll.x *= ratio;
386
+ this.current_scroll.y *= ratio;
387
+ this.zoomer.zoomBar.attr("y", this.zoomer.slider(this.options.cell_side));
388
+ this.refresh(this);
389
+ }
390
+ }
391
+
392
+ moveScroll({ dx = 0, dy = 0 }) {
393
+ const speciesWidth = (this.organisms?.length || 0) * this.options.cell_side;
394
+ const propsHeight = this.y ? this.y(this.props?.length || 0) : 0;
395
+ const maxX = Math.max(0, speciesWidth - this.heatmapWidth());
396
+ const maxY = Math.max(0, propsHeight - this.heatmapHeight());
397
+ this.current_scroll.x = Math.max(
398
+ -maxX,
399
+ Math.min(0, this.current_scroll.x + dx)
400
+ );
401
+ this.current_scroll.y = Math.max(
402
+ -maxY,
403
+ Math.min(0, this.current_scroll.y + dy)
404
+ );
405
+ this.refresh(this);
406
+ }
407
+
408
+ _adjustYScaleBasedOnSteps() {
409
+ if (!this.props) return this.y;
410
+ const side = this.options.cell_side;
411
+ const marks = {
412
+ 0: 0,
413
+ 1: side,
414
+ };
415
+
416
+ const newY = d3.scaleLinear().domain([0, 1]).range([0, side]);
417
+ this.props.forEach((prop, i) => {
418
+ if (prop.isShowingSteps) {
419
+ const prevY = newY(i);
420
+
421
+ if (!marks[i]) marks[i] = prevY;
422
+ marks[i + 1] = marks[i] + Math.max(2, prop.steps.length + 1) * side;
423
+ marks[i + 2] = marks[i + 1] + side;
424
+ const domain = Object.keys(marks)
425
+ .map(Number)
426
+ .sort((a, b) => a - b);
427
+ const range = domain.map((x) => marks[x]).map(Number);
428
+ newY.range(range).domain(domain);
429
+ }
430
+ });
431
+ this.y = newY;
432
+ return this.y;
433
+ }
434
+
435
+ draw_heatmap_panel() {
436
+ this.heatmapLayer = this.mainGroup
437
+ .append("g")
438
+ .attr("class", "heatmap-layer")
439
+ .attr("clip-path", `url(#${this.heatmapClipId})`);
440
+ this.newCols = this.heatmapLayer
441
+ .append("g")
442
+ .attr("class", "gpv-new-cols-group");
443
+ this.newRows = this.heatmapLayer
444
+ .append("g")
445
+ .attr("class", "gpv-new-rows-group");
446
+ }
447
+
448
+ draw_labels_panel() {
449
+ this.labelGroup = this.mainGroup
450
+ .append("g")
451
+ .attr("class", "gpv-label-group");
452
+ }
453
+
454
+ move_row(prop, delta) {
455
+ const pos = this.propsOrder.indexOf(prop);
456
+ if (pos !== -1) {
457
+ const tmp = this.propsOrder.splice(pos, 1);
458
+ const newPos = Math.max(0, pos + delta);
459
+ this.propsOrder = this.propsOrder
460
+ .slice(0, newPos)
461
+ .concat(tmp)
462
+ .concat(this.propsOrder.slice(newPos));
463
+ this.refresh();
464
+ }
465
+ }
466
+
467
+ sort_props() {
468
+ if (this.propsOrder) {
469
+ this.props = this.props.sort(
470
+ (a, b) =>
471
+ this.propsOrder.indexOf(a.property) -
472
+ this.propsOrder.indexOf(b.property)
473
+ );
474
+ }
475
+ }
476
+
477
+ propertyLabel(d) {
478
+ if (this.gp_label_type === "name") return d.name;
479
+ if (this.gp_label_type === "id") return d.property;
480
+ return `${d.property}:${d.name}`;
481
+ }
482
+
483
+ update_viewer(time = 0) {
484
+ this.props = this.organisms.length ? Object.values(this.data) : [];
485
+ refreshGPTotals(this);
486
+ filterByHierarchy(this);
487
+ filterByText(this);
488
+ filterByLegend(this);
489
+ this.sort_props();
490
+ this._adjustYScaleBasedOnSteps();
491
+
492
+ this.column_total_width = this.options.cell_side;
493
+ this.gp_taxonomy.width = this.heatmapWidth();
494
+ this.gp_taxonomy.height = this.treeHeight;
495
+ this.gp_taxonomy.x = this.heatmapLeft + this.current_scroll.x;
496
+ this.gp_taxonomy.y = 16;
497
+ this.gp_taxonomy.update_tree(time, this.options.cell_side);
498
+ this.current_order = this.gp_taxonomy.current_order;
499
+ this.organisms = this.gp_taxonomy.get_tax_list();
500
+ this.x
501
+ .domain(this.current_order)
502
+ .range([0, this.organisms.length * this.options.cell_side]);
503
+
504
+ const heatmapH = this.heatmapHeight();
505
+ this.current_props = this.props.filter((gp, i) => {
506
+ const y0 = this.y(i) + this.current_scroll.y;
507
+ const y1 = this.y(i + 1) + this.current_scroll.y;
508
+ return y1 >= 0 && y0 < heatmapH;
509
+ });
510
+ const dy = Math.max(0, this.props.indexOf(this.current_props[0]));
511
+ const visible_rows = this.current_props.length;
512
+
513
+ const rowY = (d, i) => this.heatmapTop + this.y(i + dy);
514
+ const heatmapX = this.heatmapAnchor;
515
+
516
+ const rows = this.newRows
517
+ .selectAll(".column")
518
+ .data(this.current_props, (d) => d.property);
519
+
520
+ rows
521
+ .attr("transform", (d, i) => `translate(${heatmapX}, ${rowY(d, i)})`)
522
+ .each((d, i, c) => this.update_col(d, i, c));
523
+
524
+ rows.exit().remove();
525
+
526
+ const newRow = rows
527
+ .enter()
528
+ .append("g")
529
+ .attr("id", (d) => `col_${d.property}`)
530
+ .attr("class", "column")
531
+ .attr("transform", (d, i) => `translate(${heatmapX}, ${rowY(d, i)})`)
532
+ .each((d, i, c) => this.update_col(d, i, c));
533
+
534
+ newRow.append("line").attr("class", "puff").attr("x2", 0);
535
+
536
+ d3.selectAll("g.column line.puff").attr(
537
+ "x1",
538
+ this.organisms.length * this.options.cell_side
539
+ );
540
+
541
+ const side = this.options.cell_side;
542
+ const template = this.options.template_link_to_GP_page;
543
+ const labels = this.labelGroup
544
+ .selectAll(".row-label")
545
+ .data(this.current_props, (d) => d.property);
546
+
547
+ labels.exit().remove();
548
+ labels.attr("transform", (d, i) => `translate(${heatmapX}, ${rowY(d, i)})`);
549
+
550
+ const newLabel = labels
551
+ .enter()
552
+ .append("g")
553
+ .attr("class", "row-label")
554
+ .attr("transform", (d, i) => `translate(${heatmapX}, ${rowY(d, i)})`);
555
+
556
+ newLabel
557
+ .append("a")
558
+ .attr("xlink:href", (d) => template.replace("{}", d.property))
559
+ .attr("target", "_blank")
560
+ .style("cursor", "pointer")
561
+ .append("text")
562
+ .attr("class", "row_title")
563
+ .attr("text-anchor", "end");
564
+
565
+ this.labelGroup
566
+ .selectAll(".row-label text.row_title")
567
+ .attr("x", -side - 6)
568
+ .attr("y", side * 0.7)
569
+ .text((d) => this.propertyLabel(d));
570
+
571
+ this.labelGroup.selectAll(".row-label").each((d, i, nodes) => {
572
+ const g = d3.select(nodes[i]);
573
+ const sampleText = d3.select("text").node();
574
+ const textHeight = sampleText ? sampleText.getBBox().height : 12;
575
+ let radius = (side - textHeight) / 2 - 4;
576
+ if (radius < 2) radius = 2;
577
+ if (radius > 6) radius = 6;
578
+ const dots = g
579
+ .selectAll(".top_level_gp")
580
+ .data(d.parent_top_properties || [], (p) => p);
581
+ dots
582
+ .attr("cy", side * 0.5)
583
+ .attr("cx", -side * 0.35)
584
+ .attr("r", radius);
585
+ dots
586
+ .enter()
587
+ .append("circle")
588
+ .attr("class", "top_level_gp")
589
+ .attr("cy", side * 0.5)
590
+ .attr("cx", -side * 0.35)
591
+ .attr("r", radius)
592
+ .style("fill", (p) => this.gp_hierarchy.color(p));
593
+ dots.exit().remove();
594
+ updateStepToggler(this, d, nodes[i], side);
595
+ });
596
+
597
+ updateRowTotalPanel(this);
598
+
599
+ const orgLines = this.newCols
600
+ .selectAll(".row")
601
+ .data(this.organisms, (p) => p);
602
+ orgLines.attr(
603
+ "transform",
604
+ (d, i) => `translate(${heatmapX + this.x(i)}, ${this.heatmapTop})`
605
+ );
606
+ orgLines.exit().remove();
607
+ orgLines
608
+ .enter()
609
+ .append("g")
610
+ .attr("class", "row")
611
+ .attr(
612
+ "transform",
613
+ (d, i) => `translate(${heatmapX + this.x(i)}, ${this.heatmapTop})`
614
+ )
615
+ .append("line")
616
+ .attr("y2", 0);
617
+ this.newCols
618
+ .selectAll(".row line")
619
+ .attr("y2", this.y(this.props.length) || 0);
620
+
621
+ updateTotalPerOrganismPanel(this);
622
+ updateMasks(this);
623
+ this.sorter.y = 0;
624
+ this.zoomer.y = this.buttonHeight;
625
+ this.sorter.refresh();
626
+ this.zoomer.refresh();
627
+ if (!this.skip_scroll_refreshing) updateScrollBars(this, visible_rows, dy);
628
+ }
629
+
630
+ update_col(gp, i, c) {
631
+ const cell_height =
632
+ this.options.cell_side *
633
+ (gp.isShowingSteps ? Math.max(2, gp.steps.length + 1) : 1);
634
+ const side = this.options.cell_side;
635
+
636
+ const newX = d3
637
+ .scaleBand()
638
+ .range([0, this.organisms.length * this.options.cell_side])
639
+ .domain(this.current_order);
640
+
641
+ const cells = d3
642
+ .select(c[i])
643
+ .selectAll(".cell")
644
+ .data(this.organisms, (d) => d);
645
+
646
+ cells
647
+ .transition()
648
+ .attr("x", (d, j) => newX(j))
649
+ .attr("width", newX.bandwidth())
650
+ .attr("height", cell_height);
651
+
652
+ cells.exit().remove();
653
+
654
+ const mouseover = (event, p) => {
655
+ d3.select(event.currentTarget.parentNode)
656
+ .select("text")
657
+ .classed("active", true);
658
+ d3.selectAll(".node--leaf text").classed("active", (d) => d.label === p);
659
+ const data = d3.select(event.currentTarget.parentNode).data();
660
+ if (data.length < 1) return;
661
+
662
+ const info = {
663
+ Property: data[0].property,
664
+ Name: data[0].name,
665
+ Organism: `${this.getOrganismNameFromTaxId(p)} (${p})`,
666
+ Value: data[0].values[p],
667
+ };
668
+ this.controller.draw_tooltip(event, info);
669
+ };
670
+ const mouseout = () => {
671
+ d3.selectAll("text").classed("active", false);
672
+ d3.selectAll(".gpv-name").remove();
673
+ this.controller.draw_tooltip();
674
+ };
675
+
676
+ cells
677
+ .enter()
678
+ .insert("rect", ":first-child")
679
+ .attr("class", "cell")
680
+ .attr("x", (d, j) => newX(j))
681
+ .attr("width", newX.bandwidth())
682
+ .attr("height", cell_height)
683
+ .on("mouseover", mouseover)
684
+ .on("mouseout", mouseout)
685
+ .style("fill", (d) => (d in gp.values ? this.c[gp.values[d]] : null));
686
+
687
+ updateSteps(this, gp, c[i], side, newX);
688
+ }
689
+
690
+ order_organisms(value) {
691
+ this.current_order = this.gp_taxonomy.orders[value];
692
+ this.order_organisms_current_order();
693
+ }
694
+
695
+ order_organisms_current_order() {
696
+ this.x.domain(this.current_order);
697
+ updateTotalPerOrganismPanel(this);
698
+ this.refresh();
699
+ }
700
+
701
+ change_gp_label(type) {
702
+ this.gp_label_type = type;
703
+ this.refresh();
704
+ }
705
+
706
+ loadGenomePropertiesText(name, text) {
707
+ loadGenomePropertiesText(this, name, text, true);
708
+ }
709
+
710
+ loadGenomePropertiesFile() {
711
+ loadGenomePropertiesFile(this);
712
+ }
713
+
714
+ getOrganismNameFromTaxId(taxId) {
715
+ return (
716
+ this.gp_taxonomy &&
717
+ this.gp_taxonomy.nodes &&
718
+ this.gp_taxonomy.nodes[taxId] &&
719
+ this.gp_taxonomy.nodes[taxId].name
720
+ );
721
+ }
722
+
723
+ refreshSVGHeight(newHeight) {
724
+ if (newHeight > this.svg.attr("height")) {
725
+ this.svg.attr("height", newHeight);
726
+ this.options.height = newHeight;
727
+ this.update_viewer();
728
+ }
729
+ }
730
+
731
+ refresh() {
732
+ transformByScroll(this);
733
+ }
734
+ }