Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bring stream examples up-to-date

  • Loading branch information...
commit 8b775c032c3738f7a8f04444165ad0936572afed 1 parent 30e81f0
@kitmonisit kitmonisit authored
Showing with 22 additions and 22 deletions.
  1. +15 −15 examples/stream/stack.js
  2. +7 −7 examples/stream/stream.js
View
30 examples/stream/stack.js
@@ -3,9 +3,9 @@ var n = 4, // number of layers
data = d3.layout.stack()(stream_layers(n, m, .1)),
color = d3.interpolateRgb("#aad", "#556");
-var p = 20,
- w = 960,
- h = 500 - .5 - p,
+var margin = 20,
+ width = 960,
+ height = 500 - .5 - margin,
mx = m,
my = d3.max(data, function(d) {
return d3.max(d, function(d) {
@@ -17,15 +17,15 @@ var p = 20,
return d.y;
});
}),
- x = function(d) { return d.x * w / mx; },
- y0 = function(d) { return h - d.y0 * h / my; },
- y1 = function(d) { return h - (d.y + d.y0) * h / my; },
- y2 = function(d) { return d.y * h / mz; }; // or `my` to not rescale
+ x = function(d) { return d.x * width / mx; },
+ y0 = function(d) { return height - d.y0 * height / my; },
+ y1 = function(d) { return height - (d.y + d.y0) * height / my; },
+ y2 = function(d) { return d.y * height / mz; }; // or `my` to not rescale
var vis = d3.select("#chart")
.append("svg")
- .attr("width", w)
- .attr("height", h + p);
+ .attr("width", width)
+ .attr("height", height + margin);
var layers = vis.selectAll("g.layer")
.data(data)
@@ -42,7 +42,7 @@ var bars = layers.selectAll("g.bar")
bars.append("rect")
.attr("width", x({x: .9}))
.attr("x", 0)
- .attr("y", h)
+ .attr("y", height)
.attr("height", 0)
.transition()
.delay(function(d, i) { return i * 10; })
@@ -54,7 +54,7 @@ var labels = vis.selectAll("text.label")
.enter().append("text")
.attr("class", "label")
.attr("x", x)
- .attr("y", h + 6)
+ .attr("y", height + 6)
.attr("dx", x({x: .45}))
.attr("dy", ".71em")
.attr("text-anchor", "middle")
@@ -62,9 +62,9 @@ var labels = vis.selectAll("text.label")
vis.append("line")
.attr("x1", 0)
- .attr("x2", w - x({x: .1}))
- .attr("y1", h)
- .attr("y2", h);
+ .attr("x2", width - x({x: .1}))
+ .attr("y1", height)
+ .attr("y2", height);
function transitionGroup() {
var group = d3.selectAll("#chart");
@@ -87,7 +87,7 @@ function transitionGroup() {
d3.select(this)
.transition()
.duration(500)
- .attr("y", function(d) { return h - y2(d); })
+ .attr("y", function(d) { return height - y2(d); })
.attr("height", y2);
}
}
View
14 examples/stream/stream.js
@@ -4,8 +4,8 @@ var n = 20, // number of layers
data1 = d3.layout.stack().offset("wiggle")(stream_layers(n, m)),
color = d3.interpolateRgb("#aad", "#556");
-var w = 960,
- h = 500,
+var width = 960,
+ height = 500,
mx = m - 1,
my = d3.max(data0.concat(data1), function(d) {
return d3.max(d, function(d) {
@@ -14,14 +14,14 @@ var w = 960,
});
var area = d3.svg.area()
- .x(function(d) { return d.x * w / mx; })
- .y0(function(d) { return h - d.y0 * h / my; })
- .y1(function(d) { return h - (d.y + d.y0) * h / my; });
+ .x(function(d) { return d.x * width / mx; })
+ .y0(function(d) { return height - d.y0 * height / my; })
+ .y1(function(d) { return height - (d.y + d.y0) * height / my; });
var vis = d3.select("#chart")
.append("svg")
- .attr("width", w)
- .attr("height", h);
+ .attr("width", width)
+ .attr("height", height);
vis.selectAll("path")
.data(data0)
Please sign in to comment.
Something went wrong with that request. Please try again.