Skip to content

Commit 1c07ab0

Browse files
committed
add fxn to find node guids
1 parent d057bbb commit 1c07ab0

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/main.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ function findNodeColor(node, colorOptions) {
379379
// steelblue
380380
return colorOptions.defaultColor ?? "#4682B4";
381381
}
382-
console.log(node);
382+
383383
let nodeList = colorOptions.nodeList;
384384

385-
if (nodeList.includes(node.id)) {
385+
if (nodeList.includes(node.data._guid)) {
386386
// charcoal
387387
return colorOptions.highlightColor ?? "#feb640";
388388
} else {
@@ -1150,6 +1150,34 @@ TidyTree.prototype.setRuler = function (show) {
11501150
return this;
11511151
};
11521152

1153+
/**
1154+
* Retrieves the GUIDs of the nodes in the TidyTree instance.
1155+
*
1156+
* @param {boolean} leavesOnly - Whether to retrieve GUIDs only for leaf nodes.
1157+
* @return {Array} An array of GUIDs of the nodes.
1158+
*/
1159+
TidyTree.prototype.getNodeGUIDs = function (leavesOnly) {
1160+
// todo: make sure these are returned in order
1161+
let nodeList = this.parent
1162+
.select("svg")
1163+
.selectAll("g.tidytree-node-leaf circle")
1164+
._groups[0];
1165+
1166+
if (!leavesOnly) {
1167+
nodeList = this.parent
1168+
.select("svg")
1169+
.selectAll("g.tidytree-node-leaf circle, g.tidytree-node-internal circle")
1170+
._groups[0];
1171+
}
1172+
1173+
let nodeGUIDs = [];
1174+
for (const node of nodeList.values()) {
1175+
nodeGUIDs.push(node.__data__.data._guid);
1176+
}
1177+
1178+
return nodeGUIDs;
1179+
}
1180+
11531181
/**
11541182
* Searches the tree, returns Search Results
11551183
* @param {Function} test A function which takes a Branch and returns a Truthy

0 commit comments

Comments
 (0)