Files
growstuff/app/assets/javascripts/graphs/width_scale.js
Brenda Wallace d2a060ad49 added JSDoc
2018-01-23 09:00:34 +13:00

39 lines
778 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 {?} data Graph data
*/
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;
}());