diff --git a/src/data/List.js b/src/data/List.js index 87f0facd632f107a23c1e6d4bd5316438a4422f3..00d49275ae0a96cc1299050da090176b27a03fae 100644 --- a/src/data/List.js +++ b/src/data/List.js @@ -35,6 +35,7 @@ import {summarizeDimensions} from './helper/dimensionHelper'; var isObject = zrUtil.isObject; var UNDEFINED = 'undefined'; +var INDEX_NOT_FOUND = -1; // Use prefix to avoid index to be the same as otherIdList[idx], // which will cause weird udpate animation. @@ -54,6 +55,7 @@ var dataCtors = { // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is // different from the Ctor of typed array. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array; +var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array; var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array; function getIndicesCtor(list) { @@ -599,13 +601,13 @@ function prepareInvertedIndex(list) { // Currently, only dimensions that has ordinalMeta can create inverted indices. var ordinalMeta = dimInfo.ordinalMeta; if (ordinalMeta) { - invertedIndices = invertedIndicesMap[dim] = new Array( + invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array( ordinalMeta.categories.length ); // The default value of TypedArray is 0. To avoid miss - // mapping to 0, we should set it as NaN. + // mapping to 0, we should set it as INDEX_NOT_FOUND. for (var i = 0; i < invertedIndices.length; i++) { - invertedIndices[i] = NaN; + invertedIndices[i] = INDEX_NOT_FOUND; } for (var i = 0; i < list._count; i++) { // Only support the case that all values are distinct. @@ -970,7 +972,7 @@ listProto.rawIndexOf = function (dim, value) { } var rawIndex = invertedIndices[value]; if (rawIndex == null || isNaN(rawIndex)) { - return -1; + return INDEX_NOT_FOUND; } return rawIndex; }; diff --git a/test/bar-stack.html b/test/bar-stack.html index 24c9edadca613b58b7c407456df1526453e97fcc..1176c30f91052a4bdb74e334c449d1c1eea96bf2 100644 --- a/test/bar-stack.html +++ b/test/bar-stack.html @@ -35,7 +35,8 @@ under the License. -
+ + + + + + + + + + + + + + + +