mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-01 13:10:58 -05:00
38 lines
807 B
JavaScript
38 lines
807 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 || {});
|
|
|
|
/**
|
|
* Object for WidthScale
|
|
* @param {Object} data Graph configuration
|
|
*/
|
|
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;
|
|
}());
|