Skip to content

Commit

Permalink
fix: fix issue brought by previous refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Aug 22, 2021
1 parent 75dc3ab commit 4d1b252
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
25 changes: 17 additions & 8 deletions src/data/DataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { DataProvider } from './helper/dataProvider';
import { parseDataValue } from './helper/dataValueHelper';
import OrdinalMeta from './OrdinalMeta';
import { Source } from './Source';
import { shouldRetrieveDataByName, Source } from './Source';

const UNDEFINED = 'undefined';
/* global Float64Array, Int32Array, Uint32Array, Uint16Array */
Expand Down Expand Up @@ -179,9 +179,9 @@ class DataStore {
private _calcDimNameToIdx = createHashMap<DimensionIndex, DimensionName>();

defaultDimValueGetter: DimValueGetter;

/**
* Initialize from data
* @param data source or data or data provider.
*/
initData(
provider: DataProvider,
Expand All @@ -202,18 +202,27 @@ class DataStore {
this._indices = null;
this.getRawIndex = this._getRawIdxIdentity;

const source = provider.getSource();
const defaultGetter = this.defaultDimValueGetter =
defaultDimValueGetters[provider.getSource().sourceFormat];
defaultDimValueGetters[source.sourceFormat];
// Default dim value getter
this._dimValueGetter = dimValueGetter || defaultGetter;

// Reset raw extent.
this._rawExtent = [];
this._dimensions = map(inputDimensions, dim => ({
// Only pick these two props. Not leak other properties like orderMeta.
type: dim.type,
property: dim.property
}));
const willRetrieveDataByName = shouldRetrieveDataByName(source);
this._dimensions = map(inputDimensions, dim => {
if (__DEV__) {
if (willRetrieveDataByName) {
assert(dim.property != null);
}
}
return {
// Only pick these two props. Not leak other properties like orderMeta.
type: dim.type,
property: dim.property
};
});

this._initDataFromProvider(0, provider.count());
}
Expand Down
9 changes: 6 additions & 3 deletions src/data/SeriesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import type Tree from './Tree';
import type { VisualMeta } from '../component/visualMap/VisualMapModel';
import {isSourceInstance, Source} from './Source';
import { LineStyleProps } from '../model/mixin/lineStyle';
import DataStore, { DimValueGetter } from './DataStore';
import DataStore, { DataStoreDimensionDefine, DimValueGetter } from './DataStore';
import { isSeriesDataSchema, SeriesDataSchema } from './helper/SeriesDataSchema';

const isObject = zrUtil.isObject;
Expand Down Expand Up @@ -528,17 +528,20 @@ class SeriesData<
dimValueGetter?: DimValueGetter
): void {
let store: DataStore;
const dimensions = this.dimensions;
const dimensionInfos = map(dimensions, this._getDimInfo, this);
if (data instanceof DataStore) {
store = data;
}

if (!store) {
const dimensions = this.dimensions;
const provider = (isSourceInstance(data) || zrUtil.isArrayLike(data))
? new DefaultDataProvider(data as Source | OptionSourceData, dimensions.length)
: data as DataProvider;
store = new DataStore();
const dimensionInfos: DataStoreDimensionDefine[] = map(dimensions, dimName => ({
type: this._dimInfos[dimName].type,
property: dimName
}));
store.initData(provider, dimensionInfos, dimValueGetter);
}

Expand Down
27 changes: 15 additions & 12 deletions src/data/helper/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class DefaultDataProvider implements DataProvider {
return 0;
}

getItem(idx: number, out?: ArrayLike<number>): OptionDataItem {
getItem(idx: number, out?: ArrayLike<OptionDataValue>): OptionDataItem {
return;
}

Expand Down Expand Up @@ -291,8 +291,11 @@ type RawSourceItemGetter = (
rawData: OptionSourceData,
startIndex: number,
dimsDef: { name?: DimensionName }[],
idx: number
) => OptionDataItem;
idx: number,
// Only used in SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW and SOURCE_FORMAT_KEYED_COLUMNS
// to avoid create a new [] if `out` is provided.
out?: ArrayLike<OptionDataValue>
) => OptionDataItem | ArrayLike<OptionDataValue>;

const getItemSimply: RawSourceItemGetter = function (
rawData, startIndex, dimsDef, idx
Expand All @@ -303,26 +306,26 @@ const getItemSimply: RawSourceItemGetter = function (
const rawSourceItemGetterMap: Dictionary<RawSourceItemGetter> = {
[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_COLUMN]: function (
rawData, startIndex, dimsDef, idx
): OptionDataValue[] {
) {
return (rawData as OptionDataValue[][])[idx + startIndex];
},
[SOURCE_FORMAT_ARRAY_ROWS + '_' + SERIES_LAYOUT_BY_ROW]: function (
rawData, startIndex, dimsDef, idx
): OptionDataValue[] {
rawData, startIndex, dimsDef, idx, out
) {
idx += startIndex;
const item = [];
const item = out || [];
const data = rawData as OptionDataValue[][];
for (let i = 0; i < data.length; i++) {
const row = data[i];
item.push(row ? row[idx] : null);
item[i] = row ? row[idx] : null;
}
return item;
},
[SOURCE_FORMAT_OBJECT_ROWS]: getItemSimply,
[SOURCE_FORMAT_KEYED_COLUMNS]: function (
rawData, startIndex, dimsDef, idx
): OptionDataValue[] {
const item = [];
rawData, startIndex, dimsDef, idx, out
) {
const item = out || [];
for (let i = 0; i < dimsDef.length; i++) {
const dimName = dimsDef[i].name;
if (__DEV__) {
Expand All @@ -331,7 +334,7 @@ const rawSourceItemGetterMap: Dictionary<RawSourceItemGetter> = {
}
}
const col = (rawData as Dictionary<OptionDataValue[]>)[dimName];
item.push(col ? col[idx] : null);
item[i] = col ? col[idx] : null;
}
return item;
},
Expand Down

0 comments on commit 4d1b252

Please sign in to comment.