Remove isNumeric util function and use Number.isFinite instead (#6106)

* remove isNumeric util function and use lodash isFinite instead

* use native Number.isFinite
This commit is contained in:
Krist Wongsuphasawat
2018-10-18 11:24:43 -07:00
committed by Chris Williams
parent 58be31af3f
commit 0aa6d90429
2 changed files with 4 additions and 7 deletions

View File

@@ -21,10 +21,6 @@ export function kmToPixels(kilometers, latitude, zoomLevel) {
return d3.round(kilometers / kmPerPixel, 2);
}
export function isNumeric(num) {
return !isNaN(parseFloat(num)) && isFinite(num);
}
export function rgbLuminance(r, g, b) {
// Formula: https://en.wikipedia.org/wiki/Relative_luminance
return LUMINANCE_RED_WEIGHT * r + LUMINANCE_GREEN_WEIGHT * g + LUMINANCE_BLUE_WEIGHT * b;

View File

@@ -6,7 +6,6 @@ import ViewportMercator from 'viewport-mercator-project';
import {
kmToPixels,
rgbLuminance,
isNumeric,
MILES_PER_KM,
} from '../../utils/common';
@@ -154,7 +153,7 @@ class ScatterPlotGlowOverlay extends React.Component {
ctx.fillStyle = gradient;
ctx.fill();
if (isNumeric(clusterLabel)) {
if (Number.isFinite(parseFloat(clusterLabel))) {
if (clusterLabel >= 10000) {
clusterLabel = Math.round(clusterLabel / 1000) + 'k';
} else if (clusterLabel >= 1000) {
@@ -187,7 +186,9 @@ class ScatterPlotGlowOverlay extends React.Component {
}
if (pointMetric !== null) {
pointLabel = isNumeric(pointMetric) ? d3.round(pointMetric, 2) : pointMetric;
pointLabel = Number.isFinite(parseFloat(pointMetric))
? d3.round(pointMetric, 2)
: pointMetric;
}
// Fall back to default points if pointRadius wasn't a numerical column