Skip to content

Instantly share code, notes, and snippets.

@hadley
Created July 6, 2012 00:16
Show Gist options
  • Save hadley/3057271 to your computer and use it in GitHub Desktop.
Save hadley/3057271 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<style></style>
<body>
<script src="http://d3js.org/d3.v2.min.js?2.9.6"></script>
<script src="http://coffeescript.org/extras/coffee-script.js"></script>
<script src="table.coffee" type="text/coffeescript"></script>
matrix = [
[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
]
identity = (x) -> x
size = d3.scale.linear().domain([0, 15]).rangeRound([10, 30])
table = d3.select("body").append("table")
table
.selectAll("tr").data(matrix).enter()
.append("tr")
.attr("class", (d, i) -> if (i % 2 == 0) then "odd" else "even")
.selectAll("td").data(identity).enter()
.append("td")
.text(identity)
.style("font-size", (d) -> size(d) + "px")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment