phyloio 2.2.2 → 2.2.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phyloio",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "JS library for visualising and comparing phylogenetic trees",
5
5
  "scripts": {
6
6
  "test": "npm run-script build-jest; jest --silent=false",
package/src/container.js CHANGED
@@ -557,7 +557,7 @@ export default class Container {
557
557
 
558
558
  }
559
559
 
560
- monocolored_check_and_collapse(colors,child ){
560
+ monocolored_check_and_collapse(colors, child, data_type){
561
561
 
562
562
  var model = this.models[this.current_model]
563
563
 
@@ -569,8 +569,11 @@ export default class Container {
569
569
  this.viewer.apply_collapse_from_data_to_d3(child.data, child)
570
570
  break;
571
571
  default:
572
- // compute the all pair of colorDifference in colors. If one above 10% return
573
- var colorArray = Array.from(colors)
572
+ if (data_type !== "num") {
573
+ break; // more than one color, categorial or explicit color, do not colapse
574
+ }
575
+ // compute the all pairs of colorDifference in colors. If one above 5% do not collapse
576
+ let colorArray = Array.from(colors)
574
577
  for (let i = 0; i < colorArray.length; i++) {
575
578
  for (let j = i + 1; j < colorArray.length; j++) {
576
579
  if (colorDifference(colorArray[i], colorArray[j]) > 0.05) {
@@ -627,13 +630,10 @@ export default class Container {
627
630
  if (!leaf.renderedColor) {
628
631
  continue
629
632
  }
630
-
631
633
  colors.add(leaf.renderedColor)
632
634
  }
633
-
634
-
635
-
636
- that.monocolored_check_and_collapse(colors,child )
635
+ const data_type = model.settings.extended_data_type[model.settings.style.color_accessor['leaf']];
636
+ that.monocolored_check_and_collapse(colors, child, data_type)
637
637
 
638
638
  viewer.apply_collapse_from_data_to_d3(child.data, child)
639
639
 
@@ -690,9 +690,8 @@ export default class Container {
690
690
 
691
691
 
692
692
  }
693
-
694
- that.monocolored_check_and_collapse(child.colors,child )
695
-
693
+ const data_type = model.settings.extended_informations[model.settings.style.color_accessor['node']];
694
+ that.monocolored_check_and_collapse(child.colors, child, data_type);
696
695
 
697
696
  }
698
697
 
@@ -740,12 +739,11 @@ export default class Container {
740
739
  child.colors = new Set()
741
740
  return
742
741
  }
743
-
744
-
745
-
746
742
  }
747
-
748
- that.monocolored_check_and_collapse(child.colors,child )
743
+ const data_type_node = model.settings.extended_informations[model.settings.style.color_accessor['node']];
744
+ const data_type_leaf = model.settings.extended_informations[model.settings.style.color_accessor['leaf']];
745
+ const data_type = (data_type_node === data_type_leaf) ? data_type_node : 'cat'
746
+ that.monocolored_check_and_collapse(child.colors, child, data_type);
749
747
 
750
748
  }
751
749
 
package/src/interface.js CHANGED
@@ -2792,7 +2792,7 @@ export default class Interface {
2792
2792
  this.container_object.collapse_node_not_colored()
2793
2793
  this.viewer.build_d3_cluster()
2794
2794
  this.viewer.render(this.viewer.hierarchy)
2795
- this.viewer.maximise_zoom()
2795
+ //this.viewer.maximise_zoom()
2796
2796
  })
2797
2797
  .style('margin', '12px 0px')
2798
2798
  .style('flex-grow', '1')
@@ -2852,7 +2852,7 @@ export default class Interface {
2852
2852
  this.container_object.collapse_node_same_color()
2853
2853
  this.viewer.build_d3_cluster()
2854
2854
  this.viewer.render(this.viewer.hierarchy)
2855
- this.viewer.maximise_zoom()
2855
+ //this.viewer.maximise_zoom()
2856
2856
  })
2857
2857
  .style('margin', '12px 0px')
2858
2858
  .style('flex-grow', '1')
@@ -3115,7 +3115,7 @@ export default class Interface {
3115
3115
 
3116
3116
 
3117
3117
  if (!(acc in this.viewer.model.settings.style.number_domain)) {
3118
- this.viewer.model.settings.style.number_domain[acc] = 3
3118
+ this.viewer.model.settings.style.number_domain[acc] = 2
3119
3119
  }
3120
3120
 
3121
3121
  this.create_color_scheme_picker(type)
@@ -3217,6 +3217,8 @@ export default class Interface {
3217
3217
  this.viewer.model.set_color_scale(type, this.api);
3218
3218
  }
3219
3219
  this.viewer.render(this.viewer.hierarchy)
3220
+ this.remove_color_legend(type)
3221
+ this.add_color_legend(type)
3220
3222
 
3221
3223
  })
3222
3224
 
@@ -3528,9 +3530,8 @@ export default class Interface {
3528
3530
  var number = this.viewer.model.settings.style.number_domain[acc];
3529
3531
 
3530
3532
  if (!(acc in this.viewer.model.settings.style.color_domain)) {
3531
- this.viewer.model.settings.style.color_domain[acc] = this.viewer.model.settings.style.color_domain_default
3532
-
3533
- var default_color = this.viewer.model.settings.style.color_domain_default
3533
+ //this.viewer.model.settings.style.color_domain[acc] = this.viewer.model.settings.style.color_domain_default
3534
+ var default_color = this.viewer.model.settings.style.color_domain_default[acc] || this.viewer.model.settings.style.color_domain_default["DEFAULT"];
3534
3535
 
3535
3536
  var w = Math.round(135/number);
3536
3537
  var color = []
package/src/model.js CHANGED
@@ -53,8 +53,16 @@ export default class Model {
53
53
  'color_extent_min': {'leaf' : {}, 'node': {"Topology":0}, 'circle': {} },
54
54
  'color_extent_max':{'leaf' : {}, 'node': {"Topology":1}, 'circle': {}},
55
55
  'number_domain':{ 'Topology': 5, 'Length': 5},
56
- 'color_domain':{'Topology' : ['#253494', '#2C7FB8', '#41B6C4', '#C7E9B4', '#FFFFCC'], 'Length': ['#253494', '#2C7FB8', '#41B6C4', '#C7E9B4', '#FFFFCC']},
57
- 'color_domain_default': ['#253494', '#2C7FB8', '#41B6C4', '#C7E9B4', '#FFFFCC'],
56
+ 'color_domain': {
57
+ 'Topology' : ["#a50026", "#f46d43", "#ffffbf", "#74add1", "#313695"],
58
+ 'Length': ['#253494', '#2C7FB8', '#41B6C4', '#C7E9B4', '#FFFFCC']
59
+ },
60
+ 'color_domain_default': {
61
+ "Topology": ["#a50026", "#f46d43", "#ffffbf", "#74add1", "#313695"],
62
+ "Length": ['#253494', '#2C7FB8', '#41B6C4', '#C7E9B4', '#FFFFCC'],
63
+ "DEFAULT": ['#C60101', '#FB6A4A', '#F7F7F7', '#6BAED6', '#253494']
64
+ }
65
+
58
66
  },
59
67
  'tree': {
60
68
  'node_vertical_size' : 30,
package/src/utils.js CHANGED
@@ -980,7 +980,14 @@ function check_if_color(query){
980
980
  }
981
981
  }
982
982
 
983
- function hexToRgb(hex) {
983
+ function hexToRgb(hex){
984
+ if (typeof hex === 'object' && hex.r !== undefined) {
985
+ return hex;
986
+ }
987
+ if (typeof hex === 'string' && hex.startsWith('rgb')) {
988
+ const values = hex.match(/\d+/g).map(Number);
989
+ return { r: values[0], g: values[1], b: values[2] };
990
+ }
984
991
  const bigint = parseInt(hex.slice(1), 16);
985
992
  const r = (bigint >> 16) & 255;
986
993
  const g = (bigint >> 8) & 255;
@@ -996,7 +1003,7 @@ function colorDifference(hex1, hex2) {
996
1003
  const bDiff = color1.b - color2.b;
997
1004
  const distance = Math.sqrt(rDiff * rDiff + gDiff * gDiff + bDiff * bDiff);
998
1005
  const maxDistance = Math.sqrt(255 * 255 * 3);
999
- return (distance / maxDistance) * 100;
1006
+ return (distance / maxDistance);
1000
1007
  }
1001
1008
 
1002
1009
  module.exports = {colorDifference, check_if_color, prepare_and_run_distance, build_table, reroot_hierarchy, screen_shot, parse_nhx, save_file_as, compute_RF_Euc, get_intersection_leaves, filter_leaves_hierarchy, remove_duplicated_and_unnamed_leaves_hierarchy};
package/src/viewer.js CHANGED
@@ -548,6 +548,7 @@ export default class Viewer {
548
548
  var acc = this.model.settings.style.color_accessor['circle']
549
549
  var type_acc = this.model.settings.extended_data_type[acc]
550
550
  var g = d.data.extended_informations[acc]
551
+ if (typeof(g) === 'undefined' || !g) return "rgba(140,140,140,0.6)";
551
552
 
552
553
  if (type_acc == 'cat'){
553
554
 
@@ -781,7 +782,8 @@ export default class Viewer {
781
782
 
782
783
  color_triangle(node_){
783
784
 
784
- var mean = array => array.reduce((a, b) => a + b) / array.length;
785
+ const mean = array => array.reduce((a, b) => a + b) / array.length;
786
+ const default_color = '#666'
785
787
 
786
788
  function mostFrequentElement(array) {
787
789
  var frequencyMap = {};
@@ -824,6 +826,7 @@ export default class Viewer {
824
826
  })
825
827
 
826
828
  metrics = removeFalsyValues(metrics)
829
+ if (metrics.length === 0) {return default_color;}
827
830
 
828
831
  var type_l = this.model.settings.extended_data_type[acc_l]
829
832
 
@@ -854,6 +857,7 @@ export default class Viewer {
854
857
  })
855
858
 
856
859
  metrics = removeFalsyValues(metrics)
860
+ if (metrics.length === 0) {return default_color;}
857
861
 
858
862
  var type_l = this.model.settings.extended_data_type[acc_l]
859
863
 
@@ -871,7 +875,7 @@ export default class Viewer {
871
875
  break
872
876
  }
873
877
 
874
- return '#666'
878
+ return default_color;
875
879
  }
876
880
 
877
881
  render_edges(source, duration){