mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(echarts): adapt y-axis ticks and padding for compact timeseries charts (#38673)
This commit is contained in:
@@ -1338,6 +1338,101 @@ test('should not apply axis bounds calculation when seriesType is not Bar for ho
|
||||
expect(xAxisRaw.max).toBeUndefined();
|
||||
});
|
||||
|
||||
test('legend is visible on tall charts when enabled by the user', () => {
|
||||
const chartProps = createTestChartProps({
|
||||
height: 400,
|
||||
formData: { showLegend: true },
|
||||
});
|
||||
const { legend } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(legend.show).toBe(true);
|
||||
});
|
||||
|
||||
test('legend is hidden on small charts even when enabled by the user', () => {
|
||||
const chartProps = createTestChartProps({
|
||||
height: 80,
|
||||
formData: { showLegend: true },
|
||||
});
|
||||
const { legend } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(legend.show).toBe(false);
|
||||
});
|
||||
|
||||
test('y-axis labels remain visible on small charts for scale reference', () => {
|
||||
const chartProps = createTestChartProps({ height: 80 });
|
||||
const { yAxis } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(yAxis.axisLabel.show).toBe(true);
|
||||
});
|
||||
|
||||
test('y-axis labels are hidden on micro charts for a sparkline view', () => {
|
||||
const chartProps = createTestChartProps({ height: 40 });
|
||||
const { yAxis } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(yAxis.axisLabel.show).toBe(false);
|
||||
});
|
||||
|
||||
test('y-axis tick count scales with chart height', () => {
|
||||
const short = transformProps(createTestChartProps({ height: 200 }));
|
||||
const tall = transformProps(createTestChartProps({ height: 500 }));
|
||||
const shortYAxis = short.echartOptions.yAxis as any;
|
||||
const tallYAxis = tall.echartOptions.yAxis as any;
|
||||
|
||||
expect(tallYAxis.splitNumber).toBeGreaterThan(shortYAxis.splitNumber);
|
||||
});
|
||||
|
||||
test('small chart y-axis uses splitNumber=1 to show only boundary labels', () => {
|
||||
const chartProps = createTestChartProps({ height: 80 });
|
||||
const { yAxis } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(yAxis.splitNumber).toBe(1);
|
||||
});
|
||||
|
||||
test('zoomable small chart preserves bottom padding for the dataZoom slider', () => {
|
||||
const chartProps = createTestChartProps({
|
||||
height: 80,
|
||||
formData: { zoomable: true },
|
||||
});
|
||||
const result = transformProps(chartProps);
|
||||
const grid = result.echartOptions.grid as any;
|
||||
|
||||
expect(grid.bottom).toBeGreaterThan(5);
|
||||
});
|
||||
|
||||
test('boundary: height at exactly 100px uses full axis behavior', () => {
|
||||
const chartProps = createTestChartProps({ height: 100 });
|
||||
const { yAxis } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(yAxis.axisLabel.show).toBe(true);
|
||||
expect(yAxis.splitNumber).toBeGreaterThanOrEqual(3);
|
||||
});
|
||||
|
||||
test('boundary: height at 99px triggers small chart behavior', () => {
|
||||
const chartProps = createTestChartProps({
|
||||
height: 99,
|
||||
formData: { showLegend: true },
|
||||
});
|
||||
const { yAxis, legend } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(yAxis.splitNumber).toBe(1);
|
||||
expect(legend.show).toBe(false);
|
||||
});
|
||||
|
||||
test('boundary: height at exactly 60px shows labels but uses compact axis', () => {
|
||||
const chartProps = createTestChartProps({ height: 60 });
|
||||
const { yAxis } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(yAxis.axisLabel.show).toBe(true);
|
||||
expect(yAxis.splitNumber).toBe(1);
|
||||
});
|
||||
|
||||
test('boundary: height at 59px triggers micro chart behavior', () => {
|
||||
const chartProps = createTestChartProps({ height: 59 });
|
||||
const { yAxis } = transformProps(chartProps).echartOptions as any;
|
||||
|
||||
expect(yAxis.axisLabel.show).toBe(false);
|
||||
});
|
||||
|
||||
test('x-axis formatter deduplicates consecutive identical labels for coarse time grains', () => {
|
||||
const yearData = [
|
||||
{ __timestamp: Date.UTC(2003, 0, 1), sales: 100 },
|
||||
|
||||
Reference in New Issue
Block a user