Skip to content

Commit

Permalink
Fix task when multiple progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Apr 22, 2018
1 parent bd9403e commit 157e961
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
21 changes: 12 additions & 9 deletions src/stream/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 22 additions & 8 deletions src/stream/task.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert} from 'zrender/src/core/util';
import {assert, isArray} from 'zrender/src/core/util';
import { __DEV__ } from '../config';

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 157e961

Please sign in to comment.