$(function(){ var svgWidth=screen.width; var svgHeight=960; var actionnaires=[]; var medias=[]; var childrenMedia=[] var lengthOfTheLongestText=0; d3.json("actionnaireEtMediafrancais.json", function(data) { var count=0; for (elem in data){ count++; actionnaires.push({id:elem,num:count}); for(var it=0;it0){ if(medias[it].parent == medias[it-1].parent){ currentActionnaire.push({name:medias[it].name,percent:medias[it].percent}); }else{ mediasByActionnaire.push({parent:medias[it-1].parent,mediasName:currentActionnaire}) currentActionnaire=[]; currentActionnaire.push({name:medias[it].name,percent:medias[it].percent}); } } if(it==medias.length-1){ mediasByActionnaire.push({parent:medias[it].parent,mediasName:currentActionnaire}) } } } //1nl, le svg principal de notre visualisation: var svg=createSvg(svgWidth,svgHeight); /** creation des actionnaires **/ //1nl, the main contenainer that will contain all the g element var container=createContainer(svg); //1nl, we add to the container all g element container.selectAll('g') .data(actionnaires) .enter() .append('g') .attr("transform", function(d, i) { return "translate(10," + i * 40 + ")"; }); //1nl, we add to the g element rect elements container.selectAll('g').append("rect") .attr("width",100) .attr("height",30) .style("fill","#5F91D5"); //and we add the text to the same element g container.selectAll('g').append("text") .attr("x",5) .attr("y",15) .attr('class',"actionnaire") .style("fill","#FFF") .text(function(d){ currentString=''+d.id; if(lengthOfTheLongestText