Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into fix/elastic#1962

Conflicts:
	src/kibana/components/vislib/vis.js
  • Loading branch information
Juan Thomassie committed Jan 20, 2015
2 parents ba5dd2a + 3105008 commit c4e7d34
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 41 deletions.
36 changes: 0 additions & 36 deletions src/kibana/components/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ define(function (require) {
return new Data(data, attr);
}

var self = this;
var offset;

if (attr.mode === 'stacked') {
Expand Down Expand Up @@ -115,41 +114,6 @@ define(function (require) {
return visData;
};

/**
* Function to determine whether to display the legend or not
* Displays legend when more than one series of data present
*
* @method isLegendShown
* @returns {boolean}
*/
Data.prototype.isLegendShown = function () {
var isLegend = false;
var visData = this.getVisData();
var sameSeriesLabel = true;
var seriesLabel;

_.forEach(visData, function countSeriesLength(obj) {
var rootSeries = obj.series || (obj.slices && obj.slices.children);
var dataLength = rootSeries ? rootSeries.length : 0;
var label = dataLength === 1 ? rootSeries[0].label || rootSeries[0].name : undefined;
var children = (obj.slices && obj.slices.children && obj.slices.children[0] && obj.slices.children[0].children);

if (!seriesLabel) {
seriesLabel = label;
}

if (seriesLabel !== label) {
sameSeriesLabel = false;
}

if (dataLength > 1 || children || !sameSeriesLabel) {
isLegend = true;
}
});

return isLegend;
};

/**
* Returns array of chart data objects for pie data objects
*
Expand Down
4 changes: 2 additions & 2 deletions src/kibana/components/vislib/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ define(function (require) {
Vis.Super.apply(this, arguments);
this.el = $el.get ? $el.get(0) : $el;
this.ChartClass = chartTypes[config.type];
this._attr = _.defaults(config || {}, {
defaultYMin: false
this._attr = _.defaults({}, config || {}, {
defaultYMin: true
});
this.eventTypes = {
enabled: []
Expand Down
5 changes: 2 additions & 3 deletions test/unit/specs/plugins/vis_types/vislib/_renderbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ define(function (require) {
Renderbot = Private(require('plugins/vis_types/_renderbot'));
VislibRenderbot = Private(require('plugins/vis_types/vislib/_vislib_renderbot'));
normalizeChartData = Private(require('components/agg_response/index'));

});
}

Expand Down Expand Up @@ -85,7 +84,7 @@ define(function (require) {
}
}, mockVisType)
};
var $el = 'element';
var $el = $('<div>testing</div>');
var createVisSpy;
var getParamsStub;
var renderbot;
Expand All @@ -100,7 +99,7 @@ define(function (require) {
it('should create a new Vis object when params change', function () {
// called on init
expect(createVisSpy.callCount).to.be(1);
renderbot.updateParams(_.clone(params));
renderbot.updateParams();
// not called again, same params
expect(createVisSpy.callCount).to.be(2);
renderbot.vis.params = { one: 'fishy', two: 'fishy' };
Expand Down
56 changes: 56 additions & 0 deletions test/unit/specs/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,62 @@ define(function (require) {
});
});

describe('getYMinValue method', function () {
var Data;
var dataSeries;
var stackedDataSeries;
var visData;
var stackedVisData;
var series;
var stackedSeries;
var minValue;
var stackedMinValue;

beforeEach(function () {
module('DataFactory');
});

beforeEach(function () {
inject(function (d3, Private) {
Data = Private(require('components/vislib/lib/data'));
dataSeries = require('vislib_fixtures/mock_data/date_histogram/_series');
stackedDataSeries = require('vislib_fixtures/mock_data/stacked/_stacked');
visData = new Data(dataSeries, {});
stackedVisData = new Data(stackedDataSeries, {});
series = visData.flatten();
stackedSeries = stackedVisData.flatten();
minValue = 4;
stackedMinValue = 15;
});
});

// The first value in the time series is less than the min date in the
// date range. It also has the largest y value. This value should be excluded
// when calculating the Y max value since it falls outside of the range.
it('should return the Y domain min value', function () {
series.forEach(function (data) {
if (!visData.shouldBeStacked(data)) {
expect(visData.getYMinValue(data)).to.be(minValue);
} else {
expect(visData.getYMinValue(data)).to.be(stackedMinValue);
}
});

series.forEach(function (data) {
expect(visData.getYMin(data)).to.be(minValue);
});

stackedSeries.forEach(function (data) {
expect(stackedVisData.getYStackMin(data)).to.be(stackedMinValue);
});
});

it('should have a minimum date value that is greater than the max value within the date range', function () {
expect(_.min(series, function (d) { return d.x; })).to.be.greaterThan(minValue);
expect(_.min(stackedSeries, function (d) { return d.x; })).to.be.greaterThan(stackedMinValue);
});
});

describe('getYMaxValue method', function () {
var Data;
var dataSeries;
Expand Down

0 comments on commit c4e7d34

Please sign in to comment.