Files
superset2/superset-frontend/plugins/plugin-chart-echarts/src/Bubble/transformProps.test.ts
T
Claude Code 2bea03b3aa fix(charts): fix Bubble chart crash and correct example's time_range to a year with real data
Two issues surfaced while verifying #42328's live thumbnail-capture work
against this example chart:

1. Bubble/transformProps.ts set `xAxis.interval` directly from the
   xAxisLabelInterval control ('auto'/'0'), but xAxis.interval forces
   echarts' IntervalScale into a fixed-tick-spacing mode that expects a
   number. This crashed the axis "nice" tick calculation for every
   bubble_v2 chart -- not just this example, any bubble chart with the
   control at its default. 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.
   There was no existing test coverage for this file; added one.

2. Once the crash was fixed, the chart rendered with zero visible
   bubbles: the previous commit's `time_range` (2014, matching the
   convention used by sibling examples on this dataset) has zero
   non-null SP_DYN_LE00_IN (life expectancy) values in this particular
   dataset. The original legacy chart's own choice of 2011 was
   deliberate -- that year has real data for all three metrics used.
2026-08-14 14:05:06 -07:00

71 lines
2.5 KiB
TypeScript

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { SqlaFormData } from '@superset-ui/core';
import transformProps from './transformProps';
import { EchartsBubbleChartProps } from './types';
const baseFormData: SqlaFormData = {
datasource: '1__table',
viz_type: 'bubble_v2',
entity: 'customer_name',
x: 'price',
y: 'sales',
size: 'count',
};
const baseChartProps = {
width: 400,
height: 400,
hooks: {},
queriesData: [
{
data: [
{ customer_name: 'A', price: 10, sales: 100, count: 5 },
{ customer_name: 'B', price: 20, sales: 200, count: 8 },
],
},
],
theme: { colorText: '#000' },
};
test('nests xAxisLabelInterval under axisLabel rather than the axis itself', () => {
// Regression test: xAxis.interval forces echarts' IntervalScale into a
// fixed-tick-spacing mode that expects a number and crashes on the
// 'auto'/'0' strings this control actually produces (observed as an
// uncaught assertion deep in echarts' axis "nice" tick calculation,
// reproducing on every dashboard bubble chart). The interval belongs on
// axisLabel, where it only controls how many labels are skipped.
const { echartOptions } = transformProps({
...baseChartProps,
formData: baseFormData,
} as unknown as EchartsBubbleChartProps);
expect((echartOptions.xAxis as any).interval).toBeUndefined();
expect((echartOptions.xAxis as any).axisLabel.interval).toBe('auto');
});
test('honors an explicit xAxisLabelInterval override', () => {
const { echartOptions } = transformProps({
...baseChartProps,
formData: { ...baseFormData, xAxisLabelInterval: '0' },
} as unknown as EchartsBubbleChartProps);
expect((echartOptions.xAxis as any).axisLabel.interval).toBe('0');
});