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
50 changes: 28 additions & 22 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,10 @@ export const sortSeries = (props: {
const legendNames = new Set<string>();
let newData = [...data];

// When seriesField exists, we need to group by dimension even without explicit sorting
const needGrouping = seriesField != null;
const commonSortFunc = getSortFuncByField(mainAxisName, dimensionField);

if (axisSortType) {
const { axis, sortType } = axisSortType;
const axisItem = Object.entries(dimensionMetricsMap).find(item => item[1].key === axis)!;
Expand All @@ -747,7 +751,6 @@ export const sortSeries = (props: {
const isDESC = sortType === 'DESC';

// x-axis sorting
const commonSortFunc = getSortFuncByField(mainAxisName, dimensionField);
if (sortByXaxis) {
newData = sortBy(newData, [commonSortFunc], false);
} else {
Expand All @@ -773,31 +776,35 @@ export const sortSeries = (props: {
if (isDESC) {
newData.reverse();
}

// Percentage processing
if (isPercent) {
const sums: number[] = [];
// Summation
for (let i = 0; i < newData.length; i++) {
const sortList = newData[i];
for (let j = 0; j < sortList.length; j++) {
if (sums[i] == null) {
sums[i] = 0;
}
sums[i] += sortList[j][yKey];
} else if (needGrouping) {
// No explicit sorting, but we need to group by dimension for series processing
newData = sortBy(newData, [commonSortFunc], false);
}

// Percentage processing
if (isPercent) {
const sums: number[] = [];
// Summation
for (let i = 0; i < newData.length; i++) {
const sortList = newData[i];
for (let j = 0; j < sortList.length; j++) {
if (sums[i] == null) {
sums[i] = 0;
}
sums[i] += sortList[j][yKey];
}
// Percentage processing
for (let i = 0; i < newData.length; i++) {
const sortList = newData[i];
for (let j = 0; j < sortList.length; j++) {
const val = sortList[j][yKey];
sortList[j][yKey] = safeParseNumberOrText(val / sums[i] * 100, 2);
}
}
// Percentage processing
for (let i = 0; i < newData.length; i++) {
const sortList = newData[i];
for (let j = 0; j < sortList.length; j++) {
const val = sortList[j][yKey];
sortList[j][yKey] = safeParseNumberOrText(val / sums[i] * 100, 2);
}
}
}

if (seriesField) {
if (seriesField) {
// Direct reading of seriesField properties is problematic,
// performance is too low, each chained call to a seriesField property takes between 20 - 40 milliseconds.
let paramField = seriesField;
Expand Down Expand Up @@ -891,7 +898,6 @@ export const sortSeries = (props: {
sortedSeries: result.slice(0, maxRenderNum),
max,
};
}
}

newData = newData.flat();
Expand Down
2 changes: 1 addition & 1 deletion src/model/echarts_column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class EchartsColumn extends EchartsBase {
);

const series: BarSeriesOption[] = [];
if (axisSortType && seriesFieldInstance) {
if (seriesFieldInstance) {
const dataIndex = isColumn ? 0 : 1;
const axisKey = isColumn ? 'xAxisIndex' : 'yAxisIndex';
const isNormal = this.stackType === StackType.None;
Expand Down
2 changes: 1 addition & 1 deletion src/model/echarts_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class EchartsLine extends EchartsBase {
});

const series: LineSeriesOption[] = [];
if (axisSortType && seriesFieldInstance) {
if (seriesFieldInstance) {
for (let i = 0; i < sortedSeries.length; i++) {
const item = sortedSeries[i];
series.push({
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const safeParseNumberOrText = (num : number | string | undefined, precisi
return '';
}
return a.toFixed(precision);
};


export const safeParseNumberOrTextWithSeparator = (num : number | string | undefined, precision: number) => {
Expand Down