move TileMap.getMinMax to Data.getGeoExtents

This commit is contained in:
Joe Fleming 2015-06-22 16:58:29 -07:00
parent 89f12e3ad9
commit 5d03edd90e
3 changed files with 22 additions and 67 deletions

View file

@ -243,6 +243,25 @@ define(function (require) {
return visData;
};
/**
* get min and max for all cols, rows of data
*
* @method getMaxMin
* @param data {Object}
* @return {Object}
*/
Data.prototype.getGeoExtents = function () {
var min = [];
var max = [];
var visData = this.getVisData();
return _.reduce(_.pluck(visData, 'geoJson.properties'), function (minMax, props) {
if (minMax.min > props.min) minMax.min = props.min;
if (minMax.max < props.max) minMax.max = props.max;
return minMax;
}, { min: Infinity, max: -Infinity });
};
/**
* Returns array of chart data objects for pie data objects
*

View file

@ -40,9 +40,9 @@ define(function (require) {
_.assign(this, this._chartData);
// add allmin and allmax to geoJson
var allMinMax = this.getMinMax(handler.data.data);
this.geoJson.properties.allmin = allMinMax.min;
this.geoJson.properties.allmax = allMinMax.max;
var geoMinMax = handler.data.getGeoExtents();
this.geoJson.properties.allmin = geoMinMax.min;
this.geoJson.properties.allmax = geoMinMax.max;
}
/**
@ -94,39 +94,6 @@ 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;
};
/**
* add Leaflet latLng to mapData properties
*

View file

@ -153,37 +153,6 @@ define(function (require) {
destroyVis(vis);
});
describe('getMinMax method', function () {
it('should return an object', function () {
vis.handler.charts.forEach(function (chart) {
var data = chart.handler.data.data;
expect(chart.getMinMax(data)).to.be.an(Object);
});
});
it('should return the min of all features.properties.value', function () {
vis.handler.charts.forEach(function (chart) {
var data = chart.handler.data.data;
var min = _.chain(data.geoJson.features)
.pluck('properties.value')
.min()
.value();
expect(chart.getMinMax(data).min).to.be(min);
});
});
it('should return the max of all features.properties.value', function () {
vis.handler.charts.forEach(function (chart) {
var data = chart.handler.data.data;
var max = _.chain(data.geoJson.features)
.pluck('properties.value')
.max()
.value();
expect(chart.getMinMax(data).max).to.be(max);
});
});
});
describe('addLatLng method', function () {
it('should add object to properties of each feature', function () {
vis.handler.charts.forEach(function (chart) {