diff --git a/src/choroplethFeature.js b/src/choroplethFeature.js index 7fd7262e2f..99b2575bb9 100644 --- a/src/choroplethFeature.js +++ b/src/choroplethFeature.js @@ -46,15 +46,15 @@ var choroplethFeature = function (arg) { ], scale: d3.scale.quantize(), accessors: { - //accessor for ID on geodata feature + //accessor for ID on geodata feature geoId: function (geoFeature) { return geoFeature.properties.GEO_ID; }, - //accessor for ID on scalar element + //accessor for ID on scalar element scalarId: function (scalarElement) { return scalarElement.id; }, - //accessor for value on scalar element + //accessor for value on scalar element scalarValue: function (scalarElement) { return scalarElement.value; } diff --git a/tests/cases/choroplethFeature.js b/tests/cases/choroplethFeature.js new file mode 100644 index 0000000000..7661192d71 --- /dev/null +++ b/tests/cases/choroplethFeature.js @@ -0,0 +1,68 @@ +// Test geo.choroplethFeature and geo.gl.choroplethFeature + +var geo = require('../test-utils').geo; +var $ = require('jquery'); +var mockVGLRenderer = require('../test-utils').mockVGLRenderer; +var restoreVGLRenderer = require('../test-utils').restoreVGLRenderer; + +describe('geo.choroplethFeature', function () { + 'use strict'; + + function create_map(opts) { + var node = $('
').css({width: '640px', height: '360px'}); + $('#map').remove(); + $('body').append(node); + opts = $.extend({}, opts); + opts.node = node; + return geo.map(opts); + } + + var mpdata = [{ + 'type': 'Feature', + 'geometry': { + 'type': 'MultiPolygon', + 'coordinates': [ + [ + [ + [101.2, 1.2], [101.8, 1.2], [101.8, 1.8], [101.2, 1.8], [101.2, 1.2] + ], + ], + [ + [ + [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] + ], + ] + ] + }, + 'properties': { + 'GEO_ID': 0 + } + }]; + + describe('create', function () { + it('create function', function () { + mockVGLRenderer(); + var map, layer, choropleth; + map = create_map(); + layer = map.createLayer('feature', {renderer: 'vgl'}); + choropleth = layer.createFeature('choropleth'); + expect(choropleth instanceof geo.choroplethFeature).toBe(true); + restoreVGLRenderer(); + }); + + it('multipolygon', function () { + mockVGLRenderer(); + var map, layer, choropleth, + scalarValues = [{'id': 0, 'value': 10}]; + + map = create_map(); + layer = map.createLayer('feature', {renderer: 'vgl'}); + choropleth = layer.createFeature('choropleth') + .data(mpdata) + .scalar(scalarValues) + .choropleth({}); + expect(choropleth instanceof geo.choroplethFeature).toBe(true); + restoreVGLRenderer(); + }); + }); +});