Skip to content

Commit

Permalink
echarts: add data zoom options (start/end/lock)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexcafe committed Jul 1, 2024
1 parent ba405ba commit 4aeb6d4
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 100 deletions.
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
66 changes: 66 additions & 0 deletions superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,72 @@ export const minorTicks: ControlSetItem = {
},
};

export const dataZoom: ControlSetItem = {
name: 'zoomable',
config: {
type: 'CheckboxControl',
label: t('Data Zoom'),
default: false,
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: 0,
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: 0,
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

0 comments on commit 4aeb6d4

Please sign in to comment.