mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
fix(plugin-chart-echarts): invalid total label location for negative values in stacked bar chart (#21032)
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
||||
getChartPadding,
|
||||
getLegendProps,
|
||||
sanitizeHtml,
|
||||
extractShowValueIndexes,
|
||||
} from '../../src/utils/series';
|
||||
import { LegendOrientation, LegendType } from '../../src/types';
|
||||
import { defaultLegendPadding } from '../../src/defaults';
|
||||
@@ -206,6 +207,124 @@ describe('extractGroupbyLabel', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('extractShowValueIndexes', () => {
|
||||
it('should return the latest index for stack', () => {
|
||||
expect(
|
||||
extractShowValueIndexes(
|
||||
[
|
||||
{
|
||||
id: 'abc',
|
||||
name: 'abc',
|
||||
data: [
|
||||
['2000-01-01', null],
|
||||
['2000-02-01', 0],
|
||||
['2000-03-01', 1],
|
||||
['2000-04-01', 0],
|
||||
['2000-05-01', null],
|
||||
['2000-06-01', 0],
|
||||
['2000-07-01', 2],
|
||||
['2000-08-01', 3],
|
||||
['2000-09-01', null],
|
||||
['2000-10-01', null],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'def',
|
||||
name: 'def',
|
||||
data: [
|
||||
['2000-01-01', null],
|
||||
['2000-02-01', 0],
|
||||
['2000-03-01', null],
|
||||
['2000-04-01', 0],
|
||||
['2000-05-01', null],
|
||||
['2000-06-01', 0],
|
||||
['2000-07-01', 2],
|
||||
['2000-08-01', 3],
|
||||
['2000-09-01', null],
|
||||
['2000-10-01', 0],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'def',
|
||||
name: 'def',
|
||||
data: [
|
||||
['2000-01-01', null],
|
||||
['2000-02-01', null],
|
||||
['2000-03-01', null],
|
||||
['2000-04-01', null],
|
||||
['2000-05-01', null],
|
||||
['2000-06-01', 3],
|
||||
['2000-07-01', null],
|
||||
['2000-08-01', null],
|
||||
['2000-09-01', null],
|
||||
['2000-10-01', null],
|
||||
],
|
||||
},
|
||||
],
|
||||
{ stack: true, onlyTotal: false, isHorizontal: false },
|
||||
),
|
||||
).toEqual([undefined, 1, 0, 1, undefined, 2, 1, 1, undefined, 1]);
|
||||
});
|
||||
|
||||
it('should handle the negative numbers for total only', () => {
|
||||
expect(
|
||||
extractShowValueIndexes(
|
||||
[
|
||||
{
|
||||
id: 'abc',
|
||||
name: 'abc',
|
||||
data: [
|
||||
['2000-01-01', null],
|
||||
['2000-02-01', 0],
|
||||
['2000-03-01', -1],
|
||||
['2000-04-01', 0],
|
||||
['2000-05-01', null],
|
||||
['2000-06-01', 0],
|
||||
['2000-07-01', -2],
|
||||
['2000-08-01', -3],
|
||||
['2000-09-01', null],
|
||||
['2000-10-01', null],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'def',
|
||||
name: 'def',
|
||||
data: [
|
||||
['2000-01-01', null],
|
||||
['2000-02-01', 0],
|
||||
['2000-03-01', null],
|
||||
['2000-04-01', 0],
|
||||
['2000-05-01', null],
|
||||
['2000-06-01', 0],
|
||||
['2000-07-01', 2],
|
||||
['2000-08-01', -3],
|
||||
['2000-09-01', null],
|
||||
['2000-10-01', 0],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'def',
|
||||
name: 'def',
|
||||
data: [
|
||||
['2000-01-01', null],
|
||||
['2000-02-01', 0],
|
||||
['2000-03-01', null],
|
||||
['2000-04-01', 1],
|
||||
['2000-05-01', null],
|
||||
['2000-06-01', 0],
|
||||
['2000-07-01', -2],
|
||||
['2000-08-01', 3],
|
||||
['2000-09-01', null],
|
||||
['2000-10-01', 0],
|
||||
],
|
||||
},
|
||||
],
|
||||
{ stack: true, onlyTotal: true, isHorizontal: false },
|
||||
),
|
||||
).toEqual([undefined, 1, 0, 2, undefined, 1, 1, 2, undefined, 1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatSeriesName', () => {
|
||||
const numberFormatter = getNumberFormatter();
|
||||
const timeFormatter = getTimeFormatter();
|
||||
|
||||
Reference in New Issue
Block a user