Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Bug] Fix radius rendering when value = 0 (#551)

Shan He36ba1b0fd8fb
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.js
index 032de569a..5a84e06d2 100644
--- a/examples/demo-app/src/app.js
+++ b/examples/demo-app/src/app.js
@@ -160,9 +160,9 @@ class App extends Component {
}
_loadSampleData() {
- // this._loadTripData();
- this._loadGeojsonData();
- this._loadIconData();
+ this._loadTripData();
+ // this._loadGeojsonData();
+ // this._loadIconData();
// this._loadH3HexagonData();
}
diff --git a/examples/demo-app/src/data/sample-trip-data.js b/examples/demo-app/src/data/sample-trip-data.js
index f9c2494a3..c2c1a88c0 100644
--- a/examples/demo-app/src/data/sample-trip-data.js
+++ b/examples/demo-app/src/data/sample-trip-data.js
@@ -65,7 +65,7 @@ export default {
[
'2015-01-15 19:05:39 +00:00',
'2015-01-15 19:32:00 +00:00',
- 1,
+ 0,
2.38,
-73.97642517,
40.73981094,
@@ -130,7 +130,7 @@ export default {
[
'2015-01-15 19:05:41 +00:00',
'2015-01-15 19:31:00 +00:00',
- 1,
+ 0,
3.6,
-73.97660065,
40.7518959,
@@ -208,7 +208,7 @@ export default {
[
'2015-01-15 19:05:42 +00:00',
'2015-01-15 19:16:18 +00:00',
- 1,
+ 0,
1.53,
-73.99112701,
40.75008011,
@@ -273,7 +273,7 @@ export default {
[
'2015-01-15 19:05:43 +00:00',
'2015-01-15 19:17:43 +00:00',
- 2,
+ 0,
2.23,
-73.98509216,
40.75698853,
@@ -494,7 +494,7 @@ export default {
[
'2015-01-15 14:00:45 +00:00',
'2015-01-15 14:10:24 +00:00',
- 1,
+ null,
1.2,
-73.9940033,
40.7513504,
@@ -585,7 +585,7 @@ export default {
[
'2015-01-15 14:00:47 +00:00',
'2015-01-15 14:16:01 +00:00',
- 1,
+ null,
1.56,
-73.95927429,
40.77437592,
@@ -593,7 +593,7 @@ export default {
40.76293945,
10.5,
true,
- 'banana peel'
+ 'banana peel 2'
],
[
'2015-01-15 14:00:47 +00:00',
@@ -663,7 +663,7 @@ export default {
[
'2015-01-15 10:26:14 +00:00',
'2015-01-15 10:49:00 +00:00',
- 2,
+ null,
6.8,
-73.97297668,
40.7611351,
@@ -671,7 +671,7 @@ export default {
40.70956421,
23,
true,
- 'banana peel'
+ 'banana peel 2'
],
[
'2015-01-15 10:26:15 +00:00',
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index 80bfab3a8..e0614e919 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -533,7 +533,7 @@ export const DEFAULT_LIGHT_SETTINGS = {
numberOfLights: 2
};
-export const NO_VALUE_COLOR = [147, 147, 147];
+export const NO_VALUE_COLOR = [0, 0, 0, 0];
export const LAYER_BLENDINGS = {
additive: {
diff --git a/src/layers/base-layer.js b/src/layers/base-layer.js
index 26d66bf5a..ebea553f5 100644
--- a/src/layers/base-layer.js
+++ b/src/layers/base-layer.js
@@ -36,13 +36,14 @@ import {
import {DataVizColors} from 'constants/custom-color-ranges';
import {LAYER_VIS_CONFIGS, DEFAULT_TEXT_LABEL} from './layer-factory';
-import {generateHashId, notNullorUndefined, isPlainObject} from 'utils/utils';
+import {generateHashId, isPlainObject} from 'utils/utils';
import {
getSampleData,
getLatLngBounds,
maybeToDate,
- getSortingFunction
+ getSortingFunction,
+ notNullorUndefined
} from 'utils/data-utils';
import {
@@ -609,11 +610,16 @@ export default class Layer {
scale,
data,
field,
- defaultValue = NO_VALUE_COLOR,
+ nullValue = NO_VALUE_COLOR,
getValue = defaultGetFieldValue
) {
const {type} = field;
const value = getValue(field, data);
+
+ if (!notNullorUndefined(value)) {
+ return nullValue;
+ }
+
let attributeValue;
if (type === ALL_FIELD_TYPES.timestamp) {
// shouldn't need to convert here
@@ -623,8 +629,8 @@ export default class Layer {
attributeValue = scale(value);
}
- if (!attributeValue) {
- attributeValue = defaultValue;
+ if (!notNullorUndefined(attributeValue)) {
+ attributeValue = nullValue;
}
return attributeValue;
diff --git a/src/layers/h3-hexagon-layer/h3-hexagon-layer.js b/src/layers/h3-hexagon-layer/h3-hexagon-layer.js
index 49f09c6e1..a7d421f9a 100644
--- a/src/layers/h3-hexagon-layer/h3-hexagon-layer.js
+++ b/src/layers/h3-hexagon-layer/h3-hexagon-layer.js
@@ -150,11 +150,11 @@ export default class HexagonIdLayer extends Layer {
// height
const sScale =
- sizeField && this.getVisChannelScale(sizeScale, sizeDomain, sizeRange);
+ sizeField && this.getVisChannelScale(sizeScale, sizeDomain, sizeRange, 0);
// coverage
const coScale =
- coverageField && this.getVisChannelScale(coverageScale, coverageDomain, coverageRange);
+ coverageField && this.getVisChannelScale(coverageScale, coverageDomain, coverageRange, 0);
const getHexId = this.getHexId(columns);
diff --git a/src/layers/icon-layer/icon-layer.js b/src/layers/icon-layer/icon-layer.js
index 95539b983..d67c0aa83 100644
--- a/src/layers/icon-layer/icon-layer.js
+++ b/src/layers/icon-layer/icon-layer.js
@@ -191,7 +191,7 @@ export default class IconLayer extends Layer {
// point radius
const rScale =
- sizeField && this.getVisChannelScale(sizeScale, sizeDomain, radiusRange);
+ sizeField && this.getVisChannelScale(sizeScale, sizeDomain, radiusRange, 0);
const getPosition = this.getPosition(columns);
const getIcon = this.getIcon(columns);
@@ -231,7 +231,7 @@ export default class IconLayer extends Layer {
}
const getRadius = rScale
- ? d => this.getEncodedChannelValue(rScale, d.data, sizeField)
+ ? d => this.getEncodedChannelValue(rScale, d.data, sizeField, 0)
: 1;
const getColor = cScale
diff --git a/src/utils/data-utils.js b/src/utils/data-utils.js
index 338419cf0..921d465f0 100644
--- a/src/utils/data-utils.js
+++ b/src/utils/data-utils.js
@@ -36,7 +36,7 @@ const MIN_LONGITUDE = -180;
export function unique(values) {
const results = [];
values.forEach(v => {
- if (!results.includes(v) && v !== null && v !== undefined) {
+ if (!results.includes(v) && notNullorUndefined(v)) {
results.push(v);
}
});
@@ -122,6 +122,10 @@ export function maybeToDate(isTime, fieldIdx, format, d) {
return d[fieldIdx];
}
+/**
+ * whether null or undefined
+ * @returns {boolean} - yes or no
+ */
export function notNullorUndefined(d) {
return d !== undefined && d !== null;
}
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 57cdcea37..a063555e7 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -50,14 +50,6 @@ export function isPlainObject(obj) {
);
}
-/**
- * whether null or undefined
- * @returns {boolean} - yes or no
- */
-export function notNullorUndefined(d) {
- return d !== undefined && d !== null;
-}
-
/**
* Capitalize first letter of a string
* @param {string} str