Skip to content

Instantly share code, notes, and snippets.

@mpmckenna8
Created February 2, 2015 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpmckenna8/c2fe31811d1de8687861 to your computer and use it in GitHub Desktop.
Save mpmckenna8/c2fe31811d1de8687861 to your computer and use it in GitHub Desktop.
rotation basics w/ d3

Want to try to practice rotating stuff, but I haven't really tried to

// this file should have my code for doing d3 stuff
var svg = d3.select('body').append('svg').attr("height", 500).attr("width", 500).attr("class", "svger")
var rectwi = 30;
var recthi = 200;
var rectbuf = 50;
svg.append("rect")
.attr("width", rectwi)
.attr("height", recthi)
.attr("fill", "yellow")
.attr("y", recthi)
.attr("x", rectbuf *4)
.transition()
.duration(8000)
.style("fill", "pink")
.attr("transform", "rotate(90)")
// setting the x and y of a group don't do nothing cause it doesn't use those attributes.
var group = svg.append("g")
.attr("y", recthi)
.attr("x", rectbuf *4)
.attr("transform", "translate(200,200)")
group.append("rect")
.transition().duration(8000)
.style("fill", "pink")
.attr("width", rectwi)
.attr("height", recthi)
.attr("transform", "rotate(180)")
.attr("y", -recthi/2)
.attr("x", -rectwi/2)
function addbar(wi, hi, x, y){
svg.append("rect")
.attr("width", rectwi)
}
<!DOCTYPE html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<link href='style.css' rel='stylesheet' />
</head>
<body>
<script src="dod3.js"></script>
</body>
</html>
.header {
margin-right:auto;
margin-left:auto;
}
.svger{
background:green;
}
svg rect {
fill:purple
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment