echarts.js 60.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// 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;
    }
}

L
tweak  
lang 已提交
15 16 17 18 19 20 21 22 23 24
/*!
 * ECharts, a javascript interactive chart library.
 *
 * Copyright (c) 2015, Baidu Inc.
 * All rights reserved.
 *
 * LICENSE
 * https://github.com/ecomfe/echarts/blob/master/LICENSE.txt
 */

L
lang 已提交
25
/**
L
lang 已提交
26
 * @module echarts
L
lang 已提交
27
 */
L
lang 已提交
28 29
define(function (require) {

30 31
    var env = require('zrender/core/env');

L
lang 已提交
32
    var GlobalModel = require('./model/Global');
L
lang 已提交
33
    var ExtensionAPI = require('./ExtensionAPI');
L
lang 已提交
34
    var CoordinateSystemManager = require('./CoordinateSystem');
P
pah100 已提交
35
    var OptionManager = require('./model/OptionManager');
L
lang 已提交
36

L
Update  
lang 已提交
37 38 39 40 41
    var ComponentModel = require('./model/Component');
    var SeriesModel = require('./model/Series');

    var ComponentView = require('./view/Component');
    var ChartView = require('./view/Chart');
L
lang 已提交
42
    var graphic = require('./util/graphic');
43
    var modelUtil = require('./util/model');
1
100pah 已提交
44
    var throttle = require('./util/throttle');
L
Update  
lang 已提交
45

L
lang 已提交
46
    var zrender = require('zrender');
L
lang 已提交
47
    var zrUtil = require('zrender/core/util');
L
lang 已提交
48
    var colorTool = require('zrender/tool/color');
L
lang 已提交
49
    var Eventful = require('zrender/mixin/Eventful');
L
lang 已提交
50
    var timsort = require('zrender/core/timsort');
L
lang 已提交
51

52
    var each = zrUtil.each;
53
    var parseClassType = ComponentModel.parseClassType;
54

55 56
    var PRIORITY_PROCESSOR_FILTER = 1000;
    var PRIORITY_PROCESSOR_STATISTIC = 5000;
57

58 59 60 61 62

    var PRIORITY_VISUAL_LAYOUT = 1000;
    var PRIORITY_VISUAL_GLOBAL = 2000;
    var PRIORITY_VISUAL_CHART = 3000;
    var PRIORITY_VISUAL_COMPONENT = 4000;
1
100pah 已提交
63 64
    // FIXME
    // necessary?
P
pah100 已提交
65
    var PRIORITY_VISUAL_BRUSH = 5000;
L
lang 已提交
66

67 68 69 70 71
    // 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]).
1
tweak  
100pah 已提交
72 73 74
    var IN_MAIN_PROCESS = '__flagInMainProcess';
    var HAS_GRADIENT_OR_PATTERN_BG = '__hasGradientOrPatternBg';
    var OPTION_UPDATED = '__optionUpdated';
1
100pah 已提交
75
    var ACTION_REG = /^[a-zA-Z0-9_]+$/;
76

77 78 79 80 81 82
    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);
        };
L
lang 已提交
83
    }
84

L
lang 已提交
85 86 87 88 89 90
    /**
     * @module echarts~MessageCenter
     */
    function MessageCenter() {
        Eventful.call(this);
    }
91 92 93
    MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
    MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
    MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
L
lang 已提交
94
    zrUtil.mixin(MessageCenter, Eventful);
95

L
lang 已提交
96 97 98
    /**
     * @module echarts~ECharts
     */
P
pah100 已提交
99
    function ECharts(dom, theme, opts) {
L
lang 已提交
100
        opts = opts || {};
L
lang 已提交
101

L
lang 已提交
102 103 104 105 106
        // Get theme by name
        if (typeof theme === 'string') {
            theme = themeStorage[theme];
        }

L
lang 已提交
107 108 109 110 111 112 113 114 115
        /**
         * @type {string}
         */
        this.id;
        /**
         * Group id
         * @type {string}
         */
        this.group;
L
lang 已提交
116
        /**
Z
zhuangzhuang 已提交
117
         * @type {HTMLElement}
L
lang 已提交
118 119 120
         * @private
         */
        this._dom = dom;
L
lang 已提交
121 122 123 124
        /**
         * @type {module:zrender/ZRender}
         * @private
         */
1
100pah 已提交
125
        var zr = this._zr = zrender.init(dom, {
126
            renderer: opts.renderer || 'canvas',
127 128 129
            devicePixelRatio: opts.devicePixelRatio,
            width: opts.width,
            height: opts.height
L
lang 已提交
130
        });
L
lang 已提交
131

1
100pah 已提交
132 133 134 135 136 137 138
        /**
         * Expect 60 pfs.
         * @type {Function}
         * @private
         */
        this._throttledZrFlush = throttle.throttle(zrUtil.bind(zr.flush, zr), 17);

L
lang 已提交
139 140 141 142
        /**
         * @type {Object}
         * @private
         */
L
lang 已提交
143
        this._theme = zrUtil.clone(theme);
L
lang 已提交
144

L
lang 已提交
145 146 147 148
        /**
         * @type {Array.<module:echarts/view/Chart>}
         * @private
         */
L
lang 已提交
149
        this._chartsViews = [];
L
lang 已提交
150 151 152 153 154

        /**
         * @type {Object.<string, module:echarts/view/Chart>}
         * @private
         */
L
lang 已提交
155 156
        this._chartsMap = {};

L
lang 已提交
157 158 159 160
        /**
         * @type {Array.<module:echarts/view/Component>}
         * @private
         */
L
lang 已提交
161
        this._componentsViews = [];
L
lang 已提交
162 163 164 165 166

        /**
         * @type {Object.<string, module:echarts/view/Component>}
         * @private
         */
L
lang 已提交
167 168
        this._componentsMap = {};

L
lang 已提交
169
        /**
P
pah100 已提交
170
         * @type {module:echarts/CoordinateSystem}
L
lang 已提交
171 172
         * @private
         */
P
pah100 已提交
173
        this._coordSysMgr = new CoordinateSystemManager();
L
lang 已提交
174

L
lang 已提交
175
        /**
P
pah100 已提交
176
         * @type {module:echarts/ExtensionAPI}
L
lang 已提交
177 178
         * @private
         */
179
        this._api = createExtensionAPI(this);
L
lang 已提交
180

L
lang 已提交
181 182
        Eventful.call(this);

L
lang 已提交
183 184 185 186 187 188
        /**
         * @type {module:echarts~MessageCenter}
         * @private
         */
        this._messageCenter = new MessageCenter();

L
lang 已提交
189 190
        // Init mouse events
        this._initEvents();
L
Resize  
lang 已提交
191 192 193

        // In case some people write `window.onresize = chart.resize`
        this.resize = zrUtil.bind(this.resize, this);
194

L
lang 已提交
195 196
        // Can't dispatch action during rendering procedure
        this._pendingActions = [];
197 198 199 200
        // Sort on demand
        function prioritySortFunc(a, b) {
            return a.prio - b.prio;
        }
L
lang 已提交
201 202
        timsort(visualFuncs, prioritySortFunc);
        timsort(dataProcessorFuncs, prioritySortFunc);
203

1
100pah 已提交
204
        zr.animation.on('frame', this._onframe, this);
205 206 207

        // ECharts instance can be used as value.
        zrUtil.setAsPrimitive(this);
L
lang 已提交
208
    }
L
lang 已提交
209

L
tweak  
lang 已提交
210
    var echartsProto = ECharts.prototype;
L
lang 已提交
211

212 213
    echartsProto._onframe = function () {
        // Lazy update
214
        if (this[OPTION_UPDATED]) {
215
            var silent = this[OPTION_UPDATED].silent;
216 217 218 219 220 221 222

            this[IN_MAIN_PROCESS] = true;

            updateMethods.prepareAndUpdate.call(this);

            this[IN_MAIN_PROCESS] = false;

223
            this[OPTION_UPDATED] = false;
224 225 226 227

            flushPendingActions.call(this, silent);

            triggerUpdatedEvent.call(this, silent);
228 229
        }
    };
230
    /**
Z
zhuangzhuang 已提交
231
     * @return {HTMLElement}
232
     */
L
tweak  
lang 已提交
233 234 235
    echartsProto.getDom = function () {
        return this._dom;
    };
L
lang 已提交
236

237 238 239
    /**
     * @return {module:zrender~ZRender}
     */
L
tweak  
lang 已提交
240 241 242
    echartsProto.getZr = function () {
        return this._zr;
    };
L
lang 已提交
243

244
    /**
245 246 247 248 249 250 251 252
     * Usage:
     * chart.setOption(option, notMerge, lazyUpdate);
     * chart.setOption(option, {
     *     notMerge: ...,
     *     lazyUpdate: ...,
     *     silent: ...
     * });
     *
253
     * @param {Object} option
254 255 256
     * @param {Object|boolean} [opts] opts or notMerge.
     * @param {boolean} [opts.notMerge=false]
     * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
257
     */
258
    echartsProto.setOption = function (option, notMerge, lazyUpdate) {
259 260 261 262
        if (__DEV__) {
            zrUtil.assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
        }

263 264 265 266 267 268 269
        var silent;
        if (zrUtil.isObject(notMerge)) {
            lazyUpdate = notMerge.lazyUpdate;
            silent = notMerge.silent;
            notMerge = notMerge.notMerge;
        }

P
pah100 已提交
270
        this[IN_MAIN_PROCESS] = true;
271

P
pah100 已提交
272
        if (!this._model || notMerge) {
L
lang 已提交
273 274 275 276
            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);
L
tweak  
lang 已提交
277
        }
L
lang 已提交
278

279
        this._model.setOption(option, optionPreprocessorFuncs);
P
pah100 已提交
280

281
        if (lazyUpdate) {
282 283
            this[OPTION_UPDATED] = {silent: silent};
            this[IN_MAIN_PROCESS] = false;
284 285 286
        }
        else {
            updateMethods.prepareAndUpdate.call(this);
287 288 289
            // Ensure zr refresh sychronously, and then pixel in canvas can be
            // fetched after `setOption`.
            this._zr.flush();
P
pah100 已提交
290

291 292
            this[OPTION_UPDATED] = false;
            this[IN_MAIN_PROCESS] = false;
L
lang 已提交
293

294 295 296
            flushPendingActions.call(this, silent);
            triggerUpdatedEvent.call(this, silent);
        }
P
pah100 已提交
297 298
    };

L
Tweak  
lang 已提交
299 300 301 302 303 304
    /**
     * @DEPRECATED
     */
    echartsProto.setTheme = function () {
        console.log('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
    };
P
pah100 已提交
305

L
tweak  
lang 已提交
306 307 308 309 310 311
    /**
     * @return {module:echarts/model/Global}
     */
    echartsProto.getModel = function () {
        return this._model;
    };
L
lang 已提交
312

L
lang 已提交
313 314 315 316
    /**
     * @return {Object}
     */
    echartsProto.getOption = function () {
317
        return this._model && this._model.getOption();
L
lang 已提交
318 319
    };

L
tweak  
lang 已提交
320 321 322 323 324 325
    /**
     * @return {number}
     */
    echartsProto.getWidth = function () {
        return this._zr.getWidth();
    };
L
lang 已提交
326

L
tweak  
lang 已提交
327 328 329 330 331 332
    /**
     * @return {number}
     */
    echartsProto.getHeight = function () {
        return this._zr.getHeight();
    };
L
lang 已提交
333

334 335 336 337 338 339 340
    /**
     * @return {number}
     */
    echartsProto.getDevicePixelRatio = function () {
        return this._zr.painter.dpr || window.devicePixelRatio || 1;
    };

L
lang 已提交
341 342 343 344 345 346 347 348 349 350
    /**
     * Get canvas which has all thing rendered
     * @param {Object} opts
     * @param {string} [opts.backgroundColor]
     */
    echartsProto.getRenderedCanvas = function (opts) {
        if (!env.canvasSupported) {
            return;
        }
        opts = opts || {};
351
        opts.pixelRatio = opts.pixelRatio || 1;
L
lang 已提交
352
        opts.backgroundColor = opts.backgroundColor
353
            || this._model.get('backgroundColor');
L
lang 已提交
354 355 356 357 358 359 360 361 362 363 364 365
        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']
366
     * @param {string} [opts.pixelRatio=1]
L
lang 已提交
367
     * @param {string} [opts.backgroundColor]
L
Tweak  
lang 已提交
368
     * @param {string} [opts.excludeComponents]
L
lang 已提交
369 370
     */
    echartsProto.getDataURL = function (opts) {
371 372
        opts = opts || {};
        var excludeComponents = opts.excludeComponents;
373 374 375
        var ecModel = this._model;
        var excludesComponentViews = [];
        var self = this;
376 377

        each(excludeComponents, function (componentType) {
378 379 380 381 382 383 384 385 386 387 388 389
            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(
L
lang 已提交
390 391
            'image/' + (opts && opts.type || 'png')
        );
392 393 394 395 396

        each(excludesComponentViews, function (view) {
            view.group.ignore = false;
        });
        return url;
L
lang 已提交
397 398 399 400 401 402 403
    };


    /**
     * @return {string}
     * @param {Object} opts
     * @param {string} [opts.type='png']
404
     * @param {string} [opts.pixelRatio=1]
L
lang 已提交
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
     * @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 = [];
421
            var dpr = (opts && opts.pixelRatio) || 1;
1
100pah 已提交
422 423

            zrUtil.each(instances, function (chart, id) {
L
lang 已提交
424
                if (chart.group === groupId) {
425 426 427
                    var canvas = chart.getRenderedCanvas(
                        zrUtil.clone(opts)
                    );
L
lang 已提交
428 429 430 431 432 433 434 435 436 437 438
                    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
                    });
                }
1
100pah 已提交
439
            });
L
lang 已提交
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

            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);
        }
    };
470

1
100pah 已提交
471
    /**
1
100pah 已提交
472
     * Convert from logical coordinate system to pixel coordinate system.
1
100pah 已提交
473 474
     * See CoordinateSystem#convertToPixel.
     * @param {string|Object} finder
1
100pah 已提交
475 476 477
     *        If string, e.g., 'geo', means {geoIndex: 0}.
     *        If Object, could contain some of these properties below:
     *        {
478 479 480 481 482 483
     *            seriesIndex / seriesId / seriesName,
     *            geoIndex / geoId, geoName,
     *            bmapIndex / bmapId / bmapName,
     *            xAxisIndex / xAxisId / xAxisName,
     *            yAxisIndex / yAxisId / yAxisName,
     *            gridIndex / gridId / gridName,
1
100pah 已提交
484 485
     *            ... (can be extended)
     *        }
1
100pah 已提交
486
     * @param {Array|number} value
1
100pah 已提交
487
     * @return {Array|number} result
1
100pah 已提交
488
     */
1
100pah 已提交
489
    echartsProto.convertToPixel = zrUtil.curry(doConvertPixel, 'convertToPixel');
1
100pah 已提交
490

1
100pah 已提交
491 492 493 494
    /**
     * Convert from pixel coordinate system to logical coordinate system.
     * See CoordinateSystem#convertFromPixel.
     * @param {string|Object} finder
1
100pah 已提交
495 496 497
     *        If string, e.g., 'geo', means {geoIndex: 0}.
     *        If Object, could contain some of these properties below:
     *        {
498 499 500 501 502 503
     *            seriesIndex / seriesId / seriesName,
     *            geoIndex / geoId / geoName,
     *            bmapIndex / bmapId / bmapName,
     *            xAxisIndex / xAxisId / xAxisName,
     *            yAxisIndex / yAxisId / yAxisName
     *            gridIndex / gridId / gridName,
1
100pah 已提交
504 505
     *            ... (can be extended)
     *        }
1
100pah 已提交
506 507 508
     * @param {Array|number} value
     * @return {Array|number} result
     */
1
100pah 已提交
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
    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:
     *        {
540 541 542 543
     *            seriesIndex / seriesId / seriesName,
     *            geoIndex / geoId / geoName,
     *            bmapIndex / bmapId / bmapName,
     *            xAxisIndex / xAxisId / xAxisName,
1
100pah 已提交
544
     *            yAxisIndex / yAxisId / yAxisName,
545
     *            gridIndex / gridId / gridName,
1
100pah 已提交
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
     *            ... (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;
1
100pah 已提交
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
    /**
     * 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);
    };

629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
    /**
     * 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];
    };

1
100pah 已提交
647

648
    var updateMethods = {
L
lang 已提交
649

650 651 652 653 654
        /**
         * @param {Object} payload
         * @private
         */
        update: function (payload) {
655
            // console.profile && console.profile('update');
L
lang 已提交
656

657
            var ecModel = this._model;
658 659
            var api = this._api;
            var coordSysMgr = this._coordSysMgr;
L
lang 已提交
660
            var zr = this._zr;
661 662 663 664
            // update before setOption
            if (!ecModel) {
                return;
            }
L
lang 已提交
665

666
            // Fixme First time update ?
667 668 669 670 671
            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.
P
pah100 已提交
672

673 674 675 676 677
            // 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);
L
lang 已提交
678

679
            stackSeriesData.call(this, ecModel);
L
lang 已提交
680

681
            coordSysMgr.update(ecModel, api);
L
lang 已提交
682

L
lang 已提交
683
            doVisualEncoding.call(this, ecModel, payload);
684

685
            doRender.call(this, ecModel, payload);
686

687
            // Set background
L
lang 已提交
688
            var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
689

L
lang 已提交
690
            var painter = zr.painter;
691
            // TODO all use clearColor ?
L
lang 已提交
692
            if (painter.isSingleCanvas && painter.isSingleCanvas()) {
L
lang 已提交
693
                zr.configLayer(0, {
L
lang 已提交
694 695 696 697
                    clearColor: backgroundColor
                });
            }
            else {
L
lang 已提交
698 699 700 701 702 703 704 705
                // In IE8
                if (!env.canvasSupported) {
                    var colorArr = colorTool.parse(backgroundColor);
                    backgroundColor = colorTool.stringify(colorArr, 'rgb');
                    if (colorArr[3] === 0) {
                        backgroundColor = 'transparent';
                    }
                }
L
lang 已提交
706
                if (backgroundColor.colorStops || backgroundColor.image) {
L
lang 已提交
707 708 709 710 711
                    // Gradient background
                    // FIXME Fixed layer?
                    zr.configLayer(0, {
                        clearColor: backgroundColor
                    });
L
lang 已提交
712 713 714
                    this[HAS_GRADIENT_OR_PATTERN_BG] = true;

                    this._dom.style.background = 'transparent';
L
lang 已提交
715 716
                }
                else {
L
lang 已提交
717
                    if (this[HAS_GRADIENT_OR_PATTERN_BG]) {
L
lang 已提交
718 719 720 721
                        zr.configLayer(0, {
                            clearColor: null
                        });
                    }
L
lang 已提交
722
                    this[HAS_GRADIENT_OR_PATTERN_BG] = false;
L
lang 已提交
723 724 725

                    this._dom.style.background = backgroundColor;
                }
L
lang 已提交
726
            }
L
lang 已提交
727

728 729 730 731
            each(postUpdateFuncs, function (func) {
                func(ecModel, api);
            });

732
            // console.profile && console.profileEnd('update');
733
        },
734

735 736 737 738 739 740
        /**
         * @param {Object} payload
         * @private
         */
        updateView: function (payload) {
            var ecModel = this._model;
741

742 743 744 745 746
            // update before setOption
            if (!ecModel) {
                return;
            }

P
pah100 已提交
747 748 749 750
            ecModel.eachSeries(function (seriesModel) {
                seriesModel.getData().clearAllVisual();
            });

751
            doVisualEncoding.call(this, ecModel, payload);
752

753 754
            invokeUpdateMethod.call(this, 'updateView', ecModel, payload);
        },
755

756 757 758 759 760 761
        /**
         * @param {Object} payload
         * @private
         */
        updateVisual: function (payload) {
            var ecModel = this._model;
762

763 764 765 766 767
            // update before setOption
            if (!ecModel) {
                return;
            }

P
pah100 已提交
768 769 770 771
            ecModel.eachSeries(function (seriesModel) {
                seriesModel.getData().clearAllVisual();
            });

1
100pah 已提交
772
            doVisualEncoding.call(this, ecModel, payload, true);
773

774 775
            invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
        },
776

777 778 779 780 781 782
        /**
         * @param {Object} payload
         * @private
         */
        updateLayout: function (payload) {
            var ecModel = this._model;
783

784 785 786 787 788
            // update before setOption
            if (!ecModel) {
                return;
            }

L
lang 已提交
789
            doLayout.call(this, ecModel, payload);
790

791 792
            invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
        },
L
lang 已提交
793

P
pah100 已提交
794 795
        /**
         * @param {Object} payload
P
pah100 已提交
796
         * @private
P
pah100 已提交
797
         */
P
pah100 已提交
798
        prepareAndUpdate: function (payload) {
P
pah100 已提交
799
            var ecModel = this._model;
800

P
pah100 已提交
801 802 803
            prepareView.call(this, 'component', ecModel);

            prepareView.call(this, 'chart', ecModel);
P
pah100 已提交
804

805
            updateMethods.update.call(this, payload);
P
pah100 已提交
806
        }
807 808 809 810 811
    };

    /**
     * @private
     */
1
tweak  
100pah 已提交
812
    function updateDirectly(ecIns, method, payload, mainType, subType) {
1
100pah 已提交
813
        var ecModel = ecIns._model;
P
pah100 已提交
814 815 816 817 818 819 820

        // broadcast
        if (!mainType) {
            each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
            return;
        }

1
tweak  
100pah 已提交
821 822 823 824
        var query = {};
        query[mainType + 'Id'] = payload[mainType + 'Id'];
        query[mainType + 'Index'] = payload[mainType + 'Index'];
        query[mainType + 'Name'] = payload[mainType + 'Name'];
825

1
100pah 已提交
826
        var condition = {mainType: mainType, query: query};
1
100pah 已提交
827
        subType && (condition.subType = subType); // subType may be '' by parseClassType;
1
100pah 已提交
828 829 830

        // If dispatchAction before setOption, do nothing.
        ecModel && ecModel.eachComponent(condition, function (model, index) {
P
pah100 已提交
831
            callView(ecIns[
1
100pah 已提交
832
                mainType === 'series' ? '_chartsMap' : '_componentsMap'
P
pah100 已提交
833
            ][model.__viewId]);
1
100pah 已提交
834
        }, ecIns);
P
pah100 已提交
835 836 837 838 839 840

        function callView(view) {
            view && view.__alive && view[method] && view[method](
                view.__model, ecModel, ecIns._api, payload
            );
        }
841
    }
842

L
Resize  
lang 已提交
843 844
    /**
     * Resize the chart
845 846 847
     * @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)
848
     * @param {boolean} [opts.silent=false]
L
Resize  
lang 已提交
849
     */
850
    echartsProto.resize = function (opts) {
851
        if (__DEV__) {
852
            zrUtil.assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
853 854
        }

P
pah100 已提交
855
        this[IN_MAIN_PROCESS] = true;
P
pah100 已提交
856

857
        this._zr.resize(opts);
P
pah100 已提交
858

P
pah100 已提交
859
        var optionChanged = this._model && this._model.resetOption('media');
860 861 862
        var updateMethod = optionChanged ? 'prepareAndUpdate' : 'update';

        updateMethods[updateMethod].call(this);
L
lang 已提交
863 864 865

        // Resize loading effect
        this._loadingFX && this._loadingFX.resize();
866

P
pah100 已提交
867
        this[IN_MAIN_PROCESS] = false;
L
lang 已提交
868

869 870 871 872 873
        var silent = opts && opts.silent;

        flushPendingActions.call(this, silent);

        triggerUpdatedEvent.call(this, silent);
L
lang 已提交
874 875 876 877 878 879 880 881 882 883
    };

    /**
     * Show loading effect
     * @param  {string} [name='default']
     * @param  {Object} [cfg]
     */
    echartsProto.showLoading = function (name, cfg) {
        if (zrUtil.isObject(name)) {
            cfg = name;
884
            name = '';
L
lang 已提交
885
        }
886 887
        name = name || 'default';

L
lang 已提交
888
        this.hideLoading();
L
lang 已提交
889 890 891 892 893 894 895
        if (!loadingEffects[name]) {
            if (__DEV__) {
                console.warn('Loading effects ' + name + ' not exists.');
            }
            return;
        }
        var el = loadingEffects[name](this._api, cfg);
L
lang 已提交
896
        var zr = this._zr;
L
lang 已提交
897
        this._loadingFX = el;
L
lang 已提交
898 899

        zr.add(el);
L
lang 已提交
900 901 902 903 904 905
    };

    /**
     * Hide loading effect
     */
    echartsProto.hideLoading = function () {
L
lang 已提交
906
        this._loadingFX && this._zr.remove(this._loadingFX);
L
lang 已提交
907
        this._loadingFX = null;
L
tweak  
lang 已提交
908
    };
P
pah100 已提交
909

L
lang 已提交
910
    /**
L
Resize  
lang 已提交
911 912
     * @param {Object} eventObj
     * @return {Object}
L
lang 已提交
913 914 915 916 917 918 919
     */
    echartsProto.makeActionFromEvent = function (eventObj) {
        var payload = zrUtil.extend({}, eventObj);
        payload.type = eventActionMap[eventObj.type];
        return payload;
    };

L
tweak  
lang 已提交
920 921 922 923
    /**
     * @pubilc
     * @param {Object} payload
     * @param {string} [payload.type] Action type
1
100pah 已提交
924 925 926 927 928 929 930
     * @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.
L
tweak  
lang 已提交
931
     */
1
100pah 已提交
932 933 934 935
    echartsProto.dispatchAction = function (payload, opt) {
        if (!zrUtil.isObject(opt)) {
            opt = {silent: !!opt};
        }
936

1
tweak  
100pah 已提交
937
        if (!actions[payload.type]) {
938 939
            return;
        }
L
lang 已提交
940

941 942 943 944 945
        // Avoid dispatch action before setOption. Especially in `connect`.
        if (!this._model) {
            return;
        }

L
lang 已提交
946 947 948 949
        // May dispatchAction in rendering procedure
        if (this[IN_MAIN_PROCESS]) {
            this._pendingActions.push(payload);
            return;
950 951
        }

1
100pah 已提交
952
        doDispatchAction.call(this, payload, opt.silent);
1
tweak  
100pah 已提交
953

1
100pah 已提交
954 955 956 957 958 959 960 961 962 963 964
        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();
        }
965

1
100pah 已提交
966
        flushPendingActions.call(this, opt.silent);
967 968

        triggerUpdatedEvent.call(this, opt.silent);
1
tweak  
100pah 已提交
969 970 971
    };

    function doDispatchAction(payload, silent) {
1
100pah 已提交
972
        var payloadType = payload.type;
P
pah100 已提交
973
        var escapeConnect = payload.escapeConnect;
1
100pah 已提交
974
        var actionWrap = actions[payloadType];
1
tweak  
100pah 已提交
975
        var actionInfo = actionWrap.actionInfo;
1
100pah 已提交
976

1
100pah 已提交
977 978
        var cptType = (actionInfo.update || 'update').split(':');
        var updateMethod = cptType.pop();
P
pah100 已提交
979
        cptType = cptType[0] != null && parseClassType(cptType[0]);
1
tweak  
100pah 已提交
980

981
        this[IN_MAIN_PROCESS] = true;
L
lang 已提交
982

983 984 985 986 987 988 989 990 991 992 993
        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;
            });
        }
P
pah100 已提交
994

995 996
        var eventObjBatch = [];
        var eventObj;
1
100pah 已提交
997 998
        var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';

P
pah100 已提交
999
        each(payloads, function (batchItem) {
1000
            // Action can specify the event by return it.
P
pah100 已提交
1001
            eventObj = actionWrap.action(batchItem, this._model, this._api);
1002 1003 1004 1005 1006 1007
            // Emit event outside
            eventObj = eventObj || zrUtil.extend({}, batchItem);
            // Convert type to eventType
            eventObj.type = actionInfo.event || eventObj.type;
            eventObjBatch.push(eventObj);

1
100pah 已提交
1008 1009 1010
            // light update does not perform data process, layout and visual.
            if (isHighDown) {
                // method, payload, mainType, subType
1
100pah 已提交
1011
                updateDirectly(this, updateMethod, batchItem, 'series');
1
100pah 已提交
1012
            }
1
100pah 已提交
1013
            else if (cptType) {
1
tweak  
100pah 已提交
1014
                updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
1
100pah 已提交
1015
            }
P
pah100 已提交
1016
        }, this);
1017

1
100pah 已提交
1018
        if (updateMethod !== 'none' && !isHighDown && !cptType) {
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
            // Still dirty
            if (this[OPTION_UPDATED]) {
                // FIXME Pass payload ?
                updateMethods.prepareAndUpdate.call(this, payload);
                this[OPTION_UPDATED] = false;
            }
            else {
                updateMethods[updateMethod].call(this, payload);
            }
        }
1029 1030 1031 1032

        // Follow the rule of action batch
        if (batched) {
            eventObj = {
1
100pah 已提交
1033
                type: actionInfo.event || payloadType,
P
pah100 已提交
1034
                escapeConnect: escapeConnect,
1035 1036 1037 1038 1039 1040 1041
                batch: eventObjBatch
            };
        }
        else {
            eventObj = eventObjBatch[0];
        }

1042 1043
        this[IN_MAIN_PROCESS] = false;

L
tweak  
lang 已提交
1044
        !silent && this._messageCenter.trigger(eventObj.type, eventObj);
1
tweak  
100pah 已提交
1045
    }
L
tweak  
lang 已提交
1046

1
tweak  
100pah 已提交
1047
    function flushPendingActions(silent) {
L
lang 已提交
1048 1049 1050
        var pendingActions = this._pendingActions;
        while (pendingActions.length) {
            var payload = pendingActions.shift();
1
tweak  
100pah 已提交
1051
            doDispatchAction.call(this, payload, silent);
L
lang 已提交
1052
        }
1
tweak  
100pah 已提交
1053
    }
L
lang 已提交
1054

1055 1056 1057 1058
    function triggerUpdatedEvent(silent) {
        !silent && this.trigger('updated');
    }

L
lang 已提交
1059 1060 1061 1062
    /**
     * Register event
     * @method
     */
1063 1064 1065
    echartsProto.on = createRegisterEventWithLowercaseName('on');
    echartsProto.off = createRegisterEventWithLowercaseName('off');
    echartsProto.one = createRegisterEventWithLowercaseName('one');
L
lang 已提交
1066

L
tweak  
lang 已提交
1067 1068 1069 1070
    /**
     * @param {string} methodName
     * @private
     */
1071
    function invokeUpdateMethod(methodName, ecModel, payload) {
1072
        var api = this._api;
L
lang 已提交
1073

L
tweak  
lang 已提交
1074
        // Update all components
L
lang 已提交
1075
        each(this._componentsViews, function (component) {
L
tweak  
lang 已提交
1076 1077
            var componentModel = component.__model;
            component[methodName](componentModel, ecModel, api, payload);
1078

L
tweak  
lang 已提交
1079 1080
            updateZ(componentModel, component);
        }, this);
L
lang 已提交
1081

L
tweak  
lang 已提交
1082 1083
        // Upate all charts
        ecModel.eachSeries(function (seriesModel, idx) {
L
lang 已提交
1084
            var chart = this._chartsMap[seriesModel.__viewId];
L
tweak  
lang 已提交
1085
            chart[methodName](seriesModel, ecModel, api, payload);
1086

L
tweak  
lang 已提交
1087
            updateZ(seriesModel, chart);
1088 1089

            updateProgressiveAndBlend(seriesModel, chart);
L
tweak  
lang 已提交
1090
        }, this);
1091

1092 1093
        // If use hover layer
        updateHoverLayerStatus(this._zr, ecModel);
1094 1095 1096 1097 1098

        // Post render
        each(postUpdateFuncs, function (func) {
            func(ecModel, api);
        });
1099
    }
L
lang 已提交
1100

L
lang 已提交
1101
    /**
L
Tweak  
lang 已提交
1102
     * Prepare view instances of charts and components
L
lang 已提交
1103 1104 1105
     * @param  {module:echarts/model/Global} ecModel
     * @private
     */
1106
    function prepareView(type, ecModel) {
L
Tweak  
lang 已提交
1107
        var isComponent = type === 'component';
L
lang 已提交
1108
        var viewList = isComponent ? this._componentsViews : this._chartsViews;
L
Tweak  
lang 已提交
1109
        var viewMap = isComponent ? this._componentsMap : this._chartsMap;
L
tweak  
lang 已提交
1110
        var zr = this._zr;
L
lang 已提交
1111

L
Tweak  
lang 已提交
1112
        for (var i = 0; i < viewList.length; i++) {
L
lang 已提交
1113
            viewList[i].__alive = false;
L
tweak  
lang 已提交
1114
        }
L
lang 已提交
1115

L
Tweak  
lang 已提交
1116 1117 1118 1119
        ecModel[isComponent ? 'eachComponent' : 'eachSeries'](function (componentType, model) {
            if (isComponent) {
                if (componentType === 'series') {
                    return;
L
lang 已提交
1120
                }
1121
            }
L
tweak  
lang 已提交
1122
            else {
L
Tweak  
lang 已提交
1123
                model = componentType;
L
tweak  
lang 已提交
1124 1125
            }

1126
            // Consider: id same and type changed.
1127
            var viewId = '_ec_' + model.id + '_' + model.type;
L
lang 已提交
1128
            var view = viewMap[viewId];
L
Tweak  
lang 已提交
1129
            if (!view) {
1130
                var classType = parseClassType(model.type);
L
Tweak  
lang 已提交
1131
                var Clazz = isComponent
L
tweak  
lang 已提交
1132
                    ? ComponentView.getClass(classType.main, classType.sub)
L
Tweak  
lang 已提交
1133
                    : ChartView.getClass(classType.sub);
L
tweak  
lang 已提交
1134
                if (Clazz) {
L
Tweak  
lang 已提交
1135 1136
                    view = new Clazz();
                    view.init(ecModel, this._api);
L
lang 已提交
1137
                    viewMap[viewId] = view;
L
Tweak  
lang 已提交
1138 1139 1140 1141 1142
                    viewList.push(view);
                    zr.add(view.group);
                }
                else {
                    // Error
L
lang 已提交
1143
                    return;
L
lang 已提交
1144
                }
1145
            }
L
Tweak  
lang 已提交
1146

1147
            model.__viewId = view.__id = viewId;
L
lang 已提交
1148
            view.__alive = true;
L
Tweak  
lang 已提交
1149
            view.__model = model;
1150 1151 1152 1153
            view.group.__ecComponentInfo = {
                mainType: model.mainType,
                index: model.componentIndex
            };
L
tweak  
lang 已提交
1154 1155
        }, this);

L
Tweak  
lang 已提交
1156 1157
        for (var i = 0; i < viewList.length;) {
            var view = viewList[i];
L
lang 已提交
1158
            if (!view.__alive) {
L
Tweak  
lang 已提交
1159
                zr.remove(view.group);
L
lang 已提交
1160
                view.dispose(ecModel, this._api);
L
Tweak  
lang 已提交
1161 1162
                viewList.splice(i, 1);
                delete viewMap[view.__id];
1163
                view.__id = view.group.__ecComponentInfo = null;
L
tweak  
lang 已提交
1164 1165 1166 1167 1168
            }
            else {
                i++;
            }
        }
1169 1170
    }

L
tweak  
lang 已提交
1171 1172 1173 1174 1175 1176
    /**
     * Processor data in each series
     *
     * @param {module:echarts/model/Global} ecModel
     * @private
     */
1177
    function processData(ecModel, api) {
1178 1179
        each(dataProcessorFuncs, function (process) {
            process.func(ecModel, api);
L
tweak  
lang 已提交
1180
        });
1181
    }
L
lang 已提交
1182

L
tweak  
lang 已提交
1183 1184 1185
    /**
     * @private
     */
1186
    function stackSeriesData(ecModel) {
L
tweak  
lang 已提交
1187 1188 1189 1190 1191 1192
        var stackedDataMap = {};
        ecModel.eachSeries(function (series) {
            var stack = series.get('stack');
            var data = series.getData();
            if (stack && data.type === 'list') {
                var previousStack = stackedDataMap[stack];
1193 1194
                // Avoid conflict with Object.prototype
                if (stackedDataMap.hasOwnProperty(stack) && previousStack) {
L
tweak  
lang 已提交
1195
                    data.stackedOn = previousStack;
L
lang 已提交
1196
                }
L
tweak  
lang 已提交
1197 1198 1199
                stackedDataMap[stack] = data;
            }
        });
1200
    }
L
lang 已提交
1201

L
tweak  
lang 已提交
1202
    /**
1203
     * Layout before each chart render there series, special visual encoding stage
L
tweak  
lang 已提交
1204 1205 1206 1207
     *
     * @param {module:echarts/model/Global} ecModel
     * @private
     */
L
lang 已提交
1208 1209
    function doLayout(ecModel, payload) {
        var api = this._api;
1210 1211 1212 1213
        each(visualFuncs, function (visual) {
            if (visual.isLayout) {
                visual.func(ecModel, api, payload);
            }
L
tweak  
lang 已提交
1214
        });
1215
    }
L
lang 已提交
1216

L
tweak  
lang 已提交
1217
    /**
1218
     * Encode visual infomation from data after data processing
L
tweak  
lang 已提交
1219 1220
     *
     * @param {module:echarts/model/Global} ecModel
1
100pah 已提交
1221 1222
     * @param {object} layout
     * @param {boolean} [excludesLayout]
L
tweak  
lang 已提交
1223 1224
     * @private
     */
1
100pah 已提交
1225
    function doVisualEncoding(ecModel, payload, excludesLayout) {
L
lang 已提交
1226
        var api = this._api;
L
lang 已提交
1227 1228 1229 1230
        ecModel.clearColorPalette();
        ecModel.eachSeries(function (seriesModel) {
            seriesModel.clearColorPalette();
        });
1231
        each(visualFuncs, function (visual) {
1
100pah 已提交
1232 1233
            (!excludesLayout || !visual.isLayout)
                && visual.func(ecModel, api, payload);
L
tweak  
lang 已提交
1234
        });
1235
    }
L
lang 已提交
1236

L
tweak  
lang 已提交
1237 1238 1239 1240
    /**
     * Render each chart and component
     * @private
     */
1241
    function doRender(ecModel, payload) {
1242
        var api = this._api;
L
tweak  
lang 已提交
1243
        // Render all components
L
lang 已提交
1244 1245 1246
        each(this._componentsViews, function (componentView) {
            var componentModel = componentView.__model;
            componentView.render(componentModel, ecModel, api, payload);
L
tweak  
lang 已提交
1247

L
lang 已提交
1248
            updateZ(componentModel, componentView);
L
tweak  
lang 已提交
1249 1250
        }, this);

L
lang 已提交
1251
        each(this._chartsViews, function (chart) {
L
lang 已提交
1252
            chart.__alive = false;
L
tweak  
lang 已提交
1253 1254 1255 1256
        }, this);

        // Render all charts
        ecModel.eachSeries(function (seriesModel, idx) {
L
lang 已提交
1257
            var chartView = this._chartsMap[seriesModel.__viewId];
L
lang 已提交
1258
            chartView.__alive = true;
L
lang 已提交
1259
            chartView.render(seriesModel, ecModel, api, payload);
L
tweak  
lang 已提交
1260

L
lang 已提交
1261 1262
            chartView.group.silent = !!seriesModel.get('silent');

L
lang 已提交
1263
            updateZ(seriesModel, chartView);
1264

1265
            updateProgressiveAndBlend(seriesModel, chartView);
L
lang 已提交
1266

L
tweak  
lang 已提交
1267 1268
        }, this);

L
lang 已提交
1269
        // If use hover layer
1270 1271
        updateHoverLayerStatus(this._zr, ecModel);

L
lang 已提交
1272
        // Remove groups of unrendered charts
L
lang 已提交
1273
        each(this._chartsViews, function (chart) {
L
lang 已提交
1274
            if (!chart.__alive) {
L
tweak  
lang 已提交
1275 1276 1277
                chart.remove(ecModel, api);
            }
        }, this);
1278
    }
L
lang 已提交
1279

L
lang 已提交
1280
    var MOUSE_EVENT_NAMES = [
1
100pah 已提交
1281 1282
        'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
        'mousedown', 'mouseup', 'globalout', 'contextmenu'
L
lang 已提交
1283 1284 1285 1286 1287 1288
    ];
    /**
     * @private
     */
    echartsProto._initEvents = function () {
        each(MOUSE_EVENT_NAMES, function (eveName) {
1289
            this._zr.on(eveName, function (e) {
L
lang 已提交
1290 1291
                var ecModel = this.getModel();
                var el = e.target;
1
100pah 已提交
1292
                var params;
1
100pah 已提交
1293

1
100pah 已提交
1294
                // no e.target when 'globalout'.
1
100pah 已提交
1295
                if (eveName === 'globalout') {
1
100pah 已提交
1296
                    params = {};
1
100pah 已提交
1297 1298
                }
                else if (el && el.dataIndex != null) {
L
lang 已提交
1299
                    var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
1
100pah 已提交
1300
                    params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType) || {};
L
lang 已提交
1301
                }
L
lang 已提交
1302 1303
                // If element has custom eventData of components
                else if (el && el.eventData) {
1
100pah 已提交
1304
                    params = zrUtil.extend({}, el.eventData);
L
lang 已提交
1305
                }
1
100pah 已提交
1306 1307 1308 1309 1310 1311 1312

                if (params) {
                    params.event = e;
                    params.type = eveName;
                    this.trigger(eveName, params);
                }

L
lang 已提交
1313 1314
            }, this);
        }, this);
L
lang 已提交
1315

L
lang 已提交
1316
        each(eventActionMap, function (actionType, eventType) {
L
lang 已提交
1317 1318 1319 1320
            this._messageCenter.on(eventType, function (event) {
                this.trigger(eventType, event);
            }, this);
        }, this);
L
lang 已提交
1321 1322
    };

L
lang 已提交
1323
    /**
L
lang 已提交
1324
     * @return {boolean}
L
lang 已提交
1325 1326 1327 1328
     */
    echartsProto.isDisposed = function () {
        return this._disposed;
    };
L
lang 已提交
1329 1330 1331 1332 1333

    /**
     * Clear
     */
    echartsProto.clear = function () {
1334
        this.setOption({ series: [] }, true);
L
lang 已提交
1335
    };
1336

L
lang 已提交
1337 1338 1339
    /**
     * Dispose instance
     */
L
tweak  
lang 已提交
1340
    echartsProto.dispose = function () {
1341 1342 1343 1344 1345 1346
        if (this._disposed) {
            if (__DEV__) {
                console.warn('Instance ' + this.id + ' has been disposed');
            }
            return;
        }
L
lang 已提交
1347
        this._disposed = true;
1348

L
lang 已提交
1349
        var api = this._api;
L
lang 已提交
1350
        var ecModel = this._model;
L
lang 已提交
1351

L
lang 已提交
1352
        each(this._componentsViews, function (component) {
L
lang 已提交
1353
            component.dispose(ecModel, api);
L
tweak  
lang 已提交
1354
        });
L
lang 已提交
1355
        each(this._chartsViews, function (chart) {
L
lang 已提交
1356
            chart.dispose(ecModel, api);
L
tweak  
lang 已提交
1357
        });
L
lang 已提交
1358

1359
        // Dispose after all views disposed
L
Tweak  
lang 已提交
1360
        this._zr.dispose();
L
lang 已提交
1361

L
lang 已提交
1362
        delete instances[this.id];
L
lang 已提交
1363 1364
    };

L
lang 已提交
1365 1366
    zrUtil.mixin(ECharts, Eventful);

1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382
    function updateHoverLayerStatus(zr, ecModel) {
        var storage = zr.storage;
        var elCount = 0;
        storage.traverse(function (el) {
            if (!el.isGroup) {
                elCount++;
            }
        });
        if (elCount > ecModel.get('hoverLayerThreshold') && !env.node) {
            storage.traverse(function (el) {
                if (!el.isGroup) {
                    el.useHoverLayer = true;
                }
            });
        }
    }
1383

1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425
    /**
     * Update chart progressive and blend.
     * @param {module:echarts/model/Series|module:echarts/model/Component} model
     * @param {module:echarts/view/Component|module:echarts/view/Chart} view
     */
    function updateProgressiveAndBlend(seriesModel, chartView) {
        // Progressive configuration
        var elCount = 0;
        chartView.group.traverse(function (el) {
            if (el.type !== 'group' && !el.ignore) {
                elCount++;
            }
        });
        var frameDrawNum = +seriesModel.get('progressive');
        var needProgressive = elCount > seriesModel.get('progressiveThreshold') && frameDrawNum && !env.node;
        if (needProgressive) {
            chartView.group.traverse(function (el) {
                // FIXME marker and other components
                if (!el.isGroup) {
                    el.progressive = needProgressive ?
                        Math.floor(elCount++ / frameDrawNum) : -1;
                    if (needProgressive) {
                        el.stopAnimation(true);
                    }
                }
            });
        }

        // Blend configration
        var blendMode = seriesModel.get('blendMode') || null;
        if (__DEV__) {
            if (!env.canvasSupported && blendMode && blendMode !== 'source-over') {
                console.warn('Only canvas support blendMode');
            }
        }
        chartView.group.traverse(function (el) {
            // FIXME marker and other components
            if (!el.isGroup) {
                el.setStyle('blend', blendMode);
            }
        });
    }
1426

L
lang 已提交
1427 1428 1429 1430 1431 1432 1433 1434 1435
    /**
     * @param {module:echarts/model/Series|module:echarts/model/Component} model
     * @param {module:echarts/view/Component|module:echarts/view/Chart} view
     */
    function updateZ(model, view) {
        var z = model.get('z');
        var zlevel = model.get('zlevel');
        // Set z and zlevel
        view.group.traverse(function (el) {
1436 1437 1438 1439
            if (el.type !== 'group') {
                z != null && (el.z = z);
                zlevel != null && (el.zlevel = zlevel);
            }
L
lang 已提交
1440 1441
        });
    }
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461

    function createExtensionAPI(ecInstance) {
        var coordSysMgr = ecInstance._coordSysMgr;
        return zrUtil.extend(new ExtensionAPI(ecInstance), {
            // Inject methods
            getCoordinateSystems: zrUtil.bind(
                coordSysMgr.getCoordinateSystems, coordSysMgr
            ),
            getComponentByElement: function (el) {
                while (el) {
                    var modelInfo = el.__ecComponentInfo;
                    if (modelInfo != null) {
                        return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
                    }
                    el = el.parent;
                }
            }
        });
    }

L
lang 已提交
1462
    /**
1463
     * @type {Object} key: actionType.
L
lang 已提交
1464 1465
     * @inner
     */
1466
    var actions = {};
P
pah100 已提交
1467

L
lang 已提交
1468
    /**
L
lang 已提交
1469
     * Map eventType to actionType
L
lang 已提交
1470 1471 1472 1473
     * @type {Object}
     */
    var eventActionMap = {};

L
lang 已提交
1474 1475 1476 1477 1478
    /**
     * Data processor functions of each stage
     * @type {Array.<Object.<string, Function>>}
     * @inner
     */
1479
    var dataProcessorFuncs = [];
L
lang 已提交
1480

1481 1482 1483 1484 1485 1486
    /**
     * @type {Array.<Function>}
     * @inner
     */
    var optionPreprocessorFuncs = [];

1487 1488 1489 1490 1491 1492
    /**
     * @type {Array.<Function>}
     * @inner
     */
    var postUpdateFuncs = [];

L
lang 已提交
1493
    /**
1494
     * Visual encoding functions of each stage
L
lang 已提交
1495 1496 1497
     * @type {Array.<Object.<string, Function>>}
     * @inner
     */
1498
    var visualFuncs = [];
L
lang 已提交
1499 1500 1501 1502 1503
    /**
     * Theme storage
     * @type {Object.<key, Object>}
     */
    var themeStorage = {};
L
lang 已提交
1504 1505 1506 1507
    /**
     * Loading effects
     */
    var loadingEffects = {};
L
lang 已提交
1508

L
lang 已提交
1509

L
lang 已提交
1510 1511 1512 1513 1514 1515
    var instances = {};
    var connectedGroups = {};

    var idBase = new Date() - 0;
    var groupIdBase = new Date() - 0;
    var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
P
pah100 已提交
1516

L
lang 已提交
1517
    /**
L
lang 已提交
1518
     * @alias module:echarts
L
lang 已提交
1519
     */
L
lang 已提交
1520 1521 1522 1523
    var echarts = {
        /**
         * @type {number}
         */
P
pah100 已提交
1524
        version: '3.6.2',
L
lang 已提交
1525
        dependencies: {
P
pah100 已提交
1526
            zrender: '3.5.2'
L
lang 已提交
1527 1528
        }
    };
L
lang 已提交
1529

L
lang 已提交
1530 1531 1532 1533 1534
    function enableConnect(chart) {
        var STATUS_PENDING = 0;
        var STATUS_UPDATING = 1;
        var STATUS_UPDATED = 2;
        var STATUS_KEY = '__connectUpdateStatus';
P
pah100 已提交
1535

L
lang 已提交
1536 1537 1538 1539 1540 1541
        function updateConnectedChartsStatus(charts, status) {
            for (var i = 0; i < charts.length; i++) {
                var otherChart = charts[i];
                otherChart[STATUS_KEY] = status;
            }
        }
P
pah100 已提交
1542

L
lang 已提交
1543 1544 1545
        zrUtil.each(eventActionMap, function (actionType, eventType) {
            chart._messageCenter.on(eventType, function (event) {
                if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
P
pah100 已提交
1546 1547 1548 1549
                    if (event && event.escapeConnect) {
                        return;
                    }

L
lang 已提交
1550 1551
                    var action = chart.makeActionFromEvent(event);
                    var otherCharts = [];
1
100pah 已提交
1552 1553

                    zrUtil.each(instances, function (otherChart) {
L
lang 已提交
1554 1555 1556
                        if (otherChart !== chart && otherChart.group === chart.group) {
                            otherCharts.push(otherChart);
                        }
1
100pah 已提交
1557 1558
                    });

L
lang 已提交
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
                    updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
                    each(otherCharts, function (otherChart) {
                        if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
                            otherChart.dispatchAction(action);
                        }
                    });
                    updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
                }
            });
        });
    }
P
pah100 已提交
1570

L
tweak  
lang 已提交
1571
    /**
Z
zhuangzhuang 已提交
1572
     * @param {HTMLElement} dom
L
tweak  
lang 已提交
1573 1574
     * @param {Object} [theme]
     * @param {Object} opts
1575 1576 1577 1578 1579 1580
     * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
     * @param {string} [opts.renderer] Currently only 'canvas' is supported.
     * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
     *                              Can be 'auto' (the same as null/undefined)
     * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
     *                               Can be 'auto' (the same as null/undefined)
L
tweak  
lang 已提交
1581 1582
     */
    echarts.init = function (dom, theme, opts) {
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592
        if (__DEV__) {
            // Check version
            if ((zrender.version.replace('.', '') - 0) < (echarts.dependencies.zrender.replace('.', '') - 0)) {
                throw new Error(
                    'ZRender ' + zrender.version
                    + ' is too old for ECharts ' + echarts.version
                    + '. Current version need ZRender '
                    + echarts.dependencies.zrender + '+'
                );
            }
P
pah100 已提交
1593

1594 1595 1596
            if (!dom) {
                throw new Error('Initialize failed: invalid dom.');
            }
P
pah100 已提交
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607
        }

        var existInstance = echarts.getInstanceByDom(dom);
        if (existInstance) {
            if (__DEV__) {
                console.warn('There is a chart instance already initialized on the dom.');
            }
            return existInstance;
        }

        if (__DEV__) {
1608 1609 1610 1611 1612 1613 1614
            if (zrUtil.isDom(dom)
                && dom.nodeName.toUpperCase() !== 'CANVAS'
                && (
                    (!dom.clientWidth && (!opts || opts.width == null))
                    || (!dom.clientHeight && (!opts || opts.height == null))
                )
            ) {
L
lang 已提交
1615
                console.warn('Can\'t get dom width or height');
1616
            }
1617
        }
L
lang 已提交
1618 1619

        var chart = new ECharts(dom, theme, opts);
L
lang 已提交
1620
        chart.id = 'ec_' + idBase++;
L
lang 已提交
1621 1622
        instances[chart.id] = chart;

P
pissang 已提交
1623 1624 1625 1626 1627 1628
        if (dom.setAttribute) {
            dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);
        }
        else {
            dom[DOM_ATTRIBUTE_KEY] = chart.id;
        }
L
lang 已提交
1629

L
lang 已提交
1630
        enableConnect(chart);
L
lang 已提交
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648

        return chart;
    };

    /**
     * @return {string|Array.<module:echarts~ECharts>} groupId
     */
    echarts.connect = function (groupId) {
        // Is array of charts
        if (zrUtil.isArray(groupId)) {
            var charts = groupId;
            groupId = null;
            // If any chart has group
            zrUtil.each(charts, function (chart) {
                if (chart.group != null) {
                    groupId = chart.group;
                }
            });
L
lang 已提交
1649
            groupId = groupId || ('g_' + groupIdBase++);
L
lang 已提交
1650 1651 1652 1653 1654 1655 1656 1657 1658
            zrUtil.each(charts, function (chart) {
                chart.group = groupId;
            });
        }
        connectedGroups[groupId] = true;
        return groupId;
    };

    /**
L
lang 已提交
1659
     * @DEPRECATED
L
lang 已提交
1660 1661 1662 1663 1664 1665
     * @return {string} groupId
     */
    echarts.disConnect = function (groupId) {
        connectedGroups[groupId] = false;
    };

L
lang 已提交
1666 1667 1668 1669 1670
    /**
     * @return {string} groupId
     */
    echarts.disconnect = echarts.disConnect;

L
lang 已提交
1671 1672 1673 1674 1675
    /**
     * Dispose a chart instance
     * @param  {module:echarts~ECharts|HTMLDomElement|string} chart
     */
    echarts.dispose = function (chart) {
P
pissang 已提交
1676
        if (typeof chart === 'string') {
L
lang 已提交
1677 1678
            chart = instances[chart];
        }
P
pissang 已提交
1679 1680 1681 1682
        else if (!(chart instanceof ECharts)){
            // Try to treat as dom
            chart = echarts.getInstanceByDom(chart);
        }
L
lang 已提交
1683 1684 1685 1686 1687 1688
        if ((chart instanceof ECharts) && !chart.isDisposed()) {
            chart.dispose();
        }
    };

    /**
Z
zhuangzhuang 已提交
1689
     * @param  {HTMLElement} dom
L
lang 已提交
1690 1691 1692
     * @return {echarts~ECharts}
     */
    echarts.getInstanceByDom = function (dom) {
P
pissang 已提交
1693 1694 1695 1696 1697 1698 1699
        var key;
        if (dom.getAttribute) {
            key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
        }
        else {
            key = dom[DOM_ATTRIBUTE_KEY];
        }
L
lang 已提交
1700 1701
        return instances[key];
    };
P
pah100 已提交
1702

L
lang 已提交
1703 1704 1705 1706 1707 1708
    /**
     * @param {string} key
     * @return {echarts~ECharts}
     */
    echarts.getInstanceById = function (key) {
        return instances[key];
L
tweak  
lang 已提交
1709
    };
L
lang 已提交
1710

L
lang 已提交
1711 1712 1713 1714 1715 1716 1717
    /**
     * Register theme
     */
    echarts.registerTheme = function (name, theme) {
        themeStorage[name] = theme;
    };

L
tweak  
lang 已提交
1718 1719 1720 1721 1722 1723 1724
    /**
     * Register option preprocessor
     * @param {Function} preprocessorFunc
     */
    echarts.registerPreprocessor = function (preprocessorFunc) {
        optionPreprocessorFuncs.push(preprocessorFunc);
    };
1725

L
tweak  
lang 已提交
1726
    /**
1727
     * @param {number} [priority=1000]
L
tweak  
lang 已提交
1728 1729
     * @param {Function} processorFunc
     */
1730 1731 1732 1733
    echarts.registerProcessor = function (priority, processorFunc) {
        if (typeof priority === 'function') {
            processorFunc = priority;
            priority = PRIORITY_PROCESSOR_FILTER;
L
tweak  
lang 已提交
1734
        }
1735 1736 1737 1738
        if (__DEV__) {
            if (isNaN(priority)) {
                throw new Error('Unkown processor priority');
            }
1739 1740 1741 1742 1743
        }
        dataProcessorFuncs.push({
            prio: priority,
            func: processorFunc
        });
L
tweak  
lang 已提交
1744
    };
L
lang 已提交
1745

1746 1747 1748 1749 1750 1751 1752 1753
    /**
     * Register postUpdater
     * @param {Function} postUpdateFunc
     */
    echarts.registerPostUpdate = function (postUpdateFunc) {
        postUpdateFuncs.push(postUpdateFunc);
    };

L
tweak  
lang 已提交
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764
    /**
     * Usage:
     * registerAction('someAction', 'someEvent', function () { ... });
     * registerAction('someAction', function () { ... });
     * registerAction(
     *     {type: 'someAction', event: 'someEvent', update: 'updateView'},
     *     function () { ... }
     * );
     *
     * @param {(string|Object)} actionInfo
     * @param {string} actionInfo.type
L
lang 已提交
1765 1766 1767 1768
     * @param {string} [actionInfo.event]
     * @param {string} [actionInfo.update]
     * @param {string} [eventName]
     * @param {Function} action
L
tweak  
lang 已提交
1769
     */
L
lang 已提交
1770 1771 1772 1773 1774
    echarts.registerAction = function (actionInfo, eventName, action) {
        if (typeof eventName === 'function') {
            action = eventName;
            eventName = '';
        }
L
tweak  
lang 已提交
1775 1776
        var actionType = zrUtil.isObject(actionInfo)
            ? actionInfo.type
L
lang 已提交
1777 1778 1779
            : ([actionInfo, actionInfo = {
                event: eventName
            }][0]);
L
lang 已提交
1780

L
lang 已提交
1781 1782
        // Event name is all lowercase
        actionInfo.event = (actionInfo.event || actionType).toLowerCase();
L
lang 已提交
1783
        eventName = actionInfo.event;
1784

1
100pah 已提交
1785 1786 1787
        // Validate action type and event name.
        zrUtil.assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));

L
tweak  
lang 已提交
1788 1789 1790
        if (!actions[actionType]) {
            actions[actionType] = {action: action, actionInfo: actionInfo};
        }
L
lang 已提交
1791
        eventActionMap[eventName] = actionType;
L
tweak  
lang 已提交
1792
    };
P
pah100 已提交
1793

L
tweak  
lang 已提交
1794 1795 1796 1797 1798 1799 1800
    /**
     * @param {string} type
     * @param {*} CoordinateSystem
     */
    echarts.registerCoordinateSystem = function (type, CoordinateSystem) {
        CoordinateSystemManager.register(type, CoordinateSystem);
    };
L
lang 已提交
1801

1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815
    /**
     * Get dimensions of specified coordinate system.
     * @param {string} type
     * @return {Array.<string|Object>}
     */
    echarts.getCoordinateSystemDimensions = function (type) {
        var coordSysCreator = CoordinateSystemManager.get(type);
        if (coordSysCreator) {
            return coordSysCreator.getDimensionsInfo
                    ? coordSysCreator.getDimensionsInfo()
                    : coordSysCreator.dimensions.slice();
        }
    };

L
tweak  
lang 已提交
1816
    /**
1817 1818 1819 1820
     * Layout is a special stage of visual encoding
     * Most visual encoding like color are common for different chart
     * But each chart has it's own layout algorithm
     *
L
lang 已提交
1821
     * @param {number} [priority=1000]
1822
     * @param {Function} layoutFunc
L
tweak  
lang 已提交
1823
     */
1824 1825 1826 1827 1828
    echarts.registerLayout = function (priority, layoutFunc) {
        if (typeof priority === 'function') {
            layoutFunc = priority;
            priority = PRIORITY_VISUAL_LAYOUT;
        }
1829 1830 1831 1832
        if (__DEV__) {
            if (isNaN(priority)) {
                throw new Error('Unkown layout priority');
            }
L
tweak  
lang 已提交
1833
        }
1834 1835 1836 1837 1838
        visualFuncs.push({
            prio: priority,
            func: layoutFunc,
            isLayout: true
        });
L
tweak  
lang 已提交
1839
    };
L
lang 已提交
1840

L
tweak  
lang 已提交
1841
    /**
L
lang 已提交
1842
     * @param {number} [priority=3000]
1843
     * @param {Function} visualFunc
L
tweak  
lang 已提交
1844
     */
1845 1846 1847 1848
    echarts.registerVisual = function (priority, visualFunc) {
        if (typeof priority === 'function') {
            visualFunc = priority;
            priority = PRIORITY_VISUAL_CHART;
L
tweak  
lang 已提交
1849
        }
1850 1851 1852 1853
        if (__DEV__) {
            if (isNaN(priority)) {
                throw new Error('Unkown visual priority');
            }
1854 1855 1856 1857 1858
        }
        visualFuncs.push({
            prio: priority,
            func: visualFunc
        });
L
tweak  
lang 已提交
1859
    };
L
Update  
lang 已提交
1860

L
lang 已提交
1861 1862 1863 1864 1865 1866 1867
    /**
     * @param {string} name
     */
    echarts.registerLoading = function (name, loadingFx) {
        loadingEffects[name] = loadingFx;
    };

L
tweak  
lang 已提交
1868 1869
    /**
     * @param {Object} opts
L
lang 已提交
1870
     * @param {string} [superClass]
L
tweak  
lang 已提交
1871
     */
1872 1873 1874 1875 1876 1877 1878
    echarts.extendComponentModel = function (opts/*, superClass*/) {
        // var Clazz = ComponentModel;
        // if (superClass) {
        //     var classType = parseClassType(superClass);
        //     Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
        // }
        return ComponentModel.extend(opts);
L
tweak  
lang 已提交
1879
    };
L
Update  
lang 已提交
1880

L
tweak  
lang 已提交
1881 1882
    /**
     * @param {Object} opts
L
lang 已提交
1883
     * @param {string} [superClass]
L
tweak  
lang 已提交
1884
     */
1885 1886 1887 1888 1889 1890 1891
    echarts.extendComponentView = function (opts/*, superClass*/) {
        // var Clazz = ComponentView;
        // if (superClass) {
        //     var classType = parseClassType(superClass);
        //     Clazz = ComponentView.getClass(classType.main, classType.sub, true);
        // }
        return ComponentView.extend(opts);
L
tweak  
lang 已提交
1892
    };
L
Update  
lang 已提交
1893

L
tweak  
lang 已提交
1894 1895
    /**
     * @param {Object} opts
L
lang 已提交
1896
     * @param {string} [superClass]
L
tweak  
lang 已提交
1897
     */
1898 1899 1900 1901 1902 1903 1904 1905
    echarts.extendSeriesModel = function (opts/*, superClass*/) {
        // var Clazz = SeriesModel;
        // if (superClass) {
        //     superClass = 'series.' + superClass.replace('series.', '');
        //     var classType = parseClassType(superClass);
        //     Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
        // }
        return SeriesModel.extend(opts);
L
tweak  
lang 已提交
1906
    };
P
pah100 已提交
1907

L
tweak  
lang 已提交
1908 1909
    /**
     * @param {Object} opts
L
lang 已提交
1910
     * @param {string} [superClass]
L
tweak  
lang 已提交
1911
     */
1912 1913 1914 1915 1916 1917 1918 1919
    echarts.extendChartView = function (opts/*, superClass*/) {
        // var Clazz = ChartView;
        // if (superClass) {
        //     superClass = superClass.replace('series.', '');
        //     var classType = parseClassType(superClass);
        //     Clazz = ChartView.getClass(classType.main, true);
        // }
        return ChartView.extend(opts);
L
lang 已提交
1920 1921
    };

1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
    /**
     * ZRender need a canvas context to do measureText.
     * But in node environment canvas may be created by node-canvas.
     * So we need to specify how to create a canvas instead of using document.createElement('canvas')
     *
     * Be careful of using it in the browser.
     *
     * @param {Function} creator
     * @example
     *     var Canvas = require('canvas');
     *     var echarts = require('echarts');
     *     echarts.setCanvasCreator(function () {
     *         // Small size is enough.
     *         return new Canvas(32, 32);
     *     });
     */
    echarts.setCanvasCreator = function (creator) {
        zrUtil.createCanvas = creator;
    };

L
lang 已提交
1942
    echarts.registerVisual(PRIORITY_VISUAL_GLOBAL, require('./visual/seriesColor'));
1943
    echarts.registerPreprocessor(require('./preprocessor/backwardCompat'));
L
lang 已提交
1944
    echarts.registerLoading('default', require('./loading/default'));
1945

1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957
    // Default action
    echarts.registerAction({
        type: 'highlight',
        event: 'highlight',
        update: 'highlight'
    }, zrUtil.noop);
    echarts.registerAction({
        type: 'downplay',
        event: 'downplay',
        update: 'downplay'
    }, zrUtil.noop);

P
pah100 已提交
1958 1959 1960 1961

    // --------
    // Exports
    // --------
L
lang 已提交
1962 1963
    echarts.zrender = zrender;

L
lang 已提交
1964 1965
    echarts.List = require('./data/List');
    echarts.Model = require('./model/Model');
P
pah100 已提交
1966

L
lang 已提交
1967 1968
    echarts.Axis = require('./coord/Axis');

L
lang 已提交
1969 1970 1971
    echarts.graphic = require('./util/graphic');
    echarts.number = require('./util/number');
    echarts.format = require('./util/format');
1
100pah 已提交
1972
    echarts.throttle = throttle.throttle;
L
lang 已提交
1973 1974
    echarts.matrix = require('zrender/core/matrix');
    echarts.vector = require('zrender/core/vector');
L
lang 已提交
1975
    echarts.color = require('zrender/tool/color');
P
pah100 已提交
1976 1977 1978

    echarts.util = {};
    each([
1979 1980
            'map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter',
            'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction',
1981
            'extend', 'defaults', 'clone', 'merge'
P
pah100 已提交
1982 1983 1984 1985 1986 1987
        ],
        function (name) {
            echarts.util[name] = zrUtil[name];
        }
    );

1988 1989
    echarts.helper = require('./helper');

L
lang 已提交
1990

1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
    // PRIORITY
    echarts.PRIORITY = {
        PROCESSOR: {
            FILTER: PRIORITY_PROCESSOR_FILTER,
            STATISTIC: PRIORITY_PROCESSOR_STATISTIC
        },
        VISUAL: {
            LAYOUT: PRIORITY_VISUAL_LAYOUT,
            GLOBAL: PRIORITY_VISUAL_GLOBAL,
            CHART: PRIORITY_VISUAL_CHART,
P
pah100 已提交
2001
            COMPONENT: PRIORITY_VISUAL_COMPONENT,
P
pah100 已提交
2002
            BRUSH: PRIORITY_VISUAL_BRUSH
2003 2004 2005
        }
    };

L
lang 已提交
2006 2007
    return echarts;
});