mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-01 05:01:04 -05:00
34 lines
704 B
JavaScript
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;
|
|
|
|
}());
|