mirror of
https://github.com/apache/superset.git
synced 2024-09-11 16:19:43 -04:00
fix: lints (mostly disabled)
This commit is contained in:
parent
b1074fc872
commit
096454e9cf
@ -28,21 +28,26 @@
|
||||
"access": "public"
|
||||
},
|
||||
"dependencies": {
|
||||
"@data-ui/xy-chart": "^0.0.80",
|
||||
"d3": "^3.5.17",
|
||||
"d3-tip": "^0.9.1",
|
||||
"dompurify": "^1.0.3",
|
||||
"fast-safe-stringify": "^2.0.6",
|
||||
"lodash": "^4.17.11",
|
||||
"mathjs": "^3.20.2",
|
||||
"bootstrap-slider": "^10.0.0",
|
||||
"d3-array": "^1.2.4",
|
||||
"d3-color": "^1.2.0",
|
||||
"d3-scale": "^2.1.2",
|
||||
"deck.gl": "^5.3.5",
|
||||
"lodash": "^4.17.15",
|
||||
"mapbox-gl": "^0.53.0",
|
||||
"moment": "^2.20.1",
|
||||
"nvd3": "1.8.6",
|
||||
"prop-types": "^15.6.2",
|
||||
"urijs": "^1.18.10"
|
||||
"mousetrap": "^1.6.1",
|
||||
"prop-types": "^15.6.0",
|
||||
"react-bootstrap-slider": "2.1.5",
|
||||
"react-map-gl": "^4.0.10",
|
||||
"underscore": "^1.8.3",
|
||||
"urijs": "^1.18.10",
|
||||
"viewport-mercator-project": "^6.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@superset-ui/chart": "^0.12.0",
|
||||
"@superset-ui/color": "^0.12.0",
|
||||
"@superset-ui/connection": "^0.12.3",
|
||||
"@superset-ui/core": "^0.12.0",
|
||||
"@superset-ui/dimension": "^0.12.0",
|
||||
"@superset-ui/number-format": "^0.12.0",
|
||||
|
@ -1,3 +1,8 @@
|
||||
/* eslint-disable react/jsx-handler-names */
|
||||
/* eslint-disable react/destructuring-assignment */
|
||||
/* eslint-disable react/forbid-prop-types */
|
||||
/* eslint-disable sort-keys */
|
||||
/* eslint-disable react/require-default-props */
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
@ -20,7 +25,7 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import DeckGLContainer from './DeckGLContainer';
|
||||
import PlaySlider from '../PlaySlider';
|
||||
import PlaySlider from './components/PlaySlider';
|
||||
|
||||
const PLAYSLIDER_HEIGHT = 20; // px
|
||||
|
||||
|
@ -1,3 +1,17 @@
|
||||
/* eslint-disable react/require-default-props */
|
||||
/* eslint-disable react/no-unused-prop-types */
|
||||
/* eslint-disable react/forbid-prop-types */
|
||||
/* eslint-disable react/no-access-state-in-setstate */
|
||||
/* eslint-disable compat/compat */
|
||||
/* eslint-disable react/destructuring-assignment */
|
||||
/* eslint-disable react/jsx-handler-names */
|
||||
/* eslint-disable react/no-unsafe */
|
||||
/* eslint-disable react/sort-comp */
|
||||
/* eslint-disable camelcase */
|
||||
/* eslint-disable no-prototype-builtins */
|
||||
/* eslint-disable sort-keys */
|
||||
/* eslint-disable no-eq-null */
|
||||
/* eslint-disable no-magic-numbers */
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
@ -22,7 +36,7 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { CategoricalColorNamespace } from '@superset-ui/color';
|
||||
import AnimatableDeckGLContainer from './AnimatableDeckGLContainer';
|
||||
import Legend from './Legend';
|
||||
import Legend from './components/Legend';
|
||||
import { hexToRGB } from './utils/colors';
|
||||
import { getPlaySliderParams } from './utils/time';
|
||||
import sandboxedEval from './utils/sandbox';
|
||||
|
@ -1,3 +1,7 @@
|
||||
/* eslint-disable react/jsx-handler-names */
|
||||
/* eslint-disable react/destructuring-assignment */
|
||||
/* 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
|
||||
|
@ -1,3 +1,13 @@
|
||||
/* eslint-disable compat/compat */
|
||||
/* eslint-disable react/no-unsafe */
|
||||
/* eslint-disable promise/always-return */
|
||||
/* eslint-disable react/jsx-handler-names */
|
||||
/* eslint-disable react/no-access-state-in-setstate */
|
||||
/* eslint-disable react/sort-comp */
|
||||
/* eslint-disable camelcase */
|
||||
/* eslint-disable react/destructuring-assignment */
|
||||
/* 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
|
||||
@ -22,7 +32,7 @@ import PropTypes from 'prop-types';
|
||||
import { SupersetClient } from '@superset-ui/connection';
|
||||
|
||||
import DeckGLContainer from '../DeckGLContainer';
|
||||
import { getExploreLongUrl } from '../../../explore/exploreUtils';
|
||||
import { getExploreLongUrl } from '../utils/explore';
|
||||
import layerGenerators from '../layers';
|
||||
|
||||
const propTypes = {
|
||||
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
.BootstrapSliderWrapper .slider-selection {
|
||||
background: #efefef;
|
||||
}
|
||||
|
||||
.BootstrapSliderWrapper .slider-handle {
|
||||
background: #b3b3b3;
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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 React from 'react';
|
||||
import ReactBootstrapSlider from 'react-bootstrap-slider';
|
||||
import 'bootstrap-slider/dist/css/bootstrap-slider.min.css';
|
||||
import './BootstrapSliderWrapper.css';
|
||||
|
||||
export default function BootstrapSliderWrapper(props) {
|
||||
return (
|
||||
<span className="BootstrapSliderWrapper">
|
||||
<ReactBootstrapSlider {...props} />
|
||||
</span>
|
||||
);
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/* eslint-disable react/destructuring-assignment */
|
||||
/* eslint-disable jsx-a11y/anchor-is-valid */
|
||||
/* 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
|
||||
@ -47,8 +51,8 @@ export default class Legend extends React.PureComponent {
|
||||
}
|
||||
|
||||
const numValue = parseFloat(value);
|
||||
return formatNumber(this.props.format, numValue);
|
||||
|
||||
return formatNumber(this.props.format, numValue);
|
||||
}
|
||||
|
||||
formatCategoryLabel(k) {
|
||||
@ -58,6 +62,7 @@ export default class Legend extends React.PureComponent {
|
||||
|
||||
if (k.includes(categoryDelimiter)) {
|
||||
const values = k.split(categoryDelimiter);
|
||||
|
||||
return this.format(values[0]) + categoryDelimiter + this.format(values[1]);
|
||||
}
|
||||
|
||||
@ -70,8 +75,9 @@ export default class Legend extends React.PureComponent {
|
||||
}
|
||||
|
||||
const categories = Object.entries(this.props.categories).map(([k, v]) => {
|
||||
const style = { color: 'rgba(' + v.color.join(', ') + ')' };
|
||||
const style = { color: `rgba(${v.color.join(', ')})` };
|
||||
const icon = v.enabled ? '\u25FC' : '\u25FB';
|
||||
|
||||
return (
|
||||
<li key={k}>
|
||||
<a
|
||||
@ -94,8 +100,8 @@ export default class Legend extends React.PureComponent {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={'legend'} style={style}>
|
||||
<ul className={'categories'}>{categories}</ul>
|
||||
<div className="legend" style={style}>
|
||||
<ul className="categories">{categories}</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -1,3 +1,11 @@
|
||||
/* eslint-disable react/jsx-handler-names */
|
||||
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
||||
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
||||
/* eslint-disable no-negated-condition */
|
||||
/* eslint-disable react/destructuring-assignment */
|
||||
/* eslint-disable no-eq-null */
|
||||
/* 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
|
||||
@ -20,7 +28,7 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Mousetrap from 'mousetrap';
|
||||
import { t } from '@superset-ui/translation';
|
||||
import BootrapSliderWrapper from '../components/BootstrapSliderWrapper';
|
||||
import BootrapSliderWrapper from './BootstrapSliderWrapper';
|
||||
import './PlaySlider.css';
|
||||
|
||||
const propTypes = {
|
||||
@ -66,24 +74,30 @@ export default class PlaySlider extends React.PureComponent {
|
||||
this.getPlayClass = this.getPlayClass.bind(this);
|
||||
this.formatter = this.formatter.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
Mousetrap.bind(['space'], this.play);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
Mousetrap.unbind(['space']);
|
||||
}
|
||||
|
||||
onChange(event) {
|
||||
this.props.onChange(event.target.value);
|
||||
if (this.state.intervalId != null) {
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
|
||||
getPlayClass() {
|
||||
if (this.state.intervalId == null) {
|
||||
return 'fa fa-play fa-lg slider-button';
|
||||
}
|
||||
|
||||
return 'fa fa-pause fa-lg slider-button';
|
||||
}
|
||||
|
||||
play() {
|
||||
if (this.props.disabled) {
|
||||
return;
|
||||
@ -95,10 +109,12 @@ export default class PlaySlider extends React.PureComponent {
|
||||
this.setState({ intervalId: id });
|
||||
}
|
||||
}
|
||||
|
||||
pause() {
|
||||
clearInterval(this.state.intervalId);
|
||||
this.setState({ intervalId: null });
|
||||
}
|
||||
|
||||
stepForward() {
|
||||
const { start, end, step, values, disabled } = this.props;
|
||||
|
||||
@ -108,10 +124,11 @@ export default class PlaySlider extends React.PureComponent {
|
||||
|
||||
const currentValues = Array.isArray(values) ? values : [values, values + step];
|
||||
const nextValues = currentValues.map(value => value + this.increment);
|
||||
const carriageReturn = (nextValues[1] > end) ? (nextValues[0] - start) : 0;
|
||||
const carriageReturn = nextValues[1] > end ? nextValues[0] - start : 0;
|
||||
|
||||
this.props.onChange(nextValues.map(value => value - carriageReturn));
|
||||
}
|
||||
|
||||
stepBackward() {
|
||||
const { start, end, step, values, disabled } = this.props;
|
||||
|
||||
@ -121,10 +138,11 @@ export default class PlaySlider extends React.PureComponent {
|
||||
|
||||
const currentValues = Array.isArray(values) ? values : [values, values + step];
|
||||
const nextValues = currentValues.map(value => value - this.increment);
|
||||
const carriageReturn = (nextValues[0] < start) ? (end - nextValues[1]) : 0;
|
||||
const carriageReturn = nextValues[0] < start ? end - nextValues[1] : 0;
|
||||
|
||||
this.props.onChange(nextValues.map(value => value + carriageReturn));
|
||||
}
|
||||
|
||||
formatter(values) {
|
||||
if (this.props.disabled) {
|
||||
return t('Data has no time steps');
|
||||
@ -136,10 +154,13 @@ export default class PlaySlider extends React.PureComponent {
|
||||
} else if (values[0] === values[1]) {
|
||||
parts = [values[0]];
|
||||
}
|
||||
return parts.map(value => (new Date(value)).toUTCString()).join(' : ');
|
||||
|
||||
return parts.map(value => new Date(value).toUTCString()).join(' : ');
|
||||
}
|
||||
|
||||
render() {
|
||||
const { start, end, step, orientation, reversed, disabled, range, values } = this.props;
|
||||
|
||||
return (
|
||||
<div className="play-slider">
|
||||
<div className="play-slider-controls padded">
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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 && (
|
||||
<div className="deckgl-tooltip">
|
||||
{
|
||||
Object.keys(o.object.extraProps).map((prop, index) =>
|
||||
{Object.keys(o.object.extraProps).map((prop, index) => (
|
||||
<TooltipRow
|
||||
key={`prop-${index}`}
|
||||
label={`${prop}: `}
|
||||
value={`${o.object.extraProps[prop]}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)],
|
||||
});
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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);
|
||||
}
|
@ -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;
|
||||
});
|
||||
}
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user