-
Notifications
You must be signed in to change notification settings - Fork 19.7k
/
Copy pathSeries.ts
762 lines (659 loc) · 25.2 KB
/
Series.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import * as zrUtil from 'zrender/src/core/util';
import env from 'zrender/src/core/env';
import * as modelUtil from '../util/model';
import {
DataHost, DimensionName, StageHandlerProgressParams,
SeriesOption, ZRColor, BoxLayoutOptionMixin,
ScaleDataValue,
Dictionary,
OptionDataItemObject,
SeriesDataType,
SeriesEncodeOptionMixin,
OptionEncodeValue,
ColorBy,
StatesOptionMixin
} from '../util/types';
import ComponentModel, { ComponentModelConstructor } from './Component';
import {PaletteMixin} from './mixin/palette';
import { DataFormatMixin } from '../model/mixin/dataFormat';
import Model from '../model/Model';
import {
getLayoutParams,
mergeLayoutParam,
fetchLayoutMode
} from '../util/layout';
import {createTask} from '../core/task';
import GlobalModel from './Global';
import { CoordinateSystem } from '../coord/CoordinateSystem';
import { ExtendableConstructor, mountExtend, Constructor } from '../util/clazz';
import { PipelineContext, SeriesTaskContext, GeneralTask, OverallTask, SeriesTask } from '../core/Scheduler';
import LegendVisualProvider from '../visual/LegendVisualProvider';
import SeriesData from '../data/SeriesData';
import Axis from '../coord/Axis';
import type { BrushCommonSelectorsForSeries, BrushSelectableArea } from '../component/brush/selector';
import makeStyleMapper from './mixin/makeStyleMapper';
import { SourceManager } from '../data/helper/sourceManager';
import { Source } from '../data/Source';
import { defaultSeriesFormatTooltip } from '../component/tooltip/seriesFormatTooltip';
import {ECSymbol} from '../util/symbol';
import {Group} from '../util/graphic';
import {LegendIconParams} from '../component/legend/LegendModel';
import {dimPermutations} from '../component/marker/MarkAreaView';
const inner = modelUtil.makeInner<{
data: SeriesData
dataBeforeProcessed: SeriesData
sourceManager: SourceManager
}, SeriesModel>();
function getSelectionKey(data: SeriesData, dataIndex: number): string {
return data.getName(dataIndex) || data.getId(dataIndex);
}
export const SERIES_UNIVERSAL_TRANSITION_PROP = '__universalTransitionEnabled';
interface SeriesModel {
/**
* Convenient for override in extended class.
* Implement it if needed.
*/
preventIncremental(): boolean;
/**
* See tooltip.
* Implement it if needed.
* @return Point of tooltip. null/undefined can be returned.
*/
getTooltipPosition(dataIndex: number): number[];
/**
* Get data indices for show tooltip content. See tooltip.
* Implement it if needed.
*/
getAxisTooltipData(
dim: DimensionName[],
value: ScaleDataValue,
baseAxis: Axis
): {
dataIndices: number[],
nestestValue: any
};
/**
* Get position for marker
*/
getMarkerPosition(
value: ScaleDataValue[],
dims?: typeof dimPermutations[number],
startingAtTick?: boolean
): number[];
/**
* Get legend icon symbol according to each series type
*/
getLegendIcon(opt: LegendIconParams): ECSymbol | Group;
/**
* See `component/brush/selector.js`
* Defined the brush selector for this series.
*/
brushSelector(
dataIndex: number,
data: SeriesData,
selectors: BrushCommonSelectorsForSeries,
area: BrushSelectableArea
): boolean;
enableAriaDecal(): void;
}
class SeriesModel<Opt extends SeriesOption = SeriesOption> extends ComponentModel<Opt> {
// [Caution]: Because this class or desecendants can be used as `XXX.extend(subProto)`,
// the class members must not be initialized in constructor or declaration place.
// Otherwise there is bad case:
// class A {xxx = 1;}
// enableClassExtend(A);
// class B extends A {}
// var C = B.extend({xxx: 5});
// var c = new C();
// console.log(c.xxx); // expect 5 but always 1.
// @readonly
type: string;
// Should be implenented in subclass.
defaultOption: SeriesOption;
// @readonly
seriesIndex: number;
// coordinateSystem will be injected in the echarts/CoordinateSystem
coordinateSystem: CoordinateSystem;
// Injected outside
dataTask: SeriesTask;
// Injected outside
pipelineContext: PipelineContext;
// ---------------------------------------
// Props to tell visual/style.ts about how to do visual encoding.
// ---------------------------------------
// legend visual provider to the legend component
legendVisualProvider: LegendVisualProvider;
// Access path of style for visual
visualStyleAccessPath: string;
// Which property is treated as main color. Which can get from the palette.
visualDrawType: 'fill' | 'stroke';
// Style mapping rules.
visualStyleMapper: ReturnType<typeof makeStyleMapper>;
// If ignore style on data. It's only for global visual/style.ts
// Enabled when series it self will handle it.
ignoreStyleOnData: boolean;
// If do symbol visual encoding
hasSymbolVisual: boolean;
// Default symbol type.
defaultSymbol: string;
// Symbol provide to legend.
legendIcon: string;
// It will be set temporary when cross series transition setting is from setOption.
// TODO if deprecate further?
[SERIES_UNIVERSAL_TRANSITION_PROP]: boolean;
// ---------------------------------------
// Props about data selection
// ---------------------------------------
private _selectedDataIndicesMap: Dictionary<number> = {};
readonly preventUsingHoverLayer: boolean;
static protoInitialize = (function () {
const proto = SeriesModel.prototype;
proto.type = 'series.__base__';
proto.seriesIndex = 0;
proto.ignoreStyleOnData = false;
proto.hasSymbolVisual = false;
proto.defaultSymbol = 'circle';
// Make sure the values can be accessed!
proto.visualStyleAccessPath = 'itemStyle';
proto.visualDrawType = 'fill';
})();
init(option: Opt, parentModel: Model, ecModel: GlobalModel) {
this.seriesIndex = this.componentIndex;
this.dataTask = createTask<SeriesTaskContext>({
count: dataTaskCount,
reset: dataTaskReset
});
this.dataTask.context = {model: this};
this.mergeDefaultAndTheme(option, ecModel);
const sourceManager = inner(this).sourceManager = new SourceManager(this);
sourceManager.prepareSource();
const data = this.getInitialData(option, ecModel);
wrapData(data, this);
this.dataTask.context.data = data;
if (__DEV__) {
zrUtil.assert(data, 'getInitialData returned invalid data.');
}
inner(this).dataBeforeProcessed = data;
// If we reverse the order (make data firstly, and then make
// dataBeforeProcessed by cloneShallow), cloneShallow will
// cause data.graph.data !== data when using
// module:echarts/data/Graph or module:echarts/data/Tree.
// See module:echarts/data/helper/linkSeriesData
// Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
// init or merge stage, because the data can be restored. So we do not `restoreData`
// and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
// Call `seriesModel.getRawData()` instead.
// this.restoreData();
autoSeriesName(this);
this._initSelectedMapFromData(data);
}
/**
* Util for merge default and theme to option
*/
mergeDefaultAndTheme(option: Opt, ecModel: GlobalModel): void {
const layoutMode = fetchLayoutMode(this);
const inputPositionParams = layoutMode
? getLayoutParams(option as BoxLayoutOptionMixin) : {};
// Backward compat: using subType on theme.
// But if name duplicate between series subType
// (for example: parallel) add component mainType,
// add suffix 'Series'.
let themeSubType = this.subType;
if ((ComponentModel as ComponentModelConstructor).hasClass(themeSubType)) {
themeSubType += 'Series';
}
zrUtil.merge(
option,
ecModel.getTheme().get(this.subType)
);
zrUtil.merge(option, this.getDefaultOption());
// Default label emphasis `show`
modelUtil.defaultEmphasis(option, 'label', ['show']);
this.fillDataTextStyle(option.data as ArrayLike<any>);
if (layoutMode) {
mergeLayoutParam(option as BoxLayoutOptionMixin, inputPositionParams, layoutMode);
}
}
mergeOption(newSeriesOption: Opt, ecModel: GlobalModel) {
// this.settingTask.dirty();
newSeriesOption = zrUtil.merge(this.option, newSeriesOption, true);
this.fillDataTextStyle(newSeriesOption.data as ArrayLike<any>);
const layoutMode = fetchLayoutMode(this);
if (layoutMode) {
mergeLayoutParam(
this.option as BoxLayoutOptionMixin,
newSeriesOption as BoxLayoutOptionMixin,
layoutMode
);
}
const sourceManager = inner(this).sourceManager;
sourceManager.dirty();
sourceManager.prepareSource();
const data = this.getInitialData(newSeriesOption, ecModel);
wrapData(data, this);
this.dataTask.dirty();
this.dataTask.context.data = data;
inner(this).dataBeforeProcessed = data;
autoSeriesName(this);
this._initSelectedMapFromData(data);
}
fillDataTextStyle(data: ArrayLike<any>): void {
// Default data label emphasis `show`
// FIXME Tree structure data ?
// FIXME Performance ?
if (data && !zrUtil.isTypedArray(data)) {
const props = ['show'];
for (let i = 0; i < data.length; i++) {
if (data[i] && data[i].label) {
modelUtil.defaultEmphasis(data[i], 'label', props);
}
}
}
}
/**
* Init a data structure from data related option in series
* Must be overridden.
*/
getInitialData(option: Opt, ecModel: GlobalModel): SeriesData {
return;
}
/**
* Append data to list
*/
appendData(params: {data: ArrayLike<any>}): void {
// FIXME ???
// (1) If data from dataset, forbidden append.
// (2) support append data of dataset.
const data = this.getRawData();
data.appendData(params.data);
}
/**
* Consider some method like `filter`, `map` need make new data,
* We should make sure that `seriesModel.getData()` get correct
* data in the stream procedure. So we fetch data from upstream
* each time `task.perform` called.
*/
getData(dataType?: SeriesDataType): SeriesData<this> {
const task = getCurrentTask(this);
if (task) {
const data = task.context.data;
return (dataType == null || !data.getLinkedData ? data : data.getLinkedData(dataType)) as SeriesData<this>;
}
else {
// When series is not alive (that may happen when click toolbox
// restore or setOption with not merge mode), series data may
// be still need to judge animation or something when graphic
// elements want to know whether fade out.
return inner(this).data as SeriesData<this>;
}
}
getAllData(): ({
data: SeriesData,
type?: SeriesDataType
})[] {
const mainData = this.getData();
return (mainData && mainData.getLinkedDataAll)
? mainData.getLinkedDataAll()
: [{ data: mainData }];
}
setData(data: SeriesData): void {
const task = getCurrentTask(this);
if (task) {
const context = task.context;
// Consider case: filter, data sample.
// FIXME:TS never used, so comment it
// if (context.data !== data && task.modifyOutputEnd) {
// task.setOutputEnd(data.count());
// }
context.outputData = data;
// Caution: setData should update context.data,
// Because getData may be called multiply in a
// single stage and expect to get the data just
// set. (For example, AxisProxy, x y both call
// getData and setDate sequentially).
// So the context.data should be fetched from
// upstream each time when a stage starts to be
// performed.
if (task !== this.dataTask) {
context.data = data;
}
}
inner(this).data = data;
}
getEncode() {
const encode = (this as Model<SeriesEncodeOptionMixin>).get('encode', true);
if (encode) {
return zrUtil.createHashMap<OptionEncodeValue, DimensionName>(encode);
}
}
getSourceManager(): SourceManager {
return inner(this).sourceManager;
}
getSource(): Source {
return this.getSourceManager().getSource();
}
/**
* Get data before processed
*/
getRawData(): SeriesData {
return inner(this).dataBeforeProcessed;
}
getColorBy(): ColorBy {
const colorBy = this.get('colorBy');
return colorBy || 'series';
}
isColorBySeries(): boolean {
return this.getColorBy() === 'series';
}
/**
* Get base axis if has coordinate system and has axis.
* By default use coordSys.getBaseAxis();
* Can be overridden for some chart.
* @return {type} description
*/
getBaseAxis(): Axis {
const coordSys = this.coordinateSystem;
// @ts-ignore
return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
}
/**
* Default tooltip formatter
*
* @param dataIndex
* @param multipleSeries
* @param dataType
* @param renderMode valid values: 'html'(by default) and 'richText'.
* 'html' is used for rendering tooltip in extra DOM form, and the result
* string is used as DOM HTML content.
* 'richText' is used for rendering tooltip in rich text form, for those where
* DOM operation is not supported.
* @return formatted tooltip with `html` and `markers`
* Notice: The override method can also return string
*/
formatTooltip(
dataIndex: number,
multipleSeries?: boolean,
dataType?: SeriesDataType
): ReturnType<DataFormatMixin['formatTooltip']> {
return defaultSeriesFormatTooltip({
series: this,
dataIndex: dataIndex,
multipleSeries: multipleSeries
});
}
isAnimationEnabled(): boolean {
const ecModel = this.ecModel;
// Disable animation if using echarts in node but not give ssr flag.
// In ssr mode, renderToString will generate svg with css animation.
if (env.node && !(ecModel && ecModel.ssr)) {
return false;
}
let animationEnabled = this.getShallow('animation');
if (animationEnabled) {
if (this.getData().count() > this.getShallow('animationThreshold')) {
animationEnabled = false;
}
}
return !!animationEnabled;
}
restoreData() {
this.dataTask.dirty();
}
getColorFromPalette(name: string, scope: any, requestColorNum?: number): ZRColor {
const ecModel = this.ecModel;
// PENDING
let color = PaletteMixin.prototype.getColorFromPalette.call(this, name, scope, requestColorNum);
if (!color) {
color = ecModel.getColorFromPalette(name, scope, requestColorNum);
}
return color;
}
/**
* Use `data.mapDimensionsAll(coordDim)` instead.
* @deprecated
*/
coordDimToDataDim(coordDim: DimensionName): DimensionName[] {
return this.getRawData().mapDimensionsAll(coordDim);
}
/**
* Get progressive rendering count each step
*/
getProgressive(): number | false {
return this.get('progressive');
}
/**
* Get progressive rendering count each step
*/
getProgressiveThreshold(): number {
return this.get('progressiveThreshold');
}
// PENGING If selectedMode is null ?
select(innerDataIndices: number[], dataType?: SeriesDataType): void {
this._innerSelect(this.getData(dataType), innerDataIndices);
}
unselect(innerDataIndices: number[], dataType?: SeriesDataType): void {
const selectedMap = this.option.selectedMap;
if (!selectedMap) {
return;
}
const selectedMode = this.option.selectedMode;
const data = this.getData(dataType);
if (selectedMode === 'series' || selectedMap === 'all') {
this.option.selectedMap = {};
this._selectedDataIndicesMap = {};
return;
}
for (let i = 0; i < innerDataIndices.length; i++) {
const dataIndex = innerDataIndices[i];
const nameOrId = getSelectionKey(data, dataIndex);
selectedMap[nameOrId] = false;
this._selectedDataIndicesMap[nameOrId] = -1;
}
}
toggleSelect(innerDataIndices: number[], dataType?: SeriesDataType): void {
const tmpArr: number[] = [];
for (let i = 0; i < innerDataIndices.length; i++) {
tmpArr[0] = innerDataIndices[i];
this.isSelected(innerDataIndices[i], dataType)
? this.unselect(tmpArr, dataType)
: this.select(tmpArr, dataType);
}
}
getSelectedDataIndices(): number[] {
if (this.option.selectedMap === 'all') {
return [].slice.call(this.getData().getIndices());
}
const selectedDataIndicesMap = this._selectedDataIndicesMap;
const nameOrIds = zrUtil.keys(selectedDataIndicesMap);
const dataIndices = [];
for (let i = 0; i < nameOrIds.length; i++) {
const dataIndex = selectedDataIndicesMap[nameOrIds[i]];
if (dataIndex >= 0) {
dataIndices.push(dataIndex);
}
}
return dataIndices;
}
isSelected(dataIndex: number, dataType?: SeriesDataType): boolean {
const selectedMap = this.option.selectedMap;
if (!selectedMap) {
return false;
}
const data = this.getData(dataType);
return (selectedMap === 'all' || selectedMap[getSelectionKey(data, dataIndex)])
&& !data.getItemModel<StatesOptionMixin<unknown, unknown>>(dataIndex).get(['select', 'disabled']);
}
isUniversalTransitionEnabled(): boolean {
if (this[SERIES_UNIVERSAL_TRANSITION_PROP]) {
return true;
}
const universalTransitionOpt = this.option.universalTransition;
// Quick reject
if (!universalTransitionOpt) {
return false;
}
if (universalTransitionOpt === true) {
return true;
}
// Can be simply 'universalTransition: true'
return universalTransitionOpt && universalTransitionOpt.enabled;
}
private _innerSelect(data: SeriesData, innerDataIndices: number[]) {
const option = this.option;
const selectedMode = option.selectedMode;
const len = innerDataIndices.length;
if (!selectedMode || !len) {
return;
}
if (selectedMode === 'series') {
option.selectedMap = 'all';
}
else if (selectedMode === 'multiple') {
if (!zrUtil.isObject(option.selectedMap)) {
option.selectedMap = {};
}
const selectedMap = option.selectedMap;
for (let i = 0; i < len; i++) {
const dataIndex = innerDataIndices[i];
// TODO different types of data share same object.
const nameOrId = getSelectionKey(data, dataIndex);
selectedMap[nameOrId] = true;
this._selectedDataIndicesMap[nameOrId] = data.getRawIndex(dataIndex);
}
}
else if (selectedMode === 'single' || selectedMode === true) {
const lastDataIndex = innerDataIndices[len - 1];
const nameOrId = getSelectionKey(data, lastDataIndex);
option.selectedMap = {
[nameOrId]: true
};
this._selectedDataIndicesMap = {
[nameOrId]: data.getRawIndex(lastDataIndex)
};
}
}
private _initSelectedMapFromData(data: SeriesData) {
// Ignore select info in data if selectedMap exists.
// NOTE It's only for legacy usage. edge data is not supported.
if (this.option.selectedMap) {
return;
}
const dataIndices: number[] = [];
if (data.hasItemOption) {
data.each(function (idx) {
const rawItem = data.getRawDataItem(idx);
if (rawItem && (rawItem as OptionDataItemObject<unknown>).selected) {
dataIndices.push(idx);
}
});
}
if (dataIndices.length > 0) {
this._innerSelect(data, dataIndices);
}
}
// /**
// * @see {module:echarts/stream/Scheduler}
// */
// abstract pipeTask: null
static registerClass(clz: Constructor): Constructor {
return ComponentModel.registerClass(clz);
}
}
interface SeriesModel<Opt extends SeriesOption = SeriesOption>
extends DataFormatMixin, PaletteMixin<Opt>, DataHost {
// methods that can be implemented optionally to provide to components
/**
* Get dimension to render shadow in dataZoom component
*/
getShadowDim?(): string
}
zrUtil.mixin(SeriesModel, DataFormatMixin);
zrUtil.mixin(SeriesModel, PaletteMixin);
export type SeriesModelConstructor = typeof SeriesModel & ExtendableConstructor;
mountExtend(SeriesModel, ComponentModel as SeriesModelConstructor);
/**
* MUST be called after `prepareSource` called
* Here we need to make auto series, especially for auto legend. But we
* do not modify series.name in option to avoid side effects.
*/
function autoSeriesName(seriesModel: SeriesModel): void {
// User specified name has higher priority, otherwise it may cause
// series can not be queried unexpectedly.
const name = seriesModel.name;
if (!modelUtil.isNameSpecified(seriesModel)) {
seriesModel.name = getSeriesAutoName(seriesModel) || name;
}
}
function getSeriesAutoName(seriesModel: SeriesModel): string {
const data = seriesModel.getRawData();
const dataDims = data.mapDimensionsAll('seriesName');
const nameArr: string[] = [];
zrUtil.each(dataDims, function (dataDim) {
const dimInfo = data.getDimensionInfo(dataDim);
dimInfo.displayName && nameArr.push(dimInfo.displayName);
});
return nameArr.join(' ');
}
function dataTaskCount(context: SeriesTaskContext): number {
return context.model.getRawData().count();
}
function dataTaskReset(context: SeriesTaskContext) {
const seriesModel = context.model;
seriesModel.setData(seriesModel.getRawData().cloneShallow());
return dataTaskProgress;
}
function dataTaskProgress(param: StageHandlerProgressParams, context: SeriesTaskContext): void {
// Avoid repeat cloneShallow when data just created in reset.
if (context.outputData && param.end > context.outputData.count()) {
context.model.getRawData().cloneShallow(context.outputData);
}
}
// TODO refactor
function wrapData(data: SeriesData, seriesModel: SeriesModel): void {
zrUtil.each(zrUtil.concatArray(data.CHANGABLE_METHODS, data.DOWNSAMPLE_METHODS), function (methodName) {
data.wrapMethod(methodName as any, zrUtil.curry(onDataChange, seriesModel));
});
}
function onDataChange(this: SeriesData, seriesModel: SeriesModel, newList: SeriesData): SeriesData {
const task = getCurrentTask(seriesModel);
if (task) {
// Consider case: filter, selectRange
task.setOutputEnd((newList || this).count());
}
return newList;
}
function getCurrentTask(seriesModel: SeriesModel): GeneralTask {
const scheduler = (seriesModel.ecModel || {}).scheduler;
const pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
if (pipeline) {
// When pipline finished, the currrentTask keep the last
// task (renderTask).
let task = pipeline.currentTask;
if (task) {
const agentStubMap = (task as OverallTask).agentStubMap;
if (agentStubMap) {
task = agentStubMap.get(seriesModel.uid);
}
}
return task;
}
}
export default SeriesModel;