Skip to content

Commit

Permalink
Merge branch 'fix/elastic#1962' into negatives
Browse files Browse the repository at this point in the history
Conflicts:
	src/kibana/components/vislib/lib/data.js
  • Loading branch information
w33ble committed Feb 5, 2015
2 parents 5483bfd + 215e8c4 commit 38b90a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 71 deletions.
74 changes: 9 additions & 65 deletions src/kibana/components/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ define(function (require) {
/**
*
*/
Data.prototype._createCache = function () {
Data.prototype._createCache = _.memoize(function () {
var cache = {
index: {
chart: 0,
Expand All @@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
});
};

Expand Down
12 changes: 6 additions & 6 deletions test/unit/specs/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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);
});
});

Expand Down
1 change: 1 addition & 0 deletions test/unit/specs/vislib/visualizations/column_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 38b90a6

Please sign in to comment.