Built with blockbuilder.org
Last active
May 13, 2019 18:04
-
-
Save alfmoh/fb673f4b02227e37fcedd2aa26b1ea51 to your computer and use it in GitHub Desktop.
circles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <style> | |
| body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
| .text { | |
| font: italic 15px sans-serif; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| console.clear(); | |
| // Feel free to change or delete any of the code you see in this editor! | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", 960) | |
| .attr("height", 500) | |
| const dataset = [1,2,3,9,5,15]; | |
| const scale = d3.scaleLinear() | |
| .domain(dataset) | |
| .range([10,50]); | |
| const colorScale = d3.scaleQuantile() | |
| .domain(dataset) | |
| .range(["red","blue"]) | |
| const g = svg.selectAll("g") | |
| .data(dataset) | |
| .enter() | |
| .append("g") | |
| .attr("transform",d=>`translate(${scale(d)},500)`) | |
| const circle = g.append("circle") | |
| .attr("r",5) | |
| .style("fill",d=>colorScale(d)) | |
| .transition() | |
| .delay(d=>d*200) | |
| .duration(1000) | |
| .attr("r",(d,i)=>d*5) | |
| .style("fill","pink") | |
| const xAxis = d3.axisBottom(scale); | |
| svg.append("g") | |
| .call(xAxis) | |
| .attr("transform","translate(10,450)") | |
| g.transition() | |
| .delay(d=>d*200) | |
| .duration(1000) | |
| .attr("transform",(d,i)=>`translate(${scale(d)},${i*50})`) | |
| g.append("text") | |
| .text(d=>d) | |
| .style("fill","white") | |
| .attr("class","text") | |
| .attr("transform",(d,i)=>`translate(${-i*2},0)`) | |
| // g.transition() | |
| // // .delay(d=>d*20) | |
| // .duration(1000) | |
| // svg.selectAll("circle") | |
| // .data(dataset) | |
| // .enter() | |
| // .append("circle") | |
| // .attr("r",1) | |
| // .attr("cy",500) | |
| // .attr("cx",(d,i)=>scale(d)) | |
| // .transition() | |
| // .delay(d=>d*200) | |
| // .duration(1000) | |
| // .attr("r",(d,i)=>d) | |
| // .attr("cx",(d,i)=>scale(d)) | |
| // .attr("cy",(d,i)=>i*50) | |
| // .style("fill",d=>colorScale(d)) | |
| // .transition() | |
| // // .delay(d=>d*20) | |
| // .duration(1000) | |
| // .attr("r",(d,i)=>d*5) | |
| // .style("fill","pink") | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment