diff --git a/datalets/graph-datalet/graph-datalet.html b/datalets/graph-datalet/graph-datalet.html index 049b910..6726077 100644 --- a/datalets/graph-datalet/graph-datalet.html +++ b/datalets/graph-datalet/graph-datalet.html @@ -65,7 +65,7 @@ Example:
-
+
@@ -79,6 +79,8 @@ Example: diff --git a/datalets/graph-datalet/static/js/buildGraph.js b/datalets/graph-datalet/static/js/buildGraph.js index 970c0e9..64105df 100644 --- a/datalets/graph-datalet/static/js/buildGraph.js +++ b/datalets/graph-datalet/static/js/buildGraph.js @@ -1,36 +1,66 @@ + +var nodes; +var links; + function buildGraph(t) { - var graph = {}; + var graph = {}; graph.nodes = t.nodes; graph.links = t.links; - force = d3.layout.force().nodes(graph.nodes).links(graph.links).size([width, height]).charge(-1e3).friction(.7).linkDistance(function (t) + force = d3.layout.force().nodes(graph.nodes).links(graph.links).size([width, height]).charge(-1e3).friction(.5).linkDistance(function (t) { return t.value ? t.value : 80 }).on("tick", tick).start(); - links = svg.selectAll(".link").data(graph.links).enter().append("line").attr("class", "link"); +svg=svg.append("g") + .call(d3.behavior.zoom().scaleExtent([.25, 20]).on("zoom", zoom)) + .append("g"); + + svg.append("rect") + .attr("fill", "white") + .attr("width", width) + .attr("height", height); - nodes = svg.selectAll(".node").data(graph.nodes).enter().append("g").attr("class", function (t) { + links = svg.selectAll(".link").data(graph.links).enter().append("line").attr("class", "link"); + + nodes = svg.selectAll(".node").data(graph.nodes).enter().append("g") + .attr("class", function (t) { return t.fixed ? "node fixed" : "node" }).attr("name", function (t) { return t.name ? t.name.split(" ").join("_").toLowerCase() : "" - }).on("mouseover", mouseover).on("mouseout", mouseout).on("click", active).append("circle").attr("class", function (t) { - return t.fixed ? "" : "drag" - }).attr("r", function (t) { - return t.r ? t.r : 15 - }).attr("style", function (t) { - return t.color ? "stroke:" + t.color : !1 - }); + }).on("mouseover", mouseover).on("mouseout", mouseout).on("click", active) + .append("circle") + .attr("class", function (t) { + return t.fixed ? "" : "drag" + }) + .attr("r", function (t) { + return t.r ? t.r : 15 + }) + .attr("style", function (t) { + return t.color ? "stroke:" + t.color : !1 + }); //d3.selectAll(".drag").call(force.drag), svg.selectAll("g.fixed").call(text); d3.selectAll(".drag").call(force.drag), svg.selectAll("g.node").call(text); - svg.call(d3.behavior.zoom().scaleExtent([1, 8]).on("zoom", zoom)); - svg.selectAll(".node").attr("transform", function(d) { return "translate(" + d + ")"; }); - svg.selectAll(".link").attr("transform", function(d) { return "translate(" + d + ")"; }); + /* d3.selectAll("circle").attr("transform", function(t) { + return "translate(" + t.x + "," + t.y + ")"; + });*/ + //d3.selectAll("circle").attr("transform", function(t) { + // return "translate(" + t + ")"; + // }); } + +function destroyGraph(){ + nodes.remove(); + links.remove(); + svg.remove(); + nodes = []; + links = []; +} + function zoom() { svg.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")"); } @@ -71,7 +101,9 @@ function tick() { return t.x = Math.max(25, Math.min(width - 50, t.x)) }).attr("cy", function (t) { return t.y = Math.max(8, Math.min(600, t.y)) - }), links.attr("x1", function (t) { + }); + + links.attr("x1", function (t) { return t.source.x }).attr("y1", function (t) { return t.source.y