Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jest.mock('@superset-ui/chart-controls', () => ({
}));

jest.mock('@superset-ui/core', () => ({
BRAND_COLOR: '#00A699',
GenericDataType: { Temporal: 2, String: 1 },
extractTimegrain: jest.fn(() => 'P1D'),
getMetricLabel: jest.fn(metric => metric),
Expand Down Expand Up @@ -280,4 +281,30 @@ describe('BigNumberWithTrendline transformProps', () => {
expect(result.bigNumber).toBe(360);
expect(result.subheader).toBe('50.0% WoW');
});

test('should not crash and should return undefined mainColor when colorPicker is null', () => {
const chartProps = {
width: 400,
height: 300,
queriesData: [
{
data: [
{ __timestamp: 1, value: 100 },
] as unknown as BigNumberDatum[],
colnames: ['__timestamp', 'value'],
coltypes: ['TEMPORAL', 'NUMERIC'],
},
],
formData: { ...baseFormData, colorPicker: null },
rawFormData: baseRawFormData,
hooks: baseHooks,
datasource: baseDatasource,
theme: { colors: { grayscale: { light5: '#eee' } } },
};

const result = transformProps(
chartProps as unknown as BigNumberWithTrendlineChartProps,
);
expect(result.mainColor).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { t } from '@apache-superset/core/translation';
import {
BRAND_COLOR,
extractTimegrain,
getNumberFormatter,
NumberFormats,
Expand Down Expand Up @@ -140,8 +141,9 @@ export default function transformProps(
const compareLag = Number(compareLag_) || 0;
let formattedSubheader = subheader;

const { r, g, b } = colorPicker;
const mainColor = `rgb(${r}, ${g}, ${b})`;
const mainColor = colorPicker
? `rgb(${colorPicker.r}, ${colorPicker.g}, ${colorPicker.b})`
: undefined;
Comment thread
rusackas marked this conversation as resolved.

const xAxisLabel = getXAxisLabel(rawFormData) as string;
let trendLineData: TimeSeriesDatum[] | undefined;
Expand Down Expand Up @@ -290,12 +292,12 @@ export default function transformProps(
symbol: 'circle',
symbolSize: 10,
showSymbol: false,
color: mainColor,
color: mainColor ?? BRAND_COLOR,
areaStyle: {
color: new graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: mainColor,
color: mainColor ?? BRAND_COLOR,
},
{
offset: 1,
Expand Down
Loading