mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
added method to get min and max from all data and tests
This commit is contained in:
parent
1225e2860f
commit
34803ed38e
2 changed files with 71 additions and 2 deletions
|
@ -37,8 +37,9 @@ define(function (require) {
|
|||
this.events = new Dispatch(handler);
|
||||
|
||||
// add allmin and allmax to geoJson
|
||||
chartData.geoJson.properties.allmin = chartData.geoJson.properties.min;
|
||||
chartData.geoJson.properties.allmax = chartData.geoJson.properties.max;
|
||||
var allMinMax = this.getMinMax(handler.data.data);
|
||||
chartData.geoJson.properties.allmin = allMinMax.min;
|
||||
chartData.geoJson.properties.allmax = allMinMax.max;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,6 +196,39 @@ define(function (require) {
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* get min and max for all cols, rows of data
|
||||
*
|
||||
* @method getMaxMin
|
||||
* @param data {Object}
|
||||
* @return {Object}
|
||||
*/
|
||||
TileMap.prototype.getMinMax = function (data) {
|
||||
var min = [];
|
||||
var max = [];
|
||||
var allData;
|
||||
|
||||
if (data.rows) {
|
||||
allData = data.rows;
|
||||
} else if (data.columns) {
|
||||
allData = data.columns;
|
||||
} else {
|
||||
allData = [data];
|
||||
}
|
||||
|
||||
allData.forEach(function (datum) {
|
||||
min.push(datum.geoJson.properties.min);
|
||||
max.push(datum.geoJson.properties.max);
|
||||
});
|
||||
|
||||
var minMax = {
|
||||
min: _.min(min),
|
||||
max: _.max(max)
|
||||
};
|
||||
|
||||
return minMax;
|
||||
};
|
||||
|
||||
/**
|
||||
* zoom map to fit all features in featureLayer
|
||||
*
|
||||
|
|
|
@ -196,6 +196,41 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMinMax method', function () {
|
||||
it('should return an object', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var data = chart.handler.data.data;
|
||||
expect(_.isObject(chart.getMinMax(data))).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the min of all features.properties.count', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var data = chart.handler.data.data;
|
||||
var min = _.chain(data.geoJson.features)
|
||||
.map(function (n) {
|
||||
return n.properties.count;
|
||||
})
|
||||
.min()
|
||||
.value();
|
||||
expect(chart.getMinMax(data).min).to.be(min);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the max of all features.properties.count', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var data = chart.handler.data.data;
|
||||
var max = _.chain(data.geoJson.features)
|
||||
.map(function (n) {
|
||||
return n.properties.count;
|
||||
})
|
||||
.max()
|
||||
.value();
|
||||
expect(chart.getMinMax(data).max).to.be(max);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue