src/js/util/helper.js
function compute_scale_domain(scaleObj, data, opts) {
	// Compute the domain (`[min, max]`) of a scale based on its data points.
	// `data` is a flat array of all values used in this scale, and is
	// created by `input-parsers/parse-<chart>.js`
	opts = opts || {};
	var scaleDomain = scaleObj.domain || [];
	var _domain;
	var defaultMin;
	var defaultMax;

	if (!isArray(data)) {
		throw new TypeError("data passed to compute_scale_domain must be an array");
	}

	var extent = d3.extent(data);
	var niced = d3.scale.linear()
			.domain(extent)
			.nice()
			.domain();

	if (!scaleObj.domain || !scaleObj.custom) {
		if (opts.nice) {
			_domain = niced;
		} else {
			_domain = extent;
		}
		defaultMin = true;
		defaultMax = true;
	} else {
		_domain = (opts.nice) ? niced : extent;
		defaultMin = (_domain[0] === scaleDomain[0] || isUndefined(scaleDomain[0]));
		defaultMax = (_domain[1] === scaleDomain[1] || isUndefined(scaleDomain[1]));
		_domain = scaleDomain;
	}

	if (opts.minZero) {
		_domain[0] = Math.min(_domain[0], 0);
	}

	return {
		domain: _domain,
		custom: (!defaultMin || !defaultMax)
	};
}
function compute_scale_domain(scaleObj, data, opts) {
	// Compute the domain (`[min, max]`) of a scale based on its data points.
	// `data` is a flat array of all values used in this scale, and is
	// created by `input-parsers/parse-<chart>.js`
	opts = opts || {};
	var scaleDomain = scaleObj.domain || [];
	var _domain;
	var defaultMin;
	var defaultMax;

	if (!isArray(data)) {
		throw new TypeError("data passed to compute_scale_domain must be an array");
	}

	var extent = d3.extent(data);
	var niced = d3.scale.linear()
			.domain(extent)
			.nice()
			.domain();

	if (!scaleObj.domain || !scaleObj.custom) {
		if (opts.nice) {
			_domain = niced;
		} else {
			_domain = extent;
		}
		defaultMin = true;
		defaultMax = true;
	} else {
		_domain = (opts.nice) ? niced : extent;
		defaultMin = (_domain[0] === scaleDomain[0] || isUndefined(scaleDomain[0]));
		defaultMax = (_domain[1] === scaleDomain[1] || isUndefined(scaleDomain[1]));
		_domain = scaleDomain;
	}

	if (opts.minZero) {
		_domain[0] = Math.min(_domain[0], 0);
	}

	return {
		domain: _domain,
		custom: (!defaultMin || !defaultMax)
	};
}
function compute_scale_domain ( scaleObj , data , opts ) { // Compute the domain (`[min, max]`) of a scale based on its data points. // `data` is a flat array of all values used in this scale, and is // created by `input-parsers/parse-<chart>.js` opts = opts || { } ; var scaleDomain = scaleObj . domain || [ ] ; var _domain ; var defaultMin ; var defaultMax ; if ( ! isArray ( data ) ) { throw new TypeError ( "data passed to compute_scale_domain must be an array" ) ; } var extent = d3 . extent ( data ) ; var niced = d3 . scale . linear ( ) . domain ( extent ) . nice ( ) . domain ( ) ; if ( ! scaleObj . domain || ! scaleObj . custom ) { if ( opts . nice ) { _domain = niced ; } else { _domain = extent ; } defaultMin = true ; defaultMax = true ; } else { _domain = ( opts . nice ) ? niced : extent ; defaultMin = ( _domain [ 0 ] === scaleDomain [ 0 ] || isUndefined ( scaleDomain [ 0 ] ) ) ; defaultMax = ( _domain [ 1 ] === scaleDomain [ 1 ] || isUndefined ( scaleDomain [ 1 ] ) ) ; _domain = scaleDomain ; } if ( opts . minZero ) { _domain [ 0 ] = Math . min ( _domain [ 0 ] , 0 ) ; } return { domain : _domain , custom : ( ! defaultMin || ! defaultMax ) } ; }
compute_scale_domain

@param scaleObj - Current scale before generating new domain
@param {number[]} data - All values in the current scale
@param {object} opts - Whether to return nice values or force a minimum of 0
or below
@return {object} { domain: [min, max], custom: <boolean> }
@static
@memberof helper
compute_scale_domain