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 2020/09/24 07:31:05 UTC

[incubator-echarts] branch list-remove-chunk updated: fix(List): fix appendData

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

shenyi pushed a commit to branch list-remove-chunk
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git


The following commit(s) were added to refs/heads/list-remove-chunk by this push:
     new d4bf86c  fix(List): fix appendData
d4bf86c is described below

commit d4bf86c963feaa12d83e0d3bd9f9b2b6249233d7
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Sep 24 15:29:34 2020 +0800

    fix(List): fix appendData
---
 src/data/List.ts                | 21 ++++++------------
 src/data/helper/dataProvider.ts | 47 ++++++++++++++++++-----------------------
 src/processor/dataSample.ts     |  7 +++---
 test/sample-compare.html        |  8 +++++--
 4 files changed, 36 insertions(+), 47 deletions(-)

diff --git a/src/data/List.ts b/src/data/List.ts
index d38e03a..3830e55 100644
--- a/src/data/List.ts
+++ b/src/data/List.ts
@@ -491,7 +491,7 @@ class List<
         if (!rawData.persistent) {
             end += start;
         }
-        this._initDataFromProvider(start, end);
+        this._initDataFromProvider(start, end, true);
     }
 
     /**
@@ -563,7 +563,7 @@ class List<
         prepareInvertedIndex(this);
     }
 
-    private _initDataFromProvider(start: number, end: number): void {
+    private _initDataFromProvider(start: number, end: number, append?: boolean): void {
         if (start >= end) {
             return;
         }
@@ -593,9 +593,7 @@ class List<
                 this._idDimIdx = i;
             }
 
-            if (!rawData.getStorage) {
-                prepareStorage(storage, dimInfo, end);
-            }
+            prepareStorage(storage, dimInfo, end, append);
         }
 
         const storageArr = this._storageArr = map(dimensions, (dim) => {
@@ -607,14 +605,7 @@ class List<
         });
 
         if (rawData.getStorage) {
-            const ret = rawData.getStorage(start, end);
-            const rawStorage = ret.storage;
-            const extent = ret.extent;
-            for (let dimIdx = 0; dimIdx < rawStorage.length; dimIdx++) {
-                storage[dimensions[dimIdx]] = storageArr[dimIdx] = rawStorage[dimIdx];
-                rawExtentArr[dimIdx][0] = Math.min(rawExtentArr[dimIdx][0], extent[dimIdx][0]);
-                rawExtentArr[dimIdx][1] = Math.max(rawExtentArr[dimIdx][1], extent[dimIdx][1]);
-            }
+            rawData.getStorage(start, end, storageArr, rawExtentArr);
         }
         else {
             let dataItem = [] as OptionDataItem;
@@ -2104,8 +2095,8 @@ class List<
 
             if (append) {
                 const oldStore = storage[dim];
-                const oldLen = oldStore.length;
-                if (oldStore && oldLen < end) {
+                const oldLen = oldStore && oldStore.length;
+                if (!(oldLen === end)) {
                     const newStore = new DataCtor(end);
                     // The cost of the copy is probably inconsiderable
                     // within the initial chunkSize.
diff --git a/src/data/helper/dataProvider.ts b/src/data/helper/dataProvider.ts
index 5f48956..69adc76 100644
--- a/src/data/helper/dataProvider.ts
+++ b/src/data/helper/dataProvider.ts
@@ -34,7 +34,7 @@ import {
     SERIES_LAYOUT_BY_COLUMN,
     SERIES_LAYOUT_BY_ROW,
     DimensionName, DimensionIndex, OptionSourceData,
-    DimensionIndexLoose, OptionDataItem, OptionDataValue, SourceFormat, SeriesLayoutBy
+    DimensionIndexLoose, OptionDataItem, OptionDataValue, SourceFormat, SeriesLayoutBy, ParsedValue
 } from '../../util/types';
 import List from '../List';
 
@@ -47,10 +47,12 @@ export interface DataProvider {
     getSource(): Source;
     count(): number;
     getItem(idx: number, out?: OptionDataItem): OptionDataItem;
-    getStorage?(start: number, end: number): {
-        storage: ArrayLike<number>[]
+    getStorage?(
+        start: number,
+        end: number,
+        out: ArrayLike<ParsedValue>[],
         extent: number[][]
-    }
+    ): void
     appendData(newData: ArrayLike<OptionDataItem>): void;
     clean(): void;
 }
@@ -60,10 +62,12 @@ let providerMethods: Dictionary<any>;
 let mountMethods: (provider: DefaultDataProvider, data: OptionSourceData, source: Source) => void;
 
 export interface DefaultDataProvider {
-    getStorage?(start: number, end: number): {
-        storage: ArrayLike<number>[],
+    getStorage?(
+        start: number,
+        end: number,
+        out: ArrayLike<ParsedValue>[],
         extent: number[][]
-    }
+    ): void
 }
 /**
  * If normal array used, mutable chunk size is supported.
@@ -178,37 +182,26 @@ export class DefaultDataProvider implements DataProvider {
         };
 
         const getStorageForTypedArray: DefaultDataProvider['getStorage'] = function (
-            this: DefaultDataProvider, start: number, end: number
+            this: DefaultDataProvider, start: number, end: number, storage: ArrayLike<ParsedValue>[], extent: number[][]
         ) {
             const data = this._data as ArrayLike<number>;
-            const Ctor = data.constructor;
             const dimSize = this._dimSize;
-            const offset = this._offset;
-            const storage: ArrayLike<number>[] = [];
-            const extent = [];
-
-            start -= offset;
-            end -= offset;
 
             for (let dim = 0; dim < dimSize; dim++) {
-                let min = Infinity;
-                let max = -Infinity;
+                const dimExtent = extent[dim];
+                let min = dimExtent[0] == null ? Infinity : dimExtent[0];
+                let max = dimExtent[1] == null ? -Infinity : dimExtent[1];
                 const count = end - start;
-                const arr = new (Ctor as any)(count);
+                const arr = storage[dim];
                 for (let i = 0; i < count; i++) {
-                    const val = data[(offset + start + i) * dimSize + dim];
-                    arr[i] = val;
+                    const val = data[(start + i) * dimSize + dim];
+                    arr[start + i] = val;
                     val < min && (min = val);
                     val > max && (max = val);
                 }
-                storage.push(arr);
-                extent.push([min, max]);
+                dimExtent[0] = min;
+                dimExtent[1] = max;
             }
-
-            return {
-                storage,
-                extent
-            };
         };
 
         const countForTypedArray: DefaultDataProvider['count'] = function (
diff --git a/src/processor/dataSample.ts b/src/processor/dataSample.ts
index 2e2fc4c..b292504 100644
--- a/src/processor/dataSample.ts
+++ b/src/processor/dataSample.ts
@@ -83,15 +83,16 @@ export default function (seriesType: string): StageHandler {
             const data = seriesModel.getData();
             const sampling = seriesModel.get('sampling');
             const coordSys = seriesModel.coordinateSystem;
-            // Only cartesian2d support down sampling
-            if (coordSys.type === 'cartesian2d' && sampling) {
+            const count = data.count();
+            // Only cartesian2d support down sampling. Disable it when there is few data.
+            if (count > 10 && coordSys.type === 'cartesian2d' && sampling) {
                 const baseAxis = coordSys.getBaseAxis();
                 const valueAxis = coordSys.getOtherAxis(baseAxis);
                 const extent = baseAxis.getExtent();
                 const dpr = api.getDevicePixelRatio();
                 // Coordinste system has been resized
                 const size = Math.abs(extent[1] - extent[0]) * (dpr || 1);
-                const rate = Math.round(data.count() / size);
+                const rate = Math.round(count / size);
 
                 if (rate > 1) {
                     if (sampling === 'lttb') {
diff --git a/test/sample-compare.html b/test/sample-compare.html
index cd840dc..d7c42b4 100644
--- a/test/sample-compare.html
+++ b/test/sample-compare.html
@@ -167,9 +167,11 @@ under the License.
 							}]
 						};
 						const startTime = performance.now();
-						myChart.setOption(opts, true);
+						myChart.setOption(opts, {
+							notMerge: true
+						});
 						const endTime = performance.now();
-						titleDom.innerHTML = `${title}(${data.length / 4}) ${(endTime - startTime).toFixed(0)} ms`;
+						titleDom.innerHTML = `${title}(${data.length / 4 * 3}) ${(endTime - startTime).toFixed(0)} ms`;
 					}
 					let status = document.getElementById('status');
 					status.textContent = 'Fetching data.json (2.07MB)....';
@@ -185,10 +187,12 @@ under the License.
 									makeChart(data, 'warmup');
 									makeChart(data, 'warmup', 'lttb');
 									makeChart(data, 'warmup', 'average');
+									makeChart(data, 'warmup', 'max');
 								}
 								status.textContent = 'Running';
 								setTimeout(() => makeChart(data, 'No Sampling', null), 500);
 								setTimeout(() => makeChart(data, 'LTTB Sampling', 'lttb'), 1000);
+								setTimeout(() => makeChart(data, 'Max Sampling', 'max'), 1500);
 								setTimeout(() => makeChart(data, 'Average Sampling', 'average'), 1500);
 							});
 						});


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