Commit 7fca3b81 authored by Conor Broderick's avatar Conor Broderick Committed by Brian Brazil

Updated routing-tree-editor (#728)

parent 6ac3790a
......@@ -57,26 +57,20 @@ d3.select(".js-parse-and-draw").on("click", function() {
// Click handler for input labelSet
d3.select(".js-find-match").on("click", function() {
labelServiceHandler();
});
d3.select(document).on("keyup", function(e) {
if (d3.event.keyCode != 13) {
return;
}
labelServiceHandler();
});
function labelServiceHandler() {
var searchValue = document.querySelector(".js-label-set-input").value
var searchValue = document.querySelector("input").value
var labelSet = parseSearch(searchValue);
var matches = match(root, labelSet)
var nodes = tree.nodes(root);
var idx = nodes.map(function(n) { return n.id }).indexOf(matches[0].id)
nodes.forEach(function(n) { n.matched = false });
nodes[idx].matched = true;
var matchedIds = matches.map(function(n) { return n.id; });
nodes.forEach(function(n) {
if (matchedIds.indexOf(n.id) > -1) {
n.matched = true;
} else {
n.matched = false;
}
});
update(root);
}
});
// Match does a depth-first left-to-right search through the route tree
// and returns the matching routing nodes.
......@@ -90,12 +84,12 @@ function match(root, labelSet) {
if (root.children) {
for (var j = 0; j < root.children.length; j++) {
child = root.children[j];
matches = match(child, labelSet)
var child = root.children[j];
var matches = match(child, labelSet);
all = all.concat(matches);
if (matches && !child.continue) {
if (matches.length && !child.continue) {
break;
}
}
......@@ -147,10 +141,6 @@ function massage(root) {
root.children = root.routes
if (root.continue != false) {
root.continue = true;
}
var matchers = []
if (root.match) {
for (var key in root.match) {
......@@ -188,27 +178,21 @@ function update(root) {
var nodes = tree.nodes(root);
var links = tree.links(nodes);
var matchedNode = nodes.find(function(n) { return n.matched })
var matchedNodes = nodes.filter(function(n) { return n.matched })
var highlight = [];
if (matchedNode) {
highlight = [matchedNode]
while (matchedNode.parent) {
highlight.push(matchedNode.parent);
matchedNode = matchedNode.parent;
if (matchedNodes.length) {
highlight = matchedNodes
matchedNodes.forEach(function(n) {
var mn = n
while (mn.parent) {
highlight.push(mn.parent);
mn = mn.parent;
}
}
});
}
var link = svg.selectAll(".link").data(links);
var drawSimple = nodes.length < 3 ? true : false;
if (drawSimple) {
// Algorithm fails to assign x attributes if nodes.length < 3. For this
// simple case, manually assign values.
nodes.forEach(function(n, i) {
n.x = i * 180 + 90;
});
}
link.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment