Skip to content

Instantly share code, notes, and snippets.

@lesliehoneybeefield
Created October 12, 2013 22:34
Show Gist options
  • Save lesliehoneybeefield/6955691 to your computer and use it in GitHub Desktop.
Save lesliehoneybeefield/6955691 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":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/hFnt0ww.png"}
var svg = d3.select("svg");
var yAxis = 100;
var xAxis = 300;
var barWidth = 40;
var barFill = "green";
var nextBarTranslate= 50;
var list=[
{foo: tributary.anim(5, 40), bar:53},
{foo:21, bar:100},
{foo:17, bar:200},
{foo:38, bar:300},
{foo:19, bar:800},
{foo:30, bar:77}
]
.sort(function(a,b) {return a.foo - b.foo})
var max = d3.max(list, function(d){return d.foo});
var maxBar = d3.max(list, function(d) {return d.bar});
var colorScale = d3.scale.linear()
.domain([0,maxBar])
.range(["red", "blue"])
function x(d,i)
{return 200 +i*50
}
var yscale = d3.scale.linear()
.domain([0, max])
.range([0,200])
svg.selectAll("rect")
.data(list)
.enter()
.append("rect")
.attr({
x: x,
y: function(d,i) {return yscale(max) - yscale(d.foo)+50},
fill: function(d,i) {return colorScale(d.bar)},
width: barWidth,
height: function(d,i) {return yscale(d.foo)},
stroke: "black",
"stroke-width": 5
})
/*var line = d3.svg.line()
.x(x)
.y(function(d,i) {
return yscale(d)
});
svg.append("path")
.attr("d", line(list))
.style({
fill: "none",
stroke: "blue"
})
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment