Skip to content

Instantly share code, notes, and snippets.

@Servuc
Last active January 16, 2017 07:36
Show Gist options
  • Save Servuc/4faf7060e5d90d963c6ad762cd075434 to your computer and use it in GitHub Desktop.
Save Servuc/4faf7060e5d90d963c6ad762cd075434 to your computer and use it in GitHub Desktop.
level
license: mit
<!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; }
</style>
</head>
<body>
<script>
var myColor = "#FFA500";
var myBackgroundColor = "#FFF";
var mySize = 500;
var myBorderSize = 0.05;
var myStrokeSize = myBorderSize * mySize / 2;
var myPercent = 50;
var myY = mySize * (myBorderSize + (1 - myBorderSize * 2) * (100 - myPercent) / 100);
var myFont = "Verdana";
var myFontSize = mySize / 4;
// Feel free to change or delete any of the code you see in this editor!
var svg = d3.select("body").append("svg")
.attr("width", mySize)
.attr("height", mySize)
svg.append("path")
.attr("d", "M 0 " + myY + " H " + mySize + " V " + mySize + " H 0")
.attr("fill", myColor);
svg.append("circle")
.attr("cy", mySize / 2)
.attr("cx", mySize / 2)
.attr("r", mySize)
.attr("stroke", myBackgroundColor)
.attr("stroke-width", mySize)
.attr("fill", "transparent");
svg.append("circle")
.attr("cy", mySize / 2)
.attr("cx", mySize / 2)
.attr("r", (mySize / 2) - myStrokeSize / 2)
.attr("stroke", myColor)
.attr("stroke-width", myStrokeSize)
.attr("fill", "transparent");
svg.append("circle")
.attr("cy", mySize / 2)
.attr("cx", mySize / 2)
.attr("r", (mySize / 2) - myStrokeSize * 1.5)
.attr("stroke", myBackgroundColor)
.attr("stroke-width", myStrokeSize)
.attr("fill", "transparent");
svg.append("text")
.attr("x", mySize / 2)
.attr("y", mySize / 2 + myFontSize / 4)
.attr("font-size", myFontSize)
.attr("font-family", myFont)
.attr("stroke", myBackgroundColor)
.attr("stroke-width", myStrokeSize / 5)
.attr("text-anchor", "middle")
.attr("fill", myColor)
.text(myPercent + "%");
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment