forked from apache/echarts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
echarts.js
2002 lines (1734 loc) · 60.4 KB
/
echarts.js
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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Enable DEV mode when using source code without build. which has no __DEV__ variable
// In build process 'typeof __DEV__' will be replace with 'boolean'
// So this code will be removed or disabled anyway after built.
if (typeof __DEV__ === 'undefined') {
// In browser
if (typeof window !== 'undefined') {
window.__DEV__ = true;
}
// In node
else if (typeof global !== 'undefined') {
global.__DEV__ = true;
}
}
/*!
* ECharts, a javascript interactive chart library.
*
* Copyright (c) 2015, Baidu Inc.
* All rights reserved.
*
* LICENSE
* https://github.com/ecomfe/echarts/blob/master/LICENSE.txt
*/
/**
* @module echarts
*/
define(function (require) {
var env = require('zrender/core/env');
var GlobalModel = require('./model/Global');
var ExtensionAPI = require('./ExtensionAPI');
var CoordinateSystemManager = require('./CoordinateSystem');
var OptionManager = require('./model/OptionManager');
var ComponentModel = require('./model/Component');
var SeriesModel = require('./model/Series');
var ComponentView = require('./view/Component');
var ChartView = require('./view/Chart');
var graphic = require('./util/graphic');
var modelUtil = require('./util/model');
var throttle = require('./util/throttle');
var zrender = require('zrender');
var zrUtil = require('zrender/core/util');
var colorTool = require('zrender/tool/color');
var Eventful = require('zrender/mixin/Eventful');
var timsort = require('zrender/core/timsort');
var each = zrUtil.each;
var parseClassType = ComponentModel.parseClassType;
var PRIORITY_PROCESSOR_FILTER = 1000;
var PRIORITY_PROCESSOR_STATISTIC = 5000;
var PRIORITY_VISUAL_LAYOUT = 1000;
var PRIORITY_VISUAL_GLOBAL = 2000;
var PRIORITY_VISUAL_CHART = 3000;
var PRIORITY_VISUAL_COMPONENT = 4000;
// FIXME
// necessary?
var PRIORITY_VISUAL_BRUSH = 5000;
// Main process have three entries: `setOption`, `dispatchAction` and `resize`,
// where they must not be invoked nestedly, except the only case: invoke
// dispatchAction with updateMethod "none" in main process.
// This flag is used to carry out this rule.
// All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
var IN_MAIN_PROCESS = '__flagInMainProcess';
var HAS_GRADIENT_OR_PATTERN_BG = '__hasGradientOrPatternBg';
var OPTION_UPDATED = '__optionUpdated';
var ACTION_REG = /^[a-zA-Z0-9_]+$/;
function createRegisterEventWithLowercaseName(method) {
return function (eventName, handler, context) {
// Event name is all lowercase
eventName = eventName && eventName.toLowerCase();
Eventful.prototype[method].call(this, eventName, handler, context);
};
}
/**
* @module echarts~MessageCenter
*/
function MessageCenter() {
Eventful.call(this);
}
MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
zrUtil.mixin(MessageCenter, Eventful);
/**
* @module echarts~ECharts
*/
function ECharts(dom, theme, opts) {
opts = opts || {};
// Get theme by name
if (typeof theme === 'string') {
theme = themeStorage[theme];
}
/**
* @type {string}
*/
this.id;
/**
* Group id
* @type {string}
*/
this.group;
/**
* @type {HTMLElement}
* @private
*/
this._dom = dom;
/**
* @type {module:zrender/ZRender}
* @private
*/
var zr = this._zr = zrender.init(dom, {
renderer: opts.renderer || 'canvas',
devicePixelRatio: opts.devicePixelRatio,
width: opts.width,
height: opts.height
});
/**
* Expect 60 pfs.
* @type {Function}
* @private
*/
this._throttledZrFlush = throttle.throttle(zrUtil.bind(zr.flush, zr), 17);
/**
* @type {Object}
* @private
*/
this._theme = zrUtil.clone(theme);
/**
* @type {Array.<module:echarts/view/Chart>}
* @private
*/
this._chartsViews = [];
/**
* @type {Object.<string, module:echarts/view/Chart>}
* @private
*/
this._chartsMap = {};
/**
* @type {Array.<module:echarts/view/Component>}
* @private
*/
this._componentsViews = [];
/**
* @type {Object.<string, module:echarts/view/Component>}
* @private
*/
this._componentsMap = {};
/**
* @type {module:echarts/CoordinateSystem}
* @private
*/
this._coordSysMgr = new CoordinateSystemManager();
/**
* @type {module:echarts/ExtensionAPI}
* @private
*/
this._api = createExtensionAPI(this);
Eventful.call(this);
/**
* @type {module:echarts~MessageCenter}
* @private
*/
this._messageCenter = new MessageCenter();
// Init mouse events
this._initEvents();
// In case some people write `window.onresize = chart.resize`
this.resize = zrUtil.bind(this.resize, this);
// Can't dispatch action during rendering procedure
this._pendingActions = [];
// Sort on demand
function prioritySortFunc(a, b) {
return a.prio - b.prio;
}
timsort(visualFuncs, prioritySortFunc);
timsort(dataProcessorFuncs, prioritySortFunc);
zr.animation.on('frame', this._onframe, this);
// ECharts instance can be used as value.
zrUtil.setAsPrimitive(this);
}
var echartsProto = ECharts.prototype;
echartsProto._onframe = function () {
// Lazy update
if (this[OPTION_UPDATED]) {
var silent = this[OPTION_UPDATED].silent;
this[IN_MAIN_PROCESS] = true;
updateMethods.prepareAndUpdate.call(this);
this[IN_MAIN_PROCESS] = false;
this[OPTION_UPDATED] = false;
flushPendingActions.call(this, silent);
triggerUpdatedEvent.call(this, silent);
}
};
/**
* @return {HTMLElement}
*/
echartsProto.getDom = function () {
return this._dom;
};
/**
* @return {module:zrender~ZRender}
*/
echartsProto.getZr = function () {
return this._zr;
};
/**
* Usage:
* chart.setOption(option, notMerge, lazyUpdate);
* chart.setOption(option, {
* notMerge: ...,
* lazyUpdate: ...,
* silent: ...
* });
*
* @param {Object} option
* @param {Object|boolean} [opts] opts or notMerge.
* @param {boolean} [opts.notMerge=false]
* @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
*/
echartsProto.setOption = function (option, notMerge, lazyUpdate) {
if (__DEV__) {
zrUtil.assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
}
var silent;
if (zrUtil.isObject(notMerge)) {
lazyUpdate = notMerge.lazyUpdate;
silent = notMerge.silent;
notMerge = notMerge.notMerge;
}
this[IN_MAIN_PROCESS] = true;
if (!this._model || notMerge) {
var optionManager = new OptionManager(this._api);
var theme = this._theme;
var ecModel = this._model = new GlobalModel(null, null, theme, optionManager);
ecModel.init(null, null, theme, optionManager);
}
this._model.setOption(option, optionPreprocessorFuncs);
if (lazyUpdate) {
this[OPTION_UPDATED] = {silent: silent};
this[IN_MAIN_PROCESS] = false;
}
else {
updateMethods.prepareAndUpdate.call(this);
// Ensure zr refresh sychronously, and then pixel in canvas can be
// fetched after `setOption`.
this._zr.flush();
this[OPTION_UPDATED] = false;
this[IN_MAIN_PROCESS] = false;
flushPendingActions.call(this, silent);
triggerUpdatedEvent.call(this, silent);
}
};
/**
* @DEPRECATED
*/
echartsProto.setTheme = function () {
console.log('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
};
/**
* @return {module:echarts/model/Global}
*/
echartsProto.getModel = function () {
return this._model;
};
/**
* @return {Object}
*/
echartsProto.getOption = function () {
return this._model && this._model.getOption();
};
/**
* @return {number}
*/
echartsProto.getWidth = function () {
return this._zr.getWidth();
};
/**
* @return {number}
*/
echartsProto.getHeight = function () {
return this._zr.getHeight();
};
/**
* @return {number}
*/
echartsProto.getDevicePixelRatio = function () {
return this._zr.painter.dpr || window.devicePixelRatio || 1;
};
/**
* Get canvas which has all thing rendered
* @param {Object} opts
* @param {string} [opts.backgroundColor]
*/
echartsProto.getRenderedCanvas = function (opts) {
if (!env.canvasSupported) {
return;
}
opts = opts || {};
opts.pixelRatio = opts.pixelRatio || 1;
opts.backgroundColor = opts.backgroundColor
|| this._model.get('backgroundColor');
var zr = this._zr;
var list = zr.storage.getDisplayList();
// Stop animations
zrUtil.each(list, function (el) {
el.stopAnimation(true);
});
return zr.painter.getRenderedCanvas(opts);
};
/**
* @return {string}
* @param {Object} opts
* @param {string} [opts.type='png']
* @param {string} [opts.pixelRatio=1]
* @param {string} [opts.backgroundColor]
* @param {string} [opts.excludeComponents]
*/
echartsProto.getDataURL = function (opts) {
opts = opts || {};
var excludeComponents = opts.excludeComponents;
var ecModel = this._model;
var excludesComponentViews = [];
var self = this;
each(excludeComponents, function (componentType) {
ecModel.eachComponent({
mainType: componentType
}, function (component) {
var view = self._componentsMap[component.__viewId];
if (!view.group.ignore) {
excludesComponentViews.push(view);
view.group.ignore = true;
}
});
});
var url = this.getRenderedCanvas(opts).toDataURL(
'image/' + (opts && opts.type || 'png')
);
each(excludesComponentViews, function (view) {
view.group.ignore = false;
});
return url;
};
/**
* @return {string}
* @param {Object} opts
* @param {string} [opts.type='png']
* @param {string} [opts.pixelRatio=1]
* @param {string} [opts.backgroundColor]
*/
echartsProto.getConnectedDataURL = function (opts) {
if (!env.canvasSupported) {
return;
}
var groupId = this.group;
var mathMin = Math.min;
var mathMax = Math.max;
var MAX_NUMBER = Infinity;
if (connectedGroups[groupId]) {
var left = MAX_NUMBER;
var top = MAX_NUMBER;
var right = -MAX_NUMBER;
var bottom = -MAX_NUMBER;
var canvasList = [];
var dpr = (opts && opts.pixelRatio) || 1;
zrUtil.each(instances, function (chart, id) {
if (chart.group === groupId) {
var canvas = chart.getRenderedCanvas(
zrUtil.clone(opts)
);
var boundingRect = chart.getDom().getBoundingClientRect();
left = mathMin(boundingRect.left, left);
top = mathMin(boundingRect.top, top);
right = mathMax(boundingRect.right, right);
bottom = mathMax(boundingRect.bottom, bottom);
canvasList.push({
dom: canvas,
left: boundingRect.left,
top: boundingRect.top
});
}
});
left *= dpr;
top *= dpr;
right *= dpr;
bottom *= dpr;
var width = right - left;
var height = bottom - top;
var targetCanvas = zrUtil.createCanvas();
targetCanvas.width = width;
targetCanvas.height = height;
var zr = zrender.init(targetCanvas);
each(canvasList, function (item) {
var img = new graphic.Image({
style: {
x: item.left * dpr - left,
y: item.top * dpr - top,
image: item.dom
}
});
zr.add(img);
});
zr.refreshImmediately();
return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
}
else {
return this.getDataURL(opts);
}
};
/**
* Convert from logical coordinate system to pixel coordinate system.
* See CoordinateSystem#convertToPixel.
* @param {string|Object} finder
* If string, e.g., 'geo', means {geoIndex: 0}.
* If Object, could contain some of these properties below:
* {
* seriesIndex / seriesId / seriesName,
* geoIndex / geoId, geoName,
* bmapIndex / bmapId / bmapName,
* xAxisIndex / xAxisId / xAxisName,
* yAxisIndex / yAxisId / yAxisName,
* gridIndex / gridId / gridName,
* ... (can be extended)
* }
* @param {Array|number} value
* @return {Array|number} result
*/
echartsProto.convertToPixel = zrUtil.curry(doConvertPixel, 'convertToPixel');
/**
* Convert from pixel coordinate system to logical coordinate system.
* See CoordinateSystem#convertFromPixel.
* @param {string|Object} finder
* If string, e.g., 'geo', means {geoIndex: 0}.
* If Object, could contain some of these properties below:
* {
* seriesIndex / seriesId / seriesName,
* geoIndex / geoId / geoName,
* bmapIndex / bmapId / bmapName,
* xAxisIndex / xAxisId / xAxisName,
* yAxisIndex / yAxisId / yAxisName
* gridIndex / gridId / gridName,
* ... (can be extended)
* }
* @param {Array|number} value
* @return {Array|number} result
*/
echartsProto.convertFromPixel = zrUtil.curry(doConvertPixel, 'convertFromPixel');
function doConvertPixel(methodName, finder, value) {
var ecModel = this._model;
var coordSysList = this._coordSysMgr.getCoordinateSystems();
var result;
finder = modelUtil.parseFinder(ecModel, finder);
for (var i = 0; i < coordSysList.length; i++) {
var coordSys = coordSysList[i];
if (coordSys[methodName]
&& (result = coordSys[methodName](ecModel, finder, value)) != null
) {
return result;
}
}
if (__DEV__) {
console.warn(
'No coordinate system that supports ' + methodName + ' found by the given finder.'
);
}
}
/**
* Is the specified coordinate systems or components contain the given pixel point.
* @param {string|Object} finder
* If string, e.g., 'geo', means {geoIndex: 0}.
* If Object, could contain some of these properties below:
* {
* seriesIndex / seriesId / seriesName,
* geoIndex / geoId / geoName,
* bmapIndex / bmapId / bmapName,
* xAxisIndex / xAxisId / xAxisName,
* yAxisIndex / yAxisId / yAxisName,
* gridIndex / gridId / gridName,
* ... (can be extended)
* }
* @param {Array|number} value
* @return {boolean} result
*/
echartsProto.containPixel = function (finder, value) {
var ecModel = this._model;
var result;
finder = modelUtil.parseFinder(ecModel, finder);
zrUtil.each(finder, function (models, key) {
key.indexOf('Models') >= 0 && zrUtil.each(models, function (model) {
var coordSys = model.coordinateSystem;
if (coordSys && coordSys.containPoint) {
result |= !!coordSys.containPoint(value);
}
else if (key === 'seriesModels') {
var view = this._chartsMap[model.__viewId];
if (view && view.containPoint) {
result |= view.containPoint(value, model);
}
else {
if (__DEV__) {
console.warn(key + ': ' + (view
? 'The found component do not support containPoint.'
: 'No view mapping to the found component.'
));
}
}
}
else {
if (__DEV__) {
console.warn(key + ': containPoint is not supported');
}
}
}, this);
}, this);
return !!result;
};
/**
* Get visual from series or data.
* @param {string|Object} finder
* If string, e.g., 'series', means {seriesIndex: 0}.
* If Object, could contain some of these properties below:
* {
* seriesIndex / seriesId / seriesName,
* dataIndex / dataIndexInside
* }
* If dataIndex is not specified, series visual will be fetched,
* but not data item visual.
* If all of seriesIndex, seriesId, seriesName are not specified,
* visual will be fetched from first series.
* @param {string} visualType 'color', 'symbol', 'symbolSize'
*/
echartsProto.getVisual = function (finder, visualType) {
var ecModel = this._model;
finder = modelUtil.parseFinder(ecModel, finder, {defaultMainType: 'series'});
var seriesModel = finder.seriesModel;
if (__DEV__) {
if (!seriesModel) {
console.warn('There is no specified seires model');
}
}
var data = seriesModel.getData();
var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
? finder.dataIndexInside
: finder.hasOwnProperty('dataIndex')
? data.indexOfRawIndex(finder.dataIndex)
: null;
return dataIndexInside != null
? data.getItemVisual(dataIndexInside, visualType)
: data.getVisual(visualType);
};
/**
* Get view of corresponding component model
* @param {module:echarts/model/Component} componentModel
* @return {module:echarts/view/Component}
*/
echartsProto.getViewOfComponentModel = function (componentModel) {
return this._componentsMap[componentModel.__viewId];
};
/**
* Get view of corresponding series model
* @param {module:echarts/model/Series} seriesModel
* @return {module:echarts/view/Chart}
*/
echartsProto.getViewOfSeriesModel = function (seriesModel) {
return this._chartsMap[seriesModel.__viewId];
};
var updateMethods = {
/**
* @param {Object} payload
* @private
*/
update: function (payload) {
// console.profile && console.profile('update');
var ecModel = this._model;
var api = this._api;
var coordSysMgr = this._coordSysMgr;
var zr = this._zr;
// update before setOption
if (!ecModel) {
return;
}
// Fixme First time update ?
ecModel.restoreData();
// TODO
// Save total ecModel here for undo/redo (after restoring data and before processing data).
// Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
// Create new coordinate system each update
// In LineView may save the old coordinate system and use it to get the orignal point
coordSysMgr.create(this._model, this._api);
processData.call(this, ecModel, api);
stackSeriesData.call(this, ecModel);
coordSysMgr.update(ecModel, api);
doVisualEncoding.call(this, ecModel, payload);
doRender.call(this, ecModel, payload);
// Set background
var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
var painter = zr.painter;
// TODO all use clearColor ?
if (painter.isSingleCanvas && painter.isSingleCanvas()) {
zr.configLayer(0, {
clearColor: backgroundColor
});
}
else {
// In IE8
if (!env.canvasSupported) {
var colorArr = colorTool.parse(backgroundColor);
backgroundColor = colorTool.stringify(colorArr, 'rgb');
if (colorArr[3] === 0) {
backgroundColor = 'transparent';
}
}
if (backgroundColor.colorStops || backgroundColor.image) {
// Gradient background
// FIXME Fixed layer?
zr.configLayer(0, {
clearColor: backgroundColor
});
this[HAS_GRADIENT_OR_PATTERN_BG] = true;
this._dom.style.background = 'transparent';
}
else {
if (this[HAS_GRADIENT_OR_PATTERN_BG]) {
zr.configLayer(0, {
clearColor: null
});
}
this[HAS_GRADIENT_OR_PATTERN_BG] = false;
this._dom.style.background = backgroundColor;
}
}
each(postUpdateFuncs, function (func) {
func(ecModel, api);
});
// console.profile && console.profileEnd('update');
},
/**
* @param {Object} payload
* @private
*/
updateView: function (payload) {
var ecModel = this._model;
// update before setOption
if (!ecModel) {
return;
}
ecModel.eachSeries(function (seriesModel) {
seriesModel.getData().clearAllVisual();
});
doVisualEncoding.call(this, ecModel, payload);
invokeUpdateMethod.call(this, 'updateView', ecModel, payload);
},
/**
* @param {Object} payload
* @private
*/
updateVisual: function (payload) {
var ecModel = this._model;
// update before setOption
if (!ecModel) {
return;
}
ecModel.eachSeries(function (seriesModel) {
seriesModel.getData().clearAllVisual();
});
doVisualEncoding.call(this, ecModel, payload, true);
invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
},
/**
* @param {Object} payload
* @private
*/
updateLayout: function (payload) {
var ecModel = this._model;
// update before setOption
if (!ecModel) {
return;
}
doLayout.call(this, ecModel, payload);
invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
},
/**
* @param {Object} payload
* @private
*/
prepareAndUpdate: function (payload) {
var ecModel = this._model;
prepareView.call(this, 'component', ecModel);
prepareView.call(this, 'chart', ecModel);
updateMethods.update.call(this, payload);
}
};
/**
* @private
*/
function updateDirectly(ecIns, method, payload, mainType, subType) {
var ecModel = ecIns._model;
// broadcast
if (!mainType) {
each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
return;
}
var query = {};
query[mainType + 'Id'] = payload[mainType + 'Id'];
query[mainType + 'Index'] = payload[mainType + 'Index'];
query[mainType + 'Name'] = payload[mainType + 'Name'];
var condition = {mainType: mainType, query: query};
subType && (condition.subType = subType); // subType may be '' by parseClassType;
// If dispatchAction before setOption, do nothing.
ecModel && ecModel.eachComponent(condition, function (model, index) {
callView(ecIns[
mainType === 'series' ? '_chartsMap' : '_componentsMap'
][model.__viewId]);
}, ecIns);
function callView(view) {
view && view.__alive && view[method] && view[method](
view.__model, ecModel, ecIns._api, payload
);
}
}
/**
* Resize the chart
* @param {Object} opts
* @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
* @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
* @param {boolean} [opts.silent=false]
*/
echartsProto.resize = function (opts) {
if (__DEV__) {
zrUtil.assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
}
this[IN_MAIN_PROCESS] = true;
this._zr.resize(opts);
var optionChanged = this._model && this._model.resetOption('media');
var updateMethod = optionChanged ? 'prepareAndUpdate' : 'update';
updateMethods[updateMethod].call(this);
// Resize loading effect
this._loadingFX && this._loadingFX.resize();
this[IN_MAIN_PROCESS] = false;
var silent = opts && opts.silent;
flushPendingActions.call(this, silent);
triggerUpdatedEvent.call(this, silent);
};
/**
* Show loading effect
* @param {string} [name='default']
* @param {Object} [cfg]
*/
echartsProto.showLoading = function (name, cfg) {
if (zrUtil.isObject(name)) {
cfg = name;
name = '';
}
name = name || 'default';
this.hideLoading();
if (!loadingEffects[name]) {
if (__DEV__) {
console.warn('Loading effects ' + name + ' not exists.');
}
return;
}
var el = loadingEffects[name](this._api, cfg);
var zr = this._zr;
this._loadingFX = el;
zr.add(el);
};
/**
* Hide loading effect
*/
echartsProto.hideLoading = function () {
this._loadingFX && this._zr.remove(this._loadingFX);
this._loadingFX = null;
};
/**
* @param {Object} eventObj
* @return {Object}
*/
echartsProto.makeActionFromEvent = function (eventObj) {
var payload = zrUtil.extend({}, eventObj);
payload.type = eventActionMap[eventObj.type];
return payload;
};
/**
* @pubilc
* @param {Object} payload
* @param {string} [payload.type] Action type
* @param {Object|boolean} [opt] If pass boolean, means opt.silent
* @param {boolean} [opt.silent=false] Whether trigger events.
* @param {boolean} [opt.flush=undefined]
* true: Flush immediately, and then pixel in canvas can be fetched
* immediately. Caution: it might affect performance.
* false: Not not flush.
* undefined: Auto decide whether perform flush.
*/
echartsProto.dispatchAction = function (payload, opt) {
if (!zrUtil.isObject(opt)) {
opt = {silent: !!opt};
}
if (!actions[payload.type]) {
return;
}
// May dispatchAction in rendering procedure
if (this[IN_MAIN_PROCESS]) {
this._pendingActions.push(payload);
return;
}
doDispatchAction.call(this, payload, opt.silent);
if (opt.flush) {
this._zr.flush(true);
}
else if (opt.flush !== false && env.browser.weChat) {
// In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
// hang when sliding page (on touch event), which cause that zr does not
// refresh util user interaction finished, which is not expected.
// But `dispatchAction` may be called too frequently when pan on touch
// screen, which impacts performance if do not throttle them.
this._throttledZrFlush();
}
flushPendingActions.call(this, opt.silent);
triggerUpdatedEvent.call(this, opt.silent);
};
function doDispatchAction(payload, silent) {
var payloadType = payload.type;
var escapeConnect = payload.escapeConnect;
var actionWrap = actions[payloadType];
var actionInfo = actionWrap.actionInfo;
var cptType = (actionInfo.update || 'update').split(':');
var updateMethod = cptType.pop();
cptType = cptType[0] != null && parseClassType(cptType[0]);
this[IN_MAIN_PROCESS] = true;
var payloads = [payload];
var batched = false;
// Batch action
if (payload.batch) {
batched = true;
payloads = zrUtil.map(payload.batch, function (item) {
item = zrUtil.defaults(zrUtil.extend({}, item), payload);
item.batch = null;
return item;
});
}
var eventObjBatch = [];
var eventObj;
var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
each(payloads, function (batchItem) {
// Action can specify the event by return it.
eventObj = actionWrap.action(batchItem, this._model, this._api);
// Emit event outside
eventObj = eventObj || zrUtil.extend({}, batchItem);
// Convert type to eventType
eventObj.type = actionInfo.event || eventObj.type;