Skip to content

Commit

Permalink
fix(plugin-chart-echarts): reorder totals and support multimetric sort (
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored and eschutho committed May 25, 2023
1 parent 3e68adf commit a1a7f69
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,29 @@ export const contributionModeControl = {
},
};

function isTemporal(controls: ControlStateMapping): boolean {
return !(
isDefined(controls?.x_axis?.value) &&
!isTemporalColumn(
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
controls?.datasource?.datasource,
)
);
}

const xAxisSortVisibility = ({ controls }: { controls: ControlStateMapping }) =>
isDefined(controls?.x_axis?.value) &&
!isTemporalColumn(
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
controls?.datasource?.datasource,
) &&
Array.isArray(controls?.groupby?.value) &&
controls.groupby.value.length === 0;
!isTemporal(controls) &&
ensureIsArray(controls?.groupby?.value).length === 0 &&
ensureIsArray(controls?.metrics?.value).length === 1;

const xAxisMultiSortVisibility = ({
controls,
}: {
controls: ControlStateMapping;
}) =>
!isTemporal(controls) &&
(!!ensureIsArray(controls?.groupby?.value).length ||
ensureIsArray(controls?.metrics?.value).length > 1);

export const xAxisSortControl = {
name: 'x_axis_sort',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ export default function transformProps(
}

const rebasedDataA = rebaseForecastDatum(data1, verboseMap);
const rawSeriesA = extractSeries(rebasedDataA, {
const [rawSeriesA] = extractSeries(rebasedDataA, {
fillNeighborValue: stack ? 0 : undefined,
xAxis: xAxisLabel,
});
const rebasedDataB = rebaseForecastDatum(data2, verboseMap);
const rawSeriesB = extractSeries(rebasedDataB, {
const [rawSeriesB] = extractSeries(rebasedDataB, {
fillNeighborValue: stackB ? 0 : undefined,
xAxis: xAxisLabel,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default function transformProps(
formatter,
showValue,
onlyTotal,
totalStackedValues,
totalStackedValues: sortedTotalValues,
showValueIndexes,
thresholdValues,
richTooltip,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ContributionType,
QueryFormColumn,
QueryFormData,
QueryFormMetric,
TimeFormatter,
TimeGranularity,
} from '@superset-ui/core';
Expand Down Expand Up @@ -65,6 +66,7 @@ export type EchartsTimeseriesFormData = QueryFormData & {
logAxis: boolean;
markerEnabled: boolean;
markerSize: number;
metrics: QueryFormMetric[];
minorSplitLine: boolean;
opacity: number;
orderDesc: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,29 @@ describe('extractSeries', () => {
abc: 5,
},
];
expect(extractSeries(data)).toEqual([
{
id: 'Hulk',
name: 'Hulk',
data: [
['2000-01-01', null],
['2000-02-01', 2],
['2000-03-01', 1],
],
},
{
id: 'abc',
name: 'abc',
data: [
['2000-01-01', 2],
['2000-02-01', 10],
['2000-03-01', 5],
],
},
const totalStackedValues = [2, 12, 6];
expect(extractSeries(data, { totalStackedValues })).toEqual([
[
{
id: 'Hulk',
name: 'Hulk',
data: [
['2000-01-01', null],
['2000-02-01', 2],
['2000-03-01', 1],
],
},
{
id: 'abc',
name: 'abc',
data: [
['2000-01-01', 2],
['2000-02-01', 10],
['2000-03-01', 5],
],
},
],
totalStackedValues,
]);
});

Expand All @@ -91,20 +95,30 @@ describe('extractSeries', () => {
abc: 5,
},
];
expect(extractSeries(data, { xAxis: 'x', removeNulls: true })).toEqual([
{
id: 'Hulk',
name: 'Hulk',
data: [[2, 1]],
},
{
id: 'abc',
name: 'abc',
data: [
[1, 2],
[2, 5],
],
},
const totalStackedValues = [3, 12, 8];
expect(
extractSeries(data, {
totalStackedValues,
xAxis: 'x',
removeNulls: true,
}),
).toEqual([
[
{
id: 'Hulk',
name: 'Hulk',
data: [[2, 1]],
},
{
id: 'abc',
name: 'abc',
data: [
[1, 2],
[2, 5],
],
},
],
totalStackedValues,
]);
});

Expand Down Expand Up @@ -151,23 +165,29 @@ describe('extractSeries', () => {
abc: null,
},
];
expect(extractSeries(data, { fillNeighborValue: 0 })).toEqual([
{
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', 0],
['2000-10-01', null],
],
},
const totalStackedValues = [0, 0, 1, 0, 0, 0, 2, 3, 0, 0];
expect(
extractSeries(data, { totalStackedValues, fillNeighborValue: 0 }),
).toEqual([
[
{
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', 0],
['2000-10-01', null],
],
},
],
totalStackedValues,
]);
});
});
Expand Down

0 comments on commit a1a7f69

Please sign in to comment.