Merge pull request #3614 from stormpython/fix/3604

Fixing regression issue with Zoom to Data Bounds Option
This commit is contained in:
Spencer 2015-05-04 08:12:37 -07:00
commit 7b3308a138
10 changed files with 82 additions and 16 deletions

View file

@ -401,7 +401,7 @@ define(function (require) {
* @returns {*} Array of data objects with x, y, y0 keys
*/
Data.prototype.stackData = function (series) {
// SHould not stack values on line chart
// Should not stack values on line chart
if (this._attr.type === 'line') return series;
return this._attr.stack(series);
};

View file

@ -74,6 +74,10 @@ define(function (require) {
return [Math.max(1, yMin), yMax];
};
YAxis.prototype._setDefaultYExtents = function () {
return this._attr.defaultYExtents;
};
/**
* Returns the domain, i.e. the extent of the y axis
*
@ -83,6 +87,7 @@ define(function (require) {
* @returns {*[]}
*/
YAxis.prototype.getDomain = function (scale, yMin, yMax) {
if (this._setDefaultYExtents()) return [yMin, yMax];
if (scale === 'log') return this.returnLogDomain(yMin, yMax); // Negative values cannot be displayed with a log scale.
if (yMin === 0 && yMax === 0) return this.throwNoResultsError(); // yMin and yMax can never both be equal to zero
@ -97,10 +102,15 @@ define(function (require) {
* @returns {D3.Scale.QuantitiveScale|*} D3 yScale function
*/
YAxis.prototype.getYScale = function (height) {
return this.yScale = this.getScaleType(this._attr.scale)
this.yScale = this.getScaleType(this._attr.scale)
.domain(this.getDomain(this._attr.scale, this.yMin, this.yMax))
.range([height, 0])
.nice();
.range([height, 0]);
// Nicing the scale, rounds values down or up to make the scale look better
// When defaultYExtents are selected, the extents (i.e. min and max) should
// be shown without any rounding.
if (!this._attr.defaultYExtents) return this.yScale.nice();
return this.yScale;
};
YAxis.prototype.tickFormat = function () {

View file

@ -0,0 +1,14 @@
<div>
<div class="vis-option-item">
<label>
<input type="checkbox" ng-model="vis.params.defaultYExtents">
Scale Y-Axis to Data Bounds
</label>
</div>
<div class="vis-option-item" ng-show="vis.hasSchemaAgg('segment', 'date_histogram')">
<label>
<input type="checkbox" ng-model="vis.params.addTimeMarker">
Current time marker
</label>
</div>
</div>

View file

@ -0,0 +1,13 @@
define(function (require) {
var _ = require('lodash');
var $ = require('jquery');
var module = require('modules').get('kibana');
module.directive('pointSeriesOptions', function ($parse, $compile) {
return {
restrict: 'E',
template: require('text!plugins/vis_types/controls/point_series_options.html'),
replace: true
};
});
});

View file

@ -11,16 +11,4 @@
Show Legend
</label>
</div>
<div class="vis-option-item">
<label>
<input type="checkbox" ng-model="vis.params.defaultYExtents" ng-checked="vis.params.defaultYExtents">
Scale Y-Axis to Data Bounds
</label>
</div>
<div class="vis-option-item" ng-show="vis.hasSchemaAgg('segment', 'date_histogram')">
<label>
<input type="checkbox" ng-model="vis.params.addTimeMarker" ng-checked="vis.params.addTimeMarker">
Current time marker
</label>
</div>
</div>

View file

@ -9,6 +9,7 @@ define(function (require) {
require('plugins/vis_types/controls/vislib_basic_options');
require('plugins/vis_types/controls/line_interpolation_option');
require('plugins/vis_types/controls/point_series_options');
_(VislibVisType).inherits(VisType);
function VislibVisType(opts) {

View file

@ -8,3 +8,4 @@
</div>
<line-interpolation-option></line-interpolation-option>
<vislib-basic-options></vislib-basic-options>
<point-series-options></point-series-options>

View file

@ -6,3 +6,4 @@
<select class="form-control" ng-model="vis.params.mode" ng-options="mode for mode in vis.type.params.modes"></select>
</div>
<vislib-basic-options></vislib-basic-options>
<point-series-options></point-series-options>

View file

@ -20,3 +20,4 @@
</div>
</div>
<vislib-basic-options></vislib-basic-options>
<point-series-options></point-series-options>

View file

@ -209,6 +209,23 @@ define(function (require) {
checkRange();
});
});
describe('should not return a nice scale when defaultYExtents is true', function () {
beforeEach(function () {
createData(defaultGraphData);
yAxis._attr.defaultYExtents = true;
yAxis.getYAxis(height);
yAxis.render();
});
it('not return a nice scale', function () {
var min = _.min(_.flatten(defaultGraphData));
var max = _.max(_.flatten(defaultGraphData));
var domain = yAxis.yAxis.scale().domain();
expect(domain[0]).to.be(min);
expect(domain[1]).to.be(max);
});
});
});
describe('getScaleType method', function () {
@ -251,6 +268,13 @@ define(function (require) {
});
describe('getDomain method', function () {
beforeEach(function () {
// Need to set this to false before each test since its
// status changes in one of the tests below. Having this set to
// true causes other tests to fail that need this attr to be set to false.
yAxis._attr.defaultYExtents = false;
});
it('should return a log domain', function () {
var scale = 'log';
var yMin = 0;
@ -261,6 +285,19 @@ define(function (require) {
expect(domain[0]).to.be(1);
});
it('should return the default y axis extents (i.e. the min and max values)', function () {
var scale = 'linear';
var yMin = 25;
var yMax = 150;
var domain;
yAxis._attr.defaultYExtents = true;
domain = yAxis.getDomain(scale, yMin, yMax);
expect(domain[0]).to.be(yMin);
expect(domain[1]).to.be(yMax);
});
it('should throw a no results error if yMin and yMax values are both 0', function () {
expect(function () {
yAxis.getDomain('linear', 0, 0);