From 8f65be1527e360678329b8dbf61845a32df38c86 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 28 Oct 2016 12:02:14 -0400 Subject: [PATCH] Rename mapColor to color. --- examples/pixelmap/main.js | 2 +- src/pixelmapFeature.js | 28 ++++++++++++++-------------- tests/cases/pixelmapFeature.js | 18 +++++++++--------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/pixelmap/main.js b/examples/pixelmap/main.js index c8caab585b..3610cb0c54 100644 --- a/examples/pixelmap/main.js +++ b/examples/pixelmap/main.js @@ -35,7 +35,7 @@ $(function () { selectionAPI: true, url: pixelmapUrl, position: {ul: {x: -180, y: 71.471178}, lr: {x: -60, y: 13.759032}}, - mapColor: function (d, idx) { + color: function (d, idx) { // Always set index 0 to transparent. Other indicies are set based on // the data value var color = {r: 0, g: 0, b: 0, a: 0}; diff --git a/src/pixelmapFeature.js b/src/pixelmapFeature.js index c657fa33a9..43c5edb237 100644 --- a/src/pixelmapFeature.js +++ b/src/pixelmapFeature.js @@ -14,10 +14,10 @@ var util = require('./util'); * @param {Object|Function|HTMLImageElement} [url] URL of a pixel map or an * HTML Image element. The rgb data is interpretted as an index of the form * 0xbbggrr. The alpha channel is ignored. - * @param {Object|Function} [mapColor] The color that should be used for each - * data element. Data elements correspond to the indices in the pixel map. - * If an index is larger than the number of data elements, it will be - * transparent. If there is more data than there are indices, it is ignored. + * @param {Object|Function} [color] The color that should be used for each data + * element. Data elements correspond to the indices in the pixel map. If an + * index is larger than the number of data elements, it will be transparent. + * If there is more data than there are indices, it is ignored. * @param {Object|Function} [position] Position of the image. Default is * (data). The position is an Object which specifies the corners of the * quad: ll, lr, ur, ul. At least two opposite corners must be specified. @@ -119,16 +119,16 @@ var pixelmapFeature = function (arg) { //////////////////////////////////////////////////////////////////////////// /** - * Get/Set mapColor accessor + * Get/Set color accessor * * @returns {geo.pixelmap} */ //////////////////////////////////////////////////////////////////////////// - this.mapColor = function (val) { + this.color = function (val) { if (val === undefined) { - return m_this.style('mapColor'); - } else if (val !== m_this.style('mapColor')) { - m_this.style('mapColor', val); + return m_this.style('color'); + } else if (val !== m_this.style('color')) { + m_this.style('color', val); m_this.dataTime().modified(); m_this.modified(); } @@ -273,7 +273,7 @@ var pixelmapFeature = function (arg) { */ this._computePixelmap = function () { var data = m_this.data() || [], - mapColorFunc = m_this.style.get('mapColor'), + colorFunc = m_this.style.get('color'), i, idx, lastidx, color, pixelData, indices, mappedColors, updateFirst, updateLast = -1, update, prepared; @@ -287,7 +287,7 @@ var pixelmapFeature = function (arg) { updateFirst = m_info.area; for (idx in mappedColors) { if (mappedColors.hasOwnProperty(idx)) { - color = mapColorFunc(data[idx], +idx) || {}; + color = colorFunc(data[idx], +idx) || {}; color = [ (color.r || 0) * 255, (color.g || 0) * 255, @@ -398,7 +398,7 @@ var pixelmapFeature = function (arg) { var style = $.extend( {}, { - mapColor: function (d, idx) { + color: function (d, idx) { return { r: (idx & 0xFF) / 255, g: ((idx >> 8) & 0xFF) / 255, @@ -416,8 +416,8 @@ var pixelmapFeature = function (arg) { if (arg.url !== undefined) { style.url = arg.url; } - if (arg.mapColor !== undefined) { - style.mapColor = arg.mapColor; + if (arg.color !== undefined) { + style.color = arg.color; } m_this.style(style); m_this.dataTime().modified(); diff --git a/tests/cases/pixelmapFeature.js b/tests/cases/pixelmapFeature.js index d3bfc6ebf4..14136bf95c 100644 --- a/tests/cases/pixelmapFeature.js +++ b/tests/cases/pixelmapFeature.js @@ -60,21 +60,21 @@ describe('geo.pixelmapFeature', function () { layer = map.createLayer('feature', {renderer: null}); pixelmap = geo.pixelmapFeature({layer: layer}); pixelmap._init(); - expect(pixelmap.mapColor()(0, 0)).toEqual({r: 0, g: 0, b: 0, a: 1}); + expect(pixelmap.color()(0, 0)).toEqual({r: 0, g: 0, b: 0, a: 1}); }); it('arg gets added to style', function () { pixelmap = geo.pixelmapFeature({layer: layer}); /* init is not automatically called on the geo.pixelmapFeature (it is * on geo.canvas.pixelmapFeature). */ pixelmap._init({ - mapColor: 'red', + color: 'red', position: position, url: testImageSrc, style: {position: {ul: {x: 1}}} }); expect(pixelmap.style('position').ul.x).toBe(-140); expect(pixelmap.style('url').slice(0, 4)).toBe('data'); - expect(pixelmap.style('mapColor')).toBe('red'); + expect(pixelmap.style('color')).toBe('red'); }); }); it('_exit', function () { @@ -256,14 +256,14 @@ describe('geo.pixelmapFeature', function () { pixelmap._update(); expect(pixelmap.maxIndex()).toBe(6); }); - it('mapColor', function () { + it('color', function () { var colorFunc = function (d, i) { return i & 1 ? 'red' : 'blue'; }; - expect(pixelmap.mapColor()(0, 2)).toEqual({r: 2 / 255, g: 0, b: 0, a: 1}); - expect(pixelmap.mapColor(colorFunc)).toBe(pixelmap); - expect(pixelmap.mapColor()(0, 2)).toEqual('blue'); - expect(pixelmap.mapColor()(0, 3)).toEqual('red'); + expect(pixelmap.color()(0, 2)).toEqual({r: 2 / 255, g: 0, b: 0, a: 1}); + expect(pixelmap.color(colorFunc)).toBe(pixelmap); + expect(pixelmap.color()(0, 2)).toEqual('blue'); + expect(pixelmap.color()(0, 3)).toEqual('red'); }); }); @@ -330,7 +330,7 @@ describe('geo.pixelmapFeature', function () { var colorFunc = function (d, i) { return i & 1 ? 'red' : 'blue'; }; - pixelmap.mapColor(colorFunc); + pixelmap.color(colorFunc); counts = $.extend({}, window._canvasLog.counts); pixelmap.draw(); });