Skip to content

Commit 67753a7

Browse files
committed
feat(time-pivot): rebuild Time-series Period Pivot on ECharts
Swap the nvd3 renderer for an ECharts line chart while reusing the already-ported period-pivot reshape verbatim: transformData buckets timestamps by the pandas-style freq offset, ranks periods most-recent first and shifts priors onto the current period's time axis. Styling matches nvd3 -- the current period draws boldly in the picked color and on top, while prior periods fade with their recency percentile. Control names and the viz_type stay the same, so saved charts keep working with no migration; nvd3-only pixel-margin and axis-min/max toggles are dropped since ECharts handles layout. The reshape tests move over unchanged, with new transformProps coverage for series ordering, fading, log scale, bounds and empty results. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 65d2ea5 commit 67753a7

16 files changed

Lines changed: 877 additions & 5 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import Echart from '../components/Echart';
20+
import { allEventHandlers } from '../utils/eventHandlers';
21+
import { TimePivotChartTransformedProps } from './types';
22+
23+
export default function EchartsTimePivot(
24+
props: TimePivotChartTransformedProps,
25+
) {
26+
const { height, width, echartOptions, refs, formData } = props;
27+
28+
const eventHandlers = allEventHandlers(props);
29+
30+
return (
31+
<Echart
32+
refs={refs}
33+
height={height}
34+
width={width}
35+
echartOptions={echartOptions}
36+
eventHandlers={eventHandlers}
37+
vizType={formData.vizType}
38+
/>
39+
);
40+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { buildQueryContext, QueryFormData } from '@superset-ui/core';
20+
21+
/**
22+
* Mirrors the legacy NVD3TimePivotViz.query_obj: a timeseries query with
23+
* the single metric.
24+
*/
25+
export default function buildQuery(formData: QueryFormData) {
26+
const { metric } = formData;
27+
return buildQueryContext(formData, baseQueryObject => [
28+
{
29+
...baseQueryObject,
30+
is_timeseries: true,
31+
metrics: metric ? [metric] : [],
32+
},
33+
]);
34+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { t } from '@apache-superset/core/translation';
20+
import { ControlPanelConfig, sections } from '@superset-ui/chart-controls';
21+
22+
// Control names match the legacy nvd3 chart so saved charts keep working
23+
// without a form-data migration. nvd3-specific pixel-margin and min/max
24+
// toggles are intentionally dropped; ECharts lays those out automatically.
25+
const config: ControlPanelConfig = {
26+
controlPanelSections: [
27+
sections.legacyTimeseriesTime,
28+
{
29+
label: t('Query'),
30+
expanded: true,
31+
controlSetRows: [
32+
['metric'],
33+
['adhoc_filters'],
34+
[
35+
{
36+
name: 'freq',
37+
config: {
38+
type: 'SelectControl',
39+
label: t('Frequency'),
40+
default: 'W-MON',
41+
freeForm: true,
42+
clearable: false,
43+
choices: [
44+
['AS', t('Year (freq=AS)')],
45+
['52W-MON', t('52 weeks starting Monday (freq=52W-MON)')],
46+
['W-SUN', t('1 week starting Sunday (freq=W-SUN)')],
47+
['W-MON', t('1 week starting Monday (freq=W-MON)')],
48+
['D', t('Day (freq=D)')],
49+
['4W-MON', t('4 weeks (freq=4W-MON)')],
50+
],
51+
description: t(
52+
`The periodicity over which to pivot time. Users can provide
53+
"Pandas" offset alias.
54+
Click on the info bubble for more details on accepted "freq" expressions.`,
55+
),
56+
tooltipOnClick: () => {
57+
window.open(
58+
'https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases',
59+
);
60+
},
61+
},
62+
},
63+
],
64+
],
65+
},
66+
{
67+
label: t('Chart Options'),
68+
expanded: true,
69+
controlSetRows: [
70+
[
71+
{
72+
name: 'show_legend',
73+
config: {
74+
type: 'CheckboxControl',
75+
label: t('Legend'),
76+
renderTrigger: true,
77+
default: true,
78+
description: t('Whether to display the legend (toggles)'),
79+
},
80+
},
81+
],
82+
['color_picker'],
83+
[
84+
{
85+
name: 'line_interpolation',
86+
config: {
87+
type: 'SelectControl',
88+
label: t('Line Style'),
89+
renderTrigger: true,
90+
choices: [
91+
['linear', t('Linear')],
92+
['cardinal', t('Smooth')],
93+
['step-before', t('Step - start')],
94+
['step-after', t('Step - end')],
95+
],
96+
default: 'linear',
97+
description: t('Line interpolation as defined by d3.js'),
98+
},
99+
},
100+
],
101+
],
102+
},
103+
{
104+
label: t('X Axis'),
105+
expanded: true,
106+
controlSetRows: [
107+
[
108+
{
109+
name: 'x_axis_label',
110+
config: {
111+
type: 'TextControl',
112+
label: t('X Axis Label'),
113+
renderTrigger: true,
114+
default: '',
115+
},
116+
},
117+
],
118+
],
119+
},
120+
{
121+
label: t('Y Axis'),
122+
expanded: true,
123+
controlSetRows: [
124+
[
125+
{
126+
name: 'y_axis_label',
127+
config: {
128+
type: 'TextControl',
129+
label: t('Y Axis Label'),
130+
renderTrigger: true,
131+
default: '',
132+
},
133+
},
134+
],
135+
['y_axis_format'],
136+
[
137+
{
138+
name: 'y_log_scale',
139+
config: {
140+
type: 'CheckboxControl',
141+
label: t('Y Log Scale'),
142+
default: false,
143+
renderTrigger: true,
144+
description: t('Use a log scale for the Y-axis'),
145+
},
146+
},
147+
],
148+
[
149+
{
150+
name: 'y_axis_bounds',
151+
config: {
152+
type: 'BoundsControl',
153+
label: t('Y Axis Bounds'),
154+
renderTrigger: true,
155+
default: [null, null],
156+
description: t(
157+
'Bounds for the Y-axis. When left empty, the bounds are ' +
158+
'dynamically defined based on the min/max of the data. Note that ' +
159+
"this feature will only expand the axis range. It won't " +
160+
"narrow the data's extent.",
161+
),
162+
},
163+
},
164+
],
165+
],
166+
},
167+
],
168+
};
169+
170+
export default config;
135 KB
Loading
129 KB
Loading
24.7 KB
Loading
10.9 KB
Loading
26.1 KB
Loading
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { t } from '@apache-superset/core/translation';
20+
import { Behavior } from '@superset-ui/core';
21+
import buildQuery from './buildQuery';
22+
import controlPanel from './controlPanel';
23+
import transformProps from './transformProps';
24+
import thumbnail from './images/thumbnail.png';
25+
import thumbnailDark from './images/thumbnail-dark.png';
26+
import example from './images/example.jpg';
27+
import exampleDark from './images/example-dark.jpg';
28+
import { EchartsTimePivotFormData, EchartsTimePivotChartProps } from './types';
29+
import { EchartsChartPlugin } from '../types';
30+
31+
export default class EchartsTimePivotChartPlugin extends EchartsChartPlugin<
32+
EchartsTimePivotFormData,
33+
EchartsTimePivotChartProps
34+
> {
35+
constructor() {
36+
super({
37+
buildQuery,
38+
controlPanel,
39+
loadChart: () => import('./EchartsTimePivot'),
40+
metadata: {
41+
behaviors: [Behavior.InteractiveChart],
42+
category: t('Evolution'),
43+
description: t(
44+
'Compares the current time period against equivalent past periods by overlaying them on a shared time axis. The current period is drawn boldly while prior periods fade with age.',
45+
),
46+
exampleGallery: [{ url: example, urlDark: exampleDark }],
47+
name: t('Time-series Period Pivot'),
48+
tags: [t('Comparison'), t('Time'), t('Trend'), t('ECharts')],
49+
thumbnail,
50+
thumbnailDark,
51+
},
52+
transformProps,
53+
});
54+
}
55+
}

0 commit comments

Comments
 (0)