From 0aa6d90429bd940d10bb489efa15a71a91dcfb52 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Thu, 18 Oct 2018 11:24:43 -0700 Subject: [PATCH] Remove isNumeric util function and use Number.isFinite instead (#6106) * remove isNumeric util function and use lodash isFinite instead * use native Number.isFinite --- superset/assets/src/utils/common.js | 4 ---- .../src/visualizations/MapBox/ScatterPlotGlowOverlay.jsx | 7 ++++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/superset/assets/src/utils/common.js b/superset/assets/src/utils/common.js index 7fa7043b38f..4da740e1931 100644 --- a/superset/assets/src/utils/common.js +++ b/superset/assets/src/utils/common.js @@ -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; diff --git a/superset/assets/src/visualizations/MapBox/ScatterPlotGlowOverlay.jsx b/superset/assets/src/visualizations/MapBox/ScatterPlotGlowOverlay.jsx index 40c5861c278..e67302aaa99 100644 --- a/superset/assets/src/visualizations/MapBox/ScatterPlotGlowOverlay.jsx +++ b/superset/assets/src/visualizations/MapBox/ScatterPlotGlowOverlay.jsx @@ -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