diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx index c5bc9d56d4..d42d415555 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx @@ -67,6 +67,8 @@ import { ExtraControlProps, SelectControlConfig, Dataset, + ControlState, + ControlPanelState, } from '../types'; import { ColumnOption } from '../components/ColumnOption'; @@ -544,6 +546,30 @@ const enableExploreDnd = isFeatureEnabled( FeatureFlag.ENABLE_EXPLORE_DRAG_AND_DROP, ); +const x_axis: SharedControlConfig = { + ...(enableExploreDnd ? dndGroupByControl : groupByControl), + label: t('X-axis'), + default: ( + control: ControlState, + controlPanel: Partial, + ) => { + // default to the chosen time column if x-axis is unset and the + // GENERIC_CHART_AXES feature flag is enabled + const { value } = control; + if (value) { + return value; + } + const timeColumn = controlPanel?.form_data?.granularity_sqla; + if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && timeColumn) { + return timeColumn; + } + return null; + }, + multi: false, + description: t('Dimension to use on x-axis.'), + validators: [validateNonEmpty], +}; + const sharedControls = { metrics: enableExploreDnd ? dnd_adhoc_metrics : metrics, metric: enableExploreDnd ? dnd_adhoc_metric : metric, @@ -579,6 +605,7 @@ const sharedControls = { series_limit_metric: enableExploreDnd ? dnd_sort_by : sort_by, legacy_order_by: enableExploreDnd ? dnd_sort_by : sort_by, truncate_metric, + x_axis, }; export { sharedControls, dndEntity, dndColumnsControl }; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/types.ts index 005d2a79f0..36df083fb8 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/types.ts @@ -25,7 +25,8 @@ import { SetDataMaskHook, } from '@superset-ui/core'; import { EChartsCoreOption } from 'echarts'; -import { EchartsTitleFormData, DEFAULT_TITLE_FORM_DATA } from '../types'; +import { EchartsTitleFormData } from '../types'; +import { DEFAULT_TITLE_FORM_DATA } from '../constants'; export type BoxPlotQueryFormData = QueryFormData & { numberFormat?: string; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts index 3d0b279cc1..aa21698139 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts @@ -35,7 +35,6 @@ import { EchartsFunnelLabelTypeType, FunnelChartTransformedProps, } from './types'; -import { DEFAULT_LEGEND_FORM_DATA } from '../types'; import { extractGroupbyLabel, getChartPadding, @@ -43,7 +42,7 @@ import { sanitizeHtml, } from '../utils/series'; import { defaultGrid, defaultTooltip } from '../defaults'; -import { OpacityEnum } from '../constants'; +import { OpacityEnum, DEFAULT_LEGEND_FORM_DATA } from '../constants'; const percentFormatter = getNumberFormatter(NumberFormats.PERCENT_2_POINT); diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/types.ts index 398fa40d57..cd392997cf 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/types.ts @@ -25,12 +25,8 @@ import { QueryFormData, SetDataMaskHook, } from '@superset-ui/core'; -import { - DEFAULT_LEGEND_FORM_DATA, - EchartsLegendFormData, - LegendOrientation, - LegendType, -} from '../types'; +import { EchartsLegendFormData, LegendOrientation, LegendType } from '../types'; +import { DEFAULT_LEGEND_FORM_DATA } from '../constants'; export type EchartsFunnelFormData = QueryFormData & EchartsLegendFormData & { diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/types.ts index f6a1b09ad6..7ae2a55595 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/types.ts @@ -22,7 +22,8 @@ import { QueryFormColumn, QueryFormData, } from '@superset-ui/core'; -import { DEFAULT_LEGEND_FORM_DATA, EChartTransformedProps } from '../types'; +import { EChartTransformedProps } from '../types'; +import { DEFAULT_LEGEND_FORM_DATA } from '../constants'; export type AxisTickLineStyle = { width: number; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Graph/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Graph/types.ts index 9cb35c1304..19938b4b19 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Graph/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Graph/types.ts @@ -19,12 +19,8 @@ import { QueryFormData } from '@superset-ui/core'; import { GraphNodeItemOption } from 'echarts/types/src/chart/graph/GraphSeries'; import { SeriesTooltipOption } from 'echarts/types/src/util/types'; -import { - DEFAULT_LEGEND_FORM_DATA, - EchartsLegendFormData, - LegendOrientation, - LegendType, -} from '../types'; +import { EchartsLegendFormData, LegendOrientation, LegendType } from '../types'; +import { DEFAULT_LEGEND_FORM_DATA } from '../constants'; export type EdgeSymbol = 'none' | 'circle' | 'arrow'; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx index fb164f1a26..4ff8831800 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx @@ -36,7 +36,7 @@ import { import { DEFAULT_FORM_DATA } from './types'; import { EchartsTimeseriesSeriesType } from '../Timeseries/types'; -import { legendSection, richTooltipSection, xAxisControl } from '../controls'; +import { legendSection, richTooltipSection } from '../controls'; const { area, @@ -295,7 +295,7 @@ const config: ControlPanelConfig = { ? { label: t('Shared query fields'), expanded: true, - controlSetRows: [[xAxisControl]], + controlSetRows: [['x_axis']], } : null, createQuerySection(t('Query A'), ''), diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts index 51938436fb..85e4030acd 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts @@ -28,17 +28,17 @@ import { QueryFormColumn, } from '@superset-ui/core'; import { - DEFAULT_LEGEND_FORM_DATA, EchartsLegendFormData, EchartsTitleFormData, - DEFAULT_TITLE_FORM_DATA, StackType, -} from '../types'; -import { - DEFAULT_FORM_DATA as TIMESERIES_DEFAULTS, EchartsTimeseriesContributionType, EchartsTimeseriesSeriesType, -} from '../Timeseries/types'; +} from '../types'; +import { + DEFAULT_LEGEND_FORM_DATA, + DEFAULT_TITLE_FORM_DATA, + DEFAULT_FORM_DATA as TIMESERIES_DEFAULTS, +} from '../constants'; export type EchartsMixedTimeseriesFormData = QueryFormData & { annotationLayers: AnnotationLayer[]; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts index c0466e6bba..b2924dc297 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts @@ -36,7 +36,7 @@ import { EchartsPieLabelType, PieChartTransformedProps, } from './types'; -import { DEFAULT_LEGEND_FORM_DATA } from '../types'; +import { DEFAULT_LEGEND_FORM_DATA, OpacityEnum } from '../constants'; import { extractGroupbyLabel, getChartPadding, @@ -45,7 +45,6 @@ import { sanitizeHtml, } from '../utils/series'; import { defaultGrid, defaultTooltip } from '../defaults'; -import { OpacityEnum } from '../constants'; import { convertInteger } from '../utils/convertInteger'; const percentFormatter = getNumberFormatter(NumberFormats.PERCENT_2_POINT); diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Pie/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Pie/types.ts index c97afd3a7c..302df265f4 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Pie/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Pie/types.ts @@ -25,12 +25,8 @@ import { QueryFormData, SetDataMaskHook, } from '@superset-ui/core'; -import { - DEFAULT_LEGEND_FORM_DATA, - EchartsLegendFormData, - LegendOrientation, - LegendType, -} from '../types'; +import { EchartsLegendFormData, LegendOrientation, LegendType } from '../types'; +import { DEFAULT_LEGEND_FORM_DATA } from '../constants'; export type EchartsPieFormData = QueryFormData & EchartsLegendFormData & { diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts index 01a20b82b4..7bcb59a064 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts @@ -36,7 +36,7 @@ import { EchartsRadarLabelType, RadarChartTransformedProps, } from './types'; -import { DEFAULT_LEGEND_FORM_DATA } from '../types'; +import { DEFAULT_LEGEND_FORM_DATA, OpacityEnum } from '../constants'; import { extractGroupbyLabel, getChartPadding, @@ -44,7 +44,6 @@ import { getLegendProps, } from '../utils/series'; import { defaultGrid, defaultTooltip } from '../defaults'; -import { OpacityEnum } from '../constants'; export function formatLabel({ params, diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/types.ts index 9b053b6264..ebe571f621 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/types.ts @@ -27,12 +27,12 @@ import { SetDataMaskHook, } from '@superset-ui/core'; import { - DEFAULT_LEGEND_FORM_DATA, EchartsLegendFormData, LabelPositionEnum, LegendOrientation, LegendType, } from '../types'; +import { DEFAULT_LEGEND_FORM_DATA } from '../constants'; type RadarColumnConfig = Record; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Area/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Area/controlPanel.tsx index c8922dd11e..7301cc26e7 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Area/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Area/controlPanel.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; +import { t } from '@superset-ui/core'; import { ControlPanelConfig, ControlPanelsContainerProps, @@ -28,10 +28,10 @@ import { } from '@superset-ui/chart-controls'; import { - DEFAULT_FORM_DATA, EchartsTimeseriesContributionType, EchartsTimeseriesSeriesType, } from '../types'; +import { DEFAULT_FORM_DATA } from '../constants'; import { legendSection, onlyTotalControl, @@ -62,7 +62,7 @@ const config: ControlPanelConfig = { label: t('Query'), expanded: true, controlSetRows: [ - isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) ? [xAxisControl] : [], + [xAxisControl], ['metrics'], ['groupby'], [ diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx index 1992f4a456..f7c96d4d36 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; +import { t } from '@superset-ui/core'; import { ControlPanelConfig, ControlPanelsContainerProps, @@ -31,10 +31,10 @@ import { } from '@superset-ui/chart-controls'; import { - DEFAULT_FORM_DATA, EchartsTimeseriesContributionType, OrientationType, } from '../../types'; +import { DEFAULT_FORM_DATA } from '../../constants'; import { legendSection, richTooltipSection, @@ -269,7 +269,7 @@ const config: ControlPanelConfig = { label: t('Query'), expanded: true, controlSetRows: [ - isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) ? [xAxisControl] : [], + [xAxisControl], ['metrics'], ['groupby'], [ diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/index.ts index 0ffc09098c..2c74e6ac69 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/index.ts @@ -25,15 +25,15 @@ import { isFeatureEnabled, t, } from '@superset-ui/core'; -import buildQuery from '../../buildQuery'; -import controlPanel from './controlPanel'; -import transformProps from '../../transformProps'; -import thumbnail from './images/thumbnail.png'; import { EchartsTimeseriesChartProps, EchartsTimeseriesFormData, EchartsTimeseriesSeriesType, } from '../../types'; +import buildQuery from '../../buildQuery'; +import controlPanel from './controlPanel'; +import transformProps from '../../transformProps'; +import thumbnail from './images/thumbnail.png'; import example1 from './images/Bar1.png'; import example2 from './images/Bar2.png'; import example3 from './images/Bar3.png'; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Line/controlPanel.tsx similarity index 97% rename from superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx rename to superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Line/controlPanel.tsx index d039a059c5..0f78f1ee19 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Line/controlPanel.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; +import { t } from '@superset-ui/core'; import { ControlPanelConfig, ControlPanelsContainerProps, @@ -28,16 +28,16 @@ import { } from '@superset-ui/chart-controls'; import { - DEFAULT_FORM_DATA, EchartsTimeseriesContributionType, EchartsTimeseriesSeriesType, -} from './types'; +} from '../../types'; +import { DEFAULT_FORM_DATA } from '../../constants'; import { legendSection, richTooltipSection, showValueSection, xAxisControl, -} from '../controls'; +} from '../../../controls'; const { area, @@ -61,7 +61,7 @@ const config: ControlPanelConfig = { label: t('Query'), expanded: true, controlSetRows: [ - isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) ? [xAxisControl] : [], + [xAxisControl], ['metrics'], ['groupby'], [ diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Line/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Line/index.ts index 6f4a780c36..0d89373c95 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Line/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Line/index.ts @@ -25,15 +25,15 @@ import { isFeatureEnabled, t, } from '@superset-ui/core'; -import buildQuery from '../../buildQuery'; -import controlPanel from '../controlPanel'; -import transformProps from '../../transformProps'; -import thumbnail from './images/thumbnail.png'; import { EchartsTimeseriesChartProps, EchartsTimeseriesFormData, EchartsTimeseriesSeriesType, } from '../../types'; +import buildQuery from '../../buildQuery'; +import controlPanel from './controlPanel'; +import transformProps from '../../transformProps'; +import thumbnail from './images/thumbnail.png'; import example1 from './images/Line1.png'; import example2 from './images/Line2.png'; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/controlPanel.tsx index fd2fa79651..471fe03d1c 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/controlPanel.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; +import { t } from '@superset-ui/core'; import { ControlPanelConfig, ControlPanelsContainerProps, @@ -27,7 +27,7 @@ import { sharedControls, } from '@superset-ui/chart-controls'; -import { DEFAULT_FORM_DATA } from '../../types'; +import { DEFAULT_FORM_DATA } from '../../constants'; import { legendSection, richTooltipSection, @@ -53,7 +53,7 @@ const config: ControlPanelConfig = { label: t('Query'), expanded: true, controlSetRows: [ - isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) ? [xAxisControl] : [], + [xAxisControl], ['metrics'], ['groupby'], ['adhoc_filters'], diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/index.ts index 7c77868a58..fc544bdf73 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/index.ts @@ -25,15 +25,15 @@ import { isFeatureEnabled, t, } from '@superset-ui/core'; -import buildQuery from '../../buildQuery'; -import controlPanel from './controlPanel'; -import transformProps from '../../transformProps'; -import thumbnail from './images/thumbnail.png'; import { EchartsTimeseriesChartProps, EchartsTimeseriesFormData, EchartsTimeseriesSeriesType, } from '../../types'; +import buildQuery from '../../buildQuery'; +import controlPanel from './controlPanel'; +import transformProps from '../../transformProps'; +import thumbnail from './images/thumbnail.png'; import example1 from './images/Scatter1.png'; const scatterTransformProps = (chartProps: EchartsTimeseriesChartProps) => diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/SmoothLine/controlPanel.tsx similarity index 96% rename from superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/controlPanel.tsx rename to superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/SmoothLine/controlPanel.tsx index 8dc34861b1..24350aebb6 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/SmoothLine/controlPanel.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; +import { t } from '@superset-ui/core'; import { ControlPanelConfig, ControlPanelsContainerProps, @@ -27,13 +27,14 @@ import { sharedControls, } from '@superset-ui/chart-controls'; -import { DEFAULT_FORM_DATA, EchartsTimeseriesContributionType } from '../types'; +import { EchartsTimeseriesContributionType } from '../../types'; +import { DEFAULT_FORM_DATA } from '../../constants'; import { legendSection, richTooltipSection, showValueSectionWithoutStack, xAxisControl, -} from '../../controls'; +} from '../../../controls'; const { contributionMode, @@ -54,7 +55,7 @@ const config: ControlPanelConfig = { label: t('Query'), expanded: true, controlSetRows: [ - isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) ? [xAxisControl] : [], + [xAxisControl], ['metrics'], ['groupby'], [ diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/SmoothLine/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/SmoothLine/index.ts index ee348b272c..c1b8ca47b1 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/SmoothLine/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/SmoothLine/index.ts @@ -25,15 +25,15 @@ import { isFeatureEnabled, t, } from '@superset-ui/core'; -import buildQuery from '../../buildQuery'; -import controlPanel from '../controlPanel'; -import transformProps from '../../transformProps'; -import thumbnail from './images/thumbnail.png'; import { EchartsTimeseriesChartProps, EchartsTimeseriesFormData, EchartsTimeseriesSeriesType, } from '../../types'; +import buildQuery from '../../buildQuery'; +import controlPanel from './controlPanel'; +import transformProps from '../../transformProps'; +import thumbnail from './images/thumbnail.png'; import example1 from './images/SmoothLine1.png'; const smoothTransformProps = (chartProps: EchartsTimeseriesChartProps) => diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/controlPanel.tsx index 2902937333..26c97bd59d 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/controlPanel.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; +import { t } from '@superset-ui/core'; import { ControlPanelConfig, ControlPanelsContainerProps, @@ -28,10 +28,10 @@ import { } from '@superset-ui/chart-controls'; import { - DEFAULT_FORM_DATA, EchartsTimeseriesContributionType, EchartsTimeseriesSeriesType, -} from '../types'; +} from '../../types'; +import { DEFAULT_FORM_DATA } from '../constants'; import { legendSection, richTooltipSection, @@ -60,7 +60,7 @@ const config: ControlPanelConfig = { label: t('Query'), expanded: true, controlSetRows: [ - isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) ? [xAxisControl] : [], + [xAxisControl], ['metrics'], ['groupby'], [ diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/index.ts index 2a24b70841..4889233ae0 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/index.ts @@ -25,14 +25,14 @@ import { isFeatureEnabled, t, } from '@superset-ui/core'; +import { + EchartsTimeseriesChartProps, + EchartsTimeseriesFormData, +} from '@superset-ui/plugin-chart-echarts'; import buildQuery from '../buildQuery'; import controlPanel from './controlPanel'; import transformProps from '../transformProps'; import thumbnail from './images/thumbnail.png'; -import { - EchartsTimeseriesChartProps, - EchartsTimeseriesFormData, -} from '../types'; import example1 from './images/Step1.png'; import example2 from './images/Step2.png'; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/constants.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/constants.ts new file mode 100644 index 0000000000..2590441ef6 --- /dev/null +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/constants.ts @@ -0,0 +1,66 @@ +/** + * 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 { sections } from '@superset-ui/chart-controls'; +import { + OrientationType, + EchartsTimeseriesSeriesType, + EchartsTimeseriesFormData, +} from './types'; +import { + DEFAULT_LEGEND_FORM_DATA, + DEFAULT_TITLE_FORM_DATA, +} from '../constants'; + +// @ts-ignore +export const DEFAULT_FORM_DATA: EchartsTimeseriesFormData = { + ...DEFAULT_LEGEND_FORM_DATA, + ...DEFAULT_TITLE_FORM_DATA, + annotationLayers: sections.annotationLayers, + area: false, + forecastEnabled: sections.FORECAST_DEFAULT_DATA.forecastEnabled, + forecastInterval: sections.FORECAST_DEFAULT_DATA.forecastInterval, + forecastPeriods: sections.FORECAST_DEFAULT_DATA.forecastPeriods, + forecastSeasonalityDaily: + sections.FORECAST_DEFAULT_DATA.forecastSeasonalityDaily, + forecastSeasonalityWeekly: + sections.FORECAST_DEFAULT_DATA.forecastSeasonalityWeekly, + forecastSeasonalityYearly: + sections.FORECAST_DEFAULT_DATA.forecastSeasonalityYearly, + logAxis: false, + markerEnabled: false, + markerSize: 6, + minorSplitLine: false, + opacity: 0.2, + orderDesc: true, + rowLimit: 10000, + seriesType: EchartsTimeseriesSeriesType.Line, + stack: false, + tooltipTimeFormat: 'smart_date', + truncateYAxis: false, + yAxisBounds: [null, null], + zoomable: false, + richTooltip: true, + xAxisLabelRotation: 0, + emitFilter: false, + groupby: [], + showValue: false, + onlyTotal: false, + percentageThreshold: 0, + orientation: OrientationType.vertical, +}; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/index.ts index 062d741402..cbdd5cb41b 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/index.ts @@ -26,7 +26,7 @@ import { t, } from '@superset-ui/core'; import buildQuery from './buildQuery'; -import controlPanel from './controlPanel'; +import controlPanel from './Regular/Line/controlPanel'; import transformProps from './transformProps'; import thumbnail from './images/thumbnail.png'; import { diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts index 89d5c1e03b..d1aa4e827b 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts @@ -36,13 +36,13 @@ import { isDerivedSeries } from '@superset-ui/chart-controls'; import { EChartsCoreOption, SeriesOption } from 'echarts'; import { ZRLineType } from 'echarts/types/src/util/types'; import { - DEFAULT_FORM_DATA, EchartsTimeseriesChartProps, EchartsTimeseriesFormData, EchartsTimeseriesSeriesType, TimeseriesChartTransformedProps, OrientationType, } from './types'; +import { DEFAULT_FORM_DATA } from './constants'; import { ForecastSeriesEnum, ForecastValue } from '../types'; import { parseYAxisBound } from '../utils/controls'; import { diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts index d9b7708146..bc7d771bac 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts @@ -24,13 +24,10 @@ import { QueryFormData, TimeGranularity, } from '@superset-ui/core'; -import { sections } from '@superset-ui/chart-controls'; import { - DEFAULT_LEGEND_FORM_DATA, EchartsLegendFormData, EChartTransformedProps, EchartsTitleFormData, - DEFAULT_TITLE_FORM_DATA, StackType, } from '../types'; @@ -93,44 +90,6 @@ export type EchartsTimeseriesFormData = QueryFormData & { } & EchartsLegendFormData & EchartsTitleFormData; -// @ts-ignore -export const DEFAULT_FORM_DATA: EchartsTimeseriesFormData = { - ...DEFAULT_LEGEND_FORM_DATA, - annotationLayers: sections.annotationLayers, - area: false, - forecastEnabled: sections.FORECAST_DEFAULT_DATA.forecastEnabled, - forecastInterval: sections.FORECAST_DEFAULT_DATA.forecastInterval, - forecastPeriods: sections.FORECAST_DEFAULT_DATA.forecastPeriods, - forecastSeasonalityDaily: - sections.FORECAST_DEFAULT_DATA.forecastSeasonalityDaily, - forecastSeasonalityWeekly: - sections.FORECAST_DEFAULT_DATA.forecastSeasonalityWeekly, - forecastSeasonalityYearly: - sections.FORECAST_DEFAULT_DATA.forecastSeasonalityYearly, - logAxis: false, - markerEnabled: false, - markerSize: 6, - minorSplitLine: false, - opacity: 0.2, - orderDesc: true, - rowLimit: 10000, - seriesType: EchartsTimeseriesSeriesType.Line, - stack: false, - tooltipTimeFormat: 'smart_date', - truncateYAxis: false, - yAxisBounds: [null, null], - zoomable: false, - richTooltip: true, - xAxisLabelRotation: 0, - emitFilter: false, - groupby: [], - showValue: false, - onlyTotal: false, - percentageThreshold: 0, - orientation: OrientationType.vertical, - ...DEFAULT_TITLE_FORM_DATA, -}; - export interface EchartsTimeseriesChartProps extends ChartProps { formData: EchartsTimeseriesFormData; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts b/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts index 513a0bebc1..7dd823f644 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/constants.ts @@ -19,7 +19,13 @@ import { JsonValue, t, TimeGranularity } from '@superset-ui/core'; import { ReactNode } from 'react'; -import { LabelPositionEnum } from './types'; +import { + EchartsLegendFormData, + EchartsTitleFormData, + LabelPositionEnum, + LegendOrientation, + LegendType, +} from './types'; // eslint-disable-next-line import/prefer-default-export export const NULL_STRING = ''; @@ -84,3 +90,20 @@ export const TIMEGRAIN_TO_TIMESTAMP = { [TimeGranularity.QUARTER]: 3600 * 1000 * 24 * 31 * 3, [TimeGranularity.YEAR]: 3600 * 1000 * 24 * 31 * 12, }; + +export const DEFAULT_LEGEND_FORM_DATA: EchartsLegendFormData = { + legendMargin: null, + legendOrientation: LegendOrientation.Top, + legendType: LegendType.Scroll, + showLegend: true, +}; + +export const DEFAULT_TITLE_FORM_DATA: EchartsTitleFormData = { + xAxisTitle: '', + xAxisTitleMargin: 0, + yAxisTitle: '', + yAxisTitleMargin: 0, + yAxisTitlePosition: 'Top', +}; + +export { DEFAULT_FORM_DATA } from './Timeseries/constants'; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx index b8d54fc09a..d832196b5e 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx @@ -17,22 +17,15 @@ * under the License. */ import React from 'react'; -import { - FeatureFlag, - isFeatureEnabled, - t, - validateNonEmpty, -} from '@superset-ui/core'; +import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; import { ControlPanelsContainerProps, - ControlPanelState, ControlSetItem, ControlSetRow, - ControlState, sharedControls, } from '@superset-ui/chart-controls'; -import { DEFAULT_LEGEND_FORM_DATA } from './types'; -import { DEFAULT_FORM_DATA } from './Timeseries/types'; +import { DEFAULT_LEGEND_FORM_DATA } from './constants'; +import { DEFAULT_FORM_DATA } from './Timeseries/constants'; const { legendMargin, legendOrientation, legendType, showLegend } = DEFAULT_LEGEND_FORM_DATA; @@ -145,32 +138,9 @@ export const onlyTotalControl: ControlSetItem = { }, }; -export const xAxisControl: ControlSetItem = { - name: 'x_axis', - config: { - ...sharedControls.groupby, - label: t('X-axis'), - default: ( - control: ControlState, - controlPanel: Partial, - ) => { - // default to the chosen time column if x-axis is unset and the - // GENERIC_CHART_AXES feature flag is enabled - const { value } = control; - if (value) { - return value; - } - const timeColumn = controlPanel?.form_data?.granularity_sqla; - if (isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && timeColumn) { - return timeColumn; - } - return null; - }, - multi: false, - description: t('Dimension to use on x-axis.'), - validators: [validateNonEmpty], - }, -}; +export const xAxisControl = isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) + ? 'x_axis' + : null; const percentageThresholdControl: ControlSetItem = { name: 'percentage_threshold', diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/index.ts index 84a1a3a3dc..9890eb4c13 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/index.ts @@ -45,7 +45,7 @@ export { default as TimeseriesTransformProps } from './Timeseries/transformProps export { default as TreeTransformProps } from './Tree/transformProps'; export { default as TreemapTransformProps } from './Treemap/transformProps'; -export { DEFAULT_FORM_DATA as TimeseriesDefaultFormData } from './Timeseries/types'; +export { DEFAULT_FORM_DATA as TimeseriesDefaultFormData } from './Timeseries/constants'; export * from './types'; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/types.ts index d84b7079c4..487c744341 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/types.ts @@ -85,13 +85,6 @@ export type EchartsLegendFormData = { showLegend: boolean; }; -export const DEFAULT_LEGEND_FORM_DATA: EchartsLegendFormData = { - legendMargin: null, - legendOrientation: LegendOrientation.Top, - legendType: LegendType.Scroll, - showLegend: true, -}; - export type EventHandlers = Record; export enum LabelPositionEnum { @@ -132,14 +125,6 @@ export interface EchartsTitleFormData { yAxisTitlePosition: string; } -export const DEFAULT_TITLE_FORM_DATA: EchartsTitleFormData = { - xAxisTitle: '', - xAxisTitleMargin: 0, - yAxisTitle: '', - yAxisTitleMargin: 0, - yAxisTitlePosition: 'Top', -}; - export type StackType = boolean | null | Partial; export * from './Timeseries/types'; diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/BoxPlot/buildQuery.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/BoxPlot/buildQuery.test.ts index 6859248713..304f5b7065 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/test/BoxPlot/buildQuery.test.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/test/BoxPlot/buildQuery.test.ts @@ -20,7 +20,7 @@ import { isPostProcessingBoxplot, PostProcessingBoxplot, } from '@superset-ui/core'; -import { DEFAULT_TITLE_FORM_DATA } from '../../src/types'; +import { DEFAULT_TITLE_FORM_DATA } from '../../src/constants'; import buildQuery from '../../src/BoxPlot/buildQuery'; import { BoxPlotQueryFormData } from '../../src/BoxPlot/types';