mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-01 13:10:58 -05:00
I've replaced one with a getMaxValue() function, which is what we actually want, and deleted the other.
51 lines
1.1 KiB
JavaScript
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;
|
|
|
|
}());
|