Skip to content

Commit

Permalink
refactor: 处理下钻在 indexData 中的存储位置
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed Oct 24, 2023
1 parent ea38a38 commit 3eaa3eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
4 changes: 2 additions & 2 deletions packages/s2-core/src/data-set/base-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export abstract class BaseDataSet {
public totalData: DataType[];

// multidimensional array to indexes data
public indexesData: DataType[][] | DataType[];
public indexesData: Record<number, DataType[][] | DataType[]>;

// 高级排序, 组内排序
public sortParams: SortParams;
Expand Down Expand Up @@ -100,7 +100,7 @@ export abstract class BaseDataSet {
this.sortParams = sortParams;
this.filterParams = filterParams;
this.displayData = this.originData;
this.indexesData = [];
this.indexesData = {};
}

public processMeta(meta: Meta[] = [], defaultExtraFieldText: string) {
Expand Down
49 changes: 19 additions & 30 deletions packages/s2-core/src/utils/dataset/pivot-data-set.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
find,
forEach,
get,
intersection,
isEmpty,
last,
reduce,
set,
} from 'lodash';
import { find, forEach, get, intersection, isEmpty, last, set } from 'lodash';
import {
EXTRA_FIELD,
ID_SEPARATOR,
Expand Down Expand Up @@ -43,26 +34,22 @@ import type { Node } from '../../facet/layout/node';

export function transformDimensionsValues(
record: DataType,
dimensions: string[],
dimensions: string[] = [],
placeholder: string = TOTAL_VALUE,
): string[] {
return reduce(
dimensions,
(res: string[], dimension: string) => {
if (dimension === EXTRA_FIELD) {
return res;
}
// push undefined when not exist
const value = record[dimension];
if (!(dimension in record)) {
res.push(placeholder);
} else {
res.push(String(value));
}
return dimensions.reduce((res: string[], dimension: string) => {
if (dimension === EXTRA_FIELD) {
return res;
},
[],
);
}
// push undefined when not exist
const value = record[dimension];
if (!(dimension in record)) {
res.push(placeholder);
} else {
res.push(String(value));
}
return res;
}, []);
}

/**
Expand Down Expand Up @@ -197,16 +184,18 @@ export function getDataPath(params: DataPathParams) {
return path;
};

const totalLength = rowDimensionValues.length + colDimensionValues.length;
const rowPath = getPath(rowFields, rowDimensionValues, rowPivotMeta);
const colPath = getPath(colFields, colDimensionValues, colPivotMeta);
return rowPath.concat(...colPath);

return [totalLength, ...rowPath, ...colPath];
}
interface Param {
rows: string[];
columns: string[];
values: string[];
originData: DataType[];
indexesData: DataType[][] | DataType[];
indexesData: Record<number, DataType[][] | DataType[]>;
totalData?: DataType[];
sortedDimensionValues: SortedDimensionValues;
rowPivotMeta?: PivotMeta;
Expand All @@ -222,8 +211,8 @@ export function transformIndexesData(params: Param) {
columns,
values,
originData = [],
indexesData = [],
totalData = [],
indexesData = {},
sortedDimensionValues,
rowPivotMeta,
colPivotMeta,
Expand Down

0 comments on commit 3eaa3eb

Please sign in to comment.