You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/07/14 09:45:32 UTC

[echarts] branch dataset-perf updated: refact: don't recreate data storage when converting float to time

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch dataset-perf
in repository https://gitbox.apache.org/repos/asf/echarts.git


The following commit(s) were added to refs/heads/dataset-perf by this push:
     new 345402d  refact: don't recreate data storage when converting float to time
345402d is described below

commit 345402df3a7ce434a184be82440288eb3ac7fdc6
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Jul 14 17:44:22 2021 +0800

    refact: don't recreate data storage when converting float to time
---
 src/chart/helper/createSeriesDataFromArray.ts |  2 +-
 src/data/DataStorage.ts                       | 35 +++++++++++++++++----------
 src/data/SeriesData.ts                        |  2 +-
 src/data/helper/dataValueHelper.ts            |  1 -
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/chart/helper/createSeriesDataFromArray.ts b/src/chart/helper/createSeriesDataFromArray.ts
index fa6a2fb..2e31963 100644
--- a/src/chart/helper/createSeriesDataFromArray.ts
+++ b/src/chart/helper/createSeriesDataFromArray.ts
@@ -151,7 +151,7 @@ function createListFromArray(
 
     if (omitUnusedDimensions) {
         // sourceOrStore
-        if (!(sourceOrStore as DataStorage).canUse(dimInfoList)) {
+        if (!(sourceOrStore as DataStorage).syncDimensionTypes(dimInfoList)) {
             dimInfoList = createDimensions(sourceOrStore, zrUtil.extend(createDimensionOptions, {
                 omitUnusedDimensions: true
             }));
diff --git a/src/data/DataStorage.ts b/src/data/DataStorage.ts
index 7c9322a..5b724b7 100644
--- a/src/data/DataStorage.ts
+++ b/src/data/DataStorage.ts
@@ -39,21 +39,26 @@ const UNDEFINED = 'undefined';
 export const CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
 export const CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
 export const CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
-export const CtorFloat64Array = typeof Float64Array === UNDEFINED ? Array : Int32Array;
+export const CtorFloat64Array = typeof Float64Array === UNDEFINED ? Array : Float64Array;
 /**
  * Multi dimensional data storage
  */
- const dataCtors = {
-    'float': typeof Float64Array === UNDEFINED
-        ? Array : Float64Array,
-    'int': typeof Int32Array === UNDEFINED
-        ? Array : Int32Array,
+const dataCtors = {
+    'float': CtorFloat64Array,
+    'int': CtorInt32Array,
     // Ordinal data type can be string or int
     'ordinal': Array,
     'number': Array,
-    'time': Array
+    'time': CtorFloat64Array
 } as const;
 
+// Dim with same category can be convert between.
+const dataCtorCategory = {
+    'float': 0, 'time': 0,
+    'number': 1, 'int': 2,
+    'ordinal': 3
+};
+
 export type DataStorageDimensionType = keyof typeof dataCtors;
 
 type DataTypedArray = Uint32Array | Int32Array | Uint16Array | Float64Array;
@@ -267,25 +272,29 @@ class DataStorage {
     }
 
     /**
-     * The dimension defines of series may be different with dataset. For example
-     * in dataset one dimension is not ordinal and being parsed to number.
-     * In this case we can't used it in series if we wan't to use it as ordinal. This storage needs to be discarded.
+     * If we using dataset.
+     * Dimensions types may only know when we initializing series.
+     * So we need to sync the type back to storage when initlializing SeriesData back
+     *
+     * Will return false if dimension type has been known and different from given.
+     * We need to recreate a new data storage in this case.
      */
     // TODO Can't sure what's frequency will this validate fail and cause datastorage recreate.
-    canUse(targetDims: DataStorageDimensionInfo[]) {
+    syncDimensionTypes(targetDims: DataStorageDimensionInfo[]) {
         for (let i = 0; i < targetDims.length; i++) {
             const targetDim = targetDims[i];
             const selfDimIdx = this.getDimensionIndex(targetDim.name);
             const selfDim = this._dimensions[selfDimIdx];
             if (
                 !selfDim
-                // Type is different
-                || selfDim.type || 'float' !== targetDim.type || 'float'
+                // Dim type can be convert between because ctors are compatitable.
+                || dataCtorCategory[selfDim.type || 'float'] !== dataCtorCategory[targetDim.type || 'float']
                 // ordinalMeta is different. Usually being on the different axis.
                 || (selfDim.ordinalMeta && selfDim.ordinalMeta !== targetDim.ordinalMeta)
             ) {
                 return false;
             }
+            selfDim.type = targetDim.type;
         }
         return true;
     }
diff --git a/src/data/SeriesData.ts b/src/data/SeriesData.ts
index 388a7f1..e2e5345 100644
--- a/src/data/SeriesData.ts
+++ b/src/data/SeriesData.ts
@@ -390,7 +390,7 @@ class SeriesData<
         const dimensions = this.dimensions;
         const dimensionInfos = map(dimensions, dimName => this._dimensionInfos[dimName]);
         if (data instanceof DataStorage) {
-            if (data.canUse(dimensionInfos)) {
+            if (data.syncDimensionTypes(dimensionInfos)) {
                 store = data;
             }
             // Sync failed
diff --git a/src/data/helper/dataValueHelper.ts b/src/data/helper/dataValueHelper.ts
index 2a625f3..1c10798 100644
--- a/src/data/helper/dataValueHelper.ts
+++ b/src/data/helper/dataValueHelper.ts
@@ -18,7 +18,6 @@
 */
 
 import { ParsedValue, DimensionType } from '../../util/types';
-import OrdinalMeta from '../OrdinalMeta';
 import { parseDate, numericToNumber } from '../../util/number';
 import { createHashMap, trim, hasOwn } from 'zrender/src/core/util';
 import { throwError } from '../../util/log';

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org