Skip to content

Commit

Permalink
feat(plugin-chart-pivot-table): multiple improvements (apache#1232)
Browse files Browse the repository at this point in the history
* feat(plugin-chart-pivot-table): multiple improvements

* emotion syntax fix
  • Loading branch information
kgabryje authored and zhaoyongjie committed Nov 17, 2021
1 parent 9d5d21a commit 2c1632f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@superset-ui/chart-controls": "0.17.69",
"@superset-ui/core": "0.17.64",
"@superset-ui/react-pivottable": "^0.12.9"
"@superset-ui/react-pivottable": "^0.12.10"
},
"peerDependencies": {
"@ant-design/icons": "^4.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getNumberFormatter,
DataRecordValue,
NumberFormatter,
useTheme,
} from '@superset-ui/core';
// @ts-ignore
import PivotTable from '@superset-ui/react-pivottable/PivotTable';
Expand All @@ -39,11 +40,12 @@ import {
} from './types';

const Styles = styled.div<PivotTableStylesProps>`
padding: ${({ theme }) => theme.gridUnit * 4}px;
height: ${({ height }) => height}px;
width: ${({ width }) => width}px;
overflow-y: scroll;
}
${({ height, width, margin }) => `
margin: ${margin}px;
height: ${height - margin * 2}px;
width: ${width - margin * 2}px;
overflow-y: scroll;
`}
`;

const METRIC_KEY = 'metric';
Expand Down Expand Up @@ -122,6 +124,7 @@ export default function PivotTableChart(props: PivotTableProps) {
dateFormatters,
} = props;

const theme = useTheme();
const defaultFormatter = getNumberFormatter(valueFormat);
const columnFormatsArray = Object.entries(columnFormats);
const hasCustomMetricFormatters = columnFormatsArray.length > 0;
Expand Down Expand Up @@ -244,7 +247,7 @@ export default function PivotTableChart(props: PivotTableProps) {
);

return (
<Styles height={height} width={width}>
<Styles height={height} width={width} margin={theme.gridUnit * 4}>
<PivotTable
data={unpivotedData}
rows={rows}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,30 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'rowTotals',
config: {
type: 'CheckboxControl',
label: t('Show rows total'),
default: false,
renderTrigger: true,
description: t('Display row level total'),
},
},
],
[
{
name: 'colTotals',
config: {
type: 'CheckboxControl',
label: t('Show columns total'),
default: false,
renderTrigger: true,
description: t('Display column level total'),
},
},
],
[
{
name: 'transposePivot',
Expand Down Expand Up @@ -208,6 +232,8 @@ const config: ControlPanelConfig = {
description: t('Order of rows'),
},
},
],
[
{
name: 'colOrder',
config: {
Expand All @@ -231,52 +257,32 @@ const config: ControlPanelConfig = {
name: 'rowSubtotalPosition',
config: {
type: 'SelectControl',
label: t('Rows subtotals position'),
label: t('Rows subtotal position'),
default: false,
choices: [
// [value, label]
[true, t('Top')],
[false, t('Bottom')],
],
renderTrigger: true,
description: t('Position of row level subtotals'),
description: t('Position of row level subtotal'),
},
},
],
[
{
name: 'colSubtotalPosition',
config: {
type: 'SelectControl',
label: t('Cols subtotals position'),
label: t('Cols subtotal position'),
default: false,
choices: [
// [value, label]
[true, t('Left')],
[false, t('Right')],
],
renderTrigger: true,
description: t('Position of column level subtotals'),
},
},
],
[
{
name: 'rowTotals',
config: {
type: 'CheckboxControl',
label: t('Show rows totals'),
default: true,
renderTrigger: true,
description: t('Display row level totals'),
},
},
{
name: 'colTotals',
config: {
type: 'CheckboxControl',
label: t('Show cols totals'),
default: true,
renderTrigger: true,
description: t('Display column level totals'),
description: t('Position of column level subtotal'),
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ColorFormatters } from '@superset-ui/chart-controls';
export interface PivotTableStylesProps {
height: number;
width: number;
margin: number;
}

export type FilterType = Record<string, DataRecordValue>;
Expand Down

0 comments on commit 2c1632f

Please sign in to comment.