Last active
August 15, 2016 15:51
-
-
Save turboMaCk/8d57adba769dbe964b5c07d1b96ec611 to your computer and use it in GitHub Desktop.
d3 rounded rect function
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> | |
<html> | |
<body> | |
<svg></svg> | |
</body> | |
</html> |
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
function roundedRect(x, y, width, height, radius) { | |
return "M" + (x + radius) + "," + y + | |
"h" + (width - radius*2) + | |
"a" + radius + "," + radius + " 0 0 1 " + radius + "," + radius + | |
"v" + (height - 2 * radius) + | |
"a" + radius + "," + radius + " 0 0 1 " + -radius + "," + radius + | |
"h" + (radius*2 - width) + | |
"a" + radius + "," + radius + " 0 0 1 " + -radius + "," + -radius + | |
"v" + (2*radius - height) + | |
"a" + radius + "," + radius + " 0 0 1 " + radius + "," + -radius + | |
"z"; | |
} | |
d3.select('svg') | |
.append('path') | |
.attr('d', function(d) { | |
return roundedRect(0,0,300,50,10); | |
}) | |
.style('fill', 'red'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment