From 157e96108025d1420eebaa867d2890d27b3552a0 Mon Sep 17 00:00:00 2001 From: sushuang Date: Mon, 23 Apr 2018 05:46:04 +0800 Subject: [PATCH] Fix task when multiple progress. --- src/stream/Scheduler.js | 21 ++++++++++++--------- src/stream/task.js | 30 ++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/stream/Scheduler.js b/src/stream/Scheduler.js index 19b3e4a287..ed7f438d23 100644 --- a/src/stream/Scheduler.js +++ b/src/stream/Scheduler.js @@ -2,7 +2,7 @@ * @module echarts/stream/Scheduler */ -import {each, isFunction, createHashMap, noop} from 'zrender/src/core/util'; +import {each, map, isArray, isFunction, createHashMap, noop} from 'zrender/src/core/util'; import {createTask} from './task'; import {getUID} from '../util/component'; import GlobalModel from '../model/Global'; @@ -444,17 +444,20 @@ function seriesTaskReset(context) { var resetDefines = context.resetDefines = normalizeToArray(context.reset( context.model, context.ecModel, context.api, context.payload )); - if (resetDefines.length) { - return seriesTaskProgress; - } + return resetDefines.length > 1 + ? map(resetDefines, function (v, idx) { + return makeSeriesTaskProgress(idx); + }) + : singleSeriesTaskProgress; } -function seriesTaskProgress(params, context) { - var data = context.data; - var resetDefines = context.resetDefines; +var singleSeriesTaskProgress = makeSeriesTaskProgress(0); + +function makeSeriesTaskProgress(resetDefineIdx) { + return function (params, context) { + var data = context.data; + var resetDefine = context.resetDefines[resetDefineIdx]; - for (var k = 0; k < resetDefines.length; k++) { - var resetDefine = resetDefines[k]; if (resetDefine && resetDefine.dataEach) { for (var i = params.start; i < params.end; i++) { resetDefine.dataEach(data, i); diff --git a/src/stream/task.js b/src/stream/task.js index e1d19bc8a6..3928e1fb19 100644 --- a/src/stream/task.js +++ b/src/stream/task.js @@ -1,4 +1,4 @@ -import {assert} from 'zrender/src/core/util'; +import {assert, isArray} from 'zrender/src/core/util'; import { __DEV__ } from '../config'; /** @@ -113,10 +113,15 @@ taskProto.perform = function (performArgs) { ); if (!skip && (forceFirstProgress || start < end)) { - iterator.reset(start, end, modBy, modDataCount); - this._progress({ - start: start, end: end, step: 1, count: end - start, next: iterator.next - }, this.context); + var progress = this._progress; + if (isArray(progress)) { + for (var i = 0; i < progress.length; i++) { + doProgress(this, progress[i], start, end, modBy, modDataCount); + } + } + else { + doProgress(this, progress, start, end, modBy, modDataCount); + } } this._dueIndex = end; @@ -189,9 +194,14 @@ taskProto.dirty = function () { this._onDirty && this._onDirty(this.context); }; -/** - * @param {Object} [params] - */ +function doProgress(taskIns, progress, start, end, modBy, modDataCount) { + iterator.reset(start, end, modBy, modDataCount); + taskIns._callingProgress = progress; + taskIns._callingProgress({ + start: start, end: end, count: end - start, next: iterator.next + }, taskIns.context); +} + function reset(taskIns, skip) { taskIns._dueIndex = taskIns._outputDueEnd = taskIns._dueEnd = 0; taskIns._settedOutputEnd = null; @@ -205,6 +215,10 @@ function reset(taskIns, skip) { forceFirstProgress = progress.forceFirstProgress; progress = progress.progress; } + // To simplify no progress checking, array must has item. + if (isArray(progress) && !progress.length) { + progress = null; + } } taskIns._progress = progress;