javascript - select a specific class with d3js to animate -



javascript - select a specific class with d3js to animate -

var data1 = [150,350,550] var data2 = [100,300,500] var samplesvg = d3.select("body") .append("svg") .attr("width", 800) .attr("height", 800); var circles1 = samplesvg .append("g") .attr("class", "circles1") .selectall(".circle1") .data(data1) .enter() .append("circle") .attr("class", "circle1") .on("mousedown", animatefirststep); var circleattributes1 = circles1 .attr("cx", function (d) { homecoming d;}) .attr("cy", 200) //.attr("class", function (d) { homecoming "circle" + d;}) .attr("r", function(d) { homecoming d/10;}) .style("fill", function(d){ var color; if (d === 150){ color = "yellow"; } else if (d === 350) { color = "orange"; } else if (d === 550) { color = "red"; } homecoming color; }) function animatefirststep(){ d3.selectall(...??...) .data(data1,function(d, i) { homecoming d; }) .transition() .delay(0) .duration(2000) .attr("r", 400) .style("opacity", 0) .each("end", animatesecondstep); };

i have 3 circles , want click on 1 of them. when click on 1 want 1 grow bigger , disappear. other 2 circles should disappear should not grow bigger. right name class of each circle "circle1". made option(which commented out) gives each circle own class based on data. have function animate circles. don't know how select specific circle mouseclick , allow 1 grow bigger , disappear while others don't grow disappear. can help me out please??

you're on right track, instead of selecting elements class in transition, i'd bind onclick event each circle using .on("click", ...) operator. have access each individual circle using d3.select(this). here's illustration of can circles1.on("click", ...) function (here i'm choosing how animate circles index i in original data, can filter value of d):

.on("click", function(d, i){ if (i == 0){ d3.select(this).transition() .delay(0) .duration(2000) .attr("r", d) .style("opacity", 0); } else{ d3.select(this) .transition() .delay(0) .duration(2000) .style("opacity", 0); } });

complete working jsfiddle here.

javascript class d3.js circle

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -