Skip to content

Instantly share code, notes, and snippets.

@shamansir
Last active August 29, 2015 14:28
Show Gist options
  • Select an option

  • Save shamansir/1d7b26fff6f650af49fb to your computer and use it in GitHub Desktop.

Select an option

Save shamansir/1d7b26fff6f650af49fb to your computer and use it in GitHub Desktop.
SVG generate partially rounded rectangle path
// based on http://bl.ocks.org/mbostock/3468167
function roundedRect(x, y, width, height, rtl, rtr, rbr, rbl) {
return "M" + x + "," + y
+ (rtl ? ("v" + rtl
+ "a" + rtl + "," + rtl + " 0 0 1 " + rtl + "," + -rtl) : "")
+ "h" + (width - (rtl ? rtl : 0) - (rtr ? rtr : 0))
+ (rtr ? ("a" + rtr + "," + rtr + " 0 0 1 " + rtr + "," + rtr) : "")
+ "v" + (height - (rtr ? rtr : 0) - (rbr ? rbr : 0))
+ (rbr ? ("a" + rbr + "," + rbr + " 0 0 1 " + -rbr + "," + rbr) : "")
+ "h" + ((rbr ? rbr : 0) + (rbl ? rbl : 0) - width)
+ (rbl ? ("a" + rbl + "," + rbl + " 0 0 1 " + -rbl + "," + -rbl) : "")
+ "v" + ((rbl ? rbl : 0) + (rtl ? rtl : 0) - height)
+ "z";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment