[ Launch: Tributary inlet ] 6843559 by hyponymous
-
-
Save hyponymous/6843559 to your computer and use it in GitHub Desktop.
Tributary inlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"Tributary inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/yqTQXXQ.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = d3.select("svg"); | |
var g = svg.append("g"); | |
g.attr("transform", "translate(10, 10)"); | |
var factDict = {}; | |
function fact(N) | |
{ | |
if (N === 0) | |
{ | |
return 1; | |
} | |
if (factDict[N]) | |
{ | |
return factDict[N]; | |
} | |
return N * fact(N - 1); | |
} | |
var N = 30; | |
var p = 0.05; | |
function choose(N, k) | |
{ | |
return fact(N) / (fact(k) * fact(N - k)); | |
} | |
var data = d3.range(N).map(function (i) | |
{ | |
return choose(N, i) * Math.pow(p, i) * Math.pow(1 - p, N - i); | |
}); | |
var width = 480; | |
var height = 360; | |
var xScale = d3.scale.ordinal().rangeRoundBands([0, width], 0.1); | |
var yScale = d3.scale.linear().range([height, 0]); | |
xScale.domain(data.map(function (d, i) { return i; })); | |
yScale.domain([0, d3.max(data)]); | |
g.selectAll(".bar") | |
.data(data) | |
.enter().append("rect") | |
.attr("class", "bar") | |
.attr("x", function (d, i) { return xScale(i); }) | |
.attr("width", xScale.rangeBand()) | |
.attr("y", function (d) { return yScale(d); }) | |
.attr("height", function (d) { return height - yScale(d); }) | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.bar | |
{ | |
fill: steelBlue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment