echarts.js 58.2 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
     */
L
lang 已提交
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 117 118 119 120
        /**
         * @type {HTMLDomElement}
         * @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
        /**
L
lang 已提交
170
         * @type {module:echarts/ExtensionAPI}
L
lang 已提交
171 172
         * @private
         */
173
        this._api = new ExtensionAPI(this);
L
lang 已提交
174

L
lang 已提交
175 176 177 178
        /**
         * @type {module:echarts/CoordinateSystem}
         * @private
         */
179
        this._coordSysMgr = new CoordinateSystemManager();
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);
L
lang 已提交
205
    }
L
lang 已提交
206

L
tweak  
lang 已提交
207
    var echartsProto = ECharts.prototype;
L
lang 已提交
208

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

            this[IN_MAIN_PROCESS] = true;

            updateMethods.prepareAndUpdate.call(this);

            this[IN_MAIN_PROCESS] = false;

220
            this[OPTION_UPDATED] = false;
221 222 223 224

            flushPendingActions.call(this, silent);

            triggerUpdatedEvent.call(this, silent);
225 226
        }
    };
227 228 229
    /**
     * @return {HTMLDomElement}
     */
L
tweak  
lang 已提交
230 231 232
    echartsProto.getDom = function () {
        return this._dom;
    };
L
lang 已提交
233

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

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

260 261 262 263 264 265 266
        var silent;
        if (zrUtil.isObject(notMerge)) {
            lazyUpdate = notMerge.lazyUpdate;
            silent = notMerge.silent;
            notMerge = notMerge.notMerge;
        }

P
pah100 已提交
267
        this[IN_MAIN_PROCESS] = true;
268

P
pah100 已提交
269
        if (!this._model || notMerge) {
L
lang 已提交
270 271 272 273
            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 已提交
274
        }
L
lang 已提交
275

1
100pah 已提交
276 277 278 279 280 281 282
        // FIXME
        // ugly
        this.__lastOnlyGraphic = !!(option && option.graphic);
        zrUtil.each(option, function (o, mainType) {
            mainType !== 'graphic' && (this.__lastOnlyGraphic = false);
        }, this);

P
pah100 已提交
283
        this._model.setOption(option, optionPreprocessorFuncs);
P
pah100 已提交
284

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

295 296
            this[OPTION_UPDATED] = false;
            this[IN_MAIN_PROCESS] = false;
L
lang 已提交
297

298 299 300
            flushPendingActions.call(this, silent);
            triggerUpdatedEvent.call(this, silent);
        }
P
pah100 已提交
301 302
    };

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

L
tweak  
lang 已提交
310 311 312 313 314 315
    /**
     * @return {module:echarts/model/Global}
     */
    echartsProto.getModel = function () {
        return this._model;
    };
L
lang 已提交
316

L
lang 已提交
317 318 319 320
    /**
     * @return {Object}
     */
    echartsProto.getOption = function () {
321
        return this._model && this._model.getOption();
L
lang 已提交
322 323
    };

L
tweak  
lang 已提交
324 325 326 327 328 329
    /**
     * @return {number}
     */
    echartsProto.getWidth = function () {
        return this._zr.getWidth();
    };
L
lang 已提交
330

L
tweak  
lang 已提交
331 332 333 334 335 336
    /**
     * @return {number}
     */
    echartsProto.getHeight = function () {
        return this._zr.getHeight();
    };
L
lang 已提交
337

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

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

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


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

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

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

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

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

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
    /**
     * 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 已提交
644

645
    var updateMethods = {
L
lang 已提交
646

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

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

663
            // Fixme First time update ?
664 665 666 667 668
            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 已提交
669

670 671 672 673 674
            // 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 已提交
675

676
            stackSeriesData.call(this, ecModel);
L
lang 已提交
677

678
            coordSysMgr.update(ecModel, api);
L
lang 已提交
679

L
lang 已提交
680
            doVisualEncoding.call(this, ecModel, payload);
681

682
            doRender.call(this, ecModel, payload);
683

684
            // Set background
L
lang 已提交
685
            var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
686

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

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

                    this._dom.style.background = backgroundColor;
                }
L
lang 已提交
723
            }
L
lang 已提交
724

725 726 727 728
            each(postUpdateFuncs, function (func) {
                func(ecModel, api);
            });

729
            // console.profile && console.profileEnd('update');
730
        },
731

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

739 740 741 742 743
            // update before setOption
            if (!ecModel) {
                return;
            }

P
pah100 已提交
744 745 746 747
            ecModel.eachSeries(function (seriesModel) {
                seriesModel.getData().clearAllVisual();
            });

748
            doVisualEncoding.call(this, ecModel, payload);
749

750 751
            invokeUpdateMethod.call(this, 'updateView', ecModel, payload);
        },
752

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

760 761 762 763 764
            // update before setOption
            if (!ecModel) {
                return;
            }

P
pah100 已提交
765 766 767 768
            ecModel.eachSeries(function (seriesModel) {
                seriesModel.getData().clearAllVisual();
            });

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

771 772
            invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
        },
773

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

781 782 783 784 785
            // update before setOption
            if (!ecModel) {
                return;
            }

L
lang 已提交
786
            doLayout.call(this, ecModel, payload);
787

788 789
            invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
        },
L
lang 已提交
790

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

P
pah100 已提交
798 799 800
            prepareView.call(this, 'component', ecModel);

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

1
100pah 已提交
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
            // FIXME
            // ugly
            if (this.__lastOnlyGraphic) {
                each(this._componentsViews, function (componentView) {
                    var componentModel = componentView.__model;
                    if (componentModel && componentModel.mainType === 'graphic') {
                        componentView.render(componentModel, ecModel, this._api, payload);
                        updateZ(componentModel, componentView);
                    }
                }, this);
                this.__lastOnlyGraphic = false;
            }
            else {
                updateMethods.update.call(this, payload);
            }
P
pah100 已提交
817
        }
818 819 820 821 822
    };

    /**
     * @private
     */
1
tweak  
100pah 已提交
823
    function updateDirectly(ecIns, method, payload, mainType, subType) {
1
100pah 已提交
824
        var ecModel = ecIns._model;
1
tweak  
100pah 已提交
825 826 827 828
        var query = {};
        query[mainType + 'Id'] = payload[mainType + 'Id'];
        query[mainType + 'Index'] = payload[mainType + 'Index'];
        query[mainType + 'Name'] = payload[mainType + 'Name'];
829

1
100pah 已提交
830
        var condition = {mainType: mainType, query: query};
1
100pah 已提交
831
        subType && (condition.subType = subType); // subType may be '' by parseClassType;
1
100pah 已提交
832 833 834 835

        // If dispatchAction before setOption, do nothing.
        ecModel && ecModel.eachComponent(condition, function (model, index) {
            var view = ecIns[
1
100pah 已提交
836 837 838
                mainType === 'series' ? '_chartsMap' : '_componentsMap'
            ][model.__viewId];
            if (view && view.__alive) {
1
100pah 已提交
839
                view[method](model, ecModel, ecIns._api, payload);
1
100pah 已提交
840
            }
1
100pah 已提交
841
        }, ecIns);
842
    }
843

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

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

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

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

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

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

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

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

        flushPendingActions.call(this, silent);

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

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

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

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

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

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

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

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

L
lang 已提交
942 943 944 945
        // May dispatchAction in rendering procedure
        if (this[IN_MAIN_PROCESS]) {
            this._pendingActions.push(payload);
            return;
946 947
        }

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

1
100pah 已提交
950 951 952 953 954 955 956 957 958 959 960
        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();
        }
961

1
100pah 已提交
962
        flushPendingActions.call(this, opt.silent);
963 964

        triggerUpdatedEvent.call(this, opt.silent);
1
tweak  
100pah 已提交
965 966 967
    };

    function doDispatchAction(payload, silent) {
1
100pah 已提交
968 969
        var payloadType = payload.type;
        var actionWrap = actions[payloadType];
1
tweak  
100pah 已提交
970
        var actionInfo = actionWrap.actionInfo;
1
100pah 已提交
971

1
100pah 已提交
972 973 974
        var cptType = (actionInfo.update || 'update').split(':');
        var updateMethod = cptType.pop();
        cptType = cptType[0] && parseClassType(cptType[0]);
1
tweak  
100pah 已提交
975

976
        this[IN_MAIN_PROCESS] = true;
L
lang 已提交
977

978 979 980 981 982 983 984 985 986 987 988
        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 已提交
989

990 991
        var eventObjBatch = [];
        var eventObj;
1
100pah 已提交
992 993
        var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';

994 995 996 997 998 999 1000 1001 1002 1003
        for (var i = 0; i < payloads.length; i++) {
            var batchItem = payloads[i];
            // Action can specify the event by return it.
            eventObj = actionWrap.action(batchItem, this._model);
            // Emit event outside
            eventObj = eventObj || zrUtil.extend({}, batchItem);
            // Convert type to eventType
            eventObj.type = actionInfo.event || eventObj.type;
            eventObjBatch.push(eventObj);

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

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

        // Follow the rule of action batch
        if (batched) {
            eventObj = {
1
100pah 已提交
1029
                type: actionInfo.event || payloadType,
1030 1031 1032 1033 1034 1035 1036
                batch: eventObjBatch
            };
        }
        else {
            eventObj = eventObjBatch[0];
        }

1037 1038
        this[IN_MAIN_PROCESS] = false;

L
tweak  
lang 已提交
1039
        !silent && this._messageCenter.trigger(eventObj.type, eventObj);
1
tweak  
100pah 已提交
1040
    }
L
tweak  
lang 已提交
1041

1
tweak  
100pah 已提交
1042
    function flushPendingActions(silent) {
L
lang 已提交
1043 1044 1045
        var pendingActions = this._pendingActions;
        while (pendingActions.length) {
            var payload = pendingActions.shift();
1
tweak  
100pah 已提交
1046
            doDispatchAction.call(this, payload, silent);
L
lang 已提交
1047
        }
1
tweak  
100pah 已提交
1048
    }
L
lang 已提交
1049

1050 1051 1052 1053
    function triggerUpdatedEvent(silent) {
        !silent && this.trigger('updated');
    }

L
lang 已提交
1054 1055 1056 1057
    /**
     * Register event
     * @method
     */
1058 1059 1060
    echartsProto.on = createRegisterEventWithLowercaseName('on');
    echartsProto.off = createRegisterEventWithLowercaseName('off');
    echartsProto.one = createRegisterEventWithLowercaseName('one');
L
lang 已提交
1061

L
tweak  
lang 已提交
1062 1063 1064 1065
    /**
     * @param {string} methodName
     * @private
     */
1066
    function invokeUpdateMethod(methodName, ecModel, payload) {
1067
        var api = this._api;
L
lang 已提交
1068

L
tweak  
lang 已提交
1069
        // Update all components
L
lang 已提交
1070
        each(this._componentsViews, function (component) {
L
tweak  
lang 已提交
1071 1072
            var componentModel = component.__model;
            component[methodName](componentModel, ecModel, api, payload);
1073

L
tweak  
lang 已提交
1074 1075
            updateZ(componentModel, component);
        }, this);
L
lang 已提交
1076

L
tweak  
lang 已提交
1077 1078
        // Upate all charts
        ecModel.eachSeries(function (seriesModel, idx) {
L
lang 已提交
1079
            var chart = this._chartsMap[seriesModel.__viewId];
L
tweak  
lang 已提交
1080
            chart[methodName](seriesModel, ecModel, api, payload);
1081

L
tweak  
lang 已提交
1082
            updateZ(seriesModel, chart);
1083 1084

            updateProgressiveAndBlend(seriesModel, chart);
L
tweak  
lang 已提交
1085
        }, this);
1086

1087 1088
        // If use hover layer
        updateHoverLayerStatus(this._zr, ecModel);
1089 1090 1091 1092 1093

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

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

L
Tweak  
lang 已提交
1107
        for (var i = 0; i < viewList.length; i++) {
L
lang 已提交
1108
            viewList[i].__alive = false;
L
tweak  
lang 已提交
1109
        }
L
lang 已提交
1110

L
Tweak  
lang 已提交
1111 1112 1113 1114
        ecModel[isComponent ? 'eachComponent' : 'eachSeries'](function (componentType, model) {
            if (isComponent) {
                if (componentType === 'series') {
                    return;
L
lang 已提交
1115
                }
1116
            }
L
tweak  
lang 已提交
1117
            else {
L
Tweak  
lang 已提交
1118
                model = componentType;
L
tweak  
lang 已提交
1119 1120
            }

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

L
lang 已提交
1142
            model.__viewId = viewId;
L
lang 已提交
1143
            view.__alive = true;
L
lang 已提交
1144
            view.__id = viewId;
L
Tweak  
lang 已提交
1145
            view.__model = model;
L
tweak  
lang 已提交
1146 1147
        }, this);

L
Tweak  
lang 已提交
1148 1149
        for (var i = 0; i < viewList.length;) {
            var view = viewList[i];
L
lang 已提交
1150
            if (!view.__alive) {
L
Tweak  
lang 已提交
1151
                zr.remove(view.group);
L
lang 已提交
1152
                view.dispose(ecModel, this._api);
L
Tweak  
lang 已提交
1153 1154
                viewList.splice(i, 1);
                delete viewMap[view.__id];
L
tweak  
lang 已提交
1155 1156 1157 1158 1159
            }
            else {
                i++;
            }
        }
1160 1161
    }

L
tweak  
lang 已提交
1162 1163 1164 1165 1166 1167
    /**
     * Processor data in each series
     *
     * @param {module:echarts/model/Global} ecModel
     * @private
     */
1168
    function processData(ecModel, api) {
1169 1170
        each(dataProcessorFuncs, function (process) {
            process.func(ecModel, api);
L
tweak  
lang 已提交
1171
        });
1172
    }
L
lang 已提交
1173

L
tweak  
lang 已提交
1174 1175 1176
    /**
     * @private
     */
1177
    function stackSeriesData(ecModel) {
L
tweak  
lang 已提交
1178 1179 1180 1181 1182 1183 1184 1185
        var stackedDataMap = {};
        ecModel.eachSeries(function (series) {
            var stack = series.get('stack');
            var data = series.getData();
            if (stack && data.type === 'list') {
                var previousStack = stackedDataMap[stack];
                if (previousStack) {
                    data.stackedOn = previousStack;
L
lang 已提交
1186
                }
L
tweak  
lang 已提交
1187 1188 1189
                stackedDataMap[stack] = data;
            }
        });
1190
    }
L
lang 已提交
1191

L
tweak  
lang 已提交
1192
    /**
1193
     * Layout before each chart render there series, special visual encoding stage
L
tweak  
lang 已提交
1194 1195 1196 1197
     *
     * @param {module:echarts/model/Global} ecModel
     * @private
     */
L
lang 已提交
1198 1199
    function doLayout(ecModel, payload) {
        var api = this._api;
1200 1201 1202 1203
        each(visualFuncs, function (visual) {
            if (visual.isLayout) {
                visual.func(ecModel, api, payload);
            }
L
tweak  
lang 已提交
1204
        });
1205
    }
L
lang 已提交
1206

L
tweak  
lang 已提交
1207
    /**
1208
     * Encode visual infomation from data after data processing
L
tweak  
lang 已提交
1209 1210
     *
     * @param {module:echarts/model/Global} ecModel
1
100pah 已提交
1211 1212
     * @param {object} layout
     * @param {boolean} [excludesLayout]
L
tweak  
lang 已提交
1213 1214
     * @private
     */
1
100pah 已提交
1215
    function doVisualEncoding(ecModel, payload, excludesLayout) {
L
lang 已提交
1216
        var api = this._api;
L
lang 已提交
1217 1218 1219 1220
        ecModel.clearColorPalette();
        ecModel.eachSeries(function (seriesModel) {
            seriesModel.clearColorPalette();
        });
1221
        each(visualFuncs, function (visual) {
1
100pah 已提交
1222 1223
            (!excludesLayout || !visual.isLayout)
                && visual.func(ecModel, api, payload);
L
tweak  
lang 已提交
1224
        });
1225
    }
L
lang 已提交
1226

L
tweak  
lang 已提交
1227 1228 1229 1230
    /**
     * Render each chart and component
     * @private
     */
1231
    function doRender(ecModel, payload) {
1232
        var api = this._api;
L
tweak  
lang 已提交
1233
        // Render all components
L
lang 已提交
1234 1235 1236
        each(this._componentsViews, function (componentView) {
            var componentModel = componentView.__model;
            componentView.render(componentModel, ecModel, api, payload);
L
tweak  
lang 已提交
1237

L
lang 已提交
1238
            updateZ(componentModel, componentView);
L
tweak  
lang 已提交
1239 1240
        }, this);

L
lang 已提交
1241
        each(this._chartsViews, function (chart) {
L
lang 已提交
1242
            chart.__alive = false;
L
tweak  
lang 已提交
1243 1244 1245 1246
        }, this);

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

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

L
lang 已提交
1253
            updateZ(seriesModel, chartView);
1254

1255
            updateProgressiveAndBlend(seriesModel, chartView);
L
lang 已提交
1256

L
tweak  
lang 已提交
1257 1258
        }, this);

L
lang 已提交
1259
        // If use hover layer
1260 1261
        updateHoverLayerStatus(this._zr, ecModel);

L
lang 已提交
1262
        // Remove groups of unrendered charts
L
lang 已提交
1263
        each(this._chartsViews, function (chart) {
L
lang 已提交
1264
            if (!chart.__alive) {
L
tweak  
lang 已提交
1265 1266 1267
                chart.remove(ecModel, api);
            }
        }, this);
1268
    }
L
lang 已提交
1269

L
lang 已提交
1270
    var MOUSE_EVENT_NAMES = [
1
100pah 已提交
1271 1272
        'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
        'mousedown', 'mouseup', 'globalout', 'contextmenu'
L
lang 已提交
1273 1274 1275 1276 1277 1278
    ];
    /**
     * @private
     */
    echartsProto._initEvents = function () {
        each(MOUSE_EVENT_NAMES, function (eveName) {
1279
            this._zr.on(eveName, function (e) {
L
lang 已提交
1280 1281
                var ecModel = this.getModel();
                var el = e.target;
1
100pah 已提交
1282
                var params;
1
100pah 已提交
1283

1
100pah 已提交
1284
                // no e.target when 'globalout'.
1
100pah 已提交
1285
                if (eveName === 'globalout') {
1
100pah 已提交
1286
                    params = {};
1
100pah 已提交
1287 1288
                }
                else if (el && el.dataIndex != null) {
L
lang 已提交
1289
                    var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
1
100pah 已提交
1290
                    params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType) || {};
L
lang 已提交
1291
                }
L
lang 已提交
1292 1293
                // If element has custom eventData of components
                else if (el && el.eventData) {
1
100pah 已提交
1294
                    params = zrUtil.extend({}, el.eventData);
L
lang 已提交
1295
                }
1
100pah 已提交
1296 1297 1298 1299 1300 1301 1302

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

L
lang 已提交
1303 1304
            }, this);
        }, this);
L
lang 已提交
1305

L
lang 已提交
1306
        each(eventActionMap, function (actionType, eventType) {
L
lang 已提交
1307 1308 1309 1310
            this._messageCenter.on(eventType, function (event) {
                this.trigger(eventType, event);
            }, this);
        }, this);
L
lang 已提交
1311 1312
    };

L
lang 已提交
1313
    /**
L
lang 已提交
1314
     * @return {boolean}
L
lang 已提交
1315 1316 1317 1318
     */
    echartsProto.isDisposed = function () {
        return this._disposed;
    };
L
lang 已提交
1319 1320 1321 1322 1323

    /**
     * Clear
     */
    echartsProto.clear = function () {
1324
        this.setOption({ series: [] }, true);
L
lang 已提交
1325
    };
L
lang 已提交
1326 1327 1328
    /**
     * Dispose instance
     */
L
tweak  
lang 已提交
1329
    echartsProto.dispose = function () {
1330 1331 1332 1333 1334 1335
        if (this._disposed) {
            if (__DEV__) {
                console.warn('Instance ' + this.id + ' has been disposed');
            }
            return;
        }
L
lang 已提交
1336
        this._disposed = true;
1337

L
lang 已提交
1338
        var api = this._api;
L
lang 已提交
1339
        var ecModel = this._model;
L
lang 已提交
1340

L
lang 已提交
1341
        each(this._componentsViews, function (component) {
L
lang 已提交
1342
            component.dispose(ecModel, api);
L
tweak  
lang 已提交
1343
        });
L
lang 已提交
1344
        each(this._chartsViews, function (chart) {
L
lang 已提交
1345
            chart.dispose(ecModel, api);
L
tweak  
lang 已提交
1346
        });
L
lang 已提交
1347

1348
        // Dispose after all views disposed
L
Tweak  
lang 已提交
1349
        this._zr.dispose();
L
lang 已提交
1350

L
lang 已提交
1351
        delete instances[this.id];
L
lang 已提交
1352 1353
    };

L
lang 已提交
1354 1355
    zrUtil.mixin(ECharts, Eventful);

1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 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
    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;
                }
            });
        }
    }
    /**
     * 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);
            }
        });
    }
L
lang 已提交
1414 1415 1416 1417 1418 1419 1420 1421 1422
    /**
     * @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) {
1423 1424 1425 1426
            if (el.type !== 'group') {
                z != null && (el.z = z);
                zlevel != null && (el.zlevel = zlevel);
            }
L
lang 已提交
1427 1428
        });
    }
L
lang 已提交
1429 1430 1431 1432
    /**
     * @type {Array.<Function>}
     * @inner
     */
P
pah100 已提交
1433 1434
    var actions = [];

L
lang 已提交
1435
    /**
L
lang 已提交
1436
     * Map eventType to actionType
L
lang 已提交
1437 1438 1439 1440
     * @type {Object}
     */
    var eventActionMap = {};

L
lang 已提交
1441 1442 1443 1444 1445
    /**
     * Data processor functions of each stage
     * @type {Array.<Object.<string, Function>>}
     * @inner
     */
1446
    var dataProcessorFuncs = [];
L
lang 已提交
1447

1448 1449 1450 1451 1452 1453
    /**
     * @type {Array.<Function>}
     * @inner
     */
    var optionPreprocessorFuncs = [];

1454 1455 1456 1457 1458 1459
    /**
     * @type {Array.<Function>}
     * @inner
     */
    var postUpdateFuncs = [];

L
lang 已提交
1460
    /**
1461
     * Visual encoding functions of each stage
L
lang 已提交
1462 1463 1464
     * @type {Array.<Object.<string, Function>>}
     * @inner
     */
1465
    var visualFuncs = [];
L
lang 已提交
1466 1467 1468 1469 1470
    /**
     * Theme storage
     * @type {Object.<key, Object>}
     */
    var themeStorage = {};
L
lang 已提交
1471 1472 1473 1474
    /**
     * Loading effects
     */
    var loadingEffects = {};
L
lang 已提交
1475

L
lang 已提交
1476

L
lang 已提交
1477 1478 1479 1480 1481 1482
    var instances = {};
    var connectedGroups = {};

    var idBase = new Date() - 0;
    var groupIdBase = new Date() - 0;
    var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
L
lang 已提交
1483
    /**
L
lang 已提交
1484
     * @alias module:echarts
L
lang 已提交
1485
     */
L
lang 已提交
1486 1487 1488 1489
    var echarts = {
        /**
         * @type {number}
         */
1
100pah 已提交
1490
        version: '3.4.0',
L
lang 已提交
1491
        dependencies: {
1
100pah 已提交
1492
            zrender: '3.3.0'
L
lang 已提交
1493 1494
        }
    };
L
lang 已提交
1495

L
lang 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
    function enableConnect(chart) {

        var STATUS_PENDING = 0;
        var STATUS_UPDATING = 1;
        var STATUS_UPDATED = 2;
        var STATUS_KEY = '__connectUpdateStatus';
        function updateConnectedChartsStatus(charts, status) {
            for (var i = 0; i < charts.length; i++) {
                var otherChart = charts[i];
                otherChart[STATUS_KEY] = status;
            }
        }
        zrUtil.each(eventActionMap, function (actionType, eventType) {
            chart._messageCenter.on(eventType, function (event) {
                if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
                    var action = chart.makeActionFromEvent(event);
                    var otherCharts = [];
1
100pah 已提交
1513 1514

                    zrUtil.each(instances, function (otherChart) {
L
lang 已提交
1515 1516 1517
                        if (otherChart !== chart && otherChart.group === chart.group) {
                            otherCharts.push(otherChart);
                        }
1
100pah 已提交
1518 1519
                    });

L
lang 已提交
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
                    updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
                    each(otherCharts, function (otherChart) {
                        if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
                            otherChart.dispatchAction(action);
                        }
                    });
                    updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
                }
            });
        });

    }
L
tweak  
lang 已提交
1532 1533 1534 1535
    /**
     * @param {HTMLDomElement} dom
     * @param {Object} [theme]
     * @param {Object} opts
1536 1537 1538 1539 1540 1541
     * @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 已提交
1542 1543
     */
    echarts.init = function (dom, theme, opts) {
1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556
        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 + '+'
                );
            }
            if (!dom) {
                throw new Error('Initialize failed: invalid dom.');
            }
L
lang 已提交
1557
            if (zrUtil.isDom(dom) && dom.nodeName.toUpperCase() !== 'CANVAS' && (!dom.clientWidth || !dom.clientHeight)) {
L
lang 已提交
1558
                console.warn('Can\'t get dom width or height');
1559
            }
1560
        }
L
lang 已提交
1561 1562

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

L
lang 已提交
1566 1567 1568
        dom.setAttribute &&
            dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);

L
lang 已提交
1569
        enableConnect(chart);
L
lang 已提交
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587

        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 已提交
1588
            groupId = groupId || ('g_' + groupIdBase++);
L
lang 已提交
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
            zrUtil.each(charts, function (chart) {
                chart.group = groupId;
            });
        }
        connectedGroups[groupId] = true;
        return groupId;
    };

    /**
     * @return {string} groupId
     */
    echarts.disConnect = function (groupId) {
        connectedGroups[groupId] = false;
    };

    /**
     * Dispose a chart instance
     * @param  {module:echarts~ECharts|HTMLDomElement|string} chart
     */
    echarts.dispose = function (chart) {
        if (zrUtil.isDom(chart)) {
            chart = echarts.getInstanceByDom(chart);
        }
        else if (typeof chart === 'string') {
            chart = instances[chart];
        }
        if ((chart instanceof ECharts) && !chart.isDisposed()) {
            chart.dispose();
        }
    };

    /**
     * @param  {HTMLDomElement} dom
     * @return {echarts~ECharts}
     */
    echarts.getInstanceByDom = function (dom) {
        var key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
        return instances[key];
    };
    /**
     * @param {string} key
     * @return {echarts~ECharts}
     */
    echarts.getInstanceById = function (key) {
        return instances[key];
L
tweak  
lang 已提交
1634
    };
L
lang 已提交
1635

L
lang 已提交
1636 1637 1638 1639 1640 1641 1642
    /**
     * Register theme
     */
    echarts.registerTheme = function (name, theme) {
        themeStorage[name] = theme;
    };

L
tweak  
lang 已提交
1643 1644 1645 1646 1647 1648 1649
    /**
     * Register option preprocessor
     * @param {Function} preprocessorFunc
     */
    echarts.registerPreprocessor = function (preprocessorFunc) {
        optionPreprocessorFuncs.push(preprocessorFunc);
    };
1650

L
tweak  
lang 已提交
1651
    /**
1652
     * @param {number} [priority=1000]
L
tweak  
lang 已提交
1653 1654
     * @param {Function} processorFunc
     */
1655 1656 1657 1658
    echarts.registerProcessor = function (priority, processorFunc) {
        if (typeof priority === 'function') {
            processorFunc = priority;
            priority = PRIORITY_PROCESSOR_FILTER;
L
tweak  
lang 已提交
1659
        }
1660 1661 1662 1663
        if (__DEV__) {
            if (isNaN(priority)) {
                throw new Error('Unkown processor priority');
            }
1664 1665 1666 1667 1668
        }
        dataProcessorFuncs.push({
            prio: priority,
            func: processorFunc
        });
L
tweak  
lang 已提交
1669
    };
L
lang 已提交
1670

1671 1672 1673 1674 1675 1676 1677 1678
    /**
     * Register postUpdater
     * @param {Function} postUpdateFunc
     */
    echarts.registerPostUpdate = function (postUpdateFunc) {
        postUpdateFuncs.push(postUpdateFunc);
    };

L
tweak  
lang 已提交
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689
    /**
     * 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 已提交
1690 1691 1692 1693
     * @param {string} [actionInfo.event]
     * @param {string} [actionInfo.update]
     * @param {string} [eventName]
     * @param {Function} action
L
tweak  
lang 已提交
1694
     */
L
lang 已提交
1695 1696 1697 1698 1699
    echarts.registerAction = function (actionInfo, eventName, action) {
        if (typeof eventName === 'function') {
            action = eventName;
            eventName = '';
        }
L
tweak  
lang 已提交
1700 1701
        var actionType = zrUtil.isObject(actionInfo)
            ? actionInfo.type
L
lang 已提交
1702 1703 1704
            : ([actionInfo, actionInfo = {
                event: eventName
            }][0]);
L
lang 已提交
1705

L
lang 已提交
1706 1707
        // Event name is all lowercase
        actionInfo.event = (actionInfo.event || actionType).toLowerCase();
L
lang 已提交
1708
        eventName = actionInfo.event;
1709

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

L
tweak  
lang 已提交
1713 1714 1715
        if (!actions[actionType]) {
            actions[actionType] = {action: action, actionInfo: actionInfo};
        }
L
lang 已提交
1716
        eventActionMap[eventName] = actionType;
L
tweak  
lang 已提交
1717
    };
P
pah100 已提交
1718

L
tweak  
lang 已提交
1719 1720 1721 1722 1723 1724 1725
    /**
     * @param {string} type
     * @param {*} CoordinateSystem
     */
    echarts.registerCoordinateSystem = function (type, CoordinateSystem) {
        CoordinateSystemManager.register(type, CoordinateSystem);
    };
L
lang 已提交
1726

L
tweak  
lang 已提交
1727
    /**
1728 1729 1730 1731
     * 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 已提交
1732
     * @param {number} [priority=1000]
1733
     * @param {Function} layoutFunc
L
tweak  
lang 已提交
1734
     */
1735 1736 1737 1738 1739
    echarts.registerLayout = function (priority, layoutFunc) {
        if (typeof priority === 'function') {
            layoutFunc = priority;
            priority = PRIORITY_VISUAL_LAYOUT;
        }
1740 1741 1742 1743
        if (__DEV__) {
            if (isNaN(priority)) {
                throw new Error('Unkown layout priority');
            }
L
tweak  
lang 已提交
1744
        }
1745 1746 1747 1748 1749
        visualFuncs.push({
            prio: priority,
            func: layoutFunc,
            isLayout: true
        });
L
tweak  
lang 已提交
1750
    };
L
lang 已提交
1751

L
tweak  
lang 已提交
1752
    /**
L
lang 已提交
1753
     * @param {number} [priority=3000]
1754
     * @param {Function} visualFunc
L
tweak  
lang 已提交
1755
     */
1756 1757 1758 1759
    echarts.registerVisual = function (priority, visualFunc) {
        if (typeof priority === 'function') {
            visualFunc = priority;
            priority = PRIORITY_VISUAL_CHART;
L
tweak  
lang 已提交
1760
        }
1761 1762 1763 1764
        if (__DEV__) {
            if (isNaN(priority)) {
                throw new Error('Unkown visual priority');
            }
1765 1766 1767 1768 1769
        }
        visualFuncs.push({
            prio: priority,
            func: visualFunc
        });
L
tweak  
lang 已提交
1770
    };
L
Update  
lang 已提交
1771

L
lang 已提交
1772 1773 1774 1775 1776 1777 1778
    /**
     * @param {string} name
     */
    echarts.registerLoading = function (name, loadingFx) {
        loadingEffects[name] = loadingFx;
    };

L
tweak  
lang 已提交
1779 1780
    /**
     * @param {Object} opts
L
lang 已提交
1781
     * @param {string} [superClass]
L
tweak  
lang 已提交
1782
     */
1783 1784 1785 1786 1787 1788 1789
    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 已提交
1790
    };
L
Update  
lang 已提交
1791

L
tweak  
lang 已提交
1792 1793
    /**
     * @param {Object} opts
L
lang 已提交
1794
     * @param {string} [superClass]
L
tweak  
lang 已提交
1795
     */
1796 1797 1798 1799 1800 1801 1802
    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 已提交
1803
    };
L
Update  
lang 已提交
1804

L
tweak  
lang 已提交
1805 1806
    /**
     * @param {Object} opts
L
lang 已提交
1807
     * @param {string} [superClass]
L
tweak  
lang 已提交
1808
     */
1809 1810 1811 1812 1813 1814 1815 1816
    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 已提交
1817
    };
P
pah100 已提交
1818

L
tweak  
lang 已提交
1819 1820
    /**
     * @param {Object} opts
L
lang 已提交
1821
     * @param {string} [superClass]
L
tweak  
lang 已提交
1822
     */
1823 1824 1825 1826 1827 1828 1829 1830
    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 已提交
1831 1832
    };

1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
    /**
     * 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 已提交
1853
    echarts.registerVisual(PRIORITY_VISUAL_GLOBAL, require('./visual/seriesColor'));
1854
    echarts.registerPreprocessor(require('./preprocessor/backwardCompat'));
L
lang 已提交
1855
    echarts.registerLoading('default', require('./loading/default'));
1856

1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868
    // Default action
    echarts.registerAction({
        type: 'highlight',
        event: 'highlight',
        update: 'highlight'
    }, zrUtil.noop);
    echarts.registerAction({
        type: 'downplay',
        event: 'downplay',
        update: 'downplay'
    }, zrUtil.noop);

P
pah100 已提交
1869 1870 1871 1872

    // --------
    // Exports
    // --------
L
lang 已提交
1873 1874 1875
    //
    echarts.List = require('./data/List');
    echarts.Model = require('./model/Model');
P
pah100 已提交
1876

L
lang 已提交
1877 1878 1879
    echarts.graphic = require('./util/graphic');
    echarts.number = require('./util/number');
    echarts.format = require('./util/format');
1
100pah 已提交
1880
    echarts.throttle = throttle.throttle;
L
lang 已提交
1881 1882
    echarts.matrix = require('zrender/core/matrix');
    echarts.vector = require('zrender/core/vector');
L
lang 已提交
1883
    echarts.color = require('zrender/tool/color');
P
pah100 已提交
1884 1885 1886

    echarts.util = {};
    each([
1887 1888 1889
            'map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter',
            'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction',
            'extend', 'defaults', 'clone'
P
pah100 已提交
1890 1891 1892 1893 1894 1895
        ],
        function (name) {
            echarts.util[name] = zrUtil[name];
        }
    );

1896 1897
    echarts.helper = require('./helper');

1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
    // 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 已提交
1908
            COMPONENT: PRIORITY_VISUAL_COMPONENT,
P
pah100 已提交
1909
            BRUSH: PRIORITY_VISUAL_BRUSH
1910 1911 1912
        }
    };

L
lang 已提交
1913 1914
    return echarts;
});