Merge branch 'fix/#1962' into negatives
Conflicts: src/kibana/components/vislib/lib/data.js
This commit is contained in:
commit
38b90a65ec
|
@ -127,7 +127,7 @@ define(function (require) {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
Data.prototype._createCache = function () {
|
||||
Data.prototype._createCache = _.memoize(function () {
|
||||
var cache = {
|
||||
index: {
|
||||
chart: 0,
|
||||
|
@ -140,7 +140,7 @@ define(function (require) {
|
|||
cache.count = this._getCounts(cache.index.chart, cache.index.stack);
|
||||
|
||||
return cache;
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Stacking function passed to the D3 Stack Layout `.out` API.
|
||||
|
@ -157,13 +157,6 @@ define(function (require) {
|
|||
this._cache = this._createCache();
|
||||
}
|
||||
|
||||
// debugging
|
||||
var da = data[this._cache.index.chart].series[this._cache.index.stack].values[this._cache.index.value];
|
||||
if (da && da.y !== 0) {
|
||||
dataCache[da.x] = dataCache[da.x] || [];
|
||||
dataCache[da.x].push(da);
|
||||
}
|
||||
|
||||
d.y0 = this._calcYZero(y, this._cache.yValsArr);
|
||||
++this._cache.index.stack;
|
||||
|
||||
|
@ -345,9 +338,6 @@ define(function (require) {
|
|||
* @returns {Number} Min y axis value
|
||||
*/
|
||||
Data.prototype.getYMinValue = function () {
|
||||
// 0 default option
|
||||
// custom min option - where they select the min value
|
||||
|
||||
var self = this;
|
||||
var arr = [];
|
||||
var grouped = (this._attr.mode === 'grouped');
|
||||
|
@ -368,9 +358,9 @@ define(function (require) {
|
|||
// push the calculated y value to the initialized array (arr)
|
||||
_.forEach(this.flatten(), function (series) {
|
||||
if (self.shouldBeStacked(series) && !grouped) {
|
||||
return arr.push(self.getYStackMin(series));
|
||||
return arr.push(self._getYExtent(series, self._getYStack, 'min'));
|
||||
}
|
||||
return arr.push(self.getYMin(series));
|
||||
return arr.push(self._getYExtent(series, self._getY, 'min'));
|
||||
});
|
||||
|
||||
return _.min(arr);
|
||||
|
@ -404,9 +394,9 @@ define(function (require) {
|
|||
// push the calculated y value to the initialized array (arr)
|
||||
_.forEach(this.flatten(), function (series) {
|
||||
if (self.shouldBeStacked(series) && !grouped) {
|
||||
return arr.push(self._getYMax(series, self._getYStack));
|
||||
return arr.push(self._getYExtent(series, self._getYStack, 'max'));
|
||||
}
|
||||
return arr.push(self._getYMax(series, self._getY));
|
||||
return arr.push(self._getYExtent(series, self._getY, 'max'));
|
||||
});
|
||||
|
||||
return _.max(arr);
|
||||
|
@ -425,59 +415,13 @@ define(function (require) {
|
|||
return this._attr.stack(series);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the smallest y stack value among all data objects
|
||||
*
|
||||
* @method getYStackMin
|
||||
* @param series {Array} Array of data objects
|
||||
* @returns {Number} Y stack max value
|
||||
*/
|
||||
Data.prototype.getYStackMin = function (series) {
|
||||
var isOrdered = (this.data.ordered && this.data.ordered.date);
|
||||
var minDate = isOrdered ? this.data.ordered.min : undefined;
|
||||
var maxDate = isOrdered ? this.data.ordered.max : undefined;
|
||||
|
||||
return d3.min(this.stackData(series), function (data) {
|
||||
return d3.min(data, function (d) {
|
||||
if (isOrdered) {
|
||||
return (d.x >= minDate && d.x <= maxDate) ? d.y0 + d.y : undefined;
|
||||
}
|
||||
|
||||
return d.y0 + d.y;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the max Y axis value for a `series` array based on
|
||||
* a specified callback function (calculation).
|
||||
*/
|
||||
Data.prototype._getYMax = function (series, calculation) {
|
||||
return d3.max(this.stackData(series), function (data) {
|
||||
return d3.max(data, calculation);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the Y domain min value
|
||||
*
|
||||
* @method getYMin
|
||||
* @param series {Array} Array of data objects
|
||||
* @returns {Number} Y domain min value
|
||||
*/
|
||||
Data.prototype.getYMin = function (series) {
|
||||
var isOrdered = (this.data.ordered && this.data.ordered.date);
|
||||
var minDate = isOrdered ? this.data.ordered.min : undefined;
|
||||
var maxDate = isOrdered ? this.data.ordered.max : undefined;
|
||||
|
||||
return d3.min(series, function (data) {
|
||||
return d3.min(data, function (d) {
|
||||
if (isOrdered) {
|
||||
return (d.x >= minDate && d.x <= maxDate) ? d.y : undefined;
|
||||
}
|
||||
|
||||
return d.y;
|
||||
});
|
||||
Data.prototype._getYExtent = function (series, calculation, extent) {
|
||||
return d3[extent](this.stackData(series), function (data) {
|
||||
return d3[extent](data, calculation);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -282,18 +282,18 @@ define(function (require) {
|
|||
it('should return the Y domain min value', function () {
|
||||
series.forEach(function (data) {
|
||||
if (!visData.shouldBeStacked(data)) {
|
||||
expect(visData.getYMinValue(data)).to.be(minValue);
|
||||
expect(visData.getYMinValue()).to.be(minValue);
|
||||
} else {
|
||||
expect(visData.getYMinValue(data)).to.be(stackedMinValue);
|
||||
expect(visData.getYMinValue()).to.be(stackedMinValue);
|
||||
}
|
||||
});
|
||||
|
||||
series.forEach(function (data) {
|
||||
expect(visData.getYMin(data)).to.be(minValue);
|
||||
expect(visData._getYExtent(data, visData._getY, 'min')).to.be(minValue);
|
||||
});
|
||||
|
||||
stackedSeries.forEach(function (data) {
|
||||
expect(stackedVisData.getYStackMin(data)).to.be(stackedMinValue);
|
||||
expect(stackedVisData._getYExtent(data, visData._getYStack, 'min')).to.be(stackedMinValue);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -337,10 +337,10 @@ define(function (require) {
|
|||
// when calculating the Y max value since it falls outside of the range.
|
||||
it('should return the Y domain max value', function () {
|
||||
series.forEach(function (data) {
|
||||
expect(visData._getYMax(data, visData._getY)).to.be(maxValue);
|
||||
expect(visData._getYExtent(data, visData._getY, 'max')).to.be(maxValue);
|
||||
});
|
||||
stackedSeries.forEach(function (data) {
|
||||
expect(stackedVisData._getYMax(data, visData._getYStack)).to.be(stackedMaxValue);
|
||||
expect(stackedVisData._getYExtent(data, visData._getYStack, 'max')).to.be(stackedMaxValue);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -207,6 +207,7 @@ define(function (require) {
|
|||
vis.handler.charts.forEach(function (chart) {
|
||||
var yAxis = chart.handler.yAxis;
|
||||
var yVals = [vis.handler.data.getYMinValue(), vis.handler.data.getYMaxValue()];
|
||||
console.log(yAxis, yVals, vis);
|
||||
|
||||
expect(yAxis.yMin).to.equal(yVals[0]);
|
||||
expect(yAxis.yMax).to.equal(yVals[1]);
|
||||
|
|
Loading…
Reference in a new issue