rename dataToHeatArray, add tests

This commit is contained in:
Joe Fleming 2015-06-24 11:01:33 -07:00
parent 885087f87e
commit 214e1af00c
2 changed files with 53 additions and 4 deletions

View file

@ -29,7 +29,7 @@ define(function (require) {
HeatmapMarker.prototype._createMarkerGroup = function (options) {
var max = _.get(this.geoJson, 'properties.allmax');
var points = this.dataToHeatArray(max);
var points = this._dataToHeatArray(max);
this._markerGroup = L.heatLayer(points, options);
this._fixTooltips();
@ -159,10 +159,10 @@ define(function (require) {
*
* @param mapData {geoJson Object}
* @param nax {Number}
* @method dataToHeatArray
* @method _dataToHeatArray
* @return {Array}
*/
HeatmapMarker.prototype.dataToHeatArray = function (max) {
HeatmapMarker.prototype._dataToHeatArray = function (max) {
var self = this;
var mapData = this.geoJson;

View file

@ -197,7 +197,6 @@ define(function (require) {
});
describe('Scaled Circles', function () {
this.timeout(0);
var zoom;
beforeEach(function () {
@ -250,5 +249,55 @@ define(function (require) {
});
});
describe('Heatmaps', function () {
beforeEach(function () {
module('MarkerFactory');
inject(function (Private) {
var MarkerClass = Private(require('components/vislib/visualizations/marker_types/heatmap'));
markerLayer = createMarker(MarkerClass);
});
});
describe('dataToHeatArray method', function () {
var max;
beforeEach(function () {
max = mapData.properties.allmax;
});
it('should return an array or values for each feature', function () {
var arr = markerLayer._dataToHeatArray(max);
expect(arr).to.be.an('array');
expect(arr).to.have.length(mapData.features.length);
});
it('should return an array item with lat, lng, metric for each feature', function () {
_.times(3, function () {
var arr = markerLayer._dataToHeatArray(max);
var index = _.random(mapData.features.length - 1);
var feature = mapData.features[index];
var featureValue = feature.properties.value;
var featureArr = feature.geometry.coordinates.slice(0).reverse().concat(featureValue);
expect(arr[index]).to.eql(featureArr);
});
});
it('should return an array item with lat, lng, normalized metric for each feature', function () {
_.times(3, function () {
markerLayer._attr.heatNormalizeData = true;
var arr = markerLayer._dataToHeatArray(max);
var index = _.random(mapData.features.length - 1);
var feature = mapData.features[index];
var featureValue = parseInt(feature.properties.value / max * 100);
var featureArr = feature.geometry.coordinates.slice(0).reverse().concat(featureValue);
expect(arr[index]).to.eql(featureArr);
});
});
});
});
});
});