diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/factory.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/factory.jsx
index 824eabd445..0442abb586 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/factory.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/factory.jsx
@@ -1,3 +1,11 @@
+/* eslint-disable react/jsx-handler-names */
+/* eslint-disable react/destructuring-assignment */
+/* eslint-disable react/sort-comp */
+/* eslint-disable camelcase */
+/* eslint-disable react/no-unsafe */
+/* eslint-disable sort-keys */
+/* eslint-disable react/no-unused-prop-types */
+/* eslint-disable react/forbid-prop-types */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Arc/Arc.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Arc/Arc.jsx
index e1998e497c..40b7ccb0d6 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Arc/Arc.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Arc/Arc.jsx
@@ -1,3 +1,5 @@
+/* eslint-disable no-magic-numbers */
+
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Geojson/Geojson.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Geojson/Geojson.jsx
index 83bb442111..80c834620d 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Geojson/Geojson.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Geojson/Geojson.jsx
@@ -1,3 +1,7 @@
+/* eslint-disable no-magic-numbers */
+/* eslint-disable react/forbid-prop-types */
+/* eslint-disable react/no-array-index-key */
+/* eslint-disable sort-keys */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Grid/Grid.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Grid/Grid.jsx
index 370cb3dfdb..54e19ead94 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Grid/Grid.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Grid/Grid.jsx
@@ -1,3 +1,5 @@
+/* eslint-disable no-magic-numbers */
+/* eslint-disable sort-keys */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -21,7 +23,7 @@ import React from 'react';
import { t } from '@superset-ui/translation';
import { commonLayerProps, getAggFunc } from '../common';
-import sandboxedEval from '../../../../modules/sandbox';
+import sandboxedEval from '../../utils/sandbox';
import { createDeckGLComponent } from '../../factory';
import TooltipRow from '../../TooltipRow';
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Hex/Hex.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Hex/Hex.jsx
index 22dd39b6ff..82c7e5c7c7 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Hex/Hex.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Hex/Hex.jsx
@@ -1,3 +1,5 @@
+/* eslint-disable no-magic-numbers */
+/* eslint-disable sort-keys */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -21,7 +23,7 @@ import React from 'react';
import { t } from '@superset-ui/translation';
import { commonLayerProps, getAggFunc } from '../common';
-import sandboxedEval from '../../../../modules/sandbox';
+import sandboxedEval from '../../utils/sandbox';
import { createDeckGLComponent } from '../../factory';
import TooltipRow from '../../TooltipRow';
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Path/Path.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Path/Path.jsx
index 15794d4ed4..9ffaf9f982 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Path/Path.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Path/Path.jsx
@@ -1,3 +1,6 @@
+/* eslint-disable react/no-array-index-key */
+/* eslint-disable no-magic-numbers */
+/* eslint-disable sort-keys */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -19,7 +22,7 @@
import { PathLayer } from 'deck.gl';
import React from 'react';
import { commonLayerProps } from '../common';
-import sandboxedEval from '../../../../modules/sandbox';
+import sandboxedEval from '../../utils/sandbox';
import { createDeckGLComponent } from '../../factory';
import TooltipRow from '../../TooltipRow';
@@ -27,15 +30,14 @@ function setTooltipContent(o) {
return (
o.object.extraProps && (
- {
- Object.keys(o.object.extraProps).map((prop, index) =>
+ {Object.keys(o.object.extraProps).map((prop, index) => (
))}
-
+
)
);
}
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Polygon/Polygon.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Polygon/Polygon.jsx
index dc62446efc..6ce3e06a22 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Polygon/Polygon.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Polygon/Polygon.jsx
@@ -1,3 +1,9 @@
+/* eslint-disable react/jsx-handler-names */
+/* eslint-disable react/destructuring-assignment */
+/* eslint-disable react/no-access-state-in-setstate */
+/* eslint-disable react/forbid-prop-types */
+/* eslint-disable no-magic-numbers */
+/* eslint-disable sort-keys */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -24,13 +30,13 @@ import PropTypes from 'prop-types';
import { PolygonLayer } from 'deck.gl';
import AnimatableDeckGLContainer from '../../AnimatableDeckGLContainer';
-import Legend from '../../../Legend';
+import Legend from '../../components/Legend';
import TooltipRow from '../../TooltipRow';
import { getBuckets, getBreakPointColorScaler } from '../../utils';
import { commonLayerProps, fitViewport } from '../common';
-import { getPlaySliderParams } from '../../../../modules/time';
-import sandboxedEval from '../../../../modules/sandbox';
+import { getPlaySliderParams } from '../../utils/time';
+import sandboxedEval from '../../utils/sandbox';
const DOUBLE_CLICK_TRESHOLD = 250; // milliseconds
@@ -71,6 +77,7 @@ export function getLayer(formData, payload, onAddFilter, setTooltip, selected, o
const sc = fd.stroke_color_picker;
let data = [...payload.data.features];
+ // eslint-disable-next-line no-eq-null
if (filters != null) {
filters.forEach(f => {
data = data.filter(f);
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Scatter/Scatter.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Scatter/Scatter.jsx
index 78e49f3fda..3e1bbbb6a6 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Scatter/Scatter.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Scatter/Scatter.jsx
@@ -1,3 +1,5 @@
+/* eslint-disable no-magic-numbers */
+/* eslint-disable sort-keys */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -22,7 +24,7 @@ import { t } from '@superset-ui/translation';
import { commonLayerProps } from '../common';
import { createCategoricalDeckGLComponent } from '../../factory';
import TooltipRow from '../../TooltipRow';
-import { unitToRadius } from '../../../../modules/geo';
+import { unitToRadius } from '../../utils/geo';
function getPoints(data) {
return data.map(d => d.position);
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Screengrid/Screengrid.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Screengrid/Screengrid.jsx
index 8c738a30e3..ed2cadd7e7 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Screengrid/Screengrid.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/Screengrid/Screengrid.jsx
@@ -1,3 +1,8 @@
+/* eslint-disable react/jsx-handler-names */
+/* eslint-disable react/destructuring-assignment */
+/* eslint-disable no-magic-numbers */
+/* eslint-disable sort-keys */
+/* eslint-disable react/forbid-prop-types */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -23,8 +28,8 @@ import PropTypes from 'prop-types';
import { ScreenGridLayer } from 'deck.gl';
import { t } from '@superset-ui/translation';
import AnimatableDeckGLContainer from '../../AnimatableDeckGLContainer';
-import { getPlaySliderParams } from '../../../../modules/time';
-import sandboxedEval from '../../../../modules/sandbox';
+import { getPlaySliderParams } from '../../utils/time';
+import sandboxedEval from '../../utils/sandbox';
import { commonLayerProps, fitViewport } from '../common';
import TooltipRow from '../../TooltipRow';
@@ -58,6 +63,7 @@ export function getLayer(formData, payload, onAddFilter, setTooltip, selected, o
data = jsFnMutator(data);
}
+ // eslint-disable-next-line no-eq-null
if (filters != null) {
filters.forEach(f => {
data = data.filter(f);
@@ -140,6 +146,7 @@ class DeckGLScreenGrid extends React.PureComponent {
onValuesChange(values) {
this.setState({
+ // eslint-disable-next-line react/no-access-state-in-setstate
values: Array.isArray(values) ? values : [values, values + this.state.getStep(values)],
});
}
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/common.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/common.jsx
index b23be4ba12..0d9bf23419 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/common.jsx
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/common.jsx
@@ -1,3 +1,4 @@
+/* eslint-disable no-magic-numbers */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,7 +19,7 @@
*/
import { fitBounds } from 'viewport-mercator-project';
import * as d3array from 'd3-array';
-import sandboxedEval from '../../../modules/sandbox';
+import sandboxedEval from '../utils/sandbox';
const PADDING = 0.25;
const GEO_BOUNDS = {
@@ -70,10 +71,10 @@ export function fitViewport(viewport, points, padding = 10) {
return {
...viewport,
...fitBounds({
- height: viewport.height,
- width: viewport.width,
- padding,
bounds,
+ height: viewport.height,
+ padding,
+ width: viewport.width,
}),
};
} catch (e) {
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/index.js
index b77d5bd12c..4ac334b5a8 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/index.js
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/layers/index.js
@@ -1,3 +1,4 @@
+/* eslint-disable sort-keys */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/transformProps.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/transformProps.js
index 02b821a0d7..db10062d7c 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/transformProps.js
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/transformProps.js
@@ -24,14 +24,14 @@ export default function transformProps(chartProps) {
return {
formData: rawFormData,
+ onAddFilter,
payload: queryData,
setControlValue,
+ setTooltip,
viewport: {
...rawFormData.viewport,
- width,
height,
+ width,
},
- onAddFilter,
- setTooltip,
};
}
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils.js
index cc5487c555..2fc36ee5e4 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils.js
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils.js
@@ -1,3 +1,5 @@
+/* eslint-disable no-magic-numbers */
+/* eslint-disable no-negated-condition */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -73,8 +75,8 @@ export function getBreakPointColorScaler(
: null;
const colorScheme = Array.isArray(linearColorScheme)
? new SequentialScheme({
- id: 'custom',
colors: linearColorScheme,
+ id: 'custom',
})
: getSequentialSchemeRegistry().get(linearColorScheme);
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/colors.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/colors.js
index 6b0f72af70..eaa1055021 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/colors.js
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/colors.js
@@ -1,3 +1,4 @@
+/* eslint-disable no-magic-numbers */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,10 +19,12 @@
*/
import { rgb } from 'd3-color';
+// eslint-disable-next-line import/prefer-default-export
export function hexToRGB(hex, alpha = 255) {
if (!hex) {
return [0, 0, 0, alpha];
}
const { r, g, b } = rgb(hex);
+
return [r, g, b, alpha];
}
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/explore.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/explore.js
new file mode 100644
index 0000000000..00f4df1485
--- /dev/null
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/explore.js
@@ -0,0 +1,47 @@
+import URI from 'urijs';
+import { safeStringify } from './safeStringify';
+
+const MAX_URL_LENGTH = 8000;
+
+export function getURIDirectory(formData, endpointType = 'base') {
+ // Building the directory part of the URI
+ let directory = '/superset/explore/';
+ if (['json', 'csv', 'query', 'results', 'samples'].indexOf(endpointType) >= 0) {
+ directory = '/superset/explore_json/';
+ }
+
+ return directory;
+}
+
+export function getExploreLongUrl(formData, endpointType, allowOverflow = true, extraSearch = {}) {
+ if (!formData.datasource) {
+ return null;
+ }
+
+ const uri = new URI('/');
+ const directory = getURIDirectory(formData, endpointType);
+ const search = uri.search(true);
+ Object.keys(extraSearch).forEach(key => {
+ search[key] = extraSearch[key];
+ });
+ search.form_data = safeStringify(formData);
+ if (endpointType === 'standalone') {
+ search.standalone = 'true';
+ }
+ const url = uri
+ .directory(directory)
+ .search(search)
+ .toString();
+ if (!allowOverflow && url.length > MAX_URL_LENGTH) {
+ const minimalFormData = {
+ datasource: formData.datasource,
+ viz_type: formData.viz_type,
+ };
+
+ return getExploreLongUrl(minimalFormData, endpointType, false, {
+ URL_IS_TOO_LONG_TO_SHARE: null,
+ });
+ }
+
+ return url;
+}
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/geo.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/geo.js
new file mode 100644
index 0000000000..fac3d60a1f
--- /dev/null
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/geo.js
@@ -0,0 +1,61 @@
+/* eslint-disable no-restricted-properties */
+/* eslint-disable no-magic-numbers */
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { roundDecimal } from './utils';
+
+export const defaultViewport = {
+ bearing: 0,
+ latitude: 31.222656842808707,
+ longitude: 6.85236157047845,
+ pitch: 0,
+ zoom: 1,
+};
+
+const METER_TO_MILE = 1609.34;
+
+export function unitToRadius(unit, num) {
+ if (unit === 'square_m') {
+ return Math.sqrt(num / Math.PI);
+ } else if (unit === 'radius_m') {
+ return num;
+ } else if (unit === 'radius_km') {
+ return num * 1000;
+ } else if (unit === 'radius_miles') {
+ return num * METER_TO_MILE;
+ } else if (unit === 'square_km') {
+ return Math.sqrt(num / Math.PI) * 1000;
+ } else if (unit === 'square_miles') {
+ return Math.sqrt(num / Math.PI) * METER_TO_MILE;
+ }
+
+ return null;
+}
+
+export const EARTH_CIRCUMFERENCE_KM = 40075.16;
+export const MILES_PER_KM = 1.60934;
+
+export function kmToPixels(kilometers, latitude, zoomLevel) {
+ // Algorithm from: https://wiki.openstreetmap.org/wiki/Zoom_levels
+ const latitudeRad = latitude * (Math.PI / 180);
+ // Seems like the zoomLevel is off by one
+ const kmPerPixel = (EARTH_CIRCUMFERENCE_KM * Math.cos(latitudeRad)) / Math.pow(2, zoomLevel + 9);
+
+ return roundDecimal(kilometers / kmPerPixel, 2);
+}
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/safeStringify.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/safeStringify.js
new file mode 100644
index 0000000000..f734e8d163
--- /dev/null
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/safeStringify.js
@@ -0,0 +1,50 @@
+/* eslint-disable consistent-return */
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * A Stringify function that will not crash when it runs into circular JSON references,
+ * unlike JSON.stringify. Any circular references are simply omitted, as if there had
+ * been no data present
+ * @param object any JSON object to be stringified
+ */
+
+// eslint-disable-next-line import/prefer-default-export
+export function safeStringify(object) {
+ const cache = new Set();
+
+ return JSON.stringify(object, (key, value) => {
+ if (typeof value === 'object' && value !== null) {
+ if (cache.has(value)) {
+ // We've seen this object before
+ try {
+ // Quick deep copy to duplicate if this is a repeat rather than a circle.
+ return JSON.parse(JSON.stringify(value));
+ } catch (err) {
+ // Discard key if value cannot be duplicated.
+ return;
+ }
+ }
+ // Store the value in our cache.
+ cache.add(value);
+ }
+
+ return value;
+ });
+}
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/sandbox.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/sandbox.js
index 7c2e77b053..0eb948ca27 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/sandbox.js
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/sandbox.js
@@ -1,3 +1,5 @@
+/* eslint-disable sort-keys */
+/* eslint-disable no-magic-numbers */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -35,15 +37,16 @@ const GLOBAL_CONTEXT = {
// Copied/modified from https://github.com/hacksparrow/safe-eval/blob/master/index.js
export default function sandboxedEval(code, context, opts) {
const sandbox = {};
- const resultKey = 'SAFE_EVAL_' + Math.floor(Math.random() * 1000000);
+ const resultKey = `SAFE_EVAL_${Math.floor(Math.random() * 1000000)}`;
sandbox[resultKey] = {};
- const codeToEval = resultKey + '=' + code;
+ const codeToEval = `${resultKey}=${code}`;
const sandboxContext = { ...GLOBAL_CONTEXT, ...context };
- Object.keys(sandboxContext).forEach(function (key) {
+ Object.keys(sandboxContext).forEach(key => {
sandbox[key] = sandboxContext[key];
});
try {
vm.runInNewContext(codeToEval, sandbox, opts);
+
return sandbox[resultKey];
} catch (error) {
return () => error;
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/time.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/time.js
index 3d4466f3cf..83c3b02c7c 100644
--- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/time.js
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/time.js
@@ -1,3 +1,8 @@
+/* eslint-disable sort-keys */
+/* eslint-disable babel/no-invalid-this */
+/* eslint-disable no-eq-null */
+/* eslint-disable no-negated-condition */
+/* eslint-disable func-names */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,20 +23,18 @@
*/
import moment from 'moment';
-
// array with the minimum values of each part of a timestamp -- note that
// months are zero-indexed in Javascript
const truncatePartTo = [
- 1, // year
- 0, // month
- 1, // day
- 0, // hour
- 0, // minute
- 0, // second
- 0, // millisecond
+ 1, // year
+ 0, // month
+ 1, // day
+ 0, // hour
+ 0, // minute
+ 0, // second
+ 0, // millisecond
];
-
export function truncate(timestamp, step) {
/*
* Truncate timestamp down to duration resolution.
@@ -41,16 +44,18 @@ export function truncate(timestamp, step) {
const explodedLowerBound = lowerBound.toArray();
const firstDiffIndex = explodedTimestamp
- .map((part, i) => (explodedLowerBound[i] !== part))
+ .map((part, i) => explodedLowerBound[i] !== part)
.indexOf(true);
const dateParts = explodedTimestamp.map((part, i) => {
if (i === firstDiffIndex) {
// truncate down to closest `truncatePartTo[i] + n * step`
const difference = part - explodedLowerBound[i];
+
return part - ((part - truncatePartTo[i]) % difference);
} else if (i < firstDiffIndex || firstDiffIndex === -1) {
return part;
}
+
return truncatePartTo[i];
});
@@ -64,11 +69,17 @@ function getStepSeconds(step, start) {
* seconds, which is why we need to know the start time.
*/
const startMillliseconds = parseInt(moment(start).format('x'), 10);
- const endMilliseconds = parseInt(moment(start).add(step).format('x'), 10);
+ const endMilliseconds = parseInt(
+ moment(start)
+ .add(step)
+ .format('x'),
+ 10,
+ );
+
return endMilliseconds - startMillliseconds;
}
-export const getPlaySliderParams = function (timestamps, timeGrain) {
+export const getPlaySliderParams = function(timestamps, timeGrain) {
const minTimestamp = moment(Math.min(...timestamps));
const maxTimestamp = moment(Math.max(...timestamps));
let step;
@@ -81,7 +92,8 @@ export const getPlaySliderParams = function (timestamps, timeGrain) {
// example, if `reference` is a Saturday and `duration` is 1 week (P1W)
// then both start and end should be Saturdays.
const parts = timeGrain.split('/', 2);
- if (parts[0].endsWith('Z')) { // ISO string
+ if (parts[0].endsWith('Z')) {
+ // ISO string
reference = moment(parts[0]);
step = moment.duration(parts[1]);
} else {
diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/utils.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/utils.js
new file mode 100644
index 0000000000..4f59617db8
--- /dev/null
+++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-preset-chart-deckgl/src/utils/utils.js
@@ -0,0 +1,34 @@
+/* eslint-disable no-magic-numbers */
+/* eslint-disable no-restricted-properties */
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/* eslint camelcase: 0 */
+
+// eslint-disable-next-line import/prefer-default-export
+export function roundDecimal(number, precision) {
+ let roundedNumber;
+ if (precision) {
+ // eslint-disable-next-line no-param-reassign
+ roundedNumber = Math.round(number * (precision = Math.pow(10, precision))) / precision;
+ } else {
+ roundedNumber = Math.round(number);
+ }
+
+ return roundedNumber;
+}