Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created October 12, 2013 22:04
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 enjalot/6955433 to your computer and use it in GitHub Desktop.
Save enjalot/6955433 to your computer and use it in GitHub Desktop.
Tributary inlet
{"description":"Tributary inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"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":true,"loop":true,"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/rqKDjH8.png"}
//http://tributary.io/inlet/6955433
var svg = d3.select("svg");
var list = d3.range(20).map(function(i) {
return {
foo: i,
bar: i
}
})
/*
var list = [
{ foo: tributary.anim(5, 40), bar: 53 },
{ foo: tributary.anim(30, 10), bar: 31 },
{ foo: tributary.anim(22, 50), bar: 45 },
{ foo: 5, bar: 57 },
{ foo: 18, bar: 26 },
{ foo: 25, bar: 87 },
{ foo: 35, bar: 41 },
{ foo: 15, bar: 57 }
]
*/
//.sort(function(a,b) { return a.foo - b.foo })
var max = d3.max(list, function(d) { return d.foo });
var yscale = d3.scale.linear()
.domain([0, max])
.range([0, 300])
var maxBar = d3.max(list, function(d) { return d.bar })
var colorScale = d3.scale.linear()
.domain([0, maxBar])
.range(["#6415F1", "#7DF060"])
.interpolate(d3.interpolateHsl)
function x(d,i) {
return 10 + i * 19
}
svg.selectAll("rect")
.data(list)
.enter()
.append("rect")
.attr({
x: x,
y: function(d,i) { return yscale(max) - yscale(d.foo) },
width: 37,
height: function(d,i) { return yscale(d.foo) },
stroke: "#ff0000",
"stroke-width": tributary.anim(1, 15),
fill: function(d,i) { return colorScale(d.bar) }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment