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

feat(legacy-plugin-chart-nvd3): add control panels #469

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/legacy-preset-chart-nvd3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"peerDependencies": {
"@superset-ui/chart": "^0.13.0",
"@superset-ui/color": "^0.13.0",
"@superset-ui/control-utils": "^0.13.0",
"@superset-ui/control-utils": "^0.13.9",
"@superset-ui/core": "^0.13.0",
"@superset-ui/dimension": "^0.13.0",
"@superset-ui/number-format": "^0.13.0",
Expand Down
101 changes: 101 additions & 0 deletions plugins/legacy-preset-chart-nvd3/src/Area/controlPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* 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 { sections } from '@superset-ui/control-utils';
import {
lineInterpolation,
showBrush,
showLegend,
showControls,
xAxisLabel,
bottomMargin,
xTicksLayout,
xAxisFormat,
yLogScale,
yAxisBounds,
xAxisShowMinmax,
richTooltip,
timeSeriesSection,
} from '../NVD3Controls';

export default {
requiresTime: true,
controlPanelSections: [
timeSeriesSection[0],
{
label: t('Chart Options'),
expanded: true,
controlSetRows: [
[showBrush, showLegend],
[
lineInterpolation,
{
name: 'stacked_style',
config: {
type: 'SelectControl',
label: t('Stacked Style'),
renderTrigger: true,
choices: [
['stack', 'stack'],
['stream', 'stream'],
['expand', 'expand'],
],
default: 'stack',
description: '',
},
},
],
['color_scheme', 'label_colors'],
[richTooltip, showControls],
],
},
{
label: t('X Axis'),
expanded: true,
controlSetRows: [
[xAxisLabel, bottomMargin],
[xTicksLayout, xAxisFormat],
[xAxisShowMinmax, null],
],
},
{
label: t('Y Axis'),
expanded: true,
controlSetRows: [
['y_axis_format', yAxisBounds],
[yLogScale, null],
],
},
timeSeriesSection[1],
sections.annotations,
],
controlOverrides: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we apply these overrides in-place instead of having this section here?

['color_scheme', 'label_colors']
[
  'color_scheme', // replace with the object and set renderTrigger to false
  'label_colors'
]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good idea, but for now I'm just trying to move the control panels while keeping them as intact as possible to minimize the chance of breaking things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kristw I'm making an internal JIRA ticket to track this, and we can go through and audit and remove (where possible) all controlOverrides. If you think it's safe enough, we can then consider removing the code that enables them, as well. We'll discuss further with you :)

color_scheme: {
renderTrigger: false,
},
},
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/legacy-preset-chart-nvd3/src/Area/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import transformProps from '../transformProps';
import thumbnail from './images/thumbnail.png';
import { ANNOTATION_TYPES } from '../vendor/superset/AnnotationTypes';
import controlPanel from './controlPanel.ts';

const metadata = new ChartMetadata({
credits: ['http://nvd3.org'],
Expand All @@ -37,6 +38,7 @@ export default class AreaChartPlugin extends ChartPlugin {
loadChart: () => import('../ReactNVD3'),
metadata,
transformProps,
controlPanel,
});
}
}
87 changes: 87 additions & 0 deletions plugins/legacy-preset-chart-nvd3/src/Bar/controlPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* 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 { sections } from '@superset-ui/control-utils';
import {
lineInterpolation,
showBrush,
showLegend,
showControls,
xAxisLabel,
yAxisLabel,
bottomMargin,
xTicksLayout,
xAxisFormat,
yLogScale,
yAxisBounds,
xAxisShowMinmax,
yAxisShowMinmax,
richTooltip,
showBarValue,
barStacked,
reduceXTicks,
leftMargin,
timeSeriesSection,
} from '../NVD3Controls';

export default {
requiresTime: true,
controlPanelSections: [
timeSeriesSection[0],
{
label: t('Chart Options'),
expanded: true,
controlSetRows: [
['color_scheme', 'label_colors'],
[showBrush, showLegend, showBarValue],
[richTooltip, barStacked],
[lineInterpolation, showControls],
[bottomMargin],
],
},
{
label: t('X Axis'),
expanded: true,
controlSetRows: [
[xAxisLabel, bottomMargin],
[xTicksLayout, xAxisFormat],
[xAxisShowMinmax, reduceXTicks],
],
},
{
label: t('Y Axis'),
expanded: true,
controlSetRows: [
[yAxisLabel, leftMargin],
[yAxisShowMinmax, yLogScale],
['y_axis_format', yAxisBounds],
],
},
timeSeriesSection[1],
sections.annotations,
],
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/legacy-preset-chart-nvd3/src/Bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import transformProps from '../transformProps';
import thumbnail from './images/thumbnail.png';
import { ANNOTATION_TYPES } from '../vendor/superset/AnnotationTypes';
import controlPanel from './controlPanel.ts';

const metadata = new ChartMetadata({
credits: ['http://nvd3.org'],
Expand All @@ -37,6 +38,7 @@ export default class BarChartPlugin extends ChartPlugin {
loadChart: () => import('../ReactNVD3'),
metadata,
transformProps,
controlPanel,
});
}
}
115 changes: 115 additions & 0 deletions plugins/legacy-preset-chart-nvd3/src/Bubble/controlPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* 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 { D3_FORMAT_OPTIONS, formatSelectOptions } from '@superset-ui/control-utils';
import {
showLegend,
xAxisLabel,
yAxisLabel,
bottomMargin,
xTicksLayout,
xAxisFormat,
yLogScale,
xAxisShowMinmax,
yAxisShowMinmax,
leftMargin,
} from '../NVD3Controls';

export default {
label: t('Bubble Chart'),
controlPanelSections: [
{
label: t('Query'),
expanded: true,
controlSetRows: [
['series', 'entity'],
['x'],
['y'],
['adhoc_filters'],
['size'],
[
{
name: 'max_bubble_size',
config: {
type: 'SelectControl',
freeForm: true,
label: t('Max Bubble Size'),
default: '25',
choices: formatSelectOptions(['5', '10', '15', '25', '50', '75', '100']),
},
},
],
['limit', null],
],
},
{
label: t('Chart Options'),
expanded: true,
controlSetRows: [
['color_scheme', 'label_colors'],
[showLegend, null],
],
},
{
label: t('X Axis'),
expanded: true,
controlSetRows: [
[xAxisLabel, leftMargin],
[
{
name: xAxisFormat.name,
config: {
...xAxisFormat.config,
default: 'SMART_NUMBER',
choices: D3_FORMAT_OPTIONS,
},
},
xTicksLayout,
],
[
{
name: 'x_log_scale',
config: {
type: 'CheckboxControl',
label: t('X Log Scale'),
default: false,
renderTrigger: true,
description: t('Use a log scale for the X-axis'),
},
},
xAxisShowMinmax,
],
],
},
{
label: t('Y Axis'),
expanded: true,
controlSetRows: [
[yAxisLabel, bottomMargin],
['y_axis_format', null],
[yLogScale, yAxisShowMinmax],
],
},
],
controlOverrides: {
color_scheme: {
renderTrigger: false,
},
},
};
2 changes: 2 additions & 0 deletions plugins/legacy-preset-chart-nvd3/src/Bubble/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { t } from '@superset-ui/translation';
import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import transformProps from '../transformProps';
import thumbnail from './images/thumbnail.png';
import controlPanel from './controlPanel.ts';

const metadata = new ChartMetadata({
credits: ['http://nvd3.org'],
Expand All @@ -35,6 +36,7 @@ export default class BubbleChartPlugin extends ChartPlugin {
loadChart: () => import('../ReactNVD3'),
metadata,
transformProps,
controlPanel,
});
}
}
Loading