Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SWP

  • Loading branch information...
commit fc9254e3f0c623f60ad373507878fd18763d0a67 1 parent cae7104
@hdemers authored
Showing with 33 additions and 12 deletions.
  1. +2 −2 birdwtch/static/css/app.less
  2. +31 −10 birdwtch/static/js/stackedbar.js
View
4 birdwtch/static/css/app.less
@@ -225,9 +225,9 @@ footer {
height: 100%;
}
-.axis text {
+text {
font: 12px sans-serif;
- fill: @darkfont;
+ fill: @fontcolor;
}
.axis path,
View
41 birdwtch/static/js/stackedbar.js
@@ -5,7 +5,7 @@ define([
"d3"
],
function ($, _, d3) {
- var exports = {};
+ var exports = {}, y_text;
var sum = function (array) {
return _.reduce(array, function (memo, num) { return memo + num; }, 0);
@@ -16,7 +16,7 @@ function ($, _, d3) {
that.init = function () {
barWidth = 20;
- margin = {top: 0, right: 100, bottom: 0, left: 0};
+ margin = {top: 0, right: 320, bottom: 0, left: 0};
width = barWidth + margin.left + margin.right;
height = $(selector).height() - margin.top - margin.bottom;
y = d3.scale.linear().rangeRound([height, 0]);
@@ -29,8 +29,10 @@ function ($, _, d3) {
};
that.draw = function (data) {
- var bars, total = sum(_.pluck(data, 'frequency')), y0 = 0;
+ var bars, texts, total = sum(_.pluck(data, 'frequency')), y0 = 0;
+ data.sort(function (a, b) { return b.frequency - a.frequency; });
+
y.domain([0, total]);
data.forEach(function (d) {
@@ -40,20 +42,34 @@ function ($, _, d3) {
});
bars = svg.selectAll(".bar")
- .data(data);
+ .data(data, function (d) {return d.name; });
- bars.enter().append("rect")
- .attr("class", function (d) {return "bar " + d.class; })
- .attr("x", 0)
- .attr("y", function (d) { return y(d.y1); })
- .attr("width", barWidth)
- .attr("height", function (d) { return y(d.y0) - y(d.y1); });
+ bars.enter()
+ .append("rect")
+ .attr("class", function (d) {return "bar " + d.class; })
+ .attr("x", 0)
+ .attr("y", function (d) { return y(d.y1); })
+ .attr("width", barWidth)
+ .attr("height", function (d) { return y(d.y0) - y(d.y1); });
+
+ texts = svg.selectAll("text")
+ .data(data, function (d) {return d.name; });
+
+ texts.enter()
+ .append("text")
+ .attr("dy", "1em")
+ .attr("x", 30)
+ .attr("y", y_text)
+ .text(function (d) { return d.name; });
bars.transition()
.duration(700)
.attr("y", function (d) { return y(d.y1); })
.attr("height", function (d) { return y(d.y0) - y(d.y1); });
+ texts.transition()
+ .duration(700)
+ .attr("y", y_text);
};
that.redraw = function () {
@@ -64,6 +80,11 @@ function ($, _, d3) {
}
};
+ y_text = function (d, i) {
+ //var height = y(d.y0) - y(d.y1);
+ return y(d.y1);
+ };
+
that.init();
return that;
};
Please sign in to comment.
Something went wrong with that request. Please try again.