Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(echarts): add data zoom options (start/end/lock) #29421

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
import { DEFAULT_FORM_DATA } from './types';
import { EchartsTimeseriesSeriesType } from '../Timeseries/types';
import {
dataZoom,
dataZoomSliderOptions,
legendSection,
minorTicks,
richTooltipSection,
Expand All @@ -54,7 +56,6 @@ const {
stack,
truncateYAxis,
yAxisBounds,
zoomable,
yAxisIndex,
} = DEFAULT_FORM_DATA;

Expand Down Expand Up @@ -301,18 +302,8 @@ const config: ControlPanelConfig = {
['color_scheme'],
...createCustomizeSection(t('Query A'), ''),
...createCustomizeSection(t('Query B'), 'B'),
[
{
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: zoomable,
renderTrigger: true,
description: t('Enable data zooming controls'),
},
},
],
[dataZoom],
...dataZoomSliderOptions,
[minorTicks],
...legendSection,
[<ControlSubSectionHeader>{t('X Axis')}</ControlSubSectionHeader>],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
truncateXAxis,
xAxisBounds,
minorTicks,
dataZoom,
dataZoomSliderOptions,
} from '../../controls';
import { AreaChartStackControlOptions } from '../../constants';

Expand All @@ -53,7 +55,6 @@ const {
seriesType,
truncateYAxis,
yAxisBounds,
zoomable,
} = DEFAULT_FORM_DATA;
const config: ControlPanelConfig = {
controlPanelSections: [
Expand Down Expand Up @@ -168,19 +169,9 @@ const config: ControlPanelConfig = {
},
},
],
[dataZoom],
...dataZoomSliderOptions,
[minorTicks],
[
{
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: zoomable,
renderTrigger: true,
description: t('Enable data zooming controls'),
},
},
],
...legendSection,
[<ControlSubSectionHeader>{t('X Axis')}</ControlSubSectionHeader>],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
sharedControls,
} from '@superset-ui/chart-controls';
import {
dataZoom,
dataZoomSliderOptions,
legendSection,
minorTicks,
richTooltipSection,
Expand All @@ -46,14 +48,8 @@ import {
TIME_SERIES_DESCRIPTION_TEXT,
} from '../../constants';

const {
logAxis,
minorSplitLine,
truncateYAxis,
yAxisBounds,
zoomable,
orientation,
} = DEFAULT_FORM_DATA;
const { logAxis, minorSplitLine, truncateYAxis, yAxisBounds, orientation } =
DEFAULT_FORM_DATA;

function createAxisTitleControl(axis: 'x' | 'y'): ControlSetRow[] {
const isXAxis = axis === 'x';
Expand Down Expand Up @@ -298,19 +294,9 @@ const config: ControlPanelConfig = {
...seriesOrderSection,
['color_scheme'],
...showValueSection,
[dataZoom],
...dataZoomSliderOptions,
[minorTicks],
[
{
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: zoomable,
renderTrigger: true,
description: t('Enable data zooming controls'),
},
},
],
...legendSection,
[<ControlSubSectionHeader>{t('X Axis')}</ControlSubSectionHeader>],
...createAxisControl('x'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
TIME_SERIES_DESCRIPTION_TEXT,
} from '../../constants';
import {
dataZoom,
dataZoomSliderOptions,
legendSection,
minorTicks,
richTooltipSection,
Expand All @@ -54,7 +56,6 @@ const {
seriesType,
truncateYAxis,
yAxisBounds,
zoomable,
} = DEFAULT_FORM_DATA;
const config: ControlPanelConfig = {
controlPanelSections: [
Expand Down Expand Up @@ -156,18 +157,8 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: zoomable,
renderTrigger: true,
description: t('Enable data zooming controls'),
},
},
],
[dataZoom],
...dataZoomSliderOptions,
[minorTicks],
...legendSection,
[<ControlSubSectionHeader>{t('X Axis')}</ControlSubSectionHeader>],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
TIME_SERIES_DESCRIPTION_TEXT,
} from '../../constants';
import {
dataZoom,
dataZoomSliderOptions,
legendSection,
minorTicks,
richTooltipSection,
Expand All @@ -50,7 +52,6 @@ const {
rowLimit,
truncateYAxis,
yAxisBounds,
zoomable,
} = DEFAULT_FORM_DATA;
const config: ControlPanelConfig = {
controlPanelSections: [
Expand Down Expand Up @@ -98,18 +99,8 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: zoomable,
renderTrigger: true,
description: t('Enable data zooming controls'),
},
},
],
[dataZoom],
...dataZoomSliderOptions,
[minorTicks],
...legendSection,
[<ControlSubSectionHeader>{t('X Axis')}</ControlSubSectionHeader>],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
TIME_SERIES_DESCRIPTION_TEXT,
} from '../../constants';
import {
dataZoom,
dataZoomSliderOptions,
legendSection,
minorTicks,
richTooltipSection,
Expand All @@ -50,7 +52,6 @@ const {
rowLimit,
truncateYAxis,
yAxisBounds,
zoomable,
} = DEFAULT_FORM_DATA;
const config: ControlPanelConfig = {
controlPanelSections: [
Expand Down Expand Up @@ -98,18 +99,8 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: zoomable,
renderTrigger: true,
description: t('Enable data zooming controls'),
},
},
],
[dataZoom],
...dataZoomSliderOptions,
[minorTicks],
...legendSection,
[<ControlSubSectionHeader>{t('X Axis')}</ControlSubSectionHeader>],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
import { EchartsTimeseriesSeriesType } from '../../types';
import { DEFAULT_FORM_DATA, TIME_SERIES_DESCRIPTION_TEXT } from '../constants';
import {
dataZoom,
dataZoomSliderOptions,
legendSection,
minorTicks,
richTooltipSection,
Expand All @@ -50,7 +52,6 @@ const {
rowLimit,
truncateYAxis,
yAxisBounds,
zoomable,
} = DEFAULT_FORM_DATA;
const config: ControlPanelConfig = {
controlPanelSections: [
Expand Down Expand Up @@ -150,18 +151,8 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: zoomable,
renderTrigger: true,
description: t('Enable data zooming controls'),
},
},
],
[dataZoom],
...dataZoomSliderOptions,
[minorTicks],
...legendSection,
[<ControlSubSectionHeader>{t('X Axis')}</ControlSubSectionHeader>],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export default function transformProps(
yAxisTitleMargin,
yAxisTitlePosition,
zoomable,
zoomStart,
zoomEnd,
zoomLock,
}: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
const refs: Refs = {};
const groupBy = ensureIsArray(groupby);
Expand Down Expand Up @@ -627,8 +630,9 @@ export default function transformProps(
? [
{
type: 'slider',
start: TIMESERIES_CONSTANTS.dataZoomStart,
end: TIMESERIES_CONSTANTS.dataZoomEnd,
start: zoomStart || TIMESERIES_CONSTANTS.dataZoomStart,
end: zoomEnd || TIMESERIES_CONSTANTS.dataZoomEnd,
zoomLock: zoomLock || false,
bottom: TIMESERIES_CONSTANTS.zoomBottom,
yAxisIndex: isHorizontal ? 0 : undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export type EchartsTimeseriesFormData = QueryFormData & {
xAxisBounds: [number | undefined | null, number | undefined | null];
yAxisBounds: [number | undefined | null, number | undefined | null];
zoomable: boolean;
zoomStart?: number;
zoomEnd?: number;
zoomLock?: boolean;
richTooltip: boolean;
xAxisLabelRotation: number;
showValue: boolean;
Expand Down
72 changes: 71 additions & 1 deletion superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import {
SORT_SERIES_CHOICES,
sharedControls,
} from '@superset-ui/chart-controls';
import { DEFAULT_LEGEND_FORM_DATA, StackControlOptions } from './constants';
import {
DEFAULT_LEGEND_FORM_DATA,
StackControlOptions,
TIMESERIES_CONSTANTS,
} from './constants';
import { DEFAULT_FORM_DATA } from './Timeseries/constants';
import { defaultXAxis } from './defaults';

Expand Down Expand Up @@ -309,6 +313,72 @@ export const minorTicks: ControlSetItem = {
},
};

export const dataZoom: ControlSetItem = {
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: DEFAULT_FORM_DATA.zoomable,
renderTrigger: true,
description: t('Enable data zooming controls'),
},
};

export const dataZoomSliderOptions: ControlSetItem[][] = [
[
{
name: 'zoomStart',
config: {
type: 'SliderControl',
label: t('Zoom Start'),
renderTrigger: true,
min: 0,
max: 100,
step: 1,
default: TIMESERIES_CONSTANTS.dataZoomStart,
description: t(
'The start percentage of the window out of the data extent, in the range of 0 ~ 100.',
),
visibility: ({ controls }: ControlPanelsContainerProps) =>
Boolean(controls?.zoomable?.value),
},
},
],
[
{
name: 'zoomEnd',
config: {
type: 'SliderControl',
label: t('Zoom End'),
renderTrigger: true,
min: 0,
max: 100,
step: 1,
default: TIMESERIES_CONSTANTS.dataZoomEnd,
description: t(
'The end percentage of the window out of the data extent, in the range of 0 ~ 100.',
),
visibility: ({ controls }: ControlPanelsContainerProps) =>
Boolean(controls?.zoomable?.value),
},
},
],
[
{
name: 'zoomLock',
config: {
type: 'CheckboxControl',
label: t('Zoom Lock'),
default: false,
renderTrigger: true,
description: t('Specify whether to lock the size of window.'),
visibility: ({ controls }: ControlPanelsContainerProps) =>
Boolean(controls?.zoomable?.value),
},
},
],
];

export const forceCategorical: ControlSetItem = {
name: 'forceCategorical',
config: {
Expand Down
Loading