Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
feat(legacy-plugin-chart-big-number): add control panel config for th…
Browse files Browse the repository at this point in the history
…e BigNumber charts (#419)

* move nvd3 controls file to the correct directory

* feat: BigNumber registers its own controls

* fix: nvd3 controls imports

* fix: disable rules for some lines

* controls -> controlPanel

* control utils got moved

* fix: control utils required from nvd3

* fix: version

Co-authored-by: Krist Wongsuphasawat <[email protected]>
  • Loading branch information
suddjian and kristw authored Apr 30, 2020
1 parent f72e2d6 commit 590c4f4
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 3 deletions.
1 change: 1 addition & 0 deletions plugins/big-number/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"peerDependencies": {
"@superset-ui/chart": "^0.13.0",
"@superset-ui/color": "^0.13.0",
"@superset-ui/control-utils": "^0.13.0",
"@superset-ui/core": "^0.13.0",
"@superset-ui/dimension": "^0.13.0",
"@superset-ui/number-format": "^0.13.0",
Expand Down
174 changes: 174 additions & 0 deletions plugins/big-number/src/BigNumber/controlPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/**
* 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 { formatSelectOptions } from '@superset-ui/control-utils';
import React from 'react';
import { headerFontSize, subheaderFontSize } from '../sharedControls';

type VisibilityProps = {
// eslint-disable-next-line camelcase
form_data: { time_range: string };
};

export default {
controlPanelSections: [
{
label: t('Query'),
expanded: true,
controlSetRows: [['metric'], ['adhoc_filters']],
},
{
label: t('Options'),
tabOverride: 'data',
expanded: true,
controlSetRows: [
[
{
name: 'compare_lag',
config: {
type: 'TextControl',
label: t('Comparison Period Lag'),
isInt: true,
description: t('Based on granularity, number of time periods to compare against'),
},
},
{
name: 'compare_suffix',
config: {
type: 'TextControl',
label: t('Comparison suffix'),
description: t('Suffix to apply after the percentage display'),
},
},
],
['y_axis_format'],
[
{
name: 'show_trend_line',
config: {
type: 'CheckboxControl',
label: t('Show Trend Line'),
renderTrigger: true,
default: true,
description: t('Whether to display the trend line'),
},
},
{
name: 'start_y_axis_at_zero',
config: {
type: 'CheckboxControl',
label: t('Start y-axis at 0'),
renderTrigger: true,
default: true,
description: t(
'Start y-axis at zero. Uncheck to start y-axis at minimum value in the data.',
),
},
},
],
[
{
name: 'time_range_fixed',
config: {
type: 'CheckboxControl',
label: t('Fix to selected Time Range'),
description: t(
'Fix the trend line to the full time range specified in case filtered results do not include the start or end dates',
),
renderTrigger: true,
visibility(props: VisibilityProps) {
const { time_range: timeRange } = props.form_data;
// only display this option when a time range is selected
return timeRange && timeRange !== 'No filter';
},
},
},
],
],
},
{
label: t('Chart Options'),
expanded: true,
controlSetRows: [['color_picker', null], [headerFontSize], [subheaderFontSize]],
},
{
label: t('Advanced Analytics'),
expanded: false,
controlSetRows: [
// eslint-disable-next-line react/jsx-key
[<h1 className="section-header">{t('Rolling Window')}</h1>],
[
{
name: 'rolling_type',
config: {
type: 'SelectControl',
label: t('Rolling Function'),
default: 'None',
choices: formatSelectOptions(['None', 'mean', 'sum', 'std', 'cumsum']),
description: t(
'Defines a rolling window function to apply, works along ' +
'with the [Periods] text box',
),
},
},
{
name: 'rolling_periods',
config: {
type: 'TextControl',
label: t('Periods'),
isInt: true,
description: t(
'Defines the size of the rolling window function, ' +
'relative to the time granularity selected',
),
},
},
{
name: 'min_periods',
config: {
type: 'TextControl',
label: t('Min Periods'),
isInt: true,
description: t(
'The minimum number of rolling periods required to show ' +
'a value. For instance if you do a cumulative sum on 7 days ' +
'you may want your "Min Period" to be 7, so that all data points ' +
'shown are the total of 7 periods. This will hide the "ramp up" ' +
'taking place over the first 7 periods',
),
},
},
],
],
},
],
controlOverrides: {
y_axis_format: {
label: t('Number format'),
},
},
sectionOverrides: {
druidTimeSeries: {
controlSetRows: [['granularity', 'druid_time_origin'], ['time_range']],
},
sqlaTimeSeries: {
controlSetRows: [['granularity_sqla', 'time_grain_sqla'], ['time_range']],
},
},
};
2 changes: 2 additions & 0 deletions plugins/big-number/src/BigNumber/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { t } from '@superset-ui/translation';
import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import controlPanel from './controlPanel';
import transformProps from './transformProps';
import thumbnail from './images/thumbnail.png';

Expand All @@ -34,6 +35,7 @@ export default class BigNumberChartPlugin extends ChartPlugin {
loadChart: () => import('./BigNumber'),
metadata,
transformProps,
controlPanel,
});
}
}
57 changes: 57 additions & 0 deletions plugins/big-number/src/BigNumberTotal/controlPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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 { headerFontSize, subheaderFontSize } from '../sharedControls';

export default {
controlPanelSections: [
{
label: t('Query'),
expanded: true,
controlSetRows: [['metric'], ['adhoc_filters']],
},
{
label: t('Options'),
expanded: true,
controlSetRows: [
[
{
name: 'subheader',
config: {
type: 'TextControl',
label: t('Subheader'),
description: t('Description text that shows up below your Big Number'),
},
},
],
['y_axis_format'],
],
},
{
label: t('Chart Options'),
expanded: true,
controlSetRows: [[headerFontSize], [subheaderFontSize]],
},
],
controlOverrides: {
y_axis_format: {
label: t('Number format'),
},
},
};
2 changes: 2 additions & 0 deletions plugins/big-number/src/BigNumberTotal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { t } from '@superset-ui/translation';
import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import controlPanel from './controlPanel';
import transformProps from '../BigNumber/transformProps';
import thumbnail from './images/thumbnail.png';

Expand All @@ -34,6 +35,7 @@ export default class BigNumberTotalChartPlugin extends ChartPlugin {
loadChart: () => import('../BigNumber/BigNumber'),
metadata,
transformProps,
controlPanel,
});
}
}
89 changes: 89 additions & 0 deletions plugins/big-number/src/sharedControls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* 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.
*/

// These are control configurations that are shared ONLY within the BigNumber viz plugin repo.
import { t } from '@superset-ui/translation';

export const headerFontSize = {
name: 'header_font_size',
config: {
type: 'SelectControl',
label: t('Big Number Font Size'),
renderTrigger: true,
clearable: false,
default: 0.4,
// Values represent the percentage of space a header should take
options: [
{
label: t('Tiny'),
value: 0.2,
},
{
label: t('Small'),
value: 0.3,
},
{
label: t('Normal'),
value: 0.4,
},
{
label: t('Large'),
value: 0.5,
},
{
label: t('Huge'),
value: 0.6,
},
],
},
};

export const subheaderFontSize = {
name: 'subheader_font_size',
config: {
type: 'SelectControl',
label: t('Subheader Font Size'),
renderTrigger: true,
clearable: false,
default: 0.15,
// Values represent the percentage of space a subheader should take
options: [
{
label: t('Tiny'),
value: 0.125,
},
{
label: t('Small'),
value: 0.15,
},
{
label: t('Normal'),
value: 0.2,
},
{
label: t('Large'),
value: 0.3,
},
{
label: t('Huge'),
value: 0.4,
},
],
},
};
1 change: 1 addition & 0 deletions plugins/legacy-preset-chart-nvd3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"peerDependencies": {
"@superset-ui/chart": "^0.13.0",
"@superset-ui/color": "^0.13.0",
"@superset-ui/control-utils": "^0.13.0",
"@superset-ui/core": "^0.13.0",
"@superset-ui/dimension": "^0.13.0",
"@superset-ui/number-format": "^0.13.0",
Expand Down
Loading

0 comments on commit 590c4f4

Please sign in to comment.