Skip to content

Commit

Permalink
refact(data): getValues from storage. add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Jul 15, 2021
1 parent 23548b8 commit 1d8da4a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
25 changes: 25 additions & 0 deletions src/data/DataStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,31 @@ class DataStorage {
return dimStore ? dimStore[this.getRawIndex(idx)] : NaN;
}

getValues(idx: number): ParsedValue[];
getValues(dimensions: readonly DimensionIndex[], idx?: number): ParsedValue[]
getValues(dimensions: readonly DimensionIndex[] | number, idx?: number): ParsedValue[] {
const values = [];
let dimArr: DimensionIndex[] = [];
if (idx == null) {
idx = dimensions as number;
// TODO get all from store?
dimensions = [];
// All dimensions
for (let i = 0; i < this._dimensions.length; i++) {
dimArr.push(i);
}
}
else {
dimArr = dimensions as DimensionIndex[];
}

for (let i = 0, len = dimArr.length; i < len; i++) {
values.push(this.get(dimArr[i], idx));
}

return values;
}

/**
* @param dim concrete dim
*/
Expand Down
16 changes: 4 additions & 12 deletions src/data/SeriesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,18 +656,10 @@ class SeriesData<
getValues(idx: number): ParsedValue[];
getValues(dimensions: readonly DimensionName[], idx: number): ParsedValue[];
getValues(dimensions: readonly DimensionName[] | number, idx?: number): ParsedValue[] {
const values = [];
if (!zrUtil.isArray(dimensions)) {
idx = dimensions as number;
// TODO get all from store?
dimensions = this.dimensions;
}

for (let i = 0, len = dimensions.length; i < len; i++) {
values.push(this.get(dimensions[i], idx));
}

return values;
const store = this._store;
return zrUtil.isArray(dimensions)
? store.getValues(map(dimensions, dim => this._getStoreDimIndex(dim)), idx)
: store.getValues(dimensions as number);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/data/helper/sourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export class SourceManager {
*/
getDataStorage(): DataStorage | undefined {
if (__DEV__) {
assert(isSeries(this._sourceHost), 'Can only call getDataStorage on series source manager.')
assert(isSeries(this._sourceHost), 'Can only call getDataStorage on series source manager.');
}
const source = this.getSource(0);
const dimensionsDefine = source.dimensionsDefine;
Expand Down

0 comments on commit 1d8da4a

Please sign in to comment.