Commit ff209db7356f4a943e2f6f77d79e531e2a34dcdd
1 parent
89ddd164
graph updates
Showing
1 changed file
with
15 additions
and
14 deletions
datalets/graph-datalet/graph-datalet.html
... | ... | @@ -154,7 +154,7 @@ Example: |
154 | 154 | } |
155 | 155 | }, |
156 | 156 | |
157 | - buildGraph: function (t){ | |
157 | + buildGraph: function (){ | |
158 | 158 | |
159 | 159 | this.svg = this.svg.append("g") |
160 | 160 | .call(d3.behavior.zoom().scaleExtent([.25, 20]).on("zoom", this.zoom)) |
... | ... | @@ -180,16 +180,16 @@ Example: |
180 | 180 | .attr("height", this.height); |
181 | 181 | |
182 | 182 | |
183 | - var graph = {}; | |
183 | + /* var graph = {}; | |
184 | 184 | |
185 | 185 | graph.nodes = t.nodes; |
186 | - graph.links = t.links; | |
186 | + graph.links = t.links;*/ | |
187 | 187 | |
188 | 188 | //pezzotto |
189 | - for(var i =0; i < graph.nodes.length; i++){ | |
189 | + for(var i =0; i < this.graph.nodes.length; i++){ | |
190 | 190 | this.svg.append("defs") |
191 | 191 | .append("pattern") |
192 | - .attr("id","image_" + graph.nodes[i].id) | |
192 | + .attr("id","image_" + this.graph.nodes[i].id) | |
193 | 193 | .attr("patternUnits","objectBoundingBox") |
194 | 194 | .attr("height","40") |
195 | 195 | .attr("width","40") |
... | ... | @@ -198,16 +198,16 @@ Example: |
198 | 198 | .attr("y","0") |
199 | 199 | .attr("height","30") |
200 | 200 | .attr("width","30") |
201 | - .attr("xlink:href", graph.nodes[i].image); | |
201 | + .attr("xlink:href", this.graph.nodes[i].image); | |
202 | 202 | } |
203 | 203 | //end pezzotto |
204 | 204 | |
205 | - force = d3.layout.force().nodes(graph.nodes).links(graph.links).size([this.width, this.height]).charge(-1e3).friction(.7).linkDistance(function (t) | |
205 | + force = d3.layout.force().nodes(this.graph.nodes).links(this.graph.links).size([this.width, this.height]).charge(-1e3).friction(.7).linkDistance(function (t) | |
206 | 206 | { |
207 | 207 | return t.value ? t.value : 80 |
208 | 208 | }).on("tick", this.tick).start(); |
209 | 209 | |
210 | - this.glinks = this.svg.selectAll(".link").data(graph.links).enter().append("line").attr("class", "link"); | |
210 | + this.glinks = this.svg.selectAll(".link").data(this.graph.links).enter().append("line").attr("class", "link"); | |
211 | 211 | |
212 | 212 | this.svg.selectAll(".link") |
213 | 213 | .attr("style", function(t){ |
... | ... | @@ -217,7 +217,7 @@ Example: |
217 | 217 | return "stroke-width:" + (t.size ? t.size : 1.0) + "px"; |
218 | 218 | }); |
219 | 219 | |
220 | - this.gnodes = this.svg.selectAll(".node").data(graph.nodes).enter().append("g") | |
220 | + this.gnodes = this.svg.selectAll(".node").data(this.graph.nodes).enter().append("g") | |
221 | 221 | .attr("class", function (t) { return t.fixed ? "node fixed" : "node"}) |
222 | 222 | .attr("id", function (t) { return "g" + t.id;}) |
223 | 223 | .attr("name", function (t) { return t.name ? t.name.split(" ").join("_").toLowerCase() : ""}) |
... | ... | @@ -270,7 +270,7 @@ Example: |
270 | 270 | }, |
271 | 271 | |
272 | 272 | tick : function () { |
273 | - if(_this.gnodes != undefined) | |
273 | + if(_this.gnodes != undefined && _this.graph.nodes.length > 0) | |
274 | 274 | { |
275 | 275 | d3.selectAll("g foreignObject").attr("x", function (t) { |
276 | 276 | return t.x + (t.r ? 0.8 * t.r : 15) |
... | ... | @@ -396,10 +396,11 @@ Example: |
396 | 396 | .attr("style", "transform:translate(0px)") |
397 | 397 | .style("position", "absolute"); |
398 | 398 | |
399 | - var g = this.graph; | |
400 | - g.nodes[0].x = this.width / 2; | |
401 | - g.nodes[0].y = this.height / 8; | |
402 | - this.buildGraph(g); | |
399 | + if(this.graph.nodes.length > 0){ | |
400 | + this.graph.nodes[0].x = this.width / 2; | |
401 | + this.graph.nodes[0].y = this.height / 8; | |
402 | + this.buildGraph(); | |
403 | + } | |
403 | 404 | } |
404 | 405 | }); |
405 | 406 | </script> | ... | ... |