Skip to content

Instantly share code, notes, and snippets.

@virtualandy
Forked from kyrasteen/hat.html
Last active August 29, 2015 14:18
Show Gist options
  • Save virtualandy/6614d5d446483579f17a to your computer and use it in GitHub Desktop.
Save virtualandy/6614d5d446483579f17a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link type="text/css" href="hat.css" rel="stylesheet"/>
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<div id="hat"></div>
<script>
var data = [100];
var hat = d3.select("#hat").append("svg")
.attr("width", 800)
.attr("height", 800)
.append("g")
.attr("fill", 'url(#diagonalHatch)')
.attr("transform", "translate(180,250)");
hat.append('defs')
.append('pattern')
.attr('id', 'diagonalHatch')
.attr('patternUnits', 'userSpaceOnUse')
.attr('width', 4)
.attr('height', 4)
.append('polyline')
.attr("points", "16,2, 20,10, 23,2")
.style("stroke", "black")
.style("fill", "#ddd");
// .attr('d', 'M-1,1 l2,-2 M0,4 l4,-4 M3,5 l2,-2');
// .attr('stroke-width', 1);
hat.selectAll("rect")
.data(data)
.enter().append("rect")
.attr("transform", "translate(0, 195)")
.attr("transform", "translate(240, 195) rotate(180)")
.attr("width", 240)
.attr("height", function(d) { return (d*7 + "px"); })
var rect = hat.append("path")
.attr("d", roundedRect(-240, -20, 240, 280, 86));
hat.append("line")
.style("stroke", "#f42369")
.style("stroke-width", 2)
.attr("x1", 0)
.attr("y1", 150)
.attr("x2", 240)
.attr("y2", 150);
function roundedRect(x, y, width, height, radius) {
return "M" + 0 + "," + 0
+ "v" + (height - radius)
+ "h" + (width)
+ "v" + (radius - height)
+ "a" + radius + "," + radius + " 1 0 0 " + -radius + "," + -radius
+ "h" + (2 * radius - width)
+ "a" + radius + "," + radius + " 0 0 0" + -radius + "," + radius
+ "z";
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment