Skip to content

Commit

Permalink
Rename mapColor to color.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Oct 28, 2016
1 parent 6e73a80 commit 8f65be1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/pixelmap/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
28 changes: 14 additions & 14 deletions src/pixelmapFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down
18 changes: 9 additions & 9 deletions tests/cases/pixelmapFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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');
});
});

Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 8f65be1

Please sign in to comment.