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() { ...@@ -57,26 +57,20 @@ d3.select(".js-parse-and-draw").on("click", function() {
// Click handler for input labelSet // Click handler for input labelSet
d3.select(".js-find-match").on("click", function() { d3.select(".js-find-match").on("click", function() {
labelServiceHandler(); var searchValue = document.querySelector("input").value
});
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 labelSet = parseSearch(searchValue); var labelSet = parseSearch(searchValue);
var matches = match(root, labelSet) var matches = match(root, labelSet)
var nodes = tree.nodes(root); var nodes = tree.nodes(root);
var idx = nodes.map(function(n) { return n.id }).indexOf(matches[0].id) var matchedIds = matches.map(function(n) { return n.id; });
nodes.forEach(function(n) { n.matched = false }); nodes.forEach(function(n) {
nodes[idx].matched = true; if (matchedIds.indexOf(n.id) > -1) {
n.matched = true;
} else {
n.matched = false;
}
});
update(root); update(root);
} });
// Match does a depth-first left-to-right search through the route tree // Match does a depth-first left-to-right search through the route tree
// and returns the matching routing nodes. // and returns the matching routing nodes.
...@@ -90,12 +84,12 @@ function match(root, labelSet) { ...@@ -90,12 +84,12 @@ function match(root, labelSet) {
if (root.children) { if (root.children) {
for (var j = 0; j < root.children.length; j++) { for (var j = 0; j < root.children.length; j++) {
child = root.children[j]; var child = root.children[j];
matches = match(child, labelSet) var matches = match(child, labelSet);
all = all.concat(matches); all = all.concat(matches);
if (matches && !child.continue) { if (matches.length && !child.continue) {
break; break;
} }
} }
...@@ -147,10 +141,6 @@ function massage(root) { ...@@ -147,10 +141,6 @@ function massage(root) {
root.children = root.routes root.children = root.routes
if (root.continue != false) {
root.continue = true;
}
var matchers = [] var matchers = []
if (root.match) { if (root.match) {
for (var key in root.match) { for (var key in root.match) {
...@@ -188,27 +178,21 @@ function update(root) { ...@@ -188,27 +178,21 @@ function update(root) {
var nodes = tree.nodes(root); var nodes = tree.nodes(root);
var links = tree.links(nodes); 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 = []; var highlight = [];
if (matchedNode) { if (matchedNodes.length) {
highlight = [matchedNode] highlight = matchedNodes
while (matchedNode.parent) { matchedNodes.forEach(function(n) {
highlight.push(matchedNode.parent); var mn = n
matchedNode = matchedNode.parent; while (mn.parent) {
highlight.push(mn.parent);
mn = mn.parent;
} }
} });
}
var link = svg.selectAll(".link").data(links); 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") link.enter().append("path")
.attr("class", "link") .attr("class", "link")
.attr("d", diagonal); .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