Skip to content

Commit a21a036

Browse files
committed
fix(time-pivot): show sparse-period symbols, legend off by default, x-axis format control
A line series with a single point renders nothing when symbols are hidden, which made sparse pivots (yearly data over 52-week periods) look empty; symbols now show for series with two or fewer points. The 40-plus period legend adds little, so it defaults off while staying togglable. Adds the x_axis_format control (D3 time formats, matching the legacy control name) applied to the axis labels. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3ac231f commit a21a036

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

superset-frontend/plugins/plugin-chart-echarts/src/TimePivot/controlPanel.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
* under the License.
1818
*/
1919
import { t } from '@apache-superset/core/translation';
20-
import { ControlPanelConfig, sections } from '@superset-ui/chart-controls';
20+
import {
21+
ControlPanelConfig,
22+
D3_TIME_FORMAT_OPTIONS,
23+
sections,
24+
} from '@superset-ui/chart-controls';
2125

2226
// Control names match the legacy nvd3 chart so saved charts keep working
2327
// without a form-data migration. nvd3-specific pixel-margin and min/max
@@ -76,7 +80,7 @@ const config: ControlPanelConfig = {
7680
type: 'CheckboxControl',
7781
label: t('Legend'),
7882
renderTrigger: true,
79-
default: true,
83+
default: false,
8084
description: t('Whether to display the legend (toggles)'),
8185
},
8286
},
@@ -117,6 +121,20 @@ const config: ControlPanelConfig = {
117121
},
118122
},
119123
],
124+
[
125+
{
126+
name: 'x_axis_format',
127+
config: {
128+
type: 'SelectControl',
129+
freeForm: true,
130+
label: t('X Axis Format'),
131+
renderTrigger: true,
132+
default: 'smart_date',
133+
choices: D3_TIME_FORMAT_OPTIONS,
134+
description: t('D3 time format for the x-axis labels'),
135+
},
136+
},
137+
],
120138
],
121139
},
122140
{

superset-frontend/plugins/plugin-chart-echarts/src/TimePivot/transformProps.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
getMetricLabel,
2121
getNumberFormatter,
2222
getTimeFormatter,
23+
smartDateFormatter,
2324
JsonObject,
2425
SMART_DATE_VERBOSE_ID,
2526
} from '@superset-ui/core';
@@ -43,6 +44,7 @@ export default function transformProps(
4344
colorPicker,
4445
showLegend,
4546
lineInterpolation,
47+
xAxisFormat,
4648
xAxisLabel,
4749
yAxisLabel,
4850
yAxisFormat,
@@ -98,7 +100,15 @@ export default function transformProps(
98100
name: xAxisLabel || undefined,
99101
nameLocation: 'middle',
100102
nameGap: theme.sizeUnit * 8,
101-
axisLabel: { color: theme.colorTextSecondary },
103+
axisLabel: {
104+
color: theme.colorTextSecondary,
105+
...(xAxisFormat && xAxisFormat !== smartDateFormatter.id
106+
? {
107+
formatter: (value: number) =>
108+
getTimeFormatter(xAxisFormat)(value),
109+
}
110+
: {}),
111+
},
102112
},
103113
yAxis: {
104114
type: yLogScale ? 'log' : 'value',
@@ -136,7 +146,9 @@ export default function transformProps(
136146
type: 'line',
137147
smooth,
138148
...(step ? { step } : {}),
139-
showSymbol: false,
149+
// a line series with one point renders nothing without its symbol;
150+
// sparse periods (e.g. yearly data pivoted by 52 weeks) need them
151+
showSymbol: s.values.filter(({ y }) => y != null).length <= 2,
140152
connectNulls: false,
141153
lineStyle: {
142154
color: colorOf(s),

superset-frontend/plugins/plugin-chart-echarts/src/TimePivot/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type EchartsTimePivotFormData = QueryFormData & {
3030
colorPicker?: { r: number; g: number; b: number; a: number };
3131
showLegend?: boolean;
3232
lineInterpolation?: string;
33+
xAxisFormat?: string;
3334
xAxisLabel?: string;
3435
yAxisLabel?: string;
3536
yAxisFormat?: string;

0 commit comments

Comments
 (0)