Skip to content

Commit 49a4086

Browse files
committed
fix(charts): fix Bubble chart axis-interval crash
xAxis.interval was set directly from the xAxisLabelInterval control ('auto'/'0'), but xAxis.interval forces echarts' IntervalScale into a fixed-tick-spacing mode that expects a number and crashes the axis "nice" tick calculation. Every bubble_v2 chart hit this at its default control value; there was no existing test coverage for this file. The interval belongs nested under axisLabel, where it only controls how many labels are skipped, matching how every other echarts chart in this codebase (e.g. Timeseries) wires it. Added a regression test. Found while building out live thumbnail capture for example dashboards (this PR) -- bubble_v2 apparently never had a real dashboard-placed chart to exercise this path before.
1 parent 3121898 commit 49a4086

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 { SqlaFormData } from '@superset-ui/core';
20+
import transformProps from './transformProps';
21+
import { EchartsBubbleChartProps } from './types';
22+
23+
const baseFormData: SqlaFormData = {
24+
datasource: '1__table',
25+
viz_type: 'bubble_v2',
26+
entity: 'customer_name',
27+
x: 'price',
28+
y: 'sales',
29+
size: 'count',
30+
};
31+
32+
const baseChartProps = {
33+
width: 400,
34+
height: 400,
35+
hooks: {},
36+
queriesData: [
37+
{
38+
data: [
39+
{ customer_name: 'A', price: 10, sales: 100, count: 5 },
40+
{ customer_name: 'B', price: 20, sales: 200, count: 8 },
41+
],
42+
},
43+
],
44+
theme: { colorText: '#000' },
45+
};
46+
47+
test('nests xAxisLabelInterval under axisLabel rather than the axis itself', () => {
48+
// Regression test: xAxis.interval forces echarts' IntervalScale into a
49+
// fixed-tick-spacing mode that expects a number and crashes on the
50+
// 'auto'/'0' strings this control actually produces (observed as an
51+
// uncaught assertion deep in echarts' axis "nice" tick calculation,
52+
// reproducing on every dashboard bubble chart). The interval belongs on
53+
// axisLabel, where it only controls how many labels are skipped.
54+
const { echartOptions } = transformProps({
55+
...baseChartProps,
56+
formData: baseFormData,
57+
} as unknown as EchartsBubbleChartProps);
58+
59+
expect((echartOptions.xAxis as any).interval).toBeUndefined();
60+
expect((echartOptions.xAxis as any).axisLabel.interval).toBe('auto');
61+
});
62+
63+
test('honors an explicit xAxisLabelInterval override', () => {
64+
const { echartOptions } = transformProps({
65+
...baseChartProps,
66+
formData: { ...baseFormData, xAxisLabelInterval: '0' },
67+
} as unknown as EchartsBubbleChartProps);
68+
69+
expect((echartOptions.xAxis as any).axisLabel.interval).toBe('0');
70+
});

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,16 @@ export default function transformProps(chartProps: EchartsBubbleChartProps) {
212212
const echartOptions: EChartsCoreOption = {
213213
series,
214214
xAxis: {
215-
axisLabel: { formatter: xAxisFormatter, rotate: xAxisLabelRotation },
215+
axisLabel: {
216+
formatter: xAxisFormatter,
217+
rotate: xAxisLabelRotation,
218+
interval: xAxisLabelInterval,
219+
},
216220
splitLine: {
217221
lineStyle: {
218222
type: 'dashed',
219223
},
220224
},
221-
interval: xAxisLabelInterval,
222225
scale: true,
223226
name: bubbleXAxisTitle,
224227
nameLocation: 'middle',

0 commit comments

Comments
 (0)