Files
growstuff/app/assets/javascripts/graphs/width_scale.js
2017-03-04 17:06:29 +13:00

34 lines
704 B
JavaScript

//=require d3
/*
Width scale is used to map the value for the length of each bar
to the display size of the svg
*/
(function(){
'use strict';
var growstuff = (window.growstuff = window.growstuff || {});
function WidthScale (data){
this._data = data;
}
WidthScale.prototype.render = function() {
var data = this._data;
var scaleType = data.width.scale;
var axisSize = data.width.size;
return d3.scale[scaleType]()
.domain([0, this.getMaxValue()])
.range([0, axisSize]);
};
WidthScale.prototype.getMaxValue = function(){
return d3.max(this._data.bars.map(function(bar) { return bar.value; }));
};
growstuff.WidthScale = WidthScale;
}());