diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/README.md b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/README.md new file mode 100644 index 0000000000..8831b4953a --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/README.md @@ -0,0 +1,34 @@ +## @superset-ui/legacy-plugin-chart-pivot-table + +[![Version](https://img.shields.io/npm/v/@superset-ui/legacy-plugin-chart-pivot-table.svg?style=flat-square)](https://img.shields.io/npm/v/@superset-ui/legacy-plugin-chart-pivot-table.svg?style=flat-square) +[![David (path)](https://img.shields.io/david/apache-superset/superset-ui.svg?path=packages%2Fsuperset-ui-legacy-plugin-chart-pivot-table&style=flat-square)](https://david-dm.org/apache-superset/superset-ui?path=packages/superset-ui-legacy-plugin-chart-pivot-table) + +This plugin provides Pivot Table for Superset. + +### Usage + +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 PivottableChartPlugin from '@superset-ui/legacy-plugin-chart-pivot-table'; + +new PivottableChartPlugin() + .configure({ key: 'pivot-table' }) + .register(); +``` + +Then use it via `SuperChart`. See [storybook](https://apache-superset.github.io/superset-ui-legacy/?selectedKind=plugin-chart-pivot-table) for more details. + +```js + +``` \ No newline at end of file diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/package.json b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/package.json new file mode 100644 index 0000000000..27264810fe --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/package.json @@ -0,0 +1,44 @@ +{ + "name": "@superset-ui/legacy-plugin-chart-pivot-table", + "version": "0.0.0", + "description": "Superset Legacy Chart - Pivot Table", + "sideEffects": false, + "main": "lib/index.js", + "module": "esm/index.js", + "files": [ + "esm", + "lib" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/apache-superset/superset-ui-legacy.git" + }, + "keywords": [ + "superset" + ], + "author": "Superset", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/apache-superset/superset-ui-legacy/issues" + }, + "homepage": "https://github.com/apache-superset/superset-ui-legacy#readme", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@superset-ui/core": "^0.9.x", + "d3": "^3.5.17", + "datatables.net-bs": "^1.10.15", + "prop-types": "^15.6.2" + }, + "devDependencies": { + "@superset-ui/chart": "^0.9.x", + "@superset-ui/number-format": "^0.9.x", + "@superset-ui/translation": "^0.9.x" + }, + "peerDependencies": { + "@superset-ui/chart": "^0.9.x", + "@superset-ui/number-format": "^0.9.x", + "@superset-ui/translation": "^0.9.x" + } +} \ No newline at end of file diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/PivotTable.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/PivotTable.js new file mode 100644 index 0000000000..11e93c2115 --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/PivotTable.js @@ -0,0 +1,109 @@ +/** + * 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, no-magic-numbers, babel/no-invalid-this, babel/new-cap */ +import dt from 'datatables.net-bs'; +import PropTypes from 'prop-types'; +import { formatNumber } from '@superset-ui/number-format'; +import fixTableHeight from './utils/fixTableHeight'; +import 'datatables.net-bs/css/dataTables.bootstrap.css'; + +const { $ } = dt; + +const propTypes = { + data: PropTypes.shape({ + // TODO: replace this with raw data in SIP-6 + html: PropTypes.string, + columns: PropTypes.arrayOf( + PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]), + ), + }), + height: PropTypes.number, + columnFormats: PropTypes.objectOf(PropTypes.string), + numberFormat: PropTypes.string, + numGroups: PropTypes.number, + verboseMap: PropTypes.objectOf(PropTypes.string), +}; + +function PivotTable(element, props) { + const { data, height, columnFormats, numberFormat, numGroups, verboseMap } = props; + + const { html, columns } = data; + const container = element; + const $container = $(element); + + // payload data is a string of html with a single table element + container.innerHTML = html; + + const cols = Array.isArray(columns[0]) ? columns.map(col => col[0]) : columns; + + // jQuery hack to set verbose names in headers + const replaceCell = function replace() { + const s = $(this)[0].textContent; + $(this)[0].textContent = verboseMap[s] || s; + }; + $container.find('thead tr:first th').each(replaceCell); + $container.find('thead tr th:first-child').each(replaceCell); + + // jQuery hack to format number + $container.find('tbody tr').each(function eachRow() { + $(this) + .find('td') + .each(function each(i) { + const metric = cols[i]; + const format = columnFormats[metric] || numberFormat || '.3s'; + const tdText = $(this)[0].textContent; + if (!Number.isNaN(tdText) && tdText !== '') { + $(this)[0].textContent = formatNumber(format, tdText); + $(this).attr('data-sort', tdText); + } + }); + }); + + if (numGroups === 1) { + // When there is only 1 group by column, + // we use the DataTable plugin to make the header fixed. + // The plugin takes care of the scrolling so we don't need + // overflow: 'auto' on the table. + container.style.overflow = 'hidden'; + const table = $container.find('table').DataTable({ + paging: false, + searching: false, + bInfo: false, + scrollY: `${height}px`, + scrollCollapse: true, + scrollX: true, + }); + table + .column('-1') + .order('desc') + .draw(); + fixTableHeight($container.find('.dataTables_wrapper'), height); + } else { + // When there is more than 1 group by column we just render the table, without using + // the DataTable plugin, so we need to handle the scrolling ourselves. + // In this case the header is not fixed. + container.style.overflow = 'auto'; + container.style.height = `${height + 10}px`; + } +} + +PivotTable.displayName = 'PivotTable'; +PivotTable.propTypes = propTypes; + +export default PivotTable; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/ReactPivotTable.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/ReactPivotTable.js new file mode 100644 index 0000000000..bb6ed6c30a --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/ReactPivotTable.js @@ -0,0 +1,22 @@ +/** + * 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 './PivotTable'; + +export default reactify(Component); diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/images/thumbnail.png b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/images/thumbnail.png new file mode 100644 index 0000000000..a22794bb9e Binary files /dev/null and b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/images/thumbnail.png differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/images/thumbnailLarge.png b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/images/thumbnailLarge.png new file mode 100644 index 0000000000..37f86af079 Binary files /dev/null and b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/images/thumbnailLarge.png differ diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/index.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/index.js new file mode 100644 index 0000000000..0f92140b32 --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/index.js @@ -0,0 +1,39 @@ +/** + * 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({ + description: '', + name: t('Pivot Table'), + thumbnail, + useLegacyApi: true, +}); + +export default class PivotTableChartPlugin extends ChartPlugin { + constructor() { + super({ + loadChart: () => import('./ReactPivotTable.js'), + metadata, + transformProps, + }); + } +} diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/transformProps.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/transformProps.js new file mode 100644 index 0000000000..0e8fa95772 --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/transformProps.js @@ -0,0 +1,33 @@ +/** + * 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 */ +export default function transformProps(chartProps) { + const { height, datasource, formData, payload } = chartProps; + const { groupby, numberFormat } = formData; + const { columnFormats, verboseMap } = datasource; + + return { + height, + data: payload.data, + columnFormats, + numGroups: groupby.length, + numberFormat, + verboseMap, + }; +} diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/utils/fixTableHeight.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/utils/fixTableHeight.js new file mode 100644 index 0000000000..d35543d58f --- /dev/null +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-pivot-table/src/utils/fixTableHeight.js @@ -0,0 +1,13 @@ +/** + * Fix the height of the table body of a DataTable with scrollY set + */ +export default function fixTableHeight($tableDom, height) { + const headHeight = $tableDom.find('.dataTables_scrollHead').height(); + const filterHeight = $tableDom.find('.dataTables_filter').height() || 0; + const pageLengthHeight = $tableDom.find('.dataTables_length').height() || 0; + const paginationHeight = $tableDom.find('.dataTables_paginate').height() || 0; + const controlsHeight = pageLengthHeight > filterHeight ? pageLengthHeight : filterHeight; + $tableDom + .find('.dataTables_scrollBody') + .css('max-height', height - headHeight - controlsHeight - paginationHeight); +} diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-rose/src/Rose.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-rose/src/Rose.js index a581baf7d8..a83b26367c 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-rose/src/Rose.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-rose/src/Rose.js @@ -279,7 +279,7 @@ function Rose(element, props) { let arcSt = computeArcStates(datum); function tween(target, resFunc) { - return function(d) { + return function doTween(d) { const interpolate = d3.interpolate(copyArc(d), copyArc(target)); return t => resFunc(Object.assign(d, interpolate(t))); diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-sunburst/src/Sunburst.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-sunburst/src/Sunburst.js index 7ec85c8392..6d7b74cc98 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-sunburst/src/Sunburst.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/superset-ui-plugins/packages/superset-ui-legacy-plugin-chart-sunburst/src/Sunburst.js @@ -279,7 +279,7 @@ function Sunburst(element, props) { .style('opacity', 1) .style('stroke', null) .style('stroke-width', null) - .each('end', function() { + .each('end', function end() { d3.select(this).on('mouseenter', mouseenter); }); }