diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/README.md b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/README.md deleted file mode 100644 index 2a00965792..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/README.md +++ /dev/null @@ -1,43 +0,0 @@ -## @superset-ui/legacy-preset-chart-nvd3 - -[![Version](https://img.shields.io/npm/v/@superset-ui/legacy-preset-chart-nvd3.svg?style=flat-square)](https://img.shields.io/npm/v/@superset-ui/legacy-preset-chart-nvd3.svg?style=flat-square) -[![David (path)](https://img.shields.io/david/apache-superset/superset-ui-plugins.svg?path=packages%2Fsuperset-ui-legacy-preset-chart-nvd3&style=flat-square)](https://david-dm.org/apache-superset/superset-ui-plugins?path=packages/superset-ui-legacy-preset-chart-nvd3) - -This plugin provides Big Number for Superset. - -### Usage - -Import the preset and register. This will register all the chart plugins under nvd3. - -```js -import { NVD3ChartPreset } from '@superset-ui/legacy-preset-chart-nvd3'; - -new NVD3ChartPreset().register(); -``` - -or register charts one by one. Configure `key`, which can be any `string`, and register the plugin. This `key` will be used to lookup this chart throughout the app. - -```js -import { AreaChartPlugin, LineChartPlugin } from '@superset-ui/legacy-preset-chart-nvd3'; - -new AreaChartPlugin() - .configure({ key: 'area' }) - .register(); -new LineChartPlugin() - .configure({ key: 'line' }) - .register(); -``` - -Then use it via `SuperChart`. See [storybook](https://apache-superset.github.io/superset-ui-plugins/?selectedKind=plugin-chart-nvd3) for more details. - -```js - -``` \ No newline at end of file diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/package.json b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/package.json deleted file mode 100644 index 317ea1793f..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/package.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "@superset-ui/legacy-preset-chart-nvd3", - "version": "0.11.0", - "description": "Superset Legacy Chart - NVD3", - "sideEffects": [ - "*.css" - ], - "main": "lib/index.js", - "module": "esm/index.js", - "files": [ - "esm", - "lib" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/apache-superset/superset-ui-plugins.git" - }, - "keywords": [ - "superset" - ], - "author": "Superset", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/apache-superset/superset-ui-plugins/issues" - }, - "homepage": "https://github.com/apache-superset/superset-ui-plugins#readme", - "publishConfig": { - "access": "public" - }, - "private": true, - "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", - "moment": "^2.20.1", - "nvd3": "1.8.6", - "prop-types": "^15.6.2", - "urijs": "^1.18.10" - }, - "peerDependencies": { - "@superset-ui/chart": "^0.12.0", - "@superset-ui/color": "^0.12.0", - "@superset-ui/core": "^0.12.0", - "@superset-ui/dimension": "^0.12.0", - "@superset-ui/number-format": "^0.12.0", - "@superset-ui/time-format": "^0.12.0", - "@superset-ui/translation": "^0.12.0", - "react": "^15 || ^16" - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/images/thumbnail.png deleted file mode 100644 index 6b2fb75d42..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/images/thumbnailLarge.png deleted file mode 100644 index 86f1080cda..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/index.js deleted file mode 100644 index e0201c5c3b..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Area/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; -import { ANNOTATION_TYPES } from '../vendor/superset/AnnotationTypes'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: '', - name: t('Area Chart'), - supportedAnnotationTypes: [ANNOTATION_TYPES.INTERVAL, ANNOTATION_TYPES.EVENT], - thumbnail, - useLegacyApi: true, -}); - -export default class AreaChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/images/thumbnail.png deleted file mode 100644 index 1ef2633122..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/images/thumbnailLarge.png deleted file mode 100644 index ab0e8d9915..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/index.js deleted file mode 100644 index 44ac24c2cb..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bar/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; -import { ANNOTATION_TYPES } from '../vendor/superset/AnnotationTypes'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: 'A bar chart where the x axis is time', - name: t('Time-series Bar Chart'), - supportedAnnotationTypes: [ANNOTATION_TYPES.INTERVAL, ANNOTATION_TYPES.EVENT], - thumbnail, - useLegacyApi: true, -}); - -export default class BarChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/images/thumbnail.png deleted file mode 100644 index 8925e50680..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/images/thumbnailLarge.png deleted file mode 100644 index de8f061a68..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/index.js deleted file mode 100644 index 554c655e81..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/BoxPlot/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: '', - name: t('Box Plot'), - thumbnail, - useLegacyApi: true, -}); - -export default class BoxPlotChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/images/thumbnail.png deleted file mode 100644 index 453388104e..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/images/thumbnailLarge.png deleted file mode 100644 index 08de51f4ff..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/index.js deleted file mode 100644 index c0d13ccfd9..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bubble/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: '', - name: t('Bubble Chart'), - thumbnail, - useLegacyApi: true, -}); - -export default class BubbleChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/images/thumbnail.png deleted file mode 100644 index f98c70f29b..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/images/thumbnailLarge.png deleted file mode 100644 index 7a66a41c7a..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/index.js deleted file mode 100644 index 6e4f40ae1c..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Bullet/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: '', - name: t('Bullet Chart'), - thumbnail, - useLegacyApi: true, -}); - -export default class BulletChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/images/thumbnail.png deleted file mode 100644 index c17af52389..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/images/thumbnailLarge.png deleted file mode 100644 index 00b0a7c515..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/index.js deleted file mode 100644 index 344f138afa..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Compare/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: t('A line chart component where you can compare the % change over time'), - name: t('Time-series Percent Change'), - thumbnail, - useLegacyApi: true, -}); - -export default class CompareChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/images/thumbnail.png deleted file mode 100644 index cdd5120d0a..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/images/thumbnailLarge.png deleted file mode 100644 index b41014788a..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/index.js deleted file mode 100644 index 9d7f318e36..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DistBar/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: t('A bar chart where the x axis is time'), - name: t('Bar Chart'), - thumbnail, - useLegacyApi: true, -}); - -export default class DistBarChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/images/thumbnail.png deleted file mode 100755 index a5f723cb23..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/images/thumbnailLarge.png deleted file mode 100755 index 23a77500b7..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/index.js deleted file mode 100644 index 3cea0a57d1..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/DualLine/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: '', - name: t('Dual Line Chart'), - thumbnail, - useLegacyApi: true, -}); - -export default class DualLineChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/images/thumbnail.png deleted file mode 100644 index 7df5084c47..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/images/thumbnailLarge.png deleted file mode 100644 index 67f8fe887f..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/index.js deleted file mode 100644 index be2f89f6b2..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Line/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; -import { ANNOTATION_TYPES } from '../vendor/superset/AnnotationTypes'; - -const metadata = new ChartMetadata({ - canBeAnnotationTypes: [ANNOTATION_TYPES.TIME_SERIES], - credits: ['http://nvd3.org'], - description: '', - name: t('Line Chart'), - supportedAnnotationTypes: [ - ANNOTATION_TYPES.TIME_SERIES, - ANNOTATION_TYPES.INTERVAL, - ANNOTATION_TYPES.EVENT, - ANNOTATION_TYPES.FORMULA, - ], - thumbnail, - useLegacyApi: true, -}); - -export default class LineChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/LineMulti.jsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/LineMulti.jsx deleted file mode 100644 index 189882be65..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/LineMulti.jsx +++ /dev/null @@ -1,170 +0,0 @@ -/** - * 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-disable sort-keys, react/require-default-props, react/forbid-prop-types */ -/* eslint-disable promise/always-return, promise/catch-or-return */ -import d3 from 'd3'; -import React from 'react'; -import PropTypes from 'prop-types'; -import { getExploreLongUrl } from '../vendor/superset/exploreUtils'; -import ReactNVD3 from '../ReactNVD3'; -import transformProps from '../transformProps'; - -const propTypes = { - width: PropTypes.number, - height: PropTypes.number, - annotationData: PropTypes.object, - datasource: PropTypes.object, - formData: PropTypes.object, - onAddFilter: PropTypes.func, - onError: PropTypes.func, -}; -const defaultProps = { - onAddFilter() {}, - onError() {}, -}; - -function getJson(url) { - return new Promise((resolve, reject) => { - d3.json(url, (error, response) => { - if (error) { - reject(error); - } else { - resolve(response.data); - } - }); - }); -} - -/* - * Show multiple line charts - * - * This visualization works by fetching the data from each of the saved - * charts, building the queryData data and passing it along to nvd3Vis. - */ -class LineMulti extends React.Component { - constructor(props) { - super(props); - this.state = { queryData: [] }; - } - - componentDidMount() { - this.loadData(this.props); - } - - componentWillReceiveProps(nextProps) { - this.loadData(nextProps); - } - - loadData(props) { - const { formData, queryData } = props; - const { slices } = queryData.data; - const { - extraFilters, - filters, - lineCharts, - lineCharts2, - prefixMetricWithSliceName, - timeRange, - } = formData; - - this.setState({ queryData: [] }); - - // fetch data from all the charts - const subslices = [ - ...slices.axis1.map(subslice => [1, subslice]), - ...slices.axis2.map(subslice => [2, subslice]), - ]; - - const promises = subslices.map(([yAxis, subslice]) => { - const subsliceFormData = subslice.form_data; - const combinedFormData = { - ...subslice.form_data, - extra_filters: extraFilters || [], - filters: (subsliceFormData.filters || []).concat(filters || []), - time_range: timeRange, - }; - const addPrefix = prefixMetricWithSliceName; - - return getJson(getExploreLongUrl(combinedFormData, 'json')).then(data => - data.map(({ key, values }) => ({ - key: addPrefix ? `${subslice.slice_name}: ${key}` : key, - type: combinedFormData.viz_type, - values, - yAxis, - })), - ); - }); - - Promise.all(promises).then(data => { - const queryDataCopy = { ...queryData }; - queryDataCopy.data = [].concat(...data); - - // add null values at the edges to fix multiChart bug when series with - // different x values use different y axes - if (lineCharts.length && lineCharts2.length) { - let minX = Infinity; - let maxX = -Infinity; - queryDataCopy.data.forEach(datum => { - minX = Math.min(minX, ...datum.values.map(v => v.x)); - maxX = Math.max(maxX, ...datum.values.map(v => v.x)); - }); - // add null values at the edges - queryDataCopy.data.forEach(datum => { - datum.values.push({ x: minX, y: null }); - datum.values.push({ x: maxX, y: null }); - }); - } - - this.setState({ queryData: queryDataCopy }); - }); - } - - render() { - const { - width, - height, - annotationData, - datasource, - formData, - onAddFilter, - onError, - } = this.props; - const { queryData } = this.state; - - return ( - - ); - } -} - -LineMulti.propTypes = propTypes; -LineMulti.defaultProps = defaultProps; - -export default LineMulti; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/images/thumbnail.png deleted file mode 100644 index f776bb847b..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/images/thumbnailLarge.png deleted file mode 100644 index 473be99b21..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/index.js deleted file mode 100644 index dfbf666214..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/LineMulti/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: '', - name: t('Multiple Line Charts'), - thumbnail, - useLegacyApi: true, -}); - -export default class LineChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('./LineMulti'), - metadata, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.css b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.css deleted file mode 100644 index 35612b25bf..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.css +++ /dev/null @@ -1,123 +0,0 @@ -/** - * 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. - */ -.superset-legacy-chart-nvd3-dist-bar { - overflow-x: auto !important; -} - -.superset-legacy-chart-nvd3-dist-bar svg.nvd3-svg { - width: auto; - font-size: 14px; -} - -.superset-legacy-chart-nvd3-bar { - overflow-x: auto !important; -} - -.superset-legacy-chart-nvd3-bar svg.nvd3-svg { - width: auto; -} - -.superset-legacy-chart-nvd3 .nv-x text{ - font-size: 12px; -} - -.superset-legacy-chart-nvd3 g.superset path { - stroke-dasharray: 5, 5; -} - -.superset-legacy-chart-nvd3 .nvtooltip tr.highlight td { - font-weight: bold; - font-size: 15px !important; -} - -.superset-legacy-chart-nvd3 text.nv-axislabel { - font-size: 14px; -} - -.superset-legacy-chart-nvd3 text.nv-axislabel { - font-size: 14px !important; -} - -.superset-legacy-chart-nvd3 g.solid path, .superset-legacy-chart-nvd3 line.solid { - stroke-dasharray: unset; -} - -.superset-legacy-chart-nvd3 g.dashed path, .superset-legacy-chart-nvd3 line.dashed { - stroke-dasharray: 5, 5; -} - -.superset-legacy-chart-nvd3 g.longDashed path, .superset-legacy-chart-nvd3 line.longDashed { - stroke-dasharray: 10, 2; -} - -.superset-legacy-chart-nvd3 g.dotted path, .superset-legacy-chart-nvd3 line.dotted { - stroke-dasharray: 1, 1; -} - -.superset-legacy-chart-nvd3 g.opacityLow path, .superset-legacy-chart-nvd3 line.opacityLow { - stroke-opacity: .2 -} - -.superset-legacy-chart-nvd3 g.opacityMedium path, .superset-legacy-chart-nvd3 line.opacityMedium { - stroke-opacity: .5 -} - -.superset-legacy-chart-nvd3 g.opacityHigh path, .superset-legacy-chart-nvd3 line.opacityHigh { - stroke-opacity: .8 -} - -.superset-legacy-chart-nvd3 g.time-shift-0 path, .superset-legacy-chart-nvd3 line.time-shift-0 { - stroke-dasharray: 5, 5; -} -.superset-legacy-chart-nvd3 g.time-shift-1 path, .superset-legacy-chart-nvd3 line.time-shift-1 { - stroke-dasharray: 1, 5; -} -.superset-legacy-chart-nvd3 g.time-shift-2 path, .superset-legacy-chart-nvd3 line.time-shift-2 { - stroke-dasharray: 10, 5; -} -.superset-legacy-chart-nvd3 g.time-shift-3 path, .superset-legacy-chart-nvd3 line.time-shift-3 { - stroke-dasharray: 5, 1; -} -.superset-legacy-chart-nvd3 g.time-shift-4 path, .superset-legacy-chart-nvd3 line.time-shift-4 { - stroke-dasharray: 5, 10; -} -.superset-legacy-chart-nvd3 g.time-shift-5 path, .superset-legacy-chart-nvd3 line.time-shift-5 { - stroke-dasharray: 0.9; -} -.superset-legacy-chart-nvd3 g.time-shift-6 path, .superset-legacy-chart-nvd3 line.time-shift-6 { - stroke-dasharray: 15, 10, 5; -} -.superset-legacy-chart-nvd3 g.time-shift-7 path, .superset-legacy-chart-nvd3 line.time-shift-7 { - stroke-dasharray: 15, 10, 5, 10; -} -.superset-legacy-chart-nvd3 g.time-shift-8 path, .superset-legacy-chart-nvd3 line.time-shift-8 { - stroke-dasharray: 15, 10, 5, 10, 15; -} -.superset-legacy-chart-nvd3 g.time-shift-9 path, .superset-legacy-chart-nvd3 line.time-shift-9 { - stroke-dasharray: 5, 5, 1, 5; -} -.superset-legacy-chart-nvd3-tr-highlight { - border-top: 1px solid; - border-bottom: 1px solid; - font-weight: bold; -} - -.superset-legacy-chart-nvd3-tr-total { - font-weight: bold; -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js deleted file mode 100644 index 4e3b2d405a..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js +++ /dev/null @@ -1,1112 +0,0 @@ -/** - * 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-disable no-magic-numbers, complexity, sort-keys */ -/* eslint-disable no-plusplus, react/forbid-prop-types */ -import { kebabCase, throttle } from 'lodash'; -import d3 from 'd3'; -import nv from 'nvd3'; -import mathjs from 'mathjs'; -import moment from 'moment'; -import PropTypes from 'prop-types'; -import { isDefined } from '@superset-ui/core'; -import { t } from '@superset-ui/translation'; -import { CategoricalColorNamespace } from '@superset-ui/color'; -import { getNumberFormatter, NumberFormats } from '@superset-ui/number-format'; -import { getTimeFormatter, smartDateVerboseFormatter } from '@superset-ui/time-format'; -import 'nvd3/build/nv.d3.min.css'; -/* eslint-disable-next-line */ -import ANNOTATION_TYPES, { applyNativeColumns } from './vendor/superset/AnnotationTypes'; -import isTruthy from './utils/isTruthy'; -import { - cleanColorInput, - computeBarChartWidth, - computeYDomain, - computeStackedYDomain, - drawBarValues, - generateBubbleTooltipContent, - generateMultiLineTooltipContent, - generateRichLineTooltipContent, - generateTimePivotTooltip, - generateTooltipClassName, - generateAreaChartTooltipContent, - getMaxLabelSize, - getTimeOrNumberFormatter, - hideTooltips, - tipFactory, - tryNumify, - removeTooltip, - setAxisShowMaxMin, - stringifyTimeRange, - wrapTooltip, -} from './utils'; -import { - annotationLayerType, - boxPlotValueType, - bulletDataType, - categoryAndValueXYType, - rgbObjectType, - numericXYType, - numberOrAutoType, - stringOrObjectWithLabelType, -} from './PropTypes'; -import './NVD3Vis.css'; - -const { getColor, getScale } = CategoricalColorNamespace; - -// Limit on how large axes margins can grow as the chart window is resized -const MAX_MARGIN_PAD = 30; -const MIN_HEIGHT_FOR_BRUSH = 480; -const MAX_NO_CHARACTERS_IN_LABEL = 40; - -const BREAKPOINTS = { - small: 340, -}; - -const TIMESERIES_VIZ_TYPES = [ - 'line', - 'dual_line', - 'line_multi', - 'area', - 'compare', - 'bar', - 'time_pivot', -]; - -const propTypes = { - data: PropTypes.oneOfType([ - PropTypes.arrayOf( - PropTypes.oneOfType([ - // pie - categoryAndValueXYType, - // dist-bar - PropTypes.shape({ - key: PropTypes.string, - values: PropTypes.arrayOf(categoryAndValueXYType), - }), - // area, line, compare, bar - PropTypes.shape({ - key: PropTypes.arrayOf(PropTypes.string), - values: PropTypes.arrayOf(numericXYType), - }), - // dual-line - PropTypes.shape({ - classed: PropTypes.string, - key: PropTypes.string, - type: PropTypes.string, - values: PropTypes.arrayOf(numericXYType), - yAxis: PropTypes.number, - }), - // box-plot - PropTypes.shape({ - label: PropTypes.string, - values: PropTypes.arrayOf(boxPlotValueType), - }), - // bubble - PropTypes.shape({ - key: PropTypes.string, - values: PropTypes.arrayOf(PropTypes.object), - }), - ]), - ), - // bullet - bulletDataType, - ]), - width: PropTypes.number, - height: PropTypes.number, - annotationData: PropTypes.object, - annotationLayers: PropTypes.arrayOf(annotationLayerType), - bottomMargin: numberOrAutoType, - colorScheme: PropTypes.string, - comparisonType: PropTypes.string, - contribution: PropTypes.bool, - leftMargin: numberOrAutoType, - onError: PropTypes.func, - showLegend: PropTypes.bool, - showMarkers: PropTypes.bool, - useRichTooltip: PropTypes.bool, - vizType: PropTypes.oneOf([ - 'area', - 'bar', - 'box_plot', - 'bubble', - 'bullet', - 'compare', - 'column', - 'dist_bar', - 'line', - 'line_multi', - 'time_pivot', - 'pie', - 'dual_line', - ]), - xAxisFormat: PropTypes.string, - numberFormat: PropTypes.string, - xAxisLabel: PropTypes.string, - xAxisShowMinMax: PropTypes.bool, - xIsLogScale: PropTypes.bool, - xTicksLayout: PropTypes.oneOf(['auto', 'staggered', '45°']), - yAxisFormat: PropTypes.string, - yAxisBounds: PropTypes.arrayOf(PropTypes.number), - yAxisLabel: PropTypes.string, - yAxisShowMinMax: PropTypes.bool, - yIsLogScale: PropTypes.bool, - // 'dist-bar' only - orderBars: PropTypes.bool, - // 'bar' or 'dist-bar' - isBarStacked: PropTypes.bool, - showBarValue: PropTypes.bool, - // 'bar', 'dist-bar' or 'column' - reduceXTicks: PropTypes.bool, - // 'bar', 'dist-bar' or 'area' - showControls: PropTypes.bool, - // 'line' only - showBrush: PropTypes.oneOf([true, 'yes', false, 'no', 'auto']), - onBrushEnd: PropTypes.func, - // 'line-multi' or 'dual-line' - yAxis2Format: PropTypes.string, - // 'line', 'time-pivot', 'dual-line' or 'line-multi' - lineInterpolation: PropTypes.string, - // 'pie' only - isDonut: PropTypes.bool, - isPieLabelOutside: PropTypes.bool, - pieLabelType: PropTypes.oneOf(['key', 'value', 'percent', 'key_value', 'key_percent']), - showLabels: PropTypes.bool, - // 'area' only - areaStackedStyle: PropTypes.string, - // 'bubble' only - entity: PropTypes.string, - maxBubbleSize: PropTypes.number, - xField: stringOrObjectWithLabelType, - yField: stringOrObjectWithLabelType, - sizeField: stringOrObjectWithLabelType, - // time-pivot only - baseColor: rgbObjectType, -}; - -const NOOP = () => {}; -const formatter = getNumberFormatter(); - -function nvd3Vis(element, props) { - const { - data, - width: maxWidth, - height: maxHeight, - annotationData, - annotationLayers = [], - areaStackedStyle, - baseColor, - bottomMargin, - colorScheme, - comparisonType, - contribution, - entity, - isBarStacked, - isDonut, - isPieLabelOutside, - leftMargin, - lineInterpolation = 'linear', - maxBubbleSize, - onBrushEnd = NOOP, - onError = NOOP, - orderBars, - pieLabelType, - reduceXTicks = false, - showBarValue, - showBrush, - showControls, - showLabels, - showLegend, - showMarkers, - sizeField, - useRichTooltip, - vizType, - xAxisFormat, - numberFormat, - xAxisLabel, - xAxisShowMinMax = false, - xField, - xIsLogScale, - xTicksLayout, - yAxisFormat, - yAxis2Format, - yAxisBounds, - yAxisLabel, - yAxisShowMinMax = false, - yField, - yIsLogScale, - } = props; - - const isExplore = document.querySelector('#explorer-container') !== null; - const container = element; - container.innerHTML = ''; - const activeAnnotationLayers = annotationLayers.filter(layer => layer.show); - const chartId = - container.parentElement && container.parentElement.id !== '' - ? container.parentElement.id - : null; - - let chart; - let width = maxWidth; - let colorKey = 'key'; - - container.style.width = `${maxWidth}px`; - container.style.height = `${maxHeight}px`; - - function isVizTypes(types) { - return types.indexOf(vizType) >= 0; - } - - const drawGraph = function drawGraph() { - const d3Element = d3.select(element); - d3Element.classed('superset-legacy-chart-nvd3', true); - d3Element.classed(`superset-legacy-chart-nvd3-${kebabCase(vizType)}`, true); - let svg = d3Element.select('svg'); - if (svg.empty()) { - svg = d3Element.append('svg'); - } - const height = vizType === 'bullet' ? Math.min(maxHeight, 50) : maxHeight; - const isTimeSeries = isVizTypes(TIMESERIES_VIZ_TYPES); - - // Handling xAxis ticks settings - const staggerLabels = xTicksLayout === 'staggered'; - const xLabelRotation = - (xTicksLayout === 'auto' && isVizTypes(['column', 'dist_bar'])) || xTicksLayout === '45°' - ? 45 - : 0; - if (xLabelRotation === 45 && isTruthy(showBrush)) { - onError(t('You cannot use 45° tick layout along with the time range filter')); - - return null; - } - - const canShowBrush = - isTruthy(showBrush) || - (showBrush === 'auto' && maxHeight >= MIN_HEIGHT_FOR_BRUSH && xTicksLayout !== '45°'); - const numberFormatter = getNumberFormatter(numberFormat); - - switch (vizType) { - case 'line': - if (canShowBrush) { - chart = nv.models.lineWithFocusChart(); - if (staggerLabels) { - // Give a bit more room to focus area if X axis ticks are staggered - chart.focus.margin({ bottom: 40 }); - chart.focusHeight(80); - } - chart.focus.xScale(d3.time.scale.utc()); - } else { - chart = nv.models.lineChart(); - } - chart.xScale(d3.time.scale.utc()); - chart.interpolate(lineInterpolation); - chart.clipEdge(false); - break; - - case 'time_pivot': - chart = nv.models.lineChart(); - chart.xScale(d3.time.scale.utc()); - chart.interpolate(lineInterpolation); - break; - - case 'dual_line': - case 'line_multi': - chart = nv.models.multiChart(); - chart.interpolate(lineInterpolation); - break; - - case 'bar': - chart = nv.models - .multiBarChart() - .showControls(showControls) - .groupSpacing(0.1); - - if (!reduceXTicks) { - width = computeBarChartWidth(data, isBarStacked, maxWidth); - } - chart.width(width); - chart.xAxis.showMaxMin(false); - chart.stacked(isBarStacked); - break; - - case 'dist_bar': - chart = nv.models - .multiBarChart() - .showControls(showControls) - .reduceXTicks(reduceXTicks) - .groupSpacing(0.1); // Distance between each group of bars. - - chart.xAxis.showMaxMin(false); - - chart.stacked(isBarStacked); - if (orderBars) { - data.forEach(d => { - d.values.sort((a, b) => (tryNumify(a.x) < tryNumify(b.x) ? -1 : 1)); - }); - } - if (!reduceXTicks) { - width = computeBarChartWidth(data, isBarStacked, maxWidth); - } - chart.width(width); - break; - - case 'pie': - chart = nv.models.pieChart(); - colorKey = 'x'; - chart.valueFormat(numberFormatter); - if (isDonut) { - chart.donut(true); - } - chart.showLabels(showLabels); - chart.labelsOutside(isPieLabelOutside); - // Configure the minimum slice size for labels to show up - chart.labelThreshold(0.05); - chart.cornerRadius(true); - - if (['key', 'value', 'percent'].indexOf(pieLabelType) >= 0) { - chart.labelType(pieLabelType); - } else if (pieLabelType === 'key_value') { - chart.labelType(d => `${d.data.x}: ${numberFormatter(d.data.y)}`); - } else if (pieLabelType === 'key_percent') { - const total = d3.sum(data, d => d.y); - chart.tooltip.valueFormatter(d => `${((d / total) * 100).toFixed()}%`); - chart.labelType(d => `${d.data.x}: ${((d.data.y / total) * 100).toFixed()}%`); - } - // Pie chart does not need top margin - chart.margin({ top: 0 }); - break; - - case 'column': - chart = nv.models.multiBarChart().reduceXTicks(false); - break; - - case 'compare': - chart = nv.models.cumulativeLineChart(); - chart.xScale(d3.time.scale.utc()); - chart.useInteractiveGuideline(true); - chart.xAxis.showMaxMin(false); - break; - - case 'bubble': - chart = nv.models.scatterChart(); - chart.showDistX(false); - chart.showDistY(false); - chart.tooltip.contentGenerator(d => - generateBubbleTooltipContent({ - point: d.point, - entity, - xField, - yField, - sizeField, - xFormatter: getTimeOrNumberFormatter(xAxisFormat), - yFormatter: getTimeOrNumberFormatter(yAxisFormat), - sizeFormatter: formatter, - }), - ); - chart.pointRange([5, maxBubbleSize ** 2]); - chart.pointDomain([0, d3.max(data, d => d3.max(d.values, v => v.size))]); - break; - - case 'area': - chart = nv.models.stackedAreaChart(); - chart.showControls(showControls); - chart.style(areaStackedStyle); - chart.xScale(d3.time.scale.utc()); - break; - - case 'box_plot': - colorKey = 'label'; - chart = nv.models.boxPlotChart(); - chart.x(d => d.label); - chart.maxBoxWidth(75); // prevent boxes from being incredibly wide - break; - - case 'bullet': - chart = nv.models.bulletChart(); - break; - - default: - throw new Error(`Unrecognized visualization for nvd3${vizType}`); - } - // Assuming the container has padding already other than for top margin - chart.margin({ left: 0, right: 0, bottom: 0 }); - - if (showBarValue) { - drawBarValues(svg, data, isBarStacked, yAxisFormat); - chart.dispatch.on('stateChange.drawBarValues', () => { - drawBarValues(svg, data, isBarStacked, yAxisFormat); - }); - } - - if (canShowBrush && onBrushEnd !== NOOP) { - chart.focus.dispatch.on('brush', event => { - const timeRange = stringifyTimeRange(event.extent); - if (timeRange) { - event.brush.on('brushend', () => { - onBrushEnd(timeRange); - }); - } - }); - } - - if (chart.xAxis && chart.xAxis.staggerLabels) { - chart.xAxis.staggerLabels(staggerLabels); - } - if (chart.xAxis && chart.xAxis.rotateLabels) { - chart.xAxis.rotateLabels(xLabelRotation); - } - if (chart.x2Axis && chart.x2Axis.staggerLabels) { - chart.x2Axis.staggerLabels(staggerLabels); - } - if (chart.x2Axis && chart.x2Axis.rotateLabels) { - chart.x2Axis.rotateLabels(xLabelRotation); - } - - if ('showLegend' in chart && typeof showLegend !== 'undefined') { - if (width < BREAKPOINTS.small && vizType !== 'pie') { - chart.showLegend(false); - } else { - chart.showLegend(showLegend); - } - } - - if (yIsLogScale) { - chart.yScale(d3.scale.log()); - } - if (xIsLogScale) { - chart.xScale(d3.scale.log()); - } - - let xAxisFormatter; - if (isTimeSeries) { - xAxisFormatter = getTimeFormatter(xAxisFormat); - // In tooltips, always use the verbose time format - chart.interactiveLayer.tooltip.headerFormatter(smartDateVerboseFormatter); - } else { - xAxisFormatter = getTimeOrNumberFormatter(xAxisFormat); - } - if (chart.x2Axis && chart.x2Axis.tickFormat) { - chart.x2Axis.tickFormat(xAxisFormatter); - } - if (chart.xAxis && chart.xAxis.tickFormat) { - const isXAxisString = isVizTypes(['dist_bar', 'box_plot']); - if (isXAxisString) { - chart.xAxis.tickFormat(d => - d.length > MAX_NO_CHARACTERS_IN_LABEL - ? `${d.substring(0, MAX_NO_CHARACTERS_IN_LABEL)}…` - : d, - ); - } else { - chart.xAxis.tickFormat(xAxisFormatter); - } - } - - let yAxisFormatter = getTimeOrNumberFormatter(yAxisFormat); - if (chart.yAxis && chart.yAxis.tickFormat) { - if (contribution || comparisonType === 'percentage') { - // When computing a "Percentage" or "Contribution" selected, we force a percentage format - yAxisFormatter = getNumberFormatter(NumberFormats.PERCENT_1_POINT); - } - chart.yAxis.tickFormat(yAxisFormatter); - } - if (chart.y2Axis && chart.y2Axis.tickFormat) { - chart.y2Axis.tickFormat(yAxisFormatter); - } - - if (chart.yAxis) { - chart.yAxis.ticks(5); - } - if (chart.y2Axis) { - chart.y2Axis.ticks(5); - } - - // Set showMaxMin for all axis - setAxisShowMaxMin(chart.xAxis, xAxisShowMinMax); - setAxisShowMaxMin(chart.x2Axis, xAxisShowMinMax); - setAxisShowMaxMin(chart.yAxis, yAxisShowMinMax); - setAxisShowMaxMin(chart.y2Axis, yAxisShowMinMax); - - if (vizType === 'time_pivot') { - if (baseColor) { - const { r, g, b } = baseColor; - chart.color(d => { - const alpha = d.rank > 0 ? d.perc * 0.5 : 1; - - return `rgba(${r}, ${g}, ${b}, ${alpha})`; - }); - } - - chart.useInteractiveGuideline(true); - chart.interactiveLayer.tooltip.contentGenerator(d => - generateTimePivotTooltip(d, xAxisFormatter, yAxisFormatter), - ); - } else if (vizType !== 'bullet') { - const colorFn = getScale(colorScheme); - chart.color(d => d.color || colorFn(cleanColorInput(d[colorKey]))); - } - - if (isVizTypes(['line', 'area']) && useRichTooltip) { - chart.useInteractiveGuideline(true); - if (vizType === 'line') { - chart.interactiveLayer.tooltip.contentGenerator(d => - generateRichLineTooltipContent(d, smartDateVerboseFormatter, yAxisFormatter), - ); - } else if (areaStackedStyle !== 'expand') { - // area chart - chart.interactiveLayer.tooltip.contentGenerator(d => - generateAreaChartTooltipContent(d, smartDateVerboseFormatter, yAxisFormatter), - ); - } - } - - if (isVizTypes(['dual_line', 'line_multi'])) { - const yAxisFormatter1 = getNumberFormatter(yAxisFormat); - const yAxisFormatter2 = getNumberFormatter(yAxis2Format); - chart.yAxis1.tickFormat(yAxisFormatter1); - chart.yAxis2.tickFormat(yAxisFormatter2); - const yAxisFormatters = data.map(datum => - datum.yAxis === 1 ? yAxisFormatter1 : yAxisFormatter2, - ); - chart.useInteractiveGuideline(true); - chart.interactiveLayer.tooltip.contentGenerator(d => - generateMultiLineTooltipContent(d, xAxisFormatter, yAxisFormatters), - ); - if (vizType === 'dual_line') { - chart.showLegend(width > BREAKPOINTS.small); - } else { - chart.showLegend(showLegend); - } - } - // This is needed for correct chart dimensions if a chart is rendered in a hidden container - chart.width(width); - chart.height(height); - - svg - .datum(data) - .transition() - .duration(500) - .attr('height', height) - .attr('width', width) - .call(chart); - - // For log scale, only show 1, 10, 100, 1000, ... - if (yIsLogScale) { - chart.yAxis.tickFormat(d => (d !== 0 && Math.log10(d) % 1 === 0 ? yAxisFormatter(d) : '')); - } - - if (xLabelRotation > 0) { - // shift labels to the left so they look better - const xTicks = svg.select('.nv-x.nv-axis > g').selectAll('g'); - xTicks.selectAll('text').attr('dx', -6.5); - } - - const applyYAxisBounds = () => { - if (chart.yDomain && Array.isArray(yAxisBounds) && yAxisBounds.length === 2) { - const [customMin, customMax] = yAxisBounds; - const hasCustomMin = isDefined(customMin) && !Number.isNaN(customMin); - const hasCustomMax = isDefined(customMax) && !Number.isNaN(customMax); - - if ((hasCustomMin || hasCustomMax) && vizType === 'area' && chart.style() === 'expand') { - // Because there are custom bounds, we need to override them back to 0%-100% since this - // is an expanded area chart - chart.yDomain([0, 1]); - } else if ( - (hasCustomMin || hasCustomMax) && - vizType === 'area' && - chart.style() === 'stream' - ) { - // Because there are custom bounds, we need to override them back to the domain of the - // data since this is a stream area chart - chart.yDomain(computeStackedYDomain(data)); - } else if (hasCustomMin && hasCustomMax) { - // Override the y domain if there's both a custom min and max - chart.yDomain([customMin, customMax]); - chart.clipEdge(true); - } else if (hasCustomMin || hasCustomMax) { - // Only one of the bounds has been set, so we need to manually calculate the other one - let [trueMin, trueMax] = [0, 1]; - - // These viz types can be stacked - // They correspond to the nvd3 stackedAreaChart and multiBarChart - if (vizType === 'area' || (isVizTypes(['bar', 'dist_bar']) && chart.stacked())) { - // This is a stacked area chart or a stacked bar chart - [trueMin, trueMax] = computeStackedYDomain(data); - } else { - [trueMin, trueMax] = computeYDomain(data); - } - - const min = hasCustomMin ? customMin : trueMin; - const max = hasCustomMax ? customMax : trueMax; - chart.yDomain([min, max]); - chart.clipEdge(true); - } - } - }; - applyYAxisBounds(); - - // Also reapply on each state change to account for enabled/disabled series - if (chart.dispatch && chart.dispatch.stateChange) { - chart.dispatch.on('stateChange.applyYAxisBounds', applyYAxisBounds); - } - - // align yAxis1 and yAxis2 ticks - if (isVizTypes(['dual_line', 'line_multi'])) { - const count = chart.yAxis1.ticks(); - const ticks1 = chart.yAxis1 - .scale() - .domain(chart.yAxis1.domain()) - .nice(count) - .ticks(count); - const ticks2 = chart.yAxis2 - .scale() - .domain(chart.yAxis2.domain()) - .nice(count) - .ticks(count); - - // match number of ticks in both axes - const difference = ticks1.length - ticks2.length; - if (ticks1.length && ticks2.length && difference !== 0) { - const smallest = difference < 0 ? ticks1 : ticks2; - const delta = smallest[1] - smallest[0]; - for (let i = 0; i < Math.abs(difference); i++) { - if (i % 2 === 0) { - smallest.unshift(smallest[0] - delta); - } else { - smallest.push(smallest[smallest.length - 1] + delta); - } - } - chart.yDomain1([ticks1[0], ticks1[ticks1.length - 1]]); - chart.yDomain2([ticks2[0], ticks2[ticks2.length - 1]]); - chart.yAxis1.tickValues(ticks1); - chart.yAxis2.tickValues(ticks2); - } - } - - if (showMarkers) { - svg - .selectAll('.nv-point') - .style('stroke-opacity', 1) - .style('fill-opacity', 1); - - // redo on legend toggle; nvd3 calls the callback *before* the line is - // drawn, so we need to add a small delay here - chart.dispatch.on('stateChange.showMarkers', () => { - setTimeout(() => { - svg - .selectAll('.nv-point') - .style('stroke-opacity', 1) - .style('fill-opacity', 1); - }, 10); - }); - } - - if (chart.yAxis !== undefined || chart.yAxis2 !== undefined) { - // Hack to adjust y axis left margin to accommodate long numbers - const marginPad = Math.ceil(Math.min(maxWidth * (isExplore ? 0.01 : 0.03), MAX_MARGIN_PAD)); - // Hack to adjust margins to accommodate long axis tick labels. - // - has to be done only after the chart has been rendered once - // - measure the width or height of the labels - // ---- (x axis labels are rotated 45 degrees so we use height), - // - adjust margins based on these measures and render again - const margins = chart.margin(); - if (chart.xAxis) { - margins.bottom = 28; - } - const maxYAxisLabelWidth = getMaxLabelSize(svg, chart.yAxis2 ? 'nv-y1' : 'nv-y'); - const maxXAxisLabelHeight = getMaxLabelSize(svg, 'nv-x'); - margins.left = maxYAxisLabelWidth + marginPad; - - if (yAxisLabel && yAxisLabel !== '') { - margins.left += 25; - } - if (showBarValue) { - // Add more margin to avoid label colliding with legend. - margins.top += 24; - } - if (xAxisShowMinMax) { - // If x bounds are shown, we need a right margin - margins.right = Math.max(20, maxXAxisLabelHeight / 2) + marginPad; - } - if (xLabelRotation === 45) { - margins.bottom = - maxXAxisLabelHeight * Math.sin((Math.PI * xLabelRotation) / 180) + marginPad + 30; - margins.right = - maxXAxisLabelHeight * Math.cos((Math.PI * xLabelRotation) / 180) + marginPad; - } else if (staggerLabels) { - margins.bottom = 40; - } - - if (isVizTypes(['dual_line', 'line_multi'])) { - const maxYAxis2LabelWidth = getMaxLabelSize(svg, 'nv-y2'); - margins.right = maxYAxis2LabelWidth + marginPad; - } - if (bottomMargin && bottomMargin !== 'auto') { - margins.bottom = parseInt(bottomMargin, 10); - } - if (leftMargin && leftMargin !== 'auto') { - margins.left = leftMargin; - } - - if (xAxisLabel && xAxisLabel !== '' && chart.xAxis) { - margins.bottom += 25; - let distance = 0; - if (margins.bottom && !Number.isNaN(margins.bottom)) { - distance = margins.bottom - 45; - } - // nvd3 bug axisLabelDistance is disregarded on xAxis - // https://github.com/krispo/angular-nvd3/issues/90 - chart.xAxis.axisLabel(xAxisLabel).axisLabelDistance(distance); - } - - if (yAxisLabel && yAxisLabel !== '' && chart.yAxis) { - let distance = 0; - if (margins.left && !Number.isNaN(margins.left)) { - distance = margins.left - 70; - } - chart.yAxis.axisLabel(yAxisLabel).axisLabelDistance(distance); - } - if (isTimeSeries && annotationData && activeAnnotationLayers.length > 0) { - // Time series annotations add additional data - const timeSeriesAnnotations = activeAnnotationLayers - .filter(layer => layer.annotationType === ANNOTATION_TYPES.TIME_SERIES) - .reduce( - (bushel, a) => - bushel.concat( - (annotationData[a.name] || []).map(series => { - if (!series) { - return {}; - } - const key = Array.isArray(series.key) - ? `${a.name}, ${series.key.join(', ')}` - : `${a.name}, ${series.key}`; - - return { - ...series, - key, - color: a.color, - strokeWidth: a.width, - classed: `${a.opacity} ${a.style} nv-timeseries-annotation-layer showMarkers${a.showMarkers} hideLine${a.hideLine}`, - }; - }), - ), - [], - ); - data.push(...timeSeriesAnnotations); - } - - // Uniquely identify tooltips based on chartId so this chart instance only - // controls its own tooltips - if (chartId) { - if (chart && chart.interactiveLayer && chart.interactiveLayer.tooltip) { - chart.interactiveLayer.tooltip.classes([generateTooltipClassName(chartId)]); - } - - if (chart && chart.tooltip) { - chart.tooltip.classes([generateTooltipClassName(chartId)]); - } - } - - // render chart - svg - .datum(data) - .transition() - .duration(500) - .attr('width', width) - .attr('height', height) - .call(chart); - - // On scroll, hide (not remove) tooltips so they can reappear on hover. - // Throttle to only 4x/second. - window.addEventListener('scroll', throttle(() => hideTooltips(false), 250)); - - // The below code should be run AFTER rendering because chart is updated in call() - if (isTimeSeries && activeAnnotationLayers.length > 0) { - // Formula annotations - const formulas = activeAnnotationLayers - .filter(a => a.annotationType === ANNOTATION_TYPES.FORMULA) - .map(a => ({ ...a, formula: mathjs.parse(a.value) })); - - let xMax; - let xMin; - let xScale; - if (vizType === 'bar') { - xMin = d3.min(data[0].values, d => d.x); - xMax = d3.max(data[0].values, d => d.x); - xScale = d3.scale - .quantile() - .domain([xMin, xMax]) - .range(chart.xAxis.range()); - } else { - xMin = chart.xAxis - .scale() - .domain()[0] - .valueOf(); - xMax = chart.xAxis - .scale() - .domain()[1] - .valueOf(); - if (chart.xScale) { - xScale = chart.xScale(); - } else if (chart.xAxis.scale) { - xScale = chart.xAxis.scale(); - } else { - xScale = d3.scale.linear(); - } - } - if (xScale && xScale.clamp) { - xScale.clamp(true); - } - - if (formulas.length > 0) { - const xValues = []; - if (vizType === 'bar') { - // For bar-charts we want one data point evaluated for every - // data point that will be displayed. - const distinct = data.reduce((xVals, d) => { - d.values.forEach(x => xVals.add(x.x)); - - return xVals; - }, new Set()); - xValues.push(...distinct.values()); - xValues.sort(); - } else { - // For every other time visualization it should be ok, to have a - // data points in even intervals. - let period = Math.min( - ...data.map(d => Math.min(...d.values.slice(1).map((v, i) => v.x - d.values[i].x))), - ); - const dataPoints = (xMax - xMin) / (period || 1); - // make sure that there are enough data points and not too many - period = dataPoints < 100 ? (xMax - xMin) / 100 : period; - period = dataPoints > 500 ? (xMax - xMin) / 500 : period; - xValues.push(xMin); - for (let x = xMin; x < xMax; x += period) { - xValues.push(x); - } - xValues.push(xMax); - } - const formulaData = formulas.map(fo => ({ - key: fo.name, - values: xValues.map(x => ({ y: fo.formula.eval({ x }), x })), - color: fo.color, - strokeWidth: fo.width, - classed: `${fo.opacity} ${fo.style}`, - })); - data.push(...formulaData); - } - const xAxis = chart.xAxis1 ? chart.xAxis1 : chart.xAxis; - const yAxis = chart.yAxis1 ? chart.yAxis1 : chart.yAxis; - const chartWidth = xAxis.scale().range()[1]; - const annotationHeight = yAxis.scale().range()[0]; - - if (annotationData) { - // Event annotations - activeAnnotationLayers - .filter( - x => - x.annotationType === ANNOTATION_TYPES.EVENT && - annotationData && - annotationData[x.name], - ) - .forEach((config, index) => { - const e = applyNativeColumns(config); - // Add event annotation layer - const annotations = d3 - .select(element) - .select('.nv-wrap') - .append('g') - .attr('class', `nv-event-annotation-layer-${index}`); - const aColor = e.color || getColor(cleanColorInput(e.name), colorScheme); - - const tip = tipFactory(e); - const records = (annotationData[e.name].records || []) - .map(r => { - const timeValue = new Date(moment.utc(r[e.timeColumn])); - - return { - ...r, - [e.timeColumn]: timeValue, - }; - }) - .filter(record => !Number.isNaN(record[e.timeColumn].getMilliseconds())); - - if (records.length) { - annotations - .selectAll('line') - .data(records) - .enter() - .append('line') - .attr({ - x1: d => xScale(new Date(d[e.timeColumn])), - y1: 0, - x2: d => xScale(new Date(d[e.timeColumn])), - y2: annotationHeight, - }) - .attr('class', `${e.opacity} ${e.style}`) - .style('stroke', aColor) - .style('stroke-width', e.width) - .on('mouseover', tip.show) - .on('mouseout', tip.hide) - .call(tip); - } - - // update annotation positions on brush event - chart.focus.dispatch.on('onBrush.event-annotation', () => { - annotations - .selectAll('line') - .data(records) - .attr({ - x1: d => xScale(new Date(d[e.timeColumn])), - y1: 0, - x2: d => xScale(new Date(d[e.timeColumn])), - y2: annotationHeight, - opacity: d => { - const x = xScale(new Date(d[e.timeColumn])); - - return x > 0 && x < chartWidth ? 1 : 0; - }, - }); - }); - }); - - // Interval annotations - activeAnnotationLayers - .filter( - x => - x.annotationType === ANNOTATION_TYPES.INTERVAL && - annotationData && - annotationData[x.name], - ) - .forEach((config, index) => { - const e = applyNativeColumns(config); - // Add interval annotation layer - const annotations = d3 - .select(element) - .select('.nv-wrap') - .append('g') - .attr('class', `nv-interval-annotation-layer-${index}`); - - const aColor = e.color || getColor(cleanColorInput(e.name), colorScheme); - const tip = tipFactory(e); - - const records = (annotationData[e.name].records || []) - .map(r => { - const timeValue = new Date(moment.utc(r[e.timeColumn])); - const intervalEndValue = new Date(moment.utc(r[e.intervalEndColumn])); - - return { - ...r, - [e.timeColumn]: timeValue, - [e.intervalEndColumn]: intervalEndValue, - }; - }) - .filter( - record => - !Number.isNaN(record[e.timeColumn].getMilliseconds()) && - !Number.isNaN(record[e.intervalEndColumn].getMilliseconds()), - ); - - if (records.length) { - annotations - .selectAll('rect') - .data(records) - .enter() - .append('rect') - .attr({ - x: d => - Math.min( - xScale(new Date(d[e.timeColumn])), - xScale(new Date(d[e.intervalEndColumn])), - ), - y: 0, - width: d => - Math.max( - Math.abs( - xScale(new Date(d[e.intervalEndColumn])) - - xScale(new Date(d[e.timeColumn])), - ), - 1, - ), - height: annotationHeight, - }) - .attr('class', `${e.opacity} ${e.style}`) - .style('stroke-width', e.width) - .style('stroke', aColor) - .style('fill', aColor) - .style('fill-opacity', 0.2) - .on('mouseover', tip.show) - .on('mouseout', tip.hide) - .call(tip); - } - - // update annotation positions on brush event - chart.focus.dispatch.on('onBrush.interval-annotation', () => { - annotations - .selectAll('rect') - .data(records) - .attr({ - x: d => xScale(new Date(d[e.timeColumn])), - width: d => { - const x1 = xScale(new Date(d[e.timeColumn])); - const x2 = xScale(new Date(d[e.intervalEndColumn])); - - return x2 - x1; - }, - }); - }); - }); - } - - // rerender chart appended with annotation layer - svg - .datum(data) - .attr('height', height) - .attr('width', width) - .call(chart); - - // Display styles for Time Series Annotations - d3.selectAll('.slice_container .nv-timeseries-annotation-layer.showMarkerstrue .nv-point') - .style('stroke-opacity', 1) - .style('fill-opacity', 1); - d3.selectAll('.slice_container .nv-timeseries-annotation-layer.hideLinetrue').style( - 'stroke-width', - 0, - ); - } - } - - wrapTooltip(chart, maxWidth); - - return chart; - }; - - // Remove tooltips before rendering chart, if the chart is being re-rendered sometimes - // there are left over tooltips in the dom, - // this will clear them before rendering the chart again. - if (chartId) { - removeTooltip(chartId); - } else { - hideTooltips(true); - } - - nv.addGraph(drawGraph); -} - -nvd3Vis.displayName = 'NVD3'; -nvd3Vis.propTypes = propTypes; -export default nvd3Vis; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/images/thumbnail.png deleted file mode 100644 index 1c93bf593a..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/images/thumbnailLarge.png deleted file mode 100644 index ab76749f74..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/index.js deleted file mode 100644 index 83d3eb5f2b..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/Pie/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: '', - name: t('Pie Chart'), - thumbnail, - useLegacyApi: true, -}); - -export default class PieChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/PropTypes.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/PropTypes.js deleted file mode 100644 index 1ebcd48c18..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/PropTypes.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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-disable sort-keys */ -import PropTypes from 'prop-types'; -import { ANNOTATION_TYPES } from './vendor/superset/AnnotationTypes'; - -export const numberOrAutoType = PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['auto'])]); - -export const stringOrObjectWithLabelType = PropTypes.oneOfType([ - PropTypes.string, - PropTypes.shape({ - label: PropTypes.string, - }), -]); - -export const rgbObjectType = PropTypes.shape({ - r: PropTypes.number.isRequired, - g: PropTypes.number.isRequired, - b: PropTypes.number.isRequired, -}); - -export const numericXYType = PropTypes.shape({ - x: PropTypes.number, - y: PropTypes.number, -}); - -export const categoryAndValueXYType = PropTypes.shape({ - x: PropTypes.string, - y: PropTypes.number, -}); - -export const boxPlotValueType = PropTypes.shape({ - outliers: PropTypes.arrayOf(PropTypes.number), - Q1: PropTypes.number, - Q2: PropTypes.number, - Q3: PropTypes.number, - whisker_high: PropTypes.number, - whisker_low: PropTypes.number, -}); - -export const bulletDataType = PropTypes.shape({ - markerLabels: PropTypes.arrayOf(PropTypes.string), - markerLineLabels: PropTypes.arrayOf(PropTypes.string), - markerLines: PropTypes.arrayOf(PropTypes.number), - markers: PropTypes.arrayOf(PropTypes.number), - measures: PropTypes.arrayOf(PropTypes.number), - rangeLabels: PropTypes.arrayOf(PropTypes.string), - ranges: PropTypes.arrayOf(PropTypes.number), -}); - -export const annotationLayerType = PropTypes.shape({ - annotationType: PropTypes.oneOf(Object.keys(ANNOTATION_TYPES)), - color: PropTypes.string, - hideLine: PropTypes.bool, - name: PropTypes.string, - opacity: PropTypes.string, - show: PropTypes.bool, - showMarkers: PropTypes.bool, - sourceType: PropTypes.string, - style: PropTypes.string, - value: PropTypes.number, - width: PropTypes.number, -}); diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/ReactNVD3.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/ReactNVD3.js deleted file mode 100644 index 9183f302c7..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/ReactNVD3.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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 { reactify } from '@superset-ui/chart'; -import Component from './NVD3Vis'; -import { hideTooltips, removeTooltip } from './utils'; - -function componentWillUnmount() { - const { id } = this.props; // eslint-disable-line babel/no-invalid-this - if (id !== null && id !== undefined) { - removeTooltip(id); - } else { - hideTooltips(true); - } -} - -export default reactify(Component, { componentWillUnmount }); diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/images/thumbnail.png deleted file mode 100644 index 83201c2bc0..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/images/thumbnail.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/images/thumbnailLarge.png deleted file mode 100644 index 149f3dae5d..0000000000 Binary files a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/images/thumbnailLarge.png and /dev/null differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/index.js deleted file mode 100644 index de11d1c492..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/TimePivot/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 { t } from '@superset-ui/translation'; -import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; -import transformProps from '../transformProps'; -import thumbnail from './images/thumbnail.png'; - -const metadata = new ChartMetadata({ - credits: ['http://nvd3.org'], - description: '', - name: t('Time-series Period Pivot'), - thumbnail, - useLegacyApi: true, -}); - -export default class TimePivotChartPlugin extends ChartPlugin { - constructor() { - super({ - loadChart: () => import('../ReactNVD3'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/index.js deleted file mode 100644 index f28da16f01..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -export { default as NVD3ChartPreset } from './preset'; -export { default as AreaChartPlugin } from './Area'; -export { default as BarChartPlugin } from './Bar'; -export { default as BoxPlotChartPlugin } from './BoxPlot'; -export { default as BubbleChartPlugin } from './Bubble'; -export { default as BulletChartPlugin } from './Bullet'; -export { default as CompareChartPlugin } from './Compare'; -export { default as DistBarChartPlugin } from './DistBar'; -export { default as DualLineChartPlugin } from './DualLine'; -export { default as LineChartPlugin } from './Line'; -export { default as LineMultiChartPlugin } from './LineMulti'; -export { default as PieChartPlugin } from './Pie'; -export { default as TimePivotChartPlugin } from './TimePivot'; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/preset.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/preset.js deleted file mode 100644 index cccb877ecd..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/preset.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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 { Preset } from '@superset-ui/core'; -import AreaChartPlugin from './Area'; -import BarChartPlugin from './Bar'; -import BoxPlotChartPlugin from './BoxPlot'; -import BubbleChartPlugin from './Bubble'; -import BulletChartPlugin from './Bullet'; -import CompareChartPlugin from './Compare'; -import DistBarChartPlugin from './DistBar'; -import DualLineChartPlugin from './DualLine'; -import LineChartPlugin from './Line'; -import LineMultiChartPlugin from './LineMulti'; -import PieChartPlugin from './Pie'; -import TimePivotChartPlugin from './TimePivot'; - -export default class NVD3ChartPreset extends Preset { - constructor() { - super({ - name: 'NVD3 charts', - plugins: [ - new AreaChartPlugin().configure({ key: 'area' }), - new BarChartPlugin().configure({ key: 'bar' }), - new BoxPlotChartPlugin().configure({ key: 'box_plot' }), - new BubbleChartPlugin().configure({ key: 'bubble' }), - new BulletChartPlugin().configure({ key: 'bullet' }), - new CompareChartPlugin().configure({ key: 'compare' }), - new DistBarChartPlugin().configure({ key: 'dist_bar' }), - new DualLineChartPlugin().configure({ key: 'dual_line' }), - new LineChartPlugin().configure({ key: 'line' }), - new LineMultiChartPlugin().configure({ key: 'line_multi' }), - new PieChartPlugin().configure({ key: 'pie' }), - new TimePivotChartPlugin().configure({ key: 'time_pivot' }), - ], - }); - } -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/transformProps.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/transformProps.js deleted file mode 100644 index 9833888499..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/transformProps.js +++ /dev/null @@ -1,134 +0,0 @@ -/** - * 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-disable sort-keys */ -import isTruthy from './utils/isTruthy'; -import { formatLabel } from './utils'; - -const NOOP = () => {}; - -export default function transformProps(chartProps) { - const { width, height, annotationData, datasource, formData, hooks, queryData } = chartProps; - - const { onAddFilter = NOOP, onError = NOOP } = hooks; - - const { - annotationLayers, - barStacked, - bottomMargin, - colorPicker, - colorScheme, - comparisonType, - contribution, - donut, - entity, - labelsOutside, - leftMargin, - lineInterpolation, - maxBubbleSize, - orderBars, - pieLabelType, - reduceXTicks, - richTooltip, - sendTimeRange, - showBarValue, - showBrush, - showControls, - showLabels, - showLegend, - showMarkers, - size, - stackedStyle, - vizType, - x, - xAxisFormat, - xAxisLabel, - xAxisShowminmax, - numberFormat, - xLogScale, - xTicksLayout, - y, - yAxisFormat, - yAxis2Format, - yAxisBounds, - yAxisLabel, - yAxisShowminmax, - yLogScale, - } = formData; - - const rawData = queryData.data || []; - const data = Array.isArray(rawData) - ? rawData.map(row => ({ - ...row, - key: formatLabel(row.key, datasource.verboseMap), - })) - : rawData; - - return { - width, - height, - data, - annotationData, - annotationLayers, - areaStackedStyle: stackedStyle, - baseColor: colorPicker, - bottomMargin, - colorScheme, - comparisonType, - contribution, - entity, - isBarStacked: barStacked, - isDonut: donut, - isPieLabelOutside: labelsOutside, - leftMargin, - lineInterpolation, - maxBubbleSize: parseInt(maxBubbleSize, 10), - numberFormat, - onBrushEnd: isTruthy(sendTimeRange) - ? timeRange => { - onAddFilter('__time_range', timeRange, false, true); - } - : undefined, - onError, - orderBars, - pieLabelType, - reduceXTicks, - showBarValue, - showBrush, - showControls, - showLabels, - showLegend, - showMarkers, - sizeField: size, - useRichTooltip: richTooltip, - vizType, - xAxisFormat, - xAxisLabel, - xAxisShowMinMax: xAxisShowminmax, - xField: x, - xIsLogScale: xLogScale, - xTicksLayout, - yAxisFormat, - yAxis2Format, - yAxisBounds, - yAxisLabel, - yAxisShowMinMax: yAxisShowminmax, - yField: y, - yIsLogScale: yLogScale, - }; -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/utils.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/utils.js deleted file mode 100644 index 1be7b7e0e2..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/utils.js +++ /dev/null @@ -1,396 +0,0 @@ -/** - * 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-disable babel/no-invalid-this, no-magic-numbers */ -import d3 from 'd3'; -import d3tip from 'd3-tip'; -import dompurify from 'dompurify'; -import { getNumberFormatter } from '@superset-ui/number-format'; -import { smartDateFormatter } from '@superset-ui/time-format'; - -// Regexp for the label added to time shifted series -// (1 hour offset, 2 days offset, etc.) -const TIME_SHIFT_PATTERN = /\d+ \w+ offset/; - -const ANIMATION_TIME = 1000; - -export function cleanColorInput(value) { - // for superset series that should have the same color - return String(value) - .trim() - .replace(' (right axis)', '') - .split(', ') - .filter(k => !TIME_SHIFT_PATTERN.test(k)) - .join(', '); -} - -/** - * If format is smart_date, format date - * Otherwise, format number with the given format name - * @param {*} format - */ -export function getTimeOrNumberFormatter(format) { - return format === 'smart_date' ? smartDateFormatter : getNumberFormatter(format); -} - -export function drawBarValues(svg, data, stacked, axisFormat) { - const format = getNumberFormatter(axisFormat); - const countSeriesDisplayed = data.filter(d => !d.disabled).length; - - const totalStackedValues = - stacked && data.length !== 0 - ? data[0].values.map((bar, iBar) => { - const bars = data.filter(series => !series.disabled).map(series => series.values[iBar]); - - return d3.sum(bars, d => d.y); - }) - : []; - - svg.selectAll('.bar-chart-label-group').remove(); - setTimeout(() => { - const groupLabels = svg - .select('g.nv-barsWrap') - .append('g') - .attr('class', 'bar-chart-label-group'); - svg - .selectAll('g.nv-group') - .filter((d, i) => !stacked || i === countSeriesDisplayed - 1) - .selectAll('rect') - .each(function each(d, index) { - const rectObj = d3.select(this); - const transformAttr = rectObj.attr('transform'); - const xPos = parseFloat(rectObj.attr('x')); - const yPos = parseFloat(rectObj.attr('y')); - const rectWidth = parseFloat(rectObj.attr('width')); - const rectHeight = parseFloat(rectObj.attr('height')); - const textEls = groupLabels - .append('text') - .text(format(stacked ? totalStackedValues[index] : d.y)) - .attr('transform', transformAttr) - .attr('class', 'bar-chart-label'); - - // fine tune text position - const bbox = textEls.node().getBBox(); - const labelWidth = bbox.width; - const labelHeight = bbox.height; - textEls.attr('x', xPos + rectWidth / 2 - labelWidth / 2); - if (rectObj.attr('class').includes('positive')) { - textEls.attr('y', yPos - 5); - } else { - textEls.attr('y', yPos + rectHeight + labelHeight); - } - }); - }, ANIMATION_TIME); -} - -// Formats the series key to account for a possible NULL value -function getFormattedKey(seriesKey, shouldDompurify) { - if (seriesKey === '') { - return `<${seriesKey.slice(1, -1)}>`; - } - - return shouldDompurify ? dompurify.sanitize(seriesKey) : seriesKey; -} - -// Custom sorted tooltip -// use a verbose formatter for times -export function generateRichLineTooltipContent(d, timeFormatter, valueFormatter) { - let tooltip = ''; - tooltip += - "'; - d.series.sort((a, b) => (a.value >= b.value ? -1 : 1)); - d.series.forEach(series => { - const key = getFormattedKey(series.key, true); - tooltip += - `` + - `' + - `` + - `` + - ''; - }); - tooltip += '
" + - `${timeFormatter(d.value)}` + - '
` + - '
' + - '
${key}${valueFormatter(series.value)}
'; - - return dompurify.sanitize(tooltip); -} - -export function generateAreaChartTooltipContent(d, timeFormatter, valueFormatter) { - const total = d.series[d.series.length - 1].value; - let tooltip = ''; - tooltip += - "' + - ''; - d.series.forEach(series => { - const key = getFormattedKey(series.key, true); - let trClass = ''; - if (series.highlight) { - trClass = 'superset-legacy-chart-nvd3-tr-highlight'; - } else if (series.key === 'TOTAL') { - trClass = 'superset-legacy-chart-nvd3-tr-total'; - } - tooltip += - `` + - `` + - `` + - `` + - `` + - ''; - }); - tooltip += '
" + - `${timeFormatter(d.value)}` + - '
CategoryValue% to total
${series.key === 'TOTAL' ? '' : '◼'}${key}${valueFormatter(series.value)}${((100 * series.value) / total).toFixed(2)}%
'; - - return dompurify.sanitize(tooltip); -} - -export function generateMultiLineTooltipContent(d, xFormatter, yFormatters) { - const tooltipTitle = xFormatter(d.value); - let tooltip = ''; - - tooltip += - "'; - - d.series.forEach((series, i) => { - const yFormatter = yFormatters[i]; - const key = getFormattedKey(series.key, false); - tooltip += - "` + - `` + - ``; - }); - - tooltip += '
" + - `${tooltipTitle}` + - '
" + - `
${key}${yFormatter(series.value)}
'; - - return tooltip; -} - -export function generateTimePivotTooltip(d, xFormatter, yFormatter) { - const tooltipTitle = xFormatter(d.value); - let tooltip = ''; - - tooltip += - "'; - - d.series.forEach(series => { - if (series.highlight) { - let label = ''; - if (series.key === 'current') { - label = series.key; - } else { - label = `${series.key} of the selected frequency:`; - } - tooltip += - "` + - `` + - ``; - } - }); - - tooltip += '
" + - `${tooltipTitle}` + - '
" + - `
${label}${yFormatter(series.value)}
'; - - return dompurify.sanitize(tooltip); -} - -function getLabel(stringOrObjectWithLabel) { - return stringOrObjectWithLabel.label || stringOrObjectWithLabel; -} - -function createHTMLRow(col1, col2) { - return `${col1}${col2}`; -} - -export function generateBubbleTooltipContent({ - point, - entity, - xField, - yField, - sizeField, - xFormatter, - yFormatter, - sizeFormatter, -}) { - let s = ''; - s += - `'; - s += createHTMLRow(getLabel(xField), xFormatter(point.x)); - s += createHTMLRow(getLabel(yField), yFormatter(point.y)); - s += createHTMLRow(getLabel(sizeField), sizeFormatter(point.size)); - s += '
` + - `${point[entity]} (${point.group})` + - '
'; - - return s; -} - -// shouldRemove indicates whether the nvtooltips should be removed from the DOM -export function hideTooltips(shouldRemove) { - const targets = document.querySelectorAll('.nvtooltip'); - if (targets.length > 0) { - // Only set opacity to 0 when hiding tooltips so they would reappear - // on hover, which sets the opacity to 1 - targets.forEach(t => { - if (shouldRemove) { - t.remove(); - } else { - // eslint-disable-next-line no-param-reassign - t.style.opacity = 0; - } - }); - } -} - -export function generateTooltipClassName(uuid) { - return `tooltip-${uuid}`; -} - -export function removeTooltip(uuid) { - const classSelector = `.${generateTooltipClassName(uuid)}`; - const target = document.querySelector(classSelector); - if (target) { - target.remove(); - } -} - -export function wrapTooltip(chart, maxWidth) { - const tooltipLayer = - chart.useInteractiveGuideline && chart.useInteractiveGuideline() - ? chart.interactiveLayer - : chart; - const tooltipGeneratorFunc = tooltipLayer.tooltip.contentGenerator(); - tooltipLayer.tooltip.contentGenerator(d => { - let tooltip = `
`; - tooltip += tooltipGeneratorFunc(d); - tooltip += '
'; - - return tooltip; - }); -} - -export function tipFactory(layer) { - return d3tip() - .attr('class', 'd3-tip') - .direction('n') - .offset([-5, 0]) - .html(d => { - if (!d) { - return ''; - } - const title = - d[layer.titleColumn] && d[layer.titleColumn].length - ? `${d[layer.titleColumn]} - ${layer.name}` - : layer.name; - const body = Array.isArray(layer.descriptionColumns) - ? layer.descriptionColumns.map(c => d[c]) - : /* eslint-disable-next-line compat/compat */ - Object.values(d); - - return `
${title}

${body.join(', ')}
`; - }); -} - -export function getMaxLabelSize(svg, axisClass) { - // axis class = .nv-y2 // second y axis on dual line chart - // axis class = .nv-x // x axis on time series line chart - const tickTexts = svg.selectAll(`.${axisClass} g.tick text`); - if (tickTexts.length > 0) { - const lengths = tickTexts[0].map(text => text.getComputedTextLength()); - - return Math.ceil(Math.max(0, ...lengths)); - } - - return 0; -} - -export function formatLabel(input, verboseMap = {}) { - // The input for label may be a string or an array of string - // When using the time shift feature, the label contains a '---' in the array - const verboseLookup = s => verboseMap[s] || s; - - return Array.isArray(input) && input.length - ? input.map(l => (TIME_SHIFT_PATTERN.test(l) ? l : verboseLookup(l))).join(', ') - : verboseLookup(input); -} - -const MIN_BAR_WIDTH = 18; - -export function computeBarChartWidth(data, stacked, maxWidth) { - const barCount = stacked - ? d3.max(data, d => d.values.length) - : d3.sum(data, d => d.values.length); - - const barWidth = barCount * MIN_BAR_WIDTH; - - return Math.max(barWidth, maxWidth); -} - -export function tryNumify(s) { - // Attempts casting to Number, returns string when failing - const n = Number(s); - - return Number.isNaN(n) ? s : n; -} - -export function stringifyTimeRange(extent) { - if (extent.some(d => d.toISOString === undefined)) { - return null; - } - - return extent.map(d => d.toISOString().slice(0, -1)).join(' : '); -} - -export function setAxisShowMaxMin(axis, showminmax) { - if (axis && axis.showMaxMin && showminmax !== undefined) { - axis.showMaxMin(showminmax); - } -} - -export function computeYDomain(data) { - if (Array.isArray(data) && data.length > 0 && Array.isArray(data[0].values)) { - const extents = data.filter(d => !d.disabled).map(row => d3.extent(row.values, v => v.y)); - const minOfMin = d3.min(extents, ([min]) => min); - const maxOfMax = d3.max(extents, ([, max]) => max); - - return [minOfMin, maxOfMax]; - } - - return [0, 1]; -} - -export function computeStackedYDomain(data) { - if (Array.isArray(data) && data.length > 0 && Array.isArray(data[0].values)) { - const series = data.filter(d => !d.disabled).map(d => d.values.map(v => v.y)); - const stackedValues = series[0].map((_, i) => series.reduce((acc, cur) => acc + cur[i], 0)); - - return [Math.min(0, ...stackedValues), Math.max(0, ...stackedValues)]; - } - - return [0, 1]; -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/utils/isTruthy.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/utils/isTruthy.js deleted file mode 100644 index 738496d8b8..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/utils/isTruthy.js +++ /dev/null @@ -1,9 +0,0 @@ -export default function isTruthy(obj) { - if (typeof obj === 'boolean') { - return obj; - } else if (typeof obj === 'string') { - return ['yes', 'y', 'true', 't', '1'].indexOf(obj.toLowerCase()) >= 0; - } - - return !!obj; -} diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/vendor/superset/AnnotationTypes.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/vendor/superset/AnnotationTypes.js deleted file mode 100644 index 8e66e1be5b..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/vendor/superset/AnnotationTypes.js +++ /dev/null @@ -1,82 +0,0 @@ -/** - * 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-disable sort-keys */ -function extractTypes(metadata) { - return Object.keys(metadata).reduce((prev, key) => { - const result = prev; - result[key] = key; - - return result; - }, {}); -} - -export const ANNOTATION_TYPES_METADATA = { - FORMULA: { - value: 'FORMULA', - label: 'Formula', - }, - EVENT: { - value: 'EVENT', - label: 'Event', - supportNativeSource: true, - }, - INTERVAL: { - value: 'INTERVAL', - label: 'Interval', - supportNativeSource: true, - }, - TIME_SERIES: { - value: 'TIME_SERIES', - label: 'Time Series', - }, -}; - -export const ANNOTATION_TYPES = extractTypes(ANNOTATION_TYPES_METADATA); - -export const DEFAULT_ANNOTATION_TYPE = ANNOTATION_TYPES.FORMULA; - -export const ANNOTATION_SOURCE_TYPES_METADATA = { - NATIVE: { - value: 'NATIVE', - label: 'Superset annotation', - }, -}; - -export const ANNOTATION_SOURCE_TYPES = extractTypes(ANNOTATION_SOURCE_TYPES_METADATA); - -export function requiresQuery(annotationSourceType) { - return !!annotationSourceType; -} - -const NATIVE_COLUMN_NAMES = { - descriptionColumns: ['long_descr'], - intervalEndColumn: 'end_dttm', - timeColumn: 'start_dttm', - titleColumn: 'short_descr', -}; - -export function applyNativeColumns(annotation) { - if (annotation.sourceType === ANNOTATION_SOURCE_TYPES.NATIVE) { - return { ...annotation, ...NATIVE_COLUMN_NAMES }; - } - - return annotation; -} - -export default ANNOTATION_TYPES; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/vendor/superset/exploreUtils.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/vendor/superset/exploreUtils.js deleted file mode 100644 index b1819515b8..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/src/vendor/superset/exploreUtils.js +++ /dev/null @@ -1,66 +0,0 @@ -/** - * 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 */ -import URI from 'urijs'; -import safeStringify from 'fast-safe-stringify'; - -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-legacy-preset-chart-nvd3/test/utils.test.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/test/utils.test.js deleted file mode 100644 index 96c042e451..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/test/utils.test.js +++ /dev/null @@ -1,189 +0,0 @@ -/** - * 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 { - computeStackedYDomain, - computeYDomain, - getTimeOrNumberFormatter, - formatLabel, - tryNumify, -} from '../src/utils'; - -const DATA = [ - { - key: ['East Asia & Pacific'], - values: [ - { - x: -315619200000.0, - y: 1031863394.0, - }, - { - x: -283996800000.0, - y: 1034767718.0, - }, - ], - }, - { - key: ['South Asia'], - values: [ - { - x: -315619200000.0, - y: 572036107.0, - }, - { - x: -283996800000.0, - y: 584143236.0, - }, - ], - }, - { - key: ['Europe & Central Asia'], - values: [ - { - x: -315619200000.0, - y: 660881033.0, - }, - { - x: -283996800000.0, - y: 668526708.0, - }, - ], - }, -]; - -const DATA_WITH_DISABLED_SERIES = [ - { - disabled: true, - key: ['East Asia & Pacific'], - values: [ - { - x: -315619200000.0, - y: 1031863394.0, - }, - { - x: -283996800000.0, - y: 1034767718.0, - }, - ], - }, - { - disabled: true, - key: ['South Asia'], - values: [ - { - x: -315619200000.0, - y: 572036107.0, - }, - { - x: -283996800000.0, - y: 584143236.0, - }, - ], - }, - { - key: ['Europe & Central Asia'], - values: [ - { - x: -315619200000.0, - y: 660881033.0, - }, - { - x: -283996800000.0, - y: 668526708.0, - }, - ], - }, -]; - -describe('nvd3/utils', () => { - describe('getTimeOrNumberFormatter(format)', () => { - it('is a function', () => { - expect(typeof getTimeOrNumberFormatter).toBe('function'); - }); - it('returns a date formatter if format is smart_date', () => { - const time = new Date(Date.UTC(2018, 10, 21, 22, 11)); - expect(getTimeOrNumberFormatter('smart_date')(time)).toBe('10:11'); - }); - it('returns a number formatter otherwise', () => { - expect(getTimeOrNumberFormatter('.3s')(3000000)).toBe('3.00M'); - expect(getTimeOrNumberFormatter()(3000100)).toBe('3M'); - }); - }); - - describe('formatLabel()', () => { - const verboseMap = { - foo: 'Foo', - bar: 'Bar', - }; - - it('formats simple labels', () => { - expect(formatLabel('foo')).toBe('foo'); - expect(formatLabel(['foo'])).toBe('foo'); - expect(formatLabel(['foo', 'bar'])).toBe('foo, bar'); - }); - it('formats simple labels with lookups', () => { - expect(formatLabel('foo', verboseMap)).toBe('Foo'); - expect(formatLabel('baz', verboseMap)).toBe('baz'); - expect(formatLabel(['foo'], verboseMap)).toBe('Foo'); - expect(formatLabel(['foo', 'bar', 'baz'], verboseMap)).toBe('Foo, Bar, baz'); - }); - it('deals with time shift properly', () => { - expect(formatLabel(['foo', '1 hour offset'], verboseMap)).toBe('Foo, 1 hour offset'); - expect(formatLabel(['foo', 'bar', 'baz', '2 hours offset'], verboseMap)).toBe( - 'Foo, Bar, baz, 2 hours offset', - ); - }); - }); - - describe('tryNumify()', () => { - it('tryNumify works as expected', () => { - expect(tryNumify(5)).toBe(5); - expect(tryNumify('5')).toBe(5); - expect(tryNumify('5.1')).toBe(5.1); - expect(tryNumify('a string')).toBe('a string'); - }); - }); - - describe('computeYDomain()', () => { - it('works with invalid data', () => { - expect(computeYDomain('foo')).toEqual([0, 1]); - }); - - it('works with all series enabled', () => { - expect(computeYDomain(DATA)).toEqual([572036107.0, 1034767718.0]); - }); - - it('works with some series disabled', () => { - expect(computeYDomain(DATA_WITH_DISABLED_SERIES)).toEqual([660881033.0, 668526708.0]); - }); - }); - - describe('computeStackedYDomain()', () => { - it('works with invalid data', () => { - expect(computeStackedYDomain('foo')).toEqual([0, 1]); - }); - - it('works with all series enabled', () => { - expect(computeStackedYDomain(DATA)).toEqual([0, 2287437662.0]); - }); - - it('works with some series disabled', () => { - expect(computeStackedYDomain(DATA_WITH_DISABLED_SERIES)).toEqual([0, 668526708.0]); - }); - }); -}); diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/test/utils/isTruthy.test.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/test/utils/isTruthy.test.js deleted file mode 100644 index 0ee3eecafc..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-nvd3/test/utils/isTruthy.test.js +++ /dev/null @@ -1,39 +0,0 @@ -import isTruthy from '../../src/utils/isTruthy'; - -describe('isTruthy', () => { - it('evals false-looking strings properly', () => { - expect(isTruthy('f')).toBe(false); - expect(isTruthy('false')).toBe(false); - expect(isTruthy('no')).toBe(false); - expect(isTruthy('n')).toBe(false); - expect(isTruthy('F')).toBe(false); - expect(isTruthy('False')).toBe(false); - expect(isTruthy('NO')).toBe(false); - expect(isTruthy('N')).toBe(false); - }); - it('evals true-looking strings properly', () => { - expect(isTruthy('t')).toBe(true); - expect(isTruthy('true')).toBe(true); - expect(isTruthy('yes')).toBe(true); - expect(isTruthy('y')).toBe(true); - expect(isTruthy('Y')).toBe(true); - expect(isTruthy('True')).toBe(true); - expect(isTruthy('Yes')).toBe(true); - expect(isTruthy('YES')).toBe(true); - }); - it('evals bools properly', () => { - expect(isTruthy(false)).toBe(false); - expect(isTruthy(true)).toBe(true); - }); - it('evals ints properly', () => { - expect(isTruthy(0)).toBe(false); - expect(isTruthy(1)).toBe(true); - }); - it('evals constants properly', () => { - expect(isTruthy(null)).toBe(false); - expect(isTruthy(undefined)).toBe(false); - }); - it('string auto is false', () => { - expect(isTruthy('false')).toBe(false); - }); -}); diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/.storybook/webpack.config.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/.storybook/webpack.config.js index d1ad3d9e14..8ad638f3a2 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/.storybook/webpack.config.js +++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/.storybook/webpack.config.js @@ -9,7 +9,6 @@ const BABEL_TYPESCRIPT_OPTIONS = { '@babel/preset-typescript', ], plugins: [ - 'lodash', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-proposal-class-properties', '@babel/plugin-syntax-dynamic-import', diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/Stories.tsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/Stories.tsx new file mode 100644 index 0000000000..282880bf35 --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/Stories.tsx @@ -0,0 +1,60 @@ +/* eslint-disable no-magic-numbers */ +import React from 'react'; +import { SuperChart } from '@superset-ui/chart'; +import payload from './payload'; +import dummyDatasource from '../../../shared/dummyDatasource'; + +export default [ + { + renderStory: () => ( + + ), + storyName: 'Basic', + storyPath: 'legacy-|preset-chart-deckgl|PathChartPlugin', + }, +]; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/index.js new file mode 100644 index 0000000000..5a603913db --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/index.js @@ -0,0 +1,8 @@ +import { PathChartPlugin } from '../../../../../superset-ui-legacy-preset-chart-deckgl/src'; +import Stories from './Stories'; + +new PathChartPlugin().configure({ key: 'deck_path' }).register(); + +export default { + examples: [...Stories], +}; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/payload.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/payload.js new file mode 100644 index 0000000000..b702b0c1bd --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-deckgl/Path/payload.js @@ -0,0 +1,207 @@ +export default { + cache_key: null, + cached_dttm: null, + cache_timeout: 86400, + error: null, + form_data: { + datasource: '11__table', + viz_type: 'deck_path', + slice_id: 72, + url_params: {}, + granularity_sqla: null, + time_grain_sqla: null, + time_range: ' : ', + line_column: 'path_json', + line_type: 'json', + row_limit: 5000, + filter_nulls: true, + adhoc_filters: [ + { + clause: 'WHERE', + expressionType: 'SIMPLE', + filterOptionName: 'b4c1a7de-17ef-4505-b688-2760c0c22e1f', + comparator: '', + operator: 'IS NOT NULL', + subject: 'path_json', + }, + ], + mapbox_style: 'mapbox://styles/mapbox/light-v9', + viewport: { + altitude: 1.5, + bearing: 0, + height: 1094, + latitude: 37.73671752604488, + longitude: -122.18885402582598, + maxLatitude: 85.05113, + maxPitch: 60, + maxZoom: 20, + minLatitude: -85.05113, + minPitch: 0, + minZoom: 0, + pitch: 0, + width: 669, + zoom: 9.51847667620428, + }, + color_picker: { a: 1, b: 135, g: 122, r: 0 }, + line_width: 150, + reverse_long_lat: false, + autozoom: true, + js_columns: ['color'], + where: '', + having: '', + having_filters: [], + filters: [{ col: 'path_json', op: 'IS NOT NULL', val: '' }], + }, + is_cached: false, + query: + 'SELECT color AS color,\n path_json AS path_json\nFROM bart_lines\nWHERE path_json IS NOT NULL\nLIMIT 5000\nOFFSET 0', + status: 'success', + stacktrace: null, + rowcount: 5, + data: { + features: [ + { + color: '#ed1c24', + path: [ + [-122.3535851, 37.9360513], + [-122.3179784, 37.9249513], + [-122.300284, 37.902646], + [-122.2843653, 37.8735039], + [-122.269058, 37.8694562], + [-122.2709185, 37.85301], + [-122.2689342, 37.8283973], + [-122.2707195, 37.8080566], + [-122.2718706, 37.804996], + [-122.2948251, 37.8064628], + [-122.3971496, 37.794745], + [-122.4030149, 37.7905282], + [-122.4084631, 37.7862646], + [-122.4157833, 37.7803439], + [-122.4219476, 37.7653052], + [-122.4206096, 37.7528545], + [-122.4359052, 37.7340058], + [-122.448995, 37.723273], + [-122.471192, 37.7067871], + [-122.4672607, 37.6842548], + [-122.4449822, 37.6635925], + [-122.4169649, 37.6372339], + [-122.3876274, 37.5993171], + ], + __timestamp: null, + extraProps: { color: '#ed1c24' }, + }, + { + color: '#faa61a', + path: [ + [-122.353165, 37.936887], + [-122.317269, 37.925655], + [-122.299272, 37.903059], + [-122.283451, 37.87404], + [-122.268045, 37.869867], + [-122.26978, 37.853024], + [-122.2677961, 37.8284091], + [-122.2695925, 37.8079322], + [-122.2721546, 37.8035508], + [-122.2666476, 37.7964139], + [-122.2253433, 37.7739122], + [-122.1985085, 37.7530763], + [-122.1625282, 37.7216747], + [-122.1280105, 37.6961822], + [-122.0888196, 37.669805], + [-122.0584803, 37.6342836], + [-122.0187396, 37.5906334], + [-121.9772135, 37.5567286], + ], + __timestamp: null, + extraProps: { color: '#faa61a' }, + }, + { + color: '#ffe800', + path: [ + [-121.945154, 38.018914], + [-122.024597, 38.003275], + [-122.029095, 37.973737], + [-122.056013, 37.928403], + [-122.067423, 37.905628], + [-122.123801, 37.893394], + [-122.183791, 37.878361], + [-122.251793, 37.844601], + [-122.2666934, 37.8282587], + [-122.2684655, 37.8078078], + [-122.2715151, 37.80322], + [-122.2947035, 37.8055689], + [-122.3969458, 37.7938605], + [-122.402211, 37.7898921], + [-122.40766, 37.7856278], + [-122.4147696, 37.779936], + [-122.4208208, 37.7651836], + [-122.4195378, 37.7525542], + [-122.4349986, 37.7334634], + [-122.4482045, 37.722627], + [-122.4701365, 37.7064541], + [-122.466233, 37.684638], + [-122.444116, 37.664174], + [-122.416038, 37.637753000000004], + [-122.392612, 37.616035], + [-122.38666, 37.599787], + ], + __timestamp: null, + extraProps: { color: '#ffe800' }, + }, + { + color: '#00aeef', + path: [ + [-121.900367, 37.701695], + [-121.928099, 37.699759], + [-122.075567, 37.690754], + [-122.1266292, 37.6975918], + [-122.160905, 37.7229335], + [-122.1968609, 37.7543157], + [-122.2239172, 37.7753131], + [-122.2653405, 37.7978803], + [-122.294582, 37.804675], + [-122.396742, 37.792976], + [-122.401407, 37.789256], + [-122.406857, 37.784991], + [-122.413756, 37.779528], + [-122.419694, 37.765062], + [-122.418466, 37.752254], + [-122.434092, 37.732921], + [-122.447414, 37.721981], + [-122.469081, 37.706121], + ], + __timestamp: null, + extraProps: { color: '#00aeef' }, + }, + { + color: '#4db848', + path: [ + [-121.9764, 37.557355], + [-122.017867, 37.591208], + [-122.057551, 37.6348], + [-122.087967, 37.670399], + [-122.1272512, 37.696851], + [-122.161717, 37.7223045], + [-122.1976851, 37.7536963], + [-122.2246308, 37.7746129], + [-122.2658775, 37.7970877], + [-122.2945333, 37.8037768], + [-122.3965382, 37.7920915], + [-122.4006031, 37.7886199], + [-122.406054, 37.7843542], + [-122.4127424, 37.77912], + [-122.4185672, 37.7649404], + [-122.4173942, 37.7519538], + [-122.4331854, 37.7323786], + [-122.4466235, 37.721335], + [-122.4683093, 37.705461], + ], + __timestamp: null, + extraProps: { color: '#4db848' }, + }, + ], + mapboxApiKey: + 'pk.eyJ1Ijoia3Jpc3R3IiwiYSI6ImNqbGg1N242NTFlczczdnBhazViMjgzZ2sifQ.lUneM-o3NucXN189EYyXxQ', + metricLabels: [], + }, +}; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/Stories.tsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/Stories.tsx deleted file mode 100644 index 2a62f4a7c3..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/Stories.tsx +++ /dev/null @@ -1,30 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import React from 'react'; -import { SuperChart } from '@superset-ui/chart'; -import data from './data'; -import dummyDatasource from '../../../shared/dummyDatasource'; - -export default [ - { - renderStory: () => ( - - ), - storyName: 'Basic', - storyPath: 'legacy-|preset-chart-nvd3|BulletChartPlugin', - }, -]; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/data.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/data.js deleted file mode 100644 index df677e9504..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/data.js +++ /dev/null @@ -1,10 +0,0 @@ -/* eslint-disable sort-keys, no-magic-numbers */ -export default { - measures: [75691], - ranges: [0, 83260.1], - rangeLabels: null, - markers: null, - markerLabels: null, - markerLines: null, - markerLineLabels: null, -}; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/index.js deleted file mode 100644 index 1ab3b9d1cc..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Bullet/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { BulletChartPlugin } from '../../../../../superset-ui-legacy-preset-chart-nvd3'; -import Stories from './Stories'; - -new BulletChartPlugin().configure({ key: 'bullet' }).register(); - -export default { - examples: [...Stories], -}; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/Stories.tsx b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/Stories.tsx deleted file mode 100644 index 9ed4cdaf27..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/Stories.tsx +++ /dev/null @@ -1,31 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import React from 'react'; -import { SuperChart } from '@superset-ui/chart'; -import data from './data'; -import dummyDatasource from '../../../shared/dummyDatasource'; - -export default [ - { - renderStory: () => ( - - ), - storyName: 'Basic', - storyPath: 'legacy-|preset-chart-nvd3|PieChartPlugin', - }, -]; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/data.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/data.js deleted file mode 100644 index 09f61ae3b6..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/data.js +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-disable sort-keys, no-magic-numbers */ -export default [ - { - x: 'boy', - y: 48133355, - }, - { - x: 'girl', - y: 32546308, - }, -]; diff --git a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/index.js b/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/index.js deleted file mode 100644 index b2b9b0938a..0000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui-plugins-deckgl/packages/superset-ui-plugins-demo/storybook/stories/legacy-preset-chart-nvd3/Pie/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { PieChartPlugin } from '../../../../../superset-ui-legacy-preset-chart-nvd3'; -import Stories from './Stories'; - -new PieChartPlugin().configure({ key: 'pie' }).register(); - -export default { - examples: [...Stories], -};