phylotree 2.3.0 → 2.4.0

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": "phylotree",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "main": "dist/phylotree.js",
5
5
  "types": "dist/phylotree.d.ts",
6
6
  "unpkg": "dist/phylotree.js",
@@ -23,38 +23,37 @@
23
23
  "index.html"
24
24
  ],
25
25
  "dependencies": {
26
- "commander": "^6.2.1",
27
- "csv-stringify": "^5.3.6",
26
+ "commander": "^14.0.0",
27
+ "csv-stringify": "^6.6.0",
28
28
  "d3": "^7.9.0",
29
29
  "fast-xml-parser": "^5.2.5",
30
- "jquery": "3",
31
- "lodash": "^4.17.11",
32
- "moment": "^2.29.4",
30
+ "jquery": "^3.7.1",
31
+ "lodash": "^4.17.21",
32
+ "moment": "^2.30.1",
33
33
  "pretty-data": "^0.40.0",
34
- "rollup-plugin-node-resolve": "^5.2.0",
35
- "underscore": "1.x",
36
- "winston": "^3.2.1"
34
+ "underscore": "^1.13.7",
35
+ "winston": "^3.17.0"
37
36
  },
38
37
  "devDependencies": {
39
- "@rollup/plugin-commonjs": "^28.0.6",
38
+ "@rollup/plugin-commonjs": "^29.0.0",
40
39
  "@rollup/plugin-node-resolve": "^16.0.1",
41
- "concurrently": "^6.2.0",
42
- "eslint": "^7.32.0",
40
+ "@rollup/plugin-terser": "^0.4.4",
41
+ "concurrently": "^9.2.0",
42
+ "@eslint/js": "^9.39.0",
43
+ "eslint": "^9.39.0",
44
+ "globals": "^16.2.0",
43
45
  "http-server": "^14.1.1",
44
- "jsdoc-to-markdown": "^7.0.1",
45
- "prettier": "^2.3.2",
46
- "rollup": "^2.50.6",
47
- "rollup-plugin-copy": "^3.3.0",
48
- "rollup-plugin-execute": "^1.1.1",
49
- "rollup-plugin-terser": "^7.0.2",
50
- "tape": "5.2.2",
51
- "yarn": "^1.22.11"
46
+ "jsdoc-to-markdown": "^9.1.0",
47
+ "prettier": "^3.7.0",
48
+ "rollup": "^4.40.0",
49
+ "rollup-plugin-copy": "^3.5.0",
50
+ "tape": "^5.9.0"
52
51
  },
53
52
  "scripts": {
54
- "lint": "eslint --ext .js --ignore-pattern data,docs,images,node_modules ./",
55
- "dev": "rollup -w -c rollup.config.js",
56
- "serve": "concurrently 'rollup -w -c rollup.config.js' 'http-server'",
57
- "build": "rollup -c rollup.config.js",
53
+ "lint": "eslint .",
54
+ "dev": "rollup -w -c rollup.config.mjs",
55
+ "serve": "concurrently 'rollup -w -c rollup.config.mjs' 'http-server'",
56
+ "build": "rollup -c rollup.config.mjs",
58
57
  "test": "tape -r source-map-support/register 'test/*-test.js'",
59
58
  "docs:generate": "jsdoc2md 'src/**/*.js' > API.md",
60
59
  "docs:validate": "jsdoc2md 'src/**/*.js' --no-cache --partial 'partials/**/*.hbs'",
@@ -1,47 +1,47 @@
1
- import { XMLParser } from 'fast-xml-parser';
1
+ import { XMLParser } from "fast-xml-parser";
2
2
 
3
3
  // Changes XML to JSON
4
4
  // Modified version from here: http://davidwalsh.name/convert-xml-json
5
5
  function xmlToJson(xml) {
6
6
 
7
- // Create the return object
8
- var obj = {};
7
+ // Create the return object
8
+ var obj = {};
9
9
 
10
- if (xml.nodeType == 1) { // element
11
- // do attributes
12
- if (xml.attributes.length > 0) {
13
- obj["@attributes"] = {};
14
- for (var j = 0; j < xml.attributes.length; j++) {
15
- var attribute = xml.attributes.item(j);
16
- obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
17
- }
18
- }
19
- } else if (xml.nodeType == 3) { // text
20
- obj = xml.nodeValue;
21
- }
10
+ if (xml.nodeType == 1) { // element
11
+ // do attributes
12
+ if (xml.attributes.length > 0) {
13
+ obj["@attributes"] = {};
14
+ for (var j = 0; j < xml.attributes.length; j++) {
15
+ var attribute = xml.attributes.item(j);
16
+ obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
17
+ }
18
+ }
19
+ } else if (xml.nodeType == 3) { // text
20
+ obj = xml.nodeValue;
21
+ }
22
22
 
23
- // do children
24
- // If just one text node inside
25
- if (xml.hasChildNodes() && xml.childNodes.length === 1 && xml.childNodes[0].nodeType === 3) {
26
- obj = xml.childNodes[0].nodeValue;
27
- }
28
- else if (xml.hasChildNodes()) {
29
- for(var i = 0; i < xml.childNodes.length; i++) {
30
- var item = xml.childNodes.item(i);
31
- var nodeName = item.nodeName;
32
- if (typeof(obj[nodeName]) == "undefined") {
33
- obj[nodeName] = xmlToJson(item);
34
- } else {
35
- if (typeof(obj[nodeName].push) == "undefined") {
36
- var old = obj[nodeName];
37
- obj[nodeName] = [];
38
- obj[nodeName].push(old);
39
- }
40
- obj[nodeName].push(xmlToJson(item));
41
- }
42
- }
43
- }
44
- return obj;
23
+ // do children
24
+ // If just one text node inside
25
+ if (xml.hasChildNodes() && xml.childNodes.length === 1 && xml.childNodes[0].nodeType === 3) {
26
+ obj = xml.childNodes[0].nodeValue;
27
+ }
28
+ else if (xml.hasChildNodes()) {
29
+ for(var i = 0; i < xml.childNodes.length; i++) {
30
+ var item = xml.childNodes.item(i);
31
+ var nodeName = item.nodeName;
32
+ if (typeof(obj[nodeName]) == "undefined") {
33
+ obj[nodeName] = xmlToJson(item);
34
+ } else {
35
+ if (typeof(obj[nodeName].push) == "undefined") {
36
+ var old = obj[nodeName];
37
+ obj[nodeName] = [];
38
+ obj[nodeName].push(old);
39
+ }
40
+ obj[nodeName].push(xmlToJson(item));
41
+ }
42
+ }
43
+ }
44
+ return obj;
45
45
  }
46
46
 
47
47
  var phyloxml_parser = function(xml, options) {
@@ -49,8 +49,8 @@ var phyloxml_parser = function(xml, options) {
49
49
  function parsePhyloxml(node, index) {
50
50
  if (node.clade) {
51
51
  if (!Array.isArray(node.clade)) {
52
- node.clade = [node.clade];
53
- }
52
+ node.clade = [node.clade];
53
+ }
54
54
  node.clade.forEach(parsePhyloxml);
55
55
  node.children = node.clade;
56
56
  delete node.clade;
@@ -72,20 +72,20 @@ var phyloxml_parser = function(xml, options) {
72
72
  var tree_json;
73
73
 
74
74
  if (typeof xml === "string") {
75
- if (DOMParser) {
76
- const parser = new DOMParser();
77
- xml = parser.parseFromString(xml, "text/xml");
78
- } else {
79
- const parser = new XMLParser();
80
- xml = parser.parse(xml);
81
- }
75
+ if (DOMParser) {
76
+ const parser = new DOMParser();
77
+ xml = parser.parseFromString(xml, "text/xml");
78
+ } else {
79
+ const parser = new XMLParser();
80
+ xml = parser.parse(xml);
81
+ }
82
82
  }
83
83
 
84
84
  xml = xmlToJson(xml);
85
85
  var phylogeny = xml.phyloxml.phylogeny;
86
86
  if (Array.isArray(phylogeny)) {
87
- phylogeny = phylogeny[0];
88
- console.warn('PhyloXML files with multiple phylogenies are not currently supported. Only the first phylogeny will be loaded.')
87
+ phylogeny = phylogeny[0];
88
+ console.warn("PhyloXML files with multiple phylogenies are not currently supported. Only the first phylogeny will be loaded.")
89
89
  }
90
90
  tree_json = phylogeny.clade;
91
91
  tree_json.name = "root";
package/src/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  export { default as phylotree } from "./main.js";
2
2
 
3
3
  export { default as pairwise_distances } from "./metrics/pairwise-distances";
4
+ export { default as pairwiseDistances } from "./metrics/pairwise-distances";
4
5
  export { default as sackin } from "./metrics/sackins";
5
6
  export { centerOfTree } from "./metrics/center-of-tree";
6
7
  export { computeMidpoint } from "./metrics/compute-midpoint";
7
8
  export { default as rootToTip, fitRootToTip } from "./metrics/root-to-tip";
8
9
 
9
10
  export { default as extract_dates } from "./extract-dates";
11
+ export { default as extractDates } from "./extract-dates";
10
12
  export { default as clusterPicker } from "./clustering/cluster-picker";
11
13
  export { default as phylopart } from "./clustering/phylopart";
12
14
 
@@ -357,7 +357,7 @@ export function defNodeLabel(_node) {
357
357
  export function nodeLabel(attr) {
358
358
  if (!arguments.length) return this._nodeLabel;
359
359
  this._nodeLabel = attr ? attr : defNodeLabel;
360
- this.update();
360
+ this.update();
361
361
  return this;
362
362
  }
363
363
 
@@ -38,11 +38,11 @@ export function initializeSelectionSets(sets) {
38
38
  * @private
39
39
  */
40
40
  export function _injectSetStyles(sets) {
41
- const styleId = 'phylotree-selection-set-styles';
41
+ const styleId = "phylotree-selection-set-styles";
42
42
  let styleEl = document.getElementById(styleId);
43
43
 
44
44
  if (!styleEl) {
45
- styleEl = document.createElement('style');
45
+ styleEl = document.createElement("style");
46
46
  styleEl.id = styleId;
47
47
  document.head.appendChild(styleEl);
48
48
  }
@@ -127,8 +127,8 @@ export function addToSet(node, setName) {
127
127
  return this;
128
128
  }
129
129
 
130
- const nodeName = typeof node === 'string' ? node : node.data.name;
131
- const nodeObj = typeof node === 'string'
130
+ const nodeName = typeof node === "string" ? node : node.data.name;
131
+ const nodeObj = typeof node === "string"
132
132
  ? this.phylotree.getNodeByName(node)
133
133
  : node;
134
134
 
@@ -141,8 +141,8 @@ export function addToSet(node, setName) {
141
141
  this._selectionSets[setName].members.add(nodeName);
142
142
  nodeObj._selectionSet = setName;
143
143
 
144
- this.emit('setChange', {
145
- action: 'add',
144
+ this.emit("setChange", {
145
+ action: "add",
146
146
  set: setName,
147
147
  node: nodeObj,
148
148
  allSets: this._getSetsSummary()
@@ -169,8 +169,8 @@ export function removeFromSet(node, setName) {
169
169
  return this;
170
170
  }
171
171
 
172
- const nodeName = typeof node === 'string' ? node : node.data.name;
173
- const nodeObj = typeof node === 'string'
172
+ const nodeName = typeof node === "string" ? node : node.data.name;
173
+ const nodeObj = typeof node === "string"
174
174
  ? this.phylotree.getNodeByName(node)
175
175
  : node;
176
176
 
@@ -180,8 +180,8 @@ export function removeFromSet(node, setName) {
180
180
  delete nodeObj._selectionSet;
181
181
  }
182
182
 
183
- this.emit('setChange', {
184
- action: 'remove',
183
+ this.emit("setChange", {
184
+ action: "remove",
185
185
  set: setName,
186
186
  node: nodeObj,
187
187
  allSets: this._getSetsSummary()