Skip to content

Instantly share code, notes, and snippets.

@aaizemberg
Created May 15, 2015 14:48
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 aaizemberg/a6db06defa2711c89fee to your computer and use it in GitHub Desktop.
Save aaizemberg/a6db06defa2711c89fee to your computer and use it in GitHub Desktop.
graphical perception (length)
<!DOCTYPE HTML>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<canvas id="myCanvas" width="600" height="200" style="border:1px solid #bbb;"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext('2d');
var w = d3.scale.linear().domain([0, 100]).range([0, canvas.width * 0.9]);
var py = d3.scale.linear().domain([0, 1]).range([0, canvas.height]);
ctx.fillStyle = "#aaa";
ctx.fillRect(0,py(1/3)-12,w(50),24);
ctx.fillRect(0,py(2/3)-12,w(100),24);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment