From ff209db7356f4a943e2f6f77d79e531e2a34dcdd Mon Sep 17 00:00:00 2001 From: luigser Date: Fri, 22 Jan 2016 13:33:29 +0100 Subject: [PATCH] graph updates --- datalets/graph-datalet/graph-datalet.html | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/datalets/graph-datalet/graph-datalet.html b/datalets/graph-datalet/graph-datalet.html index d59b6a4..4c9fbca 100755 --- a/datalets/graph-datalet/graph-datalet.html +++ b/datalets/graph-datalet/graph-datalet.html @@ -154,7 +154,7 @@ Example: } }, - buildGraph: function (t){ + buildGraph: function (){ this.svg = this.svg.append("g") .call(d3.behavior.zoom().scaleExtent([.25, 20]).on("zoom", this.zoom)) @@ -180,16 +180,16 @@ Example: .attr("height", this.height); - var graph = {}; + /* var graph = {}; graph.nodes = t.nodes; - graph.links = t.links; + graph.links = t.links;*/ //pezzotto - for(var i =0; i < graph.nodes.length; i++){ + for(var i =0; i < this.graph.nodes.length; i++){ this.svg.append("defs") .append("pattern") - .attr("id","image_" + graph.nodes[i].id) + .attr("id","image_" + this.graph.nodes[i].id) .attr("patternUnits","objectBoundingBox") .attr("height","40") .attr("width","40") @@ -198,16 +198,16 @@ Example: .attr("y","0") .attr("height","30") .attr("width","30") - .attr("xlink:href", graph.nodes[i].image); + .attr("xlink:href", this.graph.nodes[i].image); } //end pezzotto - force = d3.layout.force().nodes(graph.nodes).links(graph.links).size([this.width, this.height]).charge(-1e3).friction(.7).linkDistance(function (t) + force = d3.layout.force().nodes(this.graph.nodes).links(this.graph.links).size([this.width, this.height]).charge(-1e3).friction(.7).linkDistance(function (t) { return t.value ? t.value : 80 }).on("tick", this.tick).start(); - this.glinks = this.svg.selectAll(".link").data(graph.links).enter().append("line").attr("class", "link"); + this.glinks = this.svg.selectAll(".link").data(this.graph.links).enter().append("line").attr("class", "link"); this.svg.selectAll(".link") .attr("style", function(t){ @@ -217,7 +217,7 @@ Example: return "stroke-width:" + (t.size ? t.size : 1.0) + "px"; }); - this.gnodes = this.svg.selectAll(".node").data(graph.nodes).enter().append("g") + this.gnodes = this.svg.selectAll(".node").data(this.graph.nodes).enter().append("g") .attr("class", function (t) { return t.fixed ? "node fixed" : "node"}) .attr("id", function (t) { return "g" + t.id;}) .attr("name", function (t) { return t.name ? t.name.split(" ").join("_").toLowerCase() : ""}) @@ -270,7 +270,7 @@ Example: }, tick : function () { - if(_this.gnodes != undefined) + if(_this.gnodes != undefined && _this.graph.nodes.length > 0) { d3.selectAll("g foreignObject").attr("x", function (t) { return t.x + (t.r ? 0.8 * t.r : 15) @@ -396,10 +396,11 @@ Example: .attr("style", "transform:translate(0px)") .style("position", "absolute"); - var g = this.graph; - g.nodes[0].x = this.width / 2; - g.nodes[0].y = this.height / 8; - this.buildGraph(g); + if(this.graph.nodes.length > 0){ + this.graph.nodes[0].x = this.width / 2; + this.graph.nodes[0].y = this.height / 8; + this.buildGraph(); + } } }); -- libgit2 0.21.4