D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
headwinds
Full window
Github gist
arc ring v5
Built with
blockbuilder.org
<!DOCTYPE html> <meta charset="utf-8"> <style> .paths--straight { fill: none; stroke: transparent; } .paths--round { fill: #ccc; opacity: 0.5; } </style> <body> <script src="https://d3js.org/d3.v5.min.js"></script> <script> // https://encycolorpedia.com/ff0e45 const sentimentData = [{label: "frontend dev", value:70, color:"#00f1ba"}, {label: "design", color:"#999", value:20}, {label: "data viz", value:10, color:"#ea0061"}]; let getSentimentValues = () => { return sentimentData.map( function(node){return node.value}); }; let getSentimentColor = () => { return sentimentData.map( function(node){return node.color}); }; let sentimentValues = getSentimentValues(); let sentimentColors = getSentimentColor(); var width = 300, height = 300, outerRadius = height / 2 - 30, cornerRadius = 5; var pie = d3.pie(); var arc = d3.arc() .outerRadius(outerRadius); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); let getFill = (i) => { return sentimentColors[i]; }; var roundPath = svg.append("g") .attr("class", "path--round") .selectAll("path") .data(sentimentValues) .enter().append("path") .attr("opacity", 0.5) .attr("fill", function(d,i){return getFill(i)}); var ease = d3.easeCubic; const timer = d3.timer(function(elapsed) { //var t = ease(1 - Math.abs((elapsed % duration) / duration - .5) * 2); const duration = 2500; const t = 1 - Math.abs((elapsed % 2500) / 2500 - .5) * 2; let sentimentValues = sentimentData.map( function(node){return node.value}); const arcs = pie.padAngle(t * .01)(sentimentValues); arc.innerRadius(outerRadius / (2 - t)); roundPath.data(arcs).attr("d", arc.cornerRadius(cornerRadius)); if (t > 0.8) timer.stop(); },150); </script>
https://d3js.org/d3.v5.min.js