echarts.js 54.2 KB
Newer Older
1

L
tweak  
lang 已提交
2
/*!
S
sushuang 已提交
3 4 5 6 7 8 9 10 11
 * ECharts, a javascript interactive chart library.
 *
 * Copyright (c) 2015, Baidu Inc.
 * All rights reserved.
 *
 * LICENSE
 * https://github.com/ecomfe/echarts/blob/master/LICENSE.txt
 */

S
sushuang 已提交
12
import {__DEV__} from './config';
S
sushuang 已提交
13 14 15 16 17 18
import * as zrender from 'zrender/src/zrender';
import * as zrUtil from 'zrender/src/core/util';
import * as colorTool from 'zrender/src/tool/color';
import env from 'zrender/src/core/env';
import timsort from 'zrender/src/core/timsort';
import Eventful from 'zrender/src/mixin/Eventful';
S
sushuang 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
import GlobalModel from './model/Global';
import ExtensionAPI from './ExtensionAPI';
import CoordinateSystemManager from './CoordinateSystem';
import OptionManager from './model/OptionManager';
import backwardCompat from './preprocessor/backwardCompat';
import ComponentModel from './model/Component';
import SeriesModel from './model/Series';
import ComponentView from './view/Component';
import ChartView from './view/Chart';
import * as graphic from './util/graphic';
import * as modelUtil from './util/model';
import {throttle} from './util/throttle';
import seriesColor from './visual/seriesColor';
import loadingDefault from './loading/default';

var each = zrUtil.each;
var parseClassType = ComponentModel.parseClassType;
L
lang 已提交
36

S
sushuang 已提交
37
export var version = '3.8.5';
38

S
sushuang 已提交
39
export var dependencies = {
S
sushuang 已提交
40
    zrender: '3.7.4'
S
sushuang 已提交
41
};
42

S
sushuang 已提交
43 44 45 46 47 48 49 50 51 52 53
var PRIORITY_PROCESSOR_FILTER = 1000;
var PRIORITY_PROCESSOR_STATISTIC = 5000;

var PRIORITY_VISUAL_LAYOUT = 1000;
var PRIORITY_VISUAL_GLOBAL = 2000;
var PRIORITY_VISUAL_CHART = 3000;
var PRIORITY_VISUAL_COMPONENT = 4000;
// FIXME
// necessary?
var PRIORITY_VISUAL_BRUSH = 5000;

S
sushuang 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66
export var PRIORITY = {
    PROCESSOR: {
        FILTER: PRIORITY_PROCESSOR_FILTER,
        STATISTIC: PRIORITY_PROCESSOR_STATISTIC
    },
    VISUAL: {
        LAYOUT: PRIORITY_VISUAL_LAYOUT,
        GLOBAL: PRIORITY_VISUAL_GLOBAL,
        CHART: PRIORITY_VISUAL_CHART,
        COMPONENT: PRIORITY_VISUAL_COMPONENT,
        BRUSH: PRIORITY_VISUAL_BRUSH
    }
};
67

S
sushuang 已提交
68 69 70 71 72 73 74 75 76
// Main process have three entries: `setOption`, `dispatchAction` and `resize`,
// where they must not be invoked nestedly, except the only case: invoke
// dispatchAction with updateMethod "none" in main process.
// This flag is used to carry out this rule.
// All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
var IN_MAIN_PROCESS = '__flagInMainProcess';
var HAS_GRADIENT_OR_PATTERN_BG = '__hasGradientOrPatternBg';
var OPTION_UPDATED = '__optionUpdated';
var ACTION_REG = /^[a-zA-Z0-9_]+$/;
L
lang 已提交
77

L
lang 已提交
78

S
sushuang 已提交
79 80 81 82 83 84 85
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 已提交
86

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

S
sushuang 已提交
98 99 100 101 102
/**
 * @module echarts~ECharts
 */
function ECharts(dom, theme, opts) {
    opts = opts || {};
103

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

109
    /**
S
sushuang 已提交
110
     * @type {string}
111
     */
S
sushuang 已提交
112
    this.id;
S
sushuang 已提交
113

114
    /**
S
sushuang 已提交
115 116
     * Group id
     * @type {string}
117
     */
S
sushuang 已提交
118
    this.group;
S
sushuang 已提交
119

120
    /**
S
sushuang 已提交
121 122
     * @type {HTMLElement}
     * @private
123
     */
S
sushuang 已提交
124
    this._dom = dom;
S
sushuang 已提交
125 126 127 128

    var defaultRenderer = 'canvas';
    if (__DEV__) {
        defaultRenderer = (
P
pissang 已提交
129
            typeof window === 'undefined' ? global : window
S
sushuang 已提交
130 131 132
        ).__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
    }

L
Tweak  
lang 已提交
133
    /**
S
sushuang 已提交
134 135
     * @type {module:zrender/ZRender}
     * @private
L
Tweak  
lang 已提交
136
     */
S
sushuang 已提交
137
    var zr = this._zr = zrender.init(dom, {
S
sushuang 已提交
138
        renderer: opts.renderer || defaultRenderer,
S
sushuang 已提交
139 140 141 142
        devicePixelRatio: opts.devicePixelRatio,
        width: opts.width,
        height: opts.height
    });
P
pah100 已提交
143

L
tweak  
lang 已提交
144
    /**
S
sushuang 已提交
145 146 147
     * Expect 60 pfs.
     * @type {Function}
     * @private
L
tweak  
lang 已提交
148
     */
S
sushuang 已提交
149
    this._throttledZrFlush = throttle(zrUtil.bind(zr.flush, zr), 17);
L
lang 已提交
150

S
sushuang 已提交
151 152
    var theme = zrUtil.clone(theme);
    theme && backwardCompat(theme, true);
L
lang 已提交
153
    /**
S
sushuang 已提交
154 155
     * @type {Object}
     * @private
L
lang 已提交
156
     */
S
sushuang 已提交
157
    this._theme = theme;
L
lang 已提交
158

L
tweak  
lang 已提交
159
    /**
S
sushuang 已提交
160 161
     * @type {Array.<module:echarts/view/Chart>}
     * @private
L
tweak  
lang 已提交
162
     */
S
sushuang 已提交
163
    this._chartsViews = [];
L
lang 已提交
164

L
tweak  
lang 已提交
165
    /**
S
sushuang 已提交
166 167
     * @type {Object.<string, module:echarts/view/Chart>}
     * @private
L
tweak  
lang 已提交
168
     */
S
sushuang 已提交
169
    this._chartsMap = {};
L
lang 已提交
170

171
    /**
S
sushuang 已提交
172 173
     * @type {Array.<module:echarts/view/Component>}
     * @private
174
     */
S
sushuang 已提交
175
    this._componentsViews = [];
176

L
lang 已提交
177
    /**
S
sushuang 已提交
178 179
     * @type {Object.<string, module:echarts/view/Component>}
     * @private
L
lang 已提交
180
     */
S
sushuang 已提交
181 182
    this._componentsMap = {};

L
lang 已提交
183
    /**
S
sushuang 已提交
184 185
     * @type {module:echarts/CoordinateSystem}
     * @private
L
lang 已提交
186
     */
S
sushuang 已提交
187
    this._coordSysMgr = new CoordinateSystemManager();
L
lang 已提交
188 189

    /**
S
sushuang 已提交
190 191
     * @type {module:echarts/ExtensionAPI}
     * @private
L
lang 已提交
192
     */
S
sushuang 已提交
193
    this._api = createExtensionAPI(this);
L
lang 已提交
194

S
sushuang 已提交
195
    Eventful.call(this);
196

1
100pah 已提交
197
    /**
S
sushuang 已提交
198 199
     * @type {module:echarts~MessageCenter}
     * @private
1
100pah 已提交
200
     */
S
sushuang 已提交
201
    this._messageCenter = new MessageCenter();
1
100pah 已提交
202

S
sushuang 已提交
203 204
    // Init mouse events
    this._initEvents();
1
100pah 已提交
205

S
sushuang 已提交
206 207
    // In case some people write `window.onresize = chart.resize`
    this.resize = zrUtil.bind(this.resize, this);
1
100pah 已提交
208

S
sushuang 已提交
209 210 211 212 213 214 215 216
    // Can't dispatch action during rendering procedure
    this._pendingActions = [];
    // Sort on demand
    function prioritySortFunc(a, b) {
        return a.prio - b.prio;
    }
    timsort(visualFuncs, prioritySortFunc);
    timsort(dataProcessorFuncs, prioritySortFunc);
1
100pah 已提交
217

S
sushuang 已提交
218
    zr.animation.on('frame', this._onframe, this);
1
100pah 已提交
219

S
sushuang 已提交
220 221 222
    // ECharts instance can be used as value.
    zrUtil.setAsPrimitive(this);
}
1
100pah 已提交
223

S
sushuang 已提交
224
var echartsProto = ECharts.prototype;
1
100pah 已提交
225

S
sushuang 已提交
226 227 228 229
echartsProto._onframe = function () {
    // Lazy update
    if (this[OPTION_UPDATED]) {
        var silent = this[OPTION_UPDATED].silent;
1
100pah 已提交
230

S
sushuang 已提交
231
        this[IN_MAIN_PROCESS] = true;
1
100pah 已提交
232

S
sushuang 已提交
233
        updateMethods.prepareAndUpdate.call(this);
1
100pah 已提交
234

S
sushuang 已提交
235
        this[IN_MAIN_PROCESS] = false;
236

S
sushuang 已提交
237
        this[OPTION_UPDATED] = false;
238

S
sushuang 已提交
239
        flushPendingActions.call(this, silent);
240

S
sushuang 已提交
241 242 243 244 245 246 247 248 249
        triggerUpdatedEvent.call(this, silent);
    }
};
/**
 * @return {HTMLElement}
 */
echartsProto.getDom = function () {
    return this._dom;
};
250

S
sushuang 已提交
251 252 253 254 255 256
/**
 * @return {module:zrender~ZRender}
 */
echartsProto.getZr = function () {
    return this._zr;
};
257

S
sushuang 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
/**
 * Usage:
 * chart.setOption(option, notMerge, lazyUpdate);
 * chart.setOption(option, {
 *     notMerge: ...,
 *     lazyUpdate: ...,
 *     silent: ...
 * });
 *
 * @param {Object} option
 * @param {Object|boolean} [opts] opts or notMerge.
 * @param {boolean} [opts.notMerge=false]
 * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
 */
echartsProto.setOption = function (option, notMerge, lazyUpdate) {
    if (__DEV__) {
        zrUtil.assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
    }
276

S
sushuang 已提交
277 278 279 280 281 282
    var silent;
    if (zrUtil.isObject(notMerge)) {
        lazyUpdate = notMerge.lazyUpdate;
        silent = notMerge.silent;
        notMerge = notMerge.notMerge;
    }
283

S
sushuang 已提交
284
    this[IN_MAIN_PROCESS] = true;
285

S
sushuang 已提交
286 287 288 289 290 291
    if (!this._model || notMerge) {
        var optionManager = new OptionManager(this._api);
        var theme = this._theme;
        var ecModel = this._model = new GlobalModel(null, null, theme, optionManager);
        ecModel.init(null, null, theme, optionManager);
    }
292

S
sushuang 已提交
293
    this._model.setOption(option, optionPreprocessorFuncs);
1
100pah 已提交
294

S
sushuang 已提交
295 296 297 298 299 300 301 302 303
    if (lazyUpdate) {
        this[OPTION_UPDATED] = {silent: silent};
        this[IN_MAIN_PROCESS] = false;
    }
    else {
        updateMethods.prepareAndUpdate.call(this);
        // Ensure zr refresh sychronously, and then pixel in canvas can be
        // fetched after `setOption`.
        this._zr.flush();
L
lang 已提交
304

S
sushuang 已提交
305 306
        this[OPTION_UPDATED] = false;
        this[IN_MAIN_PROCESS] = false;
L
lang 已提交
307

S
sushuang 已提交
308 309 310 311 312 313 314 315 316 317 318
        flushPendingActions.call(this, silent);
        triggerUpdatedEvent.call(this, silent);
    }
};

/**
 * @DEPRECATED
 */
echartsProto.setTheme = function () {
    console.log('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
};
L
lang 已提交
319

S
sushuang 已提交
320 321 322 323 324 325
/**
 * @return {module:echarts/model/Global}
 */
echartsProto.getModel = function () {
    return this._model;
};
326

S
sushuang 已提交
327 328 329 330 331 332
/**
 * @return {Object}
 */
echartsProto.getOption = function () {
    return this._model && this._model.getOption();
};
P
pah100 已提交
333

S
sushuang 已提交
334 335 336 337 338 339
/**
 * @return {number}
 */
echartsProto.getWidth = function () {
    return this._zr.getWidth();
};
340

S
sushuang 已提交
341 342 343 344 345 346
/**
 * @return {number}
 */
echartsProto.getHeight = function () {
    return this._zr.getHeight();
};
L
lang 已提交
347

S
sushuang 已提交
348 349 350 351 352 353
/**
 * @return {number}
 */
echartsProto.getDevicePixelRatio = function () {
    return this._zr.painter.dpr || window.devicePixelRatio || 1;
};
L
lang 已提交
354

S
sushuang 已提交
355 356 357 358
/**
 * Get canvas which has all thing rendered
 * @param {Object} opts
 * @param {string} [opts.backgroundColor]
S
sushuang 已提交
359
 * @return {string}
S
sushuang 已提交
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
 */
echartsProto.getRenderedCanvas = function (opts) {
    if (!env.canvasSupported) {
        return;
    }
    opts = opts || {};
    opts.pixelRatio = opts.pixelRatio || 1;
    opts.backgroundColor = opts.backgroundColor
        || this._model.get('backgroundColor');
    var zr = this._zr;
    var list = zr.storage.getDisplayList();
    // Stop animations
    zrUtil.each(list, function (el) {
        el.stopAnimation(true);
    });
    return zr.painter.getRenderedCanvas(opts);
};
O
Ovilia 已提交
377

S
sushuang 已提交
378 379 380 381 382 383 384 385
/**
 * Get svg data url
 * @return {string}
 */
echartsProto.getSvgDataUrl = function () {
    if (!env.svgSupported) {
        return;
    }
O
Ovilia 已提交
386

S
sushuang 已提交
387 388 389 390 391 392
    var zr = this._zr;
    var list = zr.storage.getDisplayList();
    // Stop animations
    zrUtil.each(list, function (el) {
        el.stopAnimation(true);
    });
393

S
sushuang 已提交
394 395
    return zr.painter.pathToSvg();
};
396

S
sushuang 已提交
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
/**
 * @return {string}
 * @param {Object} opts
 * @param {string} [opts.type='png']
 * @param {string} [opts.pixelRatio=1]
 * @param {string} [opts.backgroundColor]
 * @param {string} [opts.excludeComponents]
 */
echartsProto.getDataURL = function (opts) {
    opts = opts || {};
    var excludeComponents = opts.excludeComponents;
    var ecModel = this._model;
    var excludesComponentViews = [];
    var self = this;

    each(excludeComponents, function (componentType) {
        ecModel.eachComponent({
            mainType: componentType
        }, function (component) {
            var view = self._componentsMap[component.__viewId];
            if (!view.group.ignore) {
                excludesComponentViews.push(view);
                view.group.ignore = true;
            }
        });
    });
L
lang 已提交
423

S
sushuang 已提交
424 425 426 427 428
    var url = this._zr.painter.getType() === 'svg'
        ? this.getSvgDataUrl()
        : this.getRenderedCanvas(opts).toDataURL(
            'image/' + (opts && opts.type || 'png')
        );
429

S
sushuang 已提交
430 431 432
    each(excludesComponentViews, function (view) {
        view.group.ignore = false;
    });
L
lang 已提交
433

S
sushuang 已提交
434 435
    return url;
};
436

437

S
sushuang 已提交
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
/**
 * @return {string}
 * @param {Object} opts
 * @param {string} [opts.type='png']
 * @param {string} [opts.pixelRatio=1]
 * @param {string} [opts.backgroundColor]
 */
echartsProto.getConnectedDataURL = function (opts) {
    if (!env.canvasSupported) {
        return;
    }
    var groupId = this.group;
    var mathMin = Math.min;
    var mathMax = Math.max;
    var MAX_NUMBER = Infinity;
    if (connectedGroups[groupId]) {
        var left = MAX_NUMBER;
        var top = MAX_NUMBER;
        var right = -MAX_NUMBER;
        var bottom = -MAX_NUMBER;
        var canvasList = [];
        var dpr = (opts && opts.pixelRatio) || 1;

        zrUtil.each(instances, function (chart, id) {
            if (chart.group === groupId) {
                var canvas = chart.getRenderedCanvas(
                    zrUtil.clone(opts)
                );
                var boundingRect = chart.getDom().getBoundingClientRect();
                left = mathMin(boundingRect.left, left);
                top = mathMin(boundingRect.top, top);
                right = mathMax(boundingRect.right, right);
                bottom = mathMax(boundingRect.bottom, bottom);
                canvasList.push({
                    dom: canvas,
                    left: boundingRect.left,
                    top: boundingRect.top
L
lang 已提交
475 476
                });
            }
S
sushuang 已提交
477
        });
L
lang 已提交
478

S
sushuang 已提交
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
        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
L
lang 已提交
496
                }
S
sushuang 已提交
497 498 499 500
            });
            zr.add(img);
        });
        zr.refreshImmediately();
L
lang 已提交
501

S
sushuang 已提交
502 503 504 505 506 507
        return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
    }
    else {
        return this.getDataURL(opts);
    }
};
L
lang 已提交
508

S
sushuang 已提交
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
/**
 * Convert from logical coordinate system to pixel coordinate system.
 * See CoordinateSystem#convertToPixel.
 * @param {string|Object} finder
 *        If string, e.g., 'geo', means {geoIndex: 0}.
 *        If Object, could contain some of these properties below:
 *        {
 *            seriesIndex / seriesId / seriesName,
 *            geoIndex / geoId, geoName,
 *            bmapIndex / bmapId / bmapName,
 *            xAxisIndex / xAxisId / xAxisName,
 *            yAxisIndex / yAxisId / yAxisName,
 *            gridIndex / gridId / gridName,
 *            ... (can be extended)
 *        }
 * @param {Array|number} value
 * @return {Array|number} result
 */
echartsProto.convertToPixel = zrUtil.curry(doConvertPixel, 'convertToPixel');
528

S
sushuang 已提交
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
/**
 * Convert from pixel coordinate system to logical coordinate system.
 * See CoordinateSystem#convertFromPixel.
 * @param {string|Object} finder
 *        If string, e.g., 'geo', means {geoIndex: 0}.
 *        If Object, could contain some of these properties below:
 *        {
 *            seriesIndex / seriesId / seriesName,
 *            geoIndex / geoId / geoName,
 *            bmapIndex / bmapId / bmapName,
 *            xAxisIndex / xAxisId / xAxisName,
 *            yAxisIndex / yAxisId / yAxisName
 *            gridIndex / gridId / gridName,
 *            ... (can be extended)
 *        }
 * @param {Array|number} value
 * @return {Array|number} result
 */
echartsProto.convertFromPixel = zrUtil.curry(doConvertPixel, 'convertFromPixel');
548

S
sushuang 已提交
549 550 551 552
function doConvertPixel(methodName, finder, value) {
    var ecModel = this._model;
    var coordSysList = this._coordSysMgr.getCoordinateSystems();
    var result;
553

S
sushuang 已提交
554
    finder = modelUtil.parseFinder(ecModel, finder);
555

S
sushuang 已提交
556 557 558 559 560 561 562 563
    for (var i = 0; i < coordSysList.length; i++) {
        var coordSys = coordSysList[i];
        if (coordSys[methodName]
            && (result = coordSys[methodName](ecModel, finder, value)) != null
        ) {
            return result;
        }
    }
P
pah100 已提交
564

S
sushuang 已提交
565 566 567 568 569 570
    if (__DEV__) {
        console.warn(
            'No coordinate system that supports ' + methodName + ' found by the given finder.'
        );
    }
}
571

S
sushuang 已提交
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
/**
 * Is the specified coordinate systems or components contain the given pixel point.
 * @param {string|Object} finder
 *        If string, e.g., 'geo', means {geoIndex: 0}.
 *        If Object, could contain some of these properties below:
 *        {
 *            seriesIndex / seriesId / seriesName,
 *            geoIndex / geoId / geoName,
 *            bmapIndex / bmapId / bmapName,
 *            xAxisIndex / xAxisId / xAxisName,
 *            yAxisIndex / yAxisId / yAxisName,
 *            gridIndex / gridId / gridName,
 *            ... (can be extended)
 *        }
 * @param {Array|number} value
 * @return {boolean} result
 */
echartsProto.containPixel = function (finder, value) {
    var ecModel = this._model;
    var result;
592

S
sushuang 已提交
593
    finder = modelUtil.parseFinder(ecModel, finder);
594

S
sushuang 已提交
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
    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.'
                        ));
                    }
                }
614
            }
S
sushuang 已提交
615 616 617 618 619 620 621
            else {
                if (__DEV__) {
                    console.warn(key + ': containPoint is not supported');
                }
            }
        }, this);
    }, this);
622

S
sushuang 已提交
623 624
    return !!result;
};
P
pah100 已提交
625

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

S
sushuang 已提交
644
    finder = modelUtil.parseFinder(ecModel, finder, {defaultMainType: 'series'});
645

S
sushuang 已提交
646
    var seriesModel = finder.seriesModel;
647

S
sushuang 已提交
648 649 650 651 652
    if (__DEV__) {
        if (!seriesModel) {
            console.warn('There is no specified seires model');
        }
    }
653

S
sushuang 已提交
654
    var data = seriesModel.getData();
655

S
sushuang 已提交
656 657 658 659 660
    var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
        ? finder.dataIndexInside
        : finder.hasOwnProperty('dataIndex')
        ? data.indexOfRawIndex(finder.dataIndex)
        : null;
L
lang 已提交
661

S
sushuang 已提交
662 663 664 665
    return dataIndexInside != null
        ? data.getItemVisual(dataIndexInside, visualType)
        : data.getVisual(visualType);
};
666

S
sushuang 已提交
667 668 669 670 671 672 673 674
/**
 * 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];
};
P
pah100 已提交
675

S
sushuang 已提交
676 677 678 679 680 681 682 683
/**
 * 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];
};
P
pah100 已提交
684

S
sushuang 已提交
685 686

var updateMethods = {
687 688

    /**
S
sushuang 已提交
689
     * @param {Object} payload
690 691
     * @private
     */
S
sushuang 已提交
692 693
    update: function (payload) {
        // console.profile && console.profile('update');
P
pah100 已提交
694

S
sushuang 已提交
695 696 697 698 699 700
        var ecModel = this._model;
        var api = this._api;
        var coordSysMgr = this._coordSysMgr;
        var zr = this._zr;
        // update before setOption
        if (!ecModel) {
P
pah100 已提交
701 702 703
            return;
        }

S
sushuang 已提交
704 705
        // Fixme First time update ?
        ecModel.restoreData();
706

S
sushuang 已提交
707 708 709
        // 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.
1
100pah 已提交
710

S
sushuang 已提交
711 712 713
        // 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);
P
pah100 已提交
714

S
sushuang 已提交
715
        processData.call(this, ecModel, api);
716

S
sushuang 已提交
717
        stackSeriesData.call(this, ecModel);
718

S
sushuang 已提交
719
        coordSysMgr.update(ecModel, api);
P
pah100 已提交
720

S
sushuang 已提交
721
        doVisualEncoding.call(this, ecModel, payload);
P
pah100 已提交
722

S
sushuang 已提交
723
        doRender.call(this, ecModel, payload);
724

S
sushuang 已提交
725 726
        // Set background
        var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
L
lang 已提交
727

S
sushuang 已提交
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
        var painter = zr.painter;
        // TODO all use clearColor ?
        if (painter.isSingleCanvas && painter.isSingleCanvas()) {
            zr.configLayer(0, {
                clearColor: backgroundColor
            });
        }
        else {
            // In IE8
            if (!env.canvasSupported) {
                var colorArr = colorTool.parse(backgroundColor);
                backgroundColor = colorTool.stringify(colorArr, 'rgb');
                if (colorArr[3] === 0) {
                    backgroundColor = 'transparent';
                }
            }
            if (backgroundColor.colorStops || backgroundColor.image) {
                // Gradient background
                // FIXME Fixed layer?
                zr.configLayer(0, {
                    clearColor: backgroundColor
                });
                this[HAS_GRADIENT_OR_PATTERN_BG] = true;
751

S
sushuang 已提交
752 753 754 755 756 757 758 759 760
                this._dom.style.background = 'transparent';
            }
            else {
                if (this[HAS_GRADIENT_OR_PATTERN_BG]) {
                    zr.configLayer(0, {
                        clearColor: null
                    });
                }
                this[HAS_GRADIENT_OR_PATTERN_BG] = false;
L
lang 已提交
761

S
sushuang 已提交
762 763 764
                this._dom.style.background = backgroundColor;
            }
        }
765

S
sushuang 已提交
766 767 768
        each(postUpdateFuncs, function (func) {
            func(ecModel, api);
        });
769

S
sushuang 已提交
770 771
        // console.profile && console.profileEnd('update');
    },
L
lang 已提交
772 773

    /**
S
sushuang 已提交
774 775
     * @param {Object} payload
     * @private
L
lang 已提交
776
     */
S
sushuang 已提交
777 778
    updateView: function (payload) {
        var ecModel = this._model;
779

S
sushuang 已提交
780 781
        // update before setOption
        if (!ecModel) {
L
lang 已提交
782 783
            return;
        }
L
lang 已提交
784

S
sushuang 已提交
785 786 787
        ecModel.eachSeries(function (seriesModel) {
            seriesModel.getData().clearAllVisual();
        });
L
lang 已提交
788

S
sushuang 已提交
789
        doVisualEncoding.call(this, ecModel, payload);
P
pah100 已提交
790

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

L
tweak  
lang 已提交
794 795
    /**
     * @param {Object} payload
S
sushuang 已提交
796
     * @private
L
tweak  
lang 已提交
797
     */
S
sushuang 已提交
798 799
    updateVisual: function (payload) {
        var ecModel = this._model;
800

S
sushuang 已提交
801 802
        // update before setOption
        if (!ecModel) {
803 804
            return;
        }
L
lang 已提交
805

S
sushuang 已提交
806 807 808
        ecModel.eachSeries(function (seriesModel) {
            seriesModel.getData().clearAllVisual();
        });
809

S
sushuang 已提交
810
        doVisualEncoding.call(this, ecModel, payload, true);
811

S
sushuang 已提交
812 813
        invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
    },
1
tweak  
100pah 已提交
814

S
sushuang 已提交
815 816 817 818 819 820 821 822 823 824
    /**
     * @param {Object} payload
     * @private
     */
    updateLayout: function (payload) {
        var ecModel = this._model;

        // update before setOption
        if (!ecModel) {
            return;
1
100pah 已提交
825
        }
826

S
sushuang 已提交
827
        doLayout.call(this, ecModel, payload);
828

S
sushuang 已提交
829 830 831 832 833 834 835 836 837
        invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
    },

    /**
     * @param {Object} payload
     * @private
     */
    prepareAndUpdate: function (payload) {
        var ecModel = this._model;
1
tweak  
100pah 已提交
838

S
sushuang 已提交
839
        prepareView.call(this, 'component', ecModel);
1
100pah 已提交
840

S
sushuang 已提交
841
        prepareView.call(this, 'chart', ecModel);
1
tweak  
100pah 已提交
842

S
sushuang 已提交
843 844 845
        updateMethods.update.call(this, payload);
    }
};
L
lang 已提交
846

S
sushuang 已提交
847 848 849 850 851
/**
 * @private
 */
function updateDirectly(ecIns, method, payload, mainType, subType) {
    var ecModel = ecIns._model;
P
pah100 已提交
852

S
sushuang 已提交
853 854 855 856 857
    // broadcast
    if (!mainType) {
        each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
        return;
    }
858

S
sushuang 已提交
859 860 861 862
    var query = {};
    query[mainType + 'Id'] = payload[mainType + 'Id'];
    query[mainType + 'Index'] = payload[mainType + 'Index'];
    query[mainType + 'Name'] = payload[mainType + 'Name'];
863

S
sushuang 已提交
864 865
    var condition = {mainType: mainType, query: query};
    subType && (condition.subType = subType); // subType may be '' by parseClassType;
866

S
sushuang 已提交
867 868 869 870 871 872
    // If dispatchAction before setOption, do nothing.
    ecModel && ecModel.eachComponent(condition, function (model, index) {
        callView(ecIns[
            mainType === 'series' ? '_chartsMap' : '_componentsMap'
        ][model.__viewId]);
    }, ecIns);
873

S
sushuang 已提交
874 875 876 877
    function callView(view) {
        view && view.__alive && view[method] && view[method](
            view.__model, ecModel, ecIns._api, payload
        );
1
tweak  
100pah 已提交
878
    }
S
sushuang 已提交
879
}
L
tweak  
lang 已提交
880

S
sushuang 已提交
881 882 883 884 885 886 887 888 889 890
/**
 * Resize the chart
 * @param {Object} opts
 * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
 * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
 * @param {boolean} [opts.silent=false]
 */
echartsProto.resize = function (opts) {
    if (__DEV__) {
        zrUtil.assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
1
tweak  
100pah 已提交
891
    }
L
lang 已提交
892

S
sushuang 已提交
893
    this[IN_MAIN_PROCESS] = true;
894

S
sushuang 已提交
895
    this._zr.resize(opts);
L
lang 已提交
896

S
sushuang 已提交
897 898
    var optionChanged = this._model && this._model.resetOption('media');
    var updateMethod = optionChanged ? 'prepareAndUpdate' : 'update';
L
lang 已提交
899

S
sushuang 已提交
900
    updateMethods[updateMethod].call(this);
901

S
sushuang 已提交
902 903
    // Resize loading effect
    this._loadingFX && this._loadingFX.resize();
L
lang 已提交
904

S
sushuang 已提交
905
    this[IN_MAIN_PROCESS] = false;
906

S
sushuang 已提交
907
    var silent = opts && opts.silent;
908

S
sushuang 已提交
909
    flushPendingActions.call(this, silent);
910

S
sushuang 已提交
911 912
    triggerUpdatedEvent.call(this, silent);
};
913

S
sushuang 已提交
914 915 916 917 918 919 920 921 922
/**
 * Show loading effect
 * @param  {string} [name='default']
 * @param  {Object} [cfg]
 */
echartsProto.showLoading = function (name, cfg) {
    if (zrUtil.isObject(name)) {
        cfg = name;
        name = '';
923
    }
S
sushuang 已提交
924
    name = name || 'default';
L
lang 已提交
925

S
sushuang 已提交
926 927 928 929
    this.hideLoading();
    if (!loadingEffects[name]) {
        if (__DEV__) {
            console.warn('Loading effects ' + name + ' not exists.');
L
tweak  
lang 已提交
930
        }
S
sushuang 已提交
931 932 933 934 935
        return;
    }
    var el = loadingEffects[name](this._api, cfg);
    var zr = this._zr;
    this._loadingFX = el;
L
lang 已提交
936

S
sushuang 已提交
937 938
    zr.add(el);
};
L
tweak  
lang 已提交
939

S
sushuang 已提交
940 941 942 943 944 945 946
/**
 * Hide loading effect
 */
echartsProto.hideLoading = function () {
    this._loadingFX && this._zr.remove(this._loadingFX);
    this._loadingFX = null;
};
L
Tweak  
lang 已提交
947

S
sushuang 已提交
948 949 950 951 952 953 954 955 956
/**
 * @param {Object} eventObj
 * @return {Object}
 */
echartsProto.makeActionFromEvent = function (eventObj) {
    var payload = zrUtil.extend({}, eventObj);
    payload.type = eventActionMap[eventObj.type];
    return payload;
};
L
tweak  
lang 已提交
957

S
sushuang 已提交
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
/**
 * @pubilc
 * @param {Object} payload
 * @param {string} [payload.type] Action type
 * @param {Object|boolean} [opt] If pass boolean, means opt.silent
 * @param {boolean} [opt.silent=false] Whether trigger events.
 * @param {boolean} [opt.flush=undefined]
 *                  true: Flush immediately, and then pixel in canvas can be fetched
 *                      immediately. Caution: it might affect performance.
 *                  false: Not not flush.
 *                  undefined: Auto decide whether perform flush.
 */
echartsProto.dispatchAction = function (payload, opt) {
    if (!zrUtil.isObject(opt)) {
        opt = {silent: !!opt};
973 974
    }

S
sushuang 已提交
975 976
    if (!actions[payload.type]) {
        return;
977
    }
L
lang 已提交
978

S
sushuang 已提交
979 980 981
    // Avoid dispatch action before setOption. Especially in `connect`.
    if (!this._model) {
        return;
982
    }
L
lang 已提交
983

S
sushuang 已提交
984 985 986 987
    // May dispatchAction in rendering procedure
    if (this[IN_MAIN_PROCESS]) {
        this._pendingActions.push(payload);
        return;
988
    }
L
lang 已提交
989

S
sushuang 已提交
990
    doDispatchAction.call(this, payload, opt.silent);
L
lang 已提交
991

S
sushuang 已提交
992 993 994 995 996 997 998 999 1000 1001 1002
    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();
    }
L
tweak  
lang 已提交
1003

S
sushuang 已提交
1004
    flushPendingActions.call(this, opt.silent);
L
tweak  
lang 已提交
1005

S
sushuang 已提交
1006 1007
    triggerUpdatedEvent.call(this, opt.silent);
};
L
tweak  
lang 已提交
1008

S
sushuang 已提交
1009 1010 1011 1012 1013
function doDispatchAction(payload, silent) {
    var payloadType = payload.type;
    var escapeConnect = payload.escapeConnect;
    var actionWrap = actions[payloadType];
    var actionInfo = actionWrap.actionInfo;
L
tweak  
lang 已提交
1014

S
sushuang 已提交
1015 1016 1017
    var cptType = (actionInfo.update || 'update').split(':');
    var updateMethod = cptType.pop();
    cptType = cptType[0] != null && parseClassType(cptType[0]);
L
lang 已提交
1018

S
sushuang 已提交
1019
    this[IN_MAIN_PROCESS] = true;
1020

S
sushuang 已提交
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
    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;
        });
    }
L
lang 已提交
1032

S
sushuang 已提交
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
    var eventObjBatch = [];
    var eventObj;
    var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';

    each(payloads, function (batchItem) {
        // Action can specify the event by return it.
        eventObj = actionWrap.action(batchItem, this._model, this._api);
        // Emit event outside
        eventObj = eventObj || zrUtil.extend({}, batchItem);
        // Convert type to eventType
        eventObj.type = actionInfo.event || eventObj.type;
        eventObjBatch.push(eventObj);

        // light update does not perform data process, layout and visual.
        if (isHighDown) {
            // method, payload, mainType, subType
            updateDirectly(this, updateMethod, batchItem, 'series');
        }
        else if (cptType) {
            updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
        }
    }, this);
L
tweak  
lang 已提交
1055

S
sushuang 已提交
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
    if (updateMethod !== 'none' && !isHighDown && !cptType) {
        // Still dirty
        if (this[OPTION_UPDATED]) {
            // FIXME Pass payload ?
            updateMethods.prepareAndUpdate.call(this, payload);
            this[OPTION_UPDATED] = false;
        }
        else {
            updateMethods[updateMethod].call(this, payload);
        }
    }
1067

S
sushuang 已提交
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
    // Follow the rule of action batch
    if (batched) {
        eventObj = {
            type: actionInfo.event || payloadType,
            escapeConnect: escapeConnect,
            batch: eventObjBatch
        };
    }
    else {
        eventObj = eventObjBatch[0];
1078
    }
L
lang 已提交
1079

S
sushuang 已提交
1080
    this[IN_MAIN_PROCESS] = false;
1
100pah 已提交
1081

S
sushuang 已提交
1082 1083
    !silent && this._messageCenter.trigger(eventObj.type, eventObj);
}
1
100pah 已提交
1084

S
sushuang 已提交
1085 1086 1087 1088 1089 1090 1091
function flushPendingActions(silent) {
    var pendingActions = this._pendingActions;
    while (pendingActions.length) {
        var payload = pendingActions.shift();
        doDispatchAction.call(this, payload, silent);
    }
}
L
lang 已提交
1092

S
sushuang 已提交
1093 1094 1095
function triggerUpdatedEvent(silent) {
    !silent && this.trigger('updated');
}
L
lang 已提交
1096

S
sushuang 已提交
1097 1098 1099 1100 1101 1102 1103
/**
 * Register event
 * @method
 */
echartsProto.on = createRegisterEventWithLowercaseName('on');
echartsProto.off = createRegisterEventWithLowercaseName('off');
echartsProto.one = createRegisterEventWithLowercaseName('one');
L
lang 已提交
1104

S
sushuang 已提交
1105 1106 1107 1108 1109 1110
/**
 * @param {string} methodName
 * @private
 */
function invokeUpdateMethod(methodName, ecModel, payload) {
    var api = this._api;
1111

S
sushuang 已提交
1112 1113 1114 1115
    // Update all components
    each(this._componentsViews, function (component) {
        var componentModel = component.__model;
        component[methodName](componentModel, ecModel, api, payload);
1116

S
sushuang 已提交
1117 1118
        updateZ(componentModel, component);
    }, this);
L
lang 已提交
1119

S
sushuang 已提交
1120 1121 1122 1123
    // Upate all charts
    ecModel.eachSeries(function (seriesModel, idx) {
        var chart = this._chartsMap[seriesModel.__viewId];
        chart[methodName](seriesModel, ecModel, api, payload);
L
lang 已提交
1124

S
sushuang 已提交
1125
        updateZ(seriesModel, chart);
L
lang 已提交
1126

S
sushuang 已提交
1127 1128
        updateProgressiveAndBlend(seriesModel, chart);
    }, this);
L
lang 已提交
1129

S
sushuang 已提交
1130 1131
    // If use hover layer
    updateHoverLayerStatus(this._zr, ecModel);
L
lang 已提交
1132

S
sushuang 已提交
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
    // Post render
    each(postUpdateFuncs, function (func) {
        func(ecModel, api);
    });
}

/**
 * Prepare view instances of charts and components
 * @param  {module:echarts/model/Global} ecModel
 * @private
 */
function prepareView(type, ecModel) {
    var isComponent = type === 'component';
    var viewList = isComponent ? this._componentsViews : this._chartsViews;
    var viewMap = isComponent ? this._componentsMap : this._chartsMap;
    var zr = this._zr;

    for (var i = 0; i < viewList.length; i++) {
        viewList[i].__alive = false;
1152
    }
1153

S
sushuang 已提交
1154 1155 1156 1157
    ecModel[isComponent ? 'eachComponent' : 'eachSeries'](function (componentType, model) {
        if (isComponent) {
            if (componentType === 'series') {
                return;
1158
            }
S
sushuang 已提交
1159 1160 1161
        }
        else {
            model = componentType;
1162 1163
        }

S
sushuang 已提交
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
        // Consider: id same and type changed.
        var viewId = '_ec_' + model.id + '_' + model.type;
        var view = viewMap[viewId];
        if (!view) {
            var classType = parseClassType(model.type);
            var Clazz = isComponent
                ? ComponentView.getClass(classType.main, classType.sub)
                : ChartView.getClass(classType.sub);
            if (Clazz) {
                view = new Clazz();
                view.init(ecModel, this._api);
                viewMap[viewId] = view;
                viewList.push(view);
                zr.add(view.group);
1178
            }
S
sushuang 已提交
1179 1180 1181
            else {
                // Error
                return;
1182
            }
S
sushuang 已提交
1183
        }
1184

S
sushuang 已提交
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
        model.__viewId = view.__id = viewId;
        view.__alive = true;
        view.__model = model;
        view.group.__ecComponentInfo = {
            mainType: model.mainType,
            index: model.componentIndex
        };
    }, this);

    for (var i = 0; i < viewList.length;) {
        var view = viewList[i];
        if (!view.__alive) {
            zr.remove(view.group);
            view.dispose(ecModel, this._api);
            viewList.splice(i, 1);
            delete viewMap[view.__id];
            view.__id = view.group.__ecComponentInfo = null;
        }
        else {
            i++;
        }
L
lang 已提交
1206
    }
S
sushuang 已提交
1207
}
1208

S
sushuang 已提交
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
/**
 * Processor data in each series
 *
 * @param {module:echarts/model/Global} ecModel
 * @private
 */
function processData(ecModel, api) {
    each(dataProcessorFuncs, function (process) {
        process.func(ecModel, api);
    });
}
1220

S
sushuang 已提交
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238
/**
 * @private
 */
function stackSeriesData(ecModel) {
    var stackedDataMap = {};
    ecModel.eachSeries(function (series) {
        var stack = series.get('stack');
        var data = series.getData();
        if (stack && data.type === 'list') {
            var previousStack = stackedDataMap[stack];
            // Avoid conflict with Object.prototype
            if (stackedDataMap.hasOwnProperty(stack) && previousStack) {
                data.stackedOn = previousStack;
            }
            stackedDataMap[stack] = data;
        }
    });
}
P
pah100 已提交
1239

S
sushuang 已提交
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
/**
 * Layout before each chart render there series, special visual encoding stage
 *
 * @param {module:echarts/model/Global} ecModel
 * @private
 */
function doLayout(ecModel, payload) {
    var api = this._api;
    each(visualFuncs, function (visual) {
        if (visual.isLayout) {
            visual.func(ecModel, api, payload);
        }
    });
}
L
lang 已提交
1254

S
sushuang 已提交
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
/**
 * Encode visual infomation from data after data processing
 *
 * @param {module:echarts/model/Global} ecModel
 * @param {object} layout
 * @param {boolean} [excludesLayout]
 * @private
 */
function doVisualEncoding(ecModel, payload, excludesLayout) {
    var api = this._api;
    ecModel.clearColorPalette();
    ecModel.eachSeries(function (seriesModel) {
        seriesModel.clearColorPalette();
    });
    each(visualFuncs, function (visual) {
        (!excludesLayout || !visual.isLayout)
            && visual.func(ecModel, api, payload);
    });
}
L
lang 已提交
1274

S
sushuang 已提交
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
/**
 * Render each chart and component
 * @private
 */
function doRender(ecModel, payload) {
    var api = this._api;
    // Render all components
    each(this._componentsViews, function (componentView) {
        var componentModel = componentView.__model;
        componentView.render(componentModel, ecModel, api, payload);
1285

S
sushuang 已提交
1286 1287
        updateZ(componentModel, componentView);
    }, this);
1288

S
sushuang 已提交
1289 1290 1291
    each(this._chartsViews, function (chart) {
        chart.__alive = false;
    }, this);
L
lang 已提交
1292

S
sushuang 已提交
1293 1294 1295 1296 1297
    // Render all charts
    ecModel.eachSeries(function (seriesModel, idx) {
        var chartView = this._chartsMap[seriesModel.__viewId];
        chartView.__alive = true;
        chartView.render(seriesModel, ecModel, api, payload);
L
lang 已提交
1298

S
sushuang 已提交
1299
        chartView.group.silent = !!seriesModel.get('silent');
L
lang 已提交
1300

S
sushuang 已提交
1301
        updateZ(seriesModel, chartView);
P
pah100 已提交
1302

S
sushuang 已提交
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
        updateProgressiveAndBlend(seriesModel, chartView);

    }, this);

    // If use hover layer
    updateHoverLayerStatus(this._zr, ecModel);

    // Remove groups of unrendered charts
    each(this._chartsViews, function (chart) {
        if (!chart.__alive) {
            chart.remove(ecModel, api);
L
lang 已提交
1314
        }
S
sushuang 已提交
1315 1316
    }, this);
}
L
lang 已提交
1317

S
sushuang 已提交
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
var MOUSE_EVENT_NAMES = [
    'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
    'mousedown', 'mouseup', 'globalout', 'contextmenu'
];
/**
 * @private
 */
echartsProto._initEvents = function () {
    each(MOUSE_EVENT_NAMES, function (eveName) {
        this._zr.on(eveName, function (e) {
            var ecModel = this.getModel();
            var el = e.target;
            var params;

            // no e.target when 'globalout'.
            if (eveName === 'globalout') {
                params = {};
            }
            else if (el && el.dataIndex != null) {
                var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
                params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType) || {};
            }
            // If element has custom eventData of components
            else if (el && el.eventData) {
                params = zrUtil.extend({}, el.eventData);
            }
P
pah100 已提交
1344

S
sushuang 已提交
1345 1346 1347 1348
            if (params) {
                params.event = e;
                params.type = eveName;
                this.trigger(eveName, params);
L
lang 已提交
1349
            }
S
sushuang 已提交
1350 1351 1352 1353 1354 1355 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

        }, this);
    }, this);

    each(eventActionMap, function (actionType, eventType) {
        this._messageCenter.on(eventType, function (event) {
            this.trigger(eventType, event);
        }, this);
    }, this);
};

/**
 * @return {boolean}
 */
echartsProto.isDisposed = function () {
    return this._disposed;
};

/**
 * Clear
 */
echartsProto.clear = function () {
    this.setOption({ series: [] }, true);
};

/**
 * Dispose instance
 */
echartsProto.dispose = function () {
    if (this._disposed) {
        if (__DEV__) {
            console.warn('Instance ' + this.id + ' has been disposed');
L
lang 已提交
1382
        }
S
sushuang 已提交
1383 1384 1385
        return;
    }
    this._disposed = true;
P
pah100 已提交
1386

S
sushuang 已提交
1387 1388
    var api = this._api;
    var ecModel = this._model;
P
pah100 已提交
1389

S
sushuang 已提交
1390 1391 1392 1393 1394 1395
    each(this._componentsViews, function (component) {
        component.dispose(ecModel, api);
    });
    each(this._chartsViews, function (chart) {
        chart.dispose(ecModel, api);
    });
1
100pah 已提交
1396

S
sushuang 已提交
1397 1398
    // Dispose after all views disposed
    this._zr.dispose();
1
100pah 已提交
1399

S
sushuang 已提交
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
    delete instances[this.id];
};

zrUtil.mixin(ECharts, Eventful);

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;
            }
L
lang 已提交
1418 1419
        });
    }
S
sushuang 已提交
1420
}
P
pah100 已提交
1421

S
sushuang 已提交
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
/**
 * 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);
                }
1446
            }
S
sushuang 已提交
1447 1448
        });
    }
P
pah100 已提交
1449

S
sushuang 已提交
1450 1451 1452 1453 1454
    // Blend configration
    var blendMode = seriesModel.get('blendMode') || null;
    if (__DEV__) {
        if (!env.canvasSupported && blendMode && blendMode !== 'source-over') {
            console.warn('Only canvas support blendMode');
P
pah100 已提交
1455
        }
S
sushuang 已提交
1456 1457 1458 1459 1460 1461 1462 1463
    }
    chartView.group.traverse(function (el) {
        // FIXME marker and other components
        if (!el.isGroup) {
            el.setStyle('blend', blendMode);
        }
    });
}
P
pah100 已提交
1464

S
sushuang 已提交
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476
/**
 * @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) {
        if (el.type !== 'group') {
            z != null && (el.z = z);
            zlevel != null && (el.zlevel = zlevel);
P
pah100 已提交
1477
        }
S
sushuang 已提交
1478 1479
    });
}
P
pah100 已提交
1480

S
sushuang 已提交
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
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;
1495
            }
1496
        }
S
sushuang 已提交
1497 1498
    });
}
L
lang 已提交
1499

S
sushuang 已提交
1500 1501 1502 1503 1504
/**
 * @type {Object} key: actionType.
 * @inner
 */
var actions = {};
L
lang 已提交
1505

S
sushuang 已提交
1506 1507 1508 1509 1510
/**
 * Map eventType to actionType
 * @type {Object}
 */
var eventActionMap = {};
L
lang 已提交
1511

S
sushuang 已提交
1512 1513 1514 1515 1516 1517
/**
 * Data processor functions of each stage
 * @type {Array.<Object.<string, Function>>}
 * @inner
 */
var dataProcessorFuncs = [];
L
lang 已提交
1518

S
sushuang 已提交
1519 1520 1521 1522 1523
/**
 * @type {Array.<Function>}
 * @inner
 */
var optionPreprocessorFuncs = [];
L
lang 已提交
1524

S
sushuang 已提交
1525 1526 1527 1528 1529
/**
 * @type {Array.<Function>}
 * @inner
 */
var postUpdateFuncs = [];
L
lang 已提交
1530

S
sushuang 已提交
1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
/**
 * Visual encoding functions of each stage
 * @type {Array.<Object.<string, Function>>}
 * @inner
 */
var visualFuncs = [];
/**
 * Theme storage
 * @type {Object.<key, Object>}
 */
var themeStorage = {};
/**
 * Loading effects
 */
var loadingEffects = {};
L
lang 已提交
1546

S
sushuang 已提交
1547 1548 1549 1550 1551 1552 1553
var instances = {};
var connectedGroups = {};

var idBase = new Date() - 0;
var groupIdBase = new Date() - 0;
var DOM_ATTRIBUTE_KEY = '_echarts_instance_';

S
sushuang 已提交
1554 1555
var mapDataStores = {};

S
sushuang 已提交
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565
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;
L
lang 已提交
1566
        }
S
sushuang 已提交
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607
    }

    zrUtil.each(eventActionMap, function (actionType, eventType) {
        chart._messageCenter.on(eventType, function (event) {
            if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
                if (event && event.escapeConnect) {
                    return;
                }

                var action = chart.makeActionFromEvent(event);
                var otherCharts = [];

                zrUtil.each(instances, function (otherChart) {
                    if (otherChart !== chart && otherChart.group === chart.group) {
                        otherCharts.push(otherChart);
                    }
                });

                updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
                each(otherCharts, function (otherChart) {
                    if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
                        otherChart.dispatchAction(action);
                    }
                });
                updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
            }
        });
    });
}

/**
 * @param {HTMLElement} dom
 * @param {Object} [theme]
 * @param {Object} opts
 * @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)
 */
S
sushuang 已提交
1608
export function init(dom, theme, opts) {
S
sushuang 已提交
1609 1610
    if (__DEV__) {
        // Check version
S
sushuang 已提交
1611
        if ((zrender.version.replace('.', '') - 0) < (dependencies.zrender.replace('.', '') - 0)) {
S
sushuang 已提交
1612
            throw new Error(
S
sushuang 已提交
1613
                'zrender/src ' + zrender.version
S
sushuang 已提交
1614
                + ' is too old for ECharts ' + version
S
sushuang 已提交
1615
                + '. Current version need ZRender '
S
sushuang 已提交
1616
                + dependencies.zrender + '+'
S
sushuang 已提交
1617
            );
P
pissang 已提交
1618
        }
S
sushuang 已提交
1619 1620 1621

        if (!dom) {
            throw new Error('Initialize failed: invalid dom.');
L
lang 已提交
1622
        }
S
sushuang 已提交
1623
    }
L
lang 已提交
1624

S
sushuang 已提交
1625
    var existInstance = getInstanceByDom(dom);
S
sushuang 已提交
1626 1627 1628
    if (existInstance) {
        if (__DEV__) {
            console.warn('There is a chart instance already initialized on the dom.');
P
pissang 已提交
1629
        }
S
sushuang 已提交
1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
        return existInstance;
    }

    if (__DEV__) {
        if (zrUtil.isDom(dom)
            && dom.nodeName.toUpperCase() !== 'CANVAS'
            && (
                (!dom.clientWidth && (!opts || opts.width == null))
                || (!dom.clientHeight && (!opts || opts.height == null))
            )
        ) {
            console.warn('Can\'t get dom width or height');
P
pissang 已提交
1642
        }
S
sushuang 已提交
1643
    }
P
pah100 已提交
1644

S
sushuang 已提交
1645 1646 1647
    var chart = new ECharts(dom, theme, opts);
    chart.id = 'ec_' + idBase++;
    instances[chart.id] = chart;
L
lang 已提交
1648

S
sushuang 已提交
1649 1650 1651 1652 1653 1654
    if (dom.setAttribute) {
        dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);
    }
    else {
        dom[DOM_ATTRIBUTE_KEY] = chart.id;
    }
L
lang 已提交
1655

S
sushuang 已提交
1656
    enableConnect(chart);
1657

S
sushuang 已提交
1658
    return chart;
S
sushuang 已提交
1659
}
S
sushuang 已提交
1660 1661 1662 1663

/**
 * @return {string|Array.<module:echarts~ECharts>} groupId
 */
S
sushuang 已提交
1664
export function connect(groupId) {
S
sushuang 已提交
1665 1666 1667 1668 1669 1670 1671 1672
    // 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;
1673
            }
1674
        });
S
sushuang 已提交
1675 1676 1677 1678 1679 1680 1681
        groupId = groupId || ('g_' + groupIdBase++);
        zrUtil.each(charts, function (chart) {
            chart.group = groupId;
        });
    }
    connectedGroups[groupId] = true;
    return groupId;
S
sushuang 已提交
1682
}
L
lang 已提交
1683

S
sushuang 已提交
1684 1685 1686 1687
/**
 * @DEPRECATED
 * @return {string} groupId
 */
S
sushuang 已提交
1688
export function disConnect(groupId) {
S
sushuang 已提交
1689
    connectedGroups[groupId] = false;
S
sushuang 已提交
1690
}
1691

S
sushuang 已提交
1692 1693 1694
/**
 * @return {string} groupId
 */
S
sushuang 已提交
1695
export var disconnect = disConnect;
L
lang 已提交
1696

S
sushuang 已提交
1697 1698 1699 1700
/**
 * Dispose a chart instance
 * @param  {module:echarts~ECharts|HTMLDomElement|string} chart
 */
S
sushuang 已提交
1701
export function dispose(chart) {
S
sushuang 已提交
1702 1703 1704 1705 1706
    if (typeof chart === 'string') {
        chart = instances[chart];
    }
    else if (!(chart instanceof ECharts)){
        // Try to treat as dom
S
sushuang 已提交
1707
        chart = getInstanceByDom(chart);
S
sushuang 已提交
1708 1709 1710 1711
    }
    if ((chart instanceof ECharts) && !chart.isDisposed()) {
        chart.dispose();
    }
S
sushuang 已提交
1712
}
1713

S
sushuang 已提交
1714 1715 1716 1717
/**
 * @param  {HTMLElement} dom
 * @return {echarts~ECharts}
 */
S
sushuang 已提交
1718
export function getInstanceByDom(dom) {
S
sushuang 已提交
1719 1720 1721 1722 1723 1724 1725 1726
    var key;
    if (dom.getAttribute) {
        key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
    }
    else {
        key = dom[DOM_ATTRIBUTE_KEY];
    }
    return instances[key];
S
sushuang 已提交
1727
}
1
100pah 已提交
1728

S
sushuang 已提交
1729 1730 1731 1732
/**
 * @param {string} key
 * @return {echarts~ECharts}
 */
S
sushuang 已提交
1733
export function getInstanceById(key) {
S
sushuang 已提交
1734
    return instances[key];
S
sushuang 已提交
1735
}
P
pah100 已提交
1736

S
sushuang 已提交
1737 1738 1739
/**
 * Register theme
 */
S
sushuang 已提交
1740
export function registerTheme(name, theme) {
S
sushuang 已提交
1741
    themeStorage[name] = theme;
S
sushuang 已提交
1742
}
L
lang 已提交
1743

S
sushuang 已提交
1744 1745 1746 1747
/**
 * Register option preprocessor
 * @param {Function} preprocessorFunc
 */
S
sushuang 已提交
1748
export function registerPreprocessor(preprocessorFunc) {
S
sushuang 已提交
1749
    optionPreprocessorFuncs.push(preprocessorFunc);
S
sushuang 已提交
1750
}
1751

S
sushuang 已提交
1752 1753 1754 1755
/**
 * @param {number} [priority=1000]
 * @param {Function} processorFunc
 */
S
sushuang 已提交
1756
export function registerProcessor(priority, processorFunc) {
S
sushuang 已提交
1757 1758 1759 1760 1761 1762 1763
    if (typeof priority === 'function') {
        processorFunc = priority;
        priority = PRIORITY_PROCESSOR_FILTER;
    }
    if (__DEV__) {
        if (isNaN(priority)) {
            throw new Error('Unkown processor priority');
L
tweak  
lang 已提交
1764
        }
S
sushuang 已提交
1765 1766 1767 1768 1769
    }
    dataProcessorFuncs.push({
        prio: priority,
        func: processorFunc
    });
S
sushuang 已提交
1770
}
L
lang 已提交
1771

S
sushuang 已提交
1772 1773 1774 1775
/**
 * Register postUpdater
 * @param {Function} postUpdateFunc
 */
S
sushuang 已提交
1776
export function registerPostUpdate(postUpdateFunc) {
S
sushuang 已提交
1777
    postUpdateFuncs.push(postUpdateFunc);
S
sushuang 已提交
1778
}
L
Update  
lang 已提交
1779

S
sushuang 已提交
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795
/**
 * Usage:
 * registerAction('someAction', 'someEvent', function () { ... });
 * registerAction('someAction', function () { ... });
 * registerAction(
 *     {type: 'someAction', event: 'someEvent', update: 'updateView'},
 *     function () { ... }
 * );
 *
 * @param {(string|Object)} actionInfo
 * @param {string} actionInfo.type
 * @param {string} [actionInfo.event]
 * @param {string} [actionInfo.update]
 * @param {string} [eventName]
 * @param {Function} action
 */
S
sushuang 已提交
1796
export function registerAction(actionInfo, eventName, action) {
S
sushuang 已提交
1797 1798 1799 1800 1801 1802 1803 1804 1805
    if (typeof eventName === 'function') {
        action = eventName;
        eventName = '';
    }
    var actionType = zrUtil.isObject(actionInfo)
        ? actionInfo.type
        : ([actionInfo, actionInfo = {
            event: eventName
        }][0]);
L
lang 已提交
1806

S
sushuang 已提交
1807 1808 1809
    // Event name is all lowercase
    actionInfo.event = (actionInfo.event || actionType).toLowerCase();
    eventName = actionInfo.event;
L
Update  
lang 已提交
1810

S
sushuang 已提交
1811 1812
    // Validate action type and event name.
    zrUtil.assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
L
Update  
lang 已提交
1813

S
sushuang 已提交
1814 1815 1816 1817
    if (!actions[actionType]) {
        actions[actionType] = {action: action, actionInfo: actionInfo};
    }
    eventActionMap[eventName] = actionType;
S
sushuang 已提交
1818
}
P
pah100 已提交
1819

S
sushuang 已提交
1820 1821 1822 1823
/**
 * @param {string} type
 * @param {*} CoordinateSystem
 */
S
sushuang 已提交
1824
export function registerCoordinateSystem(type, CoordinateSystem) {
S
sushuang 已提交
1825
    CoordinateSystemManager.register(type, CoordinateSystem);
S
sushuang 已提交
1826
}
L
lang 已提交
1827

S
sushuang 已提交
1828 1829 1830 1831 1832
/**
 * Get dimensions of specified coordinate system.
 * @param {string} type
 * @return {Array.<string|Object>}
 */
S
sushuang 已提交
1833
export function getCoordinateSystemDimensions(type) {
S
sushuang 已提交
1834 1835 1836 1837 1838 1839
    var coordSysCreator = CoordinateSystemManager.get(type);
    if (coordSysCreator) {
        return coordSysCreator.getDimensionsInfo
                ? coordSysCreator.getDimensionsInfo()
                : coordSysCreator.dimensions.slice();
    }
S
sushuang 已提交
1840
}
1841

S
sushuang 已提交
1842 1843 1844 1845 1846 1847 1848 1849
/**
 * 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
 *
 * @param {number} [priority=1000]
 * @param {Function} layoutFunc
 */
S
sushuang 已提交
1850
export function registerLayout(priority, layoutFunc) {
S
sushuang 已提交
1851 1852 1853 1854 1855 1856 1857
    if (typeof priority === 'function') {
        layoutFunc = priority;
        priority = PRIORITY_VISUAL_LAYOUT;
    }
    if (__DEV__) {
        if (isNaN(priority)) {
            throw new Error('Unkown layout priority');
P
pah100 已提交
1858
        }
S
sushuang 已提交
1859 1860 1861 1862 1863 1864
    }
    visualFuncs.push({
        prio: priority,
        func: layoutFunc,
        isLayout: true
    });
S
sushuang 已提交
1865
}
P
pah100 已提交
1866

S
sushuang 已提交
1867 1868 1869 1870
/**
 * @param {number} [priority=3000]
 * @param {Function} visualFunc
 */
S
sushuang 已提交
1871
export function registerVisual(priority, visualFunc) {
S
sushuang 已提交
1872 1873 1874 1875 1876 1877 1878
    if (typeof priority === 'function') {
        visualFunc = priority;
        priority = PRIORITY_VISUAL_CHART;
    }
    if (__DEV__) {
        if (isNaN(priority)) {
            throw new Error('Unkown visual priority');
1879
        }
S
sushuang 已提交
1880 1881 1882 1883 1884
    }
    visualFuncs.push({
        prio: priority,
        func: visualFunc
    });
S
sushuang 已提交
1885
}
S
sushuang 已提交
1886 1887 1888 1889

/**
 * @param {string} name
 */
S
sushuang 已提交
1890
export function registerLoading(name, loadingFx) {
S
sushuang 已提交
1891
    loadingEffects[name] = loadingFx;
S
sushuang 已提交
1892
}
S
sushuang 已提交
1893 1894 1895 1896 1897

/**
 * @param {Object} opts
 * @param {string} [superClass]
 */
S
sushuang 已提交
1898
export function extendComponentModel(opts/*, superClass*/) {
S
sushuang 已提交
1899 1900 1901 1902 1903 1904
    // var Clazz = ComponentModel;
    // if (superClass) {
    //     var classType = parseClassType(superClass);
    //     Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
    // }
    return ComponentModel.extend(opts);
S
sushuang 已提交
1905
}
S
sushuang 已提交
1906 1907 1908 1909 1910

/**
 * @param {Object} opts
 * @param {string} [superClass]
 */
S
sushuang 已提交
1911
export function extendComponentView(opts/*, superClass*/) {
S
sushuang 已提交
1912 1913 1914 1915 1916 1917
    // var Clazz = ComponentView;
    // if (superClass) {
    //     var classType = parseClassType(superClass);
    //     Clazz = ComponentView.getClass(classType.main, classType.sub, true);
    // }
    return ComponentView.extend(opts);
S
sushuang 已提交
1918
}
S
sushuang 已提交
1919 1920 1921 1922 1923

/**
 * @param {Object} opts
 * @param {string} [superClass]
 */
S
sushuang 已提交
1924
export function extendSeriesModel(opts/*, superClass*/) {
S
sushuang 已提交
1925 1926 1927 1928 1929 1930 1931
    // 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);
S
sushuang 已提交
1932
}
S
sushuang 已提交
1933 1934 1935 1936 1937

/**
 * @param {Object} opts
 * @param {string} [superClass]
 */
S
sushuang 已提交
1938
export function extendChartView(opts/*, superClass*/) {
S
sushuang 已提交
1939 1940 1941 1942 1943 1944 1945
    // var Clazz = ChartView;
    // if (superClass) {
    //     superClass = superClass.replace('series.', '');
    //     var classType = parseClassType(superClass);
    //     Clazz = ChartView.getClass(classType.main, true);
    // }
    return ChartView.extend(opts);
S
sushuang 已提交
1946
}
S
sushuang 已提交
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963

/**
 * 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);
 *     });
 */
S
sushuang 已提交
1964
export function setCanvasCreator(creator) {
S
sushuang 已提交
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003
    zrUtil.$override('createCanvas', creator);
}

/**
 * @param {string} mapName
 * @param {Object|string} geoJson
 * @param {Object} [specialAreas]
 *
 * @example
 *     $.get('USA.json', function (geoJson) {
 *         echarts.registerMap('USA', geoJson);
 *         // Or
 *         echarts.registerMap('USA', {
 *             geoJson: geoJson,
 *             specialAreas: {}
 *         })
 *     });
 */
export function registerMap(mapName, geoJson, specialAreas) {
    if (geoJson.geoJson && !geoJson.features) {
        specialAreas = geoJson.specialAreas;
        geoJson = geoJson.geoJson;
    }
    if (typeof geoJson === 'string') {
        geoJson = (typeof JSON !== 'undefined' && JSON.parse)
            ? JSON.parse(geoJson) : (new Function('return (' + geoJson + ');'))();
    }
    mapDataStores[mapName] = {
        geoJson: geoJson,
        specialAreas: specialAreas
    };
}

/**
 * @param {string} mapName
 * @return {Object}
 */
export function getMap(mapName) {
    return mapDataStores[mapName];
S
sushuang 已提交
2004
}
S
sushuang 已提交
2005

S
sushuang 已提交
2006 2007 2008
registerVisual(PRIORITY_VISUAL_GLOBAL, seriesColor);
registerPreprocessor(backwardCompat);
registerLoading('default', loadingDefault);
S
sushuang 已提交
2009

S
sushuang 已提交
2010 2011
// Default actions

S
sushuang 已提交
2012
registerAction({
S
sushuang 已提交
2013 2014 2015 2016
    type: 'highlight',
    event: 'highlight',
    update: 'highlight'
}, zrUtil.noop);
S
sushuang 已提交
2017

S
sushuang 已提交
2018
registerAction({
S
sushuang 已提交
2019 2020 2021 2022 2023
    type: 'downplay',
    event: 'downplay',
    update: 'downplay'
}, zrUtil.noop);

S
sushuang 已提交
2024

S
sushuang 已提交
2025 2026 2027
// For backward compatibility, where the namespace `dataTool` will
// be mounted on `echarts` is the extension `dataTool` is imported.
export var dataTool = {};