Commit 8211b3e5 authored by stuart nelson's avatar stuart nelson Committed by GitHub

Fix jQuery and Tree creation errors (#467)

* Use d3 to handle keyboard event

jQuery isn't always being loaded before the
routing-tree script is executed.

We cannot guarantee when jQuery will be available,
but d3 will be loaded before the routing-tree
script. This change preserves the previous
functionality.

* Add simple case for handling fewer than 3 nodes

The tree algorithm being used doesn't properly handle 1 or 2 nodes.
parent f6458a13
...@@ -60,8 +60,8 @@ d3.select(".js-find-match").on("click", function() { ...@@ -60,8 +60,8 @@ d3.select(".js-find-match").on("click", function() {
labelServiceHandler(); labelServiceHandler();
}); });
$(document).on("keyup", function(e) { d3.select(document).on("keyup", function(e) {
if (e.keyCode != 13) { if (d3.event.keyCode != 13) {
return; return;
} }
labelServiceHandler(); labelServiceHandler();
...@@ -200,6 +200,15 @@ function update(root) { ...@@ -200,6 +200,15 @@ function update(root) {
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