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
23 changes: 18 additions & 5 deletions src/data/SeriesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

/* global Int32Array */
/* global Int32Array, Map */


import * as zrUtil from 'zrender/src/core/util';
Expand Down Expand Up @@ -225,7 +225,7 @@ class SeriesData<

private _dimSummary: DimensionSummary;

private _invertedIndicesMap: Record<SeriesDimensionName, ArrayLike<number>>;
private _invertedIndicesMap: Record<SeriesDimensionName, ArrayLike<number> | Map<number, number>>;

private _calculationInfo: DataCalculationInfo<HostModel> = {} as DataCalculationInfo<HostModel>;

Expand Down Expand Up @@ -861,7 +861,7 @@ class SeriesData<
* Only support the dimension which inverted index created.
* Do not support other cases until required.
* @param dim concrete dim
* @param value ordinal index
* @param value ordinal index or time value
* @return rawIndex
*/
rawIndexOf(dim: SeriesDimensionName, value: OrdinalNumber): number {
Expand All @@ -871,7 +871,13 @@ class SeriesData<
throw new Error('Do not supported yet');
}
}
const rawIndex = invertedIndices && invertedIndices[value];
let rawIndex: number | undefined;
if (invertedIndices instanceof Map) {
rawIndex = invertedIndices.get(value);
}
else {
rawIndex = invertedIndices && invertedIndices[value];
}
if (rawIndex == null || isNaN(rawIndex)) {
return INDEX_NOT_FOUND;
}
Expand Down Expand Up @@ -1393,7 +1399,6 @@ class SeriesData<
const invertedIndicesMap = data._invertedIndicesMap;
zrUtil.each(invertedIndicesMap, function (invertedIndices, dim) {
const dimInfo = data._dimInfos[dim];
// Currently, only dimensions that has ordinalMeta can create inverted indices.
const ordinalMeta = dimInfo.ordinalMeta;
const store = data._store;
if (ordinalMeta) {
Expand All @@ -1410,6 +1415,14 @@ class SeriesData<
invertedIndices[store.get(dimInfo.storeDimIndex, i) as number] = i;
}
}
else if (dimInfo.type === 'time') {
const timeInvertedIndices = invertedIndicesMap[dim] = new Map<number, number>();
for (let i = 0; i < store.count(); i++) {
const timeValue = store.get(dimInfo.storeDimIndex, i) as number;
// Only support the case that all values are distinct.
timeInvertedIndices.set(timeValue, i);
}
}
});
};

Expand Down
4 changes: 2 additions & 2 deletions src/data/helper/dataStackHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export function enableDataStack(
}

if (mayStack && !dimensionInfo.isExtraCoord) {
// Find the first ordinal dimension as the stackedByDimInfo.
if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
// Find the first ordinal or time dimension as the stackedByDimInfo.
if (!byIndex && !stackedByDimInfo && (dimensionInfo.ordinalMeta || dimensionInfo.type === 'time')) {
stackedByDimInfo = dimensionInfo;
}
// Find the first stackable dimension as the stackedDimInfo.
Expand Down
177 changes: 177 additions & 0 deletions test/bar-stack-time.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading