Skip to content

Instantly share code, notes, and snippets.

@trinary
Created September 14, 2013 07:52
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 trinary/6559756 to your computer and use it in GitHub Desktop.
Save trinary/6559756 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/CBVHaJ3.png"}
var events =
[
{
"name" : "TEXT",
"usage" : [
[0,1],
[5,20],
[60,40],
[120,0]
]
},
{
"name" : "SA",
"usage" : [
[120,0],
[140,90],
[160,40],
[220,10]
]
},
{
"name" : "WT",
"usage" : [
[220,10],
[340,190],
[460,140],
[520,110]
]
}
];
var margin = {top: 20, right: 80, bottom: 80, left: 80},
width = tributary.sw
height = tributary.sh
var x = d3.scale.linear()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var color = d3.scale.category10();
var x_max = d3.max(events, function(d) { return d3.max(d.usage,function(u) { return u[0]; })})
var y_max = d3.max(events, function(d) { return d3.max(d.usage,function(u) { return u[1]; })})
x.domain([0, x_max]);
y.domain([0, y_max]);
var svg = d3.select("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("text-anchor", "end")
.attr("x", width/2 + 50)
.attr("y", 50)
.text("Time (Sec)");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("x", -height/2 + 50)
.attr("y", -50)
.style("text-anchor", "end")
.text("Space Usage (MB)");
var area = d3.svg.area()
.x(function(d) { return x(d[0]); })
.y0(height)
.y1(function(d) { return y(d[1]); });
var ev = svg.selectAll(".event")
.data(events)
.enter().append("path")
.attr("class", "area")
.attr("fill",function(d) { return color(d.name); })
.attr("d", function(d) { return area(d.usage) })
.style("stroke", function(d) { return color(d.name); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment