diff --git a/content/index.html b/content/index.html index db56337..feca92b 100644 --- a/content/index.html +++ b/content/index.html @@ -339,6 +339,17 @@ else $("#graph").removeClass("vscodeTheme"); break; + case 'highlight': + // TODO: I'm sure this can be done in one line?! + const plainNodes = gv.nodesByName(); + const nodesSelected = Array(); + for (n of message.value) { + nodesSelected.push(plainNodes[n]); + } + const nodes = $(nodesSelected); + + gv.highlight(nodes, true) + break; } }, false); @@ -347,6 +358,9 @@ }; function DomToJsonAttribs(element) { + if (element === null || element === undefined || element.attributes === undefined) + return; + var result = {} const attribs = element.attributes; for (let i = 0; i < attribs.length; i++) { @@ -356,6 +370,77 @@ return result; } + function findNodeWithAttr(elem, attr) { + if (elem === null || elem === undefined) + return undefined; + + if (elem.attributes !== undefined && elem.attributes[attr]) + return elem; + + return findNodeWithAttr(elem.parentElement, attr); + } + + function isNonEmptyTextNode(elem) { + return elem.nodeName && + (elem.nodeName == "#text" || elem.nodeName == "text") && + elem.textContent && + elem.textContent.trim().length > 0 ; + } + + function findNextText(elem) { + if (isNonEmptyTextNode(elem)) + return elem.textContent; + + if (!elem.parentElement) + return undefined; + + siblings = elem.parentElement.childNodes; + + // skip until we find the originating node + i = 0; + for (;i 5 || + Math.abs(arrow.attr("y1") - evt.y) > 5) + arrow.attr("marker-end", "url(#triangle)"); + + arrow + .attr("x2", evt.x) + .attr("y2", evt.y); + } + }); + + // skip the first level to allow drag of the canvas + dragHandler(d3.select("svg").select("g").selectAll("g")); + $(document).keydown(function (evt) { // press escape to cancel highlight if (evt.keyCode == 27) {