Files
growstuff/app/assets/javascripts/graphs/bar_group.js
Miles Gould 8083ae9052 Remove duplicate getBarValues() methods
I've replaced one with a getMaxValue() function, which is what we
actually want, and deleted the other.
2017-01-05 11:18:51 +00:00

51 lines
1.1 KiB
JavaScript

//= require graphs/width_scale
//= require graphs/height_scale
(function(){
'use strict';
/*
This represents bars for a bar graph.
Currently these are used for HorizontalBarGraph.
*/
var growstuff = (window.growstuff = window.growstuff || {});
var WidthScale = growstuff.WidthScale;
var HeightScale = growstuff.HeightScale;
function BarGroup(data) {
this._data = data;
}
BarGroup.prototype.render = function(root){
var data = this._data;
var bars = this._data.bars;
var widthScale = new WidthScale(data).render();
var heightScale = new HeightScale(data).render();
return root.append('g')
.attr("class", "bar")
.selectAll("rect")
.data(bars.map(function(bar) { return bar.value; }))
.enter()
.append("rect")
.attr("y", function(d, i){
return heightScale(i);
})
.attr("height", heightScale.rangeBand())
.attr("fill", data.bar_color)
.attr("width", function(d){
return widthScale(d);
})
.append("title")
.text(function(d){
return 'This value is ' + d + '.';
});
};
growstuff.BarGroup = BarGroup;
}());