Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
Created July 11, 2018 01:44
Show Gist options
  • Save FreeFly19/2cf9f38a6ec1bdc0fc5616bf50d523ca to your computer and use it in GitHub Desktop.
Save FreeFly19/2cf9f38a6ec1bdc0fc5616bf50d523ca to your computer and use it in GitHub Desktop.
d3.event.preventDefault();
let nodeGroup = g.select('#' + d3.event.toElement.parentNode.id);
const r = 30;
const k = Math.PI * 2 / (100 / r);
const arcPercentLength = percent => (k * percent + ' ' + (k * 100 - percent));
const rotate = times => -times * r * Math.PI * 2;
const colors = [
'#ce994b',
'#4b99ce',
'#4bce99',
'#ce4b99',
'#99ce4b',
];
colors.forEach((color, i) => {
nodeGroup
.append("circle")
.attr('dx', nodeGroup.select('circle').attr('dx'))
.attr('dy', nodeGroup.select('circle').attr('dy'))
.attr('r', r)
.attr('stroke-dasharray', arcPercentLength(80 / colors.length))
.attr('stroke-dashoffset', rotate(i / colors.length))
.attr('stroke', color)
.attr('stroke-width', r / 1.75)
.attr('fill', 'transparent')
.on('click', function (n) {
console.log(i, n);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment