i'm trying graph example: http://bl.ocks.org/mbostock/1747543 problem have when execute html, there error says:
syntaxerror: expected expression, got '.'
my code is:
var width = 900, height = 500; var color = d3.scale.category20(); var force = d3.layout.force() .gravity(.1) .charge(-120) .linkdistance(30) .size([width, height]); var svg = d3.select("body").select('#contenedor').select('#contenido').append("svg") .attr("width", width) .attr("height", height); d3.json("fisica_noms.json", function(error, graph) { if (error) throw error; var clusters = [] var getcolors = function(category){ var nods = graph.nodes; var subs = []; var m = {}; (var ele in nods){ for(var categs in ele){ if (!m[categs] && categs == category){ m[categs] = true; subs.push(categs); }; }; }; return subs; }; var samecategory = function(category,subcategory){ var nods = graph.nodes; var subs = []; for(var i=0; i<nods.length;i++){ if(nods[i][category]===subcategory){ subs.push(nods[i])}; }; return subs }; var searchclusters = function(){ var nods = graph.nodes; var ncom = getcolors('comunitat').length; for(var i=0; i<ncom;i++){ clusters.push(samecategory('comunitat',i)); clusters[i] = d3.max(clusters[i], function(d) {return d.degree;}); }; force .nodes(graph.nodes) .links(graph.links) .start(); var link = svg.selectall(".link") .data(graph.links) .enter().append("line") .attr("class", "link") .style("weight", function(d) { return math.sqrt(d.value); }); force.linkstrength(function(link){return link.value}) ; var node = svg.selectall(".node") .data(graph.nodes) .enter().append("circle") .attr("class", "node") .attr("r", function(d){return d.degree/60}) .style("fill", function(d) { return color(d.comunitat); }) .call(force.drag) .on('click',function(d){showinfo(d);}); node.append("title") .text(function(d) { return d.id; }); force.on("tick",tick); function tick (e) { link.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.target.x; }) .attr("y2", function(d) { return d.target.y; }); console.log(e); node.attr("cx", function(d) { return d.x; }) .attr("cy", function(d) { return d.y; }); .each(cluster(10 * e.alpha * e.alpha)) }; // move d adjacent cluster node. function cluster(alpha) { return function(d) { var cluster = clusters[d.comunitat]; if (cluster === d) return; var x = d.x - cluster.x, y = d.y - cluster.y, l = math.sqrt(x * x + y * y), r = d.degree/60 + cluster.degree/60; if (l != r) { l = (l - r) / l * alpha; d.x -= x *= l; d.y -= y *= l; cluster.x += x; cluster.y += y; } }; } }); }; the console says error here:
.each(cluster(10 * e.alpha * e.alpha))
Comments
Post a Comment