echarts.js 19.7 KB
Newer Older
L
lang 已提交
1
/**
L
lang 已提交
2
 * @module echarts
L
lang 已提交
3
 */
L
lang 已提交
4 5
define(function (require) {

L
lang 已提交
6
    var GlobalModel = require('./model/Global');
L
lang 已提交
7
    var ExtensionAPI = require('./ExtensionAPI');
L
lang 已提交
8
    var CoordinateSystemManager = require('./CoordinateSystem');
L
lang 已提交
9

L
Update  
lang 已提交
10 11 12 13 14 15
    var ComponentModel = require('./model/Component');
    var SeriesModel = require('./model/Series');

    var ComponentView = require('./view/Component');
    var ChartView = require('./view/Chart');

L
lang 已提交
16 17
    var scaleClasses = require('./scale/scale');

L
lang 已提交
18
    var zrender = require('zrender');
L
lang 已提交
19
    var zrUtil = require('zrender/core/util');
L
lang 已提交
20 21
    var colorTool = require('zrender/tool/color');
    var env = require('zrender/core/env');
L
lang 已提交
22
    var Eventful = require('zrender/mixin/Eventful');
L
lang 已提交
23

24 25
    var each = zrUtil.each;

26 27
    var VISUAL_CODING_STAGES = ['echarts', 'chart', 'component'];

L
lang 已提交
28
    // TODO Transform first or filter first
L
lang 已提交
29 30
    var PROCESSOR_STAGES = ['transform', 'filter', 'statistic'];

L
lang 已提交
31 32 33
    /**
     * @module echarts~ECharts
     */
L
lang 已提交
34
    function ECharts (dom, theme, opts) {
L
lang 已提交
35
        opts = opts || {};
L
lang 已提交
36

L
lang 已提交
37 38 39 40 41
        /**
         * @type {HTMLDomElement}
         * @private
         */
        this._dom = dom;
L
lang 已提交
42 43 44 45
        /**
         * @type {module:zrender/ZRender}
         * @private
         */
L
lang 已提交
46 47 48
        this._zr = zrender.init(dom, {
            renderer: opts.renderer || 'canvas'
        });
L
lang 已提交
49

L
lang 已提交
50 51 52 53
        /**
         * @type {Object}
         * @private
         */
L
lang 已提交
54
        this._theme = zrUtil.clone(theme);
L
lang 已提交
55

L
lang 已提交
56 57 58 59
        /**
         * @type {Array.<module:echarts/view/Chart>}
         * @private
         */
L
lang 已提交
60
        this._chartsList = [];
L
lang 已提交
61 62 63 64 65

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

L
lang 已提交
68 69 70 71
        /**
         * @type {Array.<module:echarts/view/Component>}
         * @private
         */
L
lang 已提交
72
        this._componentsList = [];
L
lang 已提交
73 74 75 76 77

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

L
lang 已提交
80
        /**
L
lang 已提交
81
         * @type {module:echarts/ExtensionAPI}
L
lang 已提交
82 83
         * @private
         */
L
lang 已提交
84
        this._extensionAPI = new ExtensionAPI(this);
L
lang 已提交
85

L
lang 已提交
86 87 88 89
        /**
         * @type {module:echarts/CoordinateSystem}
         * @private
         */
L
lang 已提交
90
        this._coordinateSystem = new CoordinateSystemManager();
L
lang 已提交
91

L
lang 已提交
92 93 94 95
        Eventful.call(this);

        // Init mouse events
        this._initEvents();
L
lang 已提交
96
    }
L
lang 已提交
97

L
tweak  
lang 已提交
98
    var echartsProto = ECharts.prototype;
L
lang 已提交
99

L
tweak  
lang 已提交
100 101 102
    echartsProto.getDom = function () {
        return this._dom;
    };
L
lang 已提交
103

L
tweak  
lang 已提交
104 105 106
    echartsProto.getZr = function () {
        return this._zr;
    };
L
lang 已提交
107

L
tweak  
lang 已提交
108 109 110
    echartsProto.setOption = function (option, notMerge, refreshImmediately) {
        // PENDING
        option = zrUtil.clone(option, true);
111

L
tweak  
lang 已提交
112 113 114
        each(optionPreprocessorFuncs, function (preProcess) {
            preProcess(option);
        });
L
lang 已提交
115

L
tweak  
lang 已提交
116 117 118 119 120 121 122 123 124
        var ecModel = this._model;
        if (!ecModel || notMerge) {
            ecModel = new GlobalModel(option, null, this._theme);
            this._model = ecModel;
        }
        else {
            ecModel.restoreData();
            ecModel.mergeOption(option);
        }
L
lang 已提交
125

L
tweak  
lang 已提交
126
        this._prepareComponents(ecModel);
L
lang 已提交
127

L
tweak  
lang 已提交
128
        this._prepareCharts(ecModel);
L
lang 已提交
129

L
tweak  
lang 已提交
130
        this.update();
L
lang 已提交
131

L
tweak  
lang 已提交
132 133
        refreshImmediately && this._zr.refreshImmediately();
    };
L
lang 已提交
134

L
tweak  
lang 已提交
135 136 137 138 139 140
    /**
     * @return {module:echarts/model/Global}
     */
    echartsProto.getModel = function () {
        return this._model;
    };
L
lang 已提交
141

L
tweak  
lang 已提交
142 143 144 145 146 147
    /**
     * @return {number}
     */
    echartsProto.getWidth = function () {
        return this._zr.getWidth();
    };
L
lang 已提交
148

L
tweak  
lang 已提交
149 150 151 152 153 154
    /**
     * @return {number}
     */
    echartsProto.getHeight = function () {
        return this._zr.getHeight();
    };
L
lang 已提交
155

L
tweak  
lang 已提交
156 157 158 159
    /**
     * @param {Object} payload
     */
    echartsProto.update = function (payload) {
L
lang 已提交
160
        // console.time && console.time('update');
161

L
tweak  
lang 已提交
162
        var ecModel = this._model;
L
lang 已提交
163

L
tweak  
lang 已提交
164
        ecModel.restoreData();
L
lang 已提交
165

L
tweak  
lang 已提交
166 167 168
        // 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 已提交
169

L
tweak  
lang 已提交
170
        this._processData(ecModel);
L
lang 已提交
171

L
tweak  
lang 已提交
172
        this._stackSeriesData(ecModel);
L
lang 已提交
173

L
tweak  
lang 已提交
174
        this._coordinateSystem.update(ecModel, this._extensionAPI);
L
lang 已提交
175

L
tweak  
lang 已提交
176
        this._doLayout(ecModel, payload);
177

L
tweak  
lang 已提交
178
        this._doVisualCoding(ecModel, payload);
179

L
tweak  
lang 已提交
180
        this._doRender(ecModel, payload);
181

L
tweak  
lang 已提交
182 183 184 185 186 187 188 189
        // Set background
        var backgroundColor = ecModel.get('backgroundColor');
        // In IE8
        if (!env.canvasSupported) {
            var colorArr = colorTool.parse(backgroundColor);
            backgroundColor = colorTool.stringify(colorArr, 'rgb');
            if (colorArr[3] === 0) {
                backgroundColor = 'transparent';
L
lang 已提交
190
            }
L
tweak  
lang 已提交
191 192
        }
        backgroundColor && (this._dom.style.backgroundColor = backgroundColor);
L
lang 已提交
193

L
lang 已提交
194
        // console.time && console.timeEnd('update');
L
tweak  
lang 已提交
195
    };
196

L
tweak  
lang 已提交
197 198 199 200 201 202
    // PENDING
    /**
     * @param {Object} payload
     */
    echartsProto.updateView = function (payload) {
        var ecModel = this._model;
203

L
tweak  
lang 已提交
204
        this._doLayout(ecModel, payload);
205

L
tweak  
lang 已提交
206
        this._doVisualCoding(ecModel, payload);
207

L
tweak  
lang 已提交
208 209
        this._invokeUpdateMethod('updateView', ecModel, payload);
    };
210

L
tweak  
lang 已提交
211 212 213 214 215
    /**
     * @param {Object} payload
     */
    echartsProto.updateVisual = function (payload) {
        var ecModel = this._model;
216

L
tweak  
lang 已提交
217
        this._doVisualCoding(ecModel, payload);
218

L
tweak  
lang 已提交
219 220
        this._invokeUpdateMethod('updateVisual', ecModel, payload);
    };
221

L
tweak  
lang 已提交
222 223 224 225 226
    /**
     * @param {Object} payload
     */
    echartsProto.updateLayout = function (payload) {
        var ecModel = this._model;
227

L
tweak  
lang 已提交
228
        this._doLayout(ecModel, payload);
229

L
tweak  
lang 已提交
230 231
        this._invokeUpdateMethod('updateLayout', ecModel, payload);
    };
L
lang 已提交
232

L
tweak  
lang 已提交
233 234
    echartsProto.resize = function () {
        // var ecModel = this._model;
L
lang 已提交
235

L
tweak  
lang 已提交
236
        // this._coordinateSystem.resize(ecModel, this._extensionAPI);
L
lang 已提交
237

L
tweak  
lang 已提交
238
        // this._doVisualCoding(ecModel);
L
lang 已提交
239

L
tweak  
lang 已提交
240
        // this._doLayout(ecModel);
L
lang 已提交
241

L
tweak  
lang 已提交
242
        // this._doRender(ecModel);
L
lang 已提交
243

L
tweak  
lang 已提交
244 245
        this.update();
    };
P
pah100 已提交
246

L
lang 已提交
247 248 249 250 251 252 253 254 255
    /**
     * @return {[type]} [description]
     */
    echartsProto.makeActionFromEvent = function (eventObj) {
        var payload = zrUtil.extend({}, eventObj);
        payload.type = eventActionMap[eventObj.type];
        return payload;
    };

L
tweak  
lang 已提交
256 257 258 259 260 261 262 263 264
    /**
     * @pubilc
     * @param {Object} payload
     * @param {string} [payload.type] Action type
     * @param {number} [payload.from] From uid
     */
    echartsProto.dispatch = function (payload) {
        var actionWrap = actions[payload.type];
        if (actionWrap) {
L
lang 已提交
265 266
            var actionInfo = actionWrap.actionInfo;
            var updateMethod = actionInfo.update || 'update';
L
tweak  
lang 已提交
267 268
            actionWrap.action(payload, this._model);
            updateMethod !== 'none' && this[updateMethod](payload);
L
lang 已提交
269 270 271 272 273 274

            // Emit event outside
            // Convert type to eventType
            var eventObj = zrUtil.extend({}, payload);
            eventObj.type = actionInfo.event || eventObj.type;
            this.trigger(eventObj.type, eventObj);
L
tweak  
lang 已提交
275 276
        }
    };
277

L
tweak  
lang 已提交
278 279 280 281 282 283
    /**
     * @param {string} methodName
     * @private
     */
    echartsProto._invokeUpdateMethod = function (methodName, ecModel, payload) {
        var api = this._extensionAPI;
L
lang 已提交
284

L
tweak  
lang 已提交
285 286 287 288
        // Update all components
        each(this._componentsList, function (component) {
            var componentModel = component.__model;
            component[methodName](componentModel, ecModel, api, payload);
289

L
tweak  
lang 已提交
290 291
            updateZ(componentModel, component);
        }, this);
L
lang 已提交
292

L
tweak  
lang 已提交
293 294
        // Upate all charts
        ecModel.eachSeries(function (seriesModel, idx) {
295
            var chart = this._chartsMap[seriesModel.getId()];
L
tweak  
lang 已提交
296
            chart[methodName](seriesModel, ecModel, api, payload);
297

L
tweak  
lang 已提交
298 299
            updateZ(seriesModel, chart);
        }, this);
300

L
tweak  
lang 已提交
301
    };
L
lang 已提交
302

L
lang 已提交
303 304 305 306 307
    /**
     * Prepare charts view instances
     * @param  {module:echarts/model/Global} ecModel
     * @private
     */
L
tweak  
lang 已提交
308
    echartsProto._prepareCharts = function (ecModel) {
L
lang 已提交
309

L
tweak  
lang 已提交
310 311 312
        var chartsList = this._chartsList;
        var chartsMap = this._chartsMap;
        var zr = this._zr;
L
lang 已提交
313

L
tweak  
lang 已提交
314 315 316
        for (var i = 0; i < chartsList.length; i++) {
            chartsList[i].__keepAlive = false;
        }
L
lang 已提交
317

L
tweak  
lang 已提交
318
        ecModel.eachSeries(function (seriesModel, idx) {
319
            var id = seriesModel.getId();
L
tweak  
lang 已提交
320 321 322 323 324 325 326 327 328 329 330 331

            var chart = chartsMap[id];
            if (!chart) {
                var Clazz = ChartView.getClass(
                    ComponentModel.parseComponentType(seriesModel.type).sub
                );
                if (Clazz) {
                    chart = new Clazz();
                    chart.init(ecModel, this._extensionAPI);
                    chartsMap[id] = chart;
                    chartsList.push(chart);
                    zr.add(chart.group);
L
lang 已提交
332 333
                }
                else {
L
tweak  
lang 已提交
334
                    // Error
L
lang 已提交
335
                }
336
            }
L
lang 已提交
337

L
tweak  
lang 已提交
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
            chart.__keepAlive = true;
            chart.__id = id;
        }, this);

        for (var i = 0; i < chartsList.length;) {
            var chart = chartsList[i];
            if (!chart.__keepAlive) {
                zr.remove(chart.group);
                chart.dispose(this._extensionAPI);
                chartsList.splice(i, 1);
                delete chartsMap[chart.__id];
            }
            else {
                i++;
            }
        }
    };
L
lang 已提交
355

L
lang 已提交
356 357 358 359 360
    /**
     * Prepare component view instances
     * @param  {module:echarts/model/Global} ecModel
     * @private
     */
L
tweak  
lang 已提交
361
    echartsProto._prepareComponents = function (ecModel) {
L
lang 已提交
362

L
tweak  
lang 已提交
363 364
        var componentsMap = this._componentsMap;
        var componentsList = this._componentsList;
L
lang 已提交
365

L
tweak  
lang 已提交
366 367 368
        for (var i = 0; i < componentsList.length; i++) {
            componentsList[i].__keepAlive = true;
        }
369

L
tweak  
lang 已提交
370 371 372 373 374
        ecModel.eachComponent(function (componentType, componentModel) {
            if (componentType === 'series') {
                return;
            }

375
            var id = componentModel.getId();
L
tweak  
lang 已提交
376 377 378 379 380 381 382 383 384 385 386 387 388 389
            var component = componentsMap[id];
            if (!component) {
                // Create and add component
                var Clazz = ComponentView.getClass(
                    componentType, componentModel.option.type
                );

                if (Clazz) {
                    component = new Clazz();
                    component.init(ecModel, this._extensionAPI);
                    componentsMap[id] = component;
                    componentsList.push(component);

                    this._zr.add(component.group);
L
lang 已提交
390
                }
391
            }
L
tweak  
lang 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
            component.__id = id;
            component.__keepAlive = true;
            // Used in rendering
            component.__model = componentModel;
        }, this);

        for (var i = 0; i < componentsList.length;) {
            var component = componentsList[i];
            if (!component.__keepAlive) {
                this._zr.remove(component.group);
                component.dispose(this._extensionAPI);
                componentsList.splice(i, 1);
                delete componentsMap[component.__id];
            }
            else {
                i++;
            }
        }
    };
L
lang 已提交
411

L
tweak  
lang 已提交
412 413 414 415 416 417 418 419 420 421
    /**
     * Processor data in each series
     *
     * @param {module:echarts/model/Global} ecModel
     * @private
     */
    echartsProto._processData = function (ecModel) {
        each(PROCESSOR_STAGES, function (stage) {
            each(dataProcessorFuncs[stage] || [], function (process) {
                process(ecModel);
L
lang 已提交
422
            });
L
tweak  
lang 已提交
423 424
        });
    };
L
lang 已提交
425

L
tweak  
lang 已提交
426 427 428 429 430 431 432 433 434 435 436 437
    /**
     * @private
     */
    echartsProto._stackSeriesData = function (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];
                if (previousStack) {
                    data.stackedOn = previousStack;
L
lang 已提交
438
                }
L
tweak  
lang 已提交
439 440 441 442
                stackedDataMap[stack] = data;
            }
        });
    };
L
lang 已提交
443

L
tweak  
lang 已提交
444
    /**
L
lang 已提交
445
     * Layout before each chart render there series, after visual coding and data processing
L
tweak  
lang 已提交
446 447 448 449 450 451 452 453 454 455
     *
     * @param {module:echarts/model/Global} ecModel
     * @private
     */
    echartsProto._doLayout = function (ecModel, payload) {
        var api = this._extensionAPI;
        each(layoutFuncs, function (layout) {
            layout(ecModel, api, payload);
        });
    };
L
lang 已提交
456

L
tweak  
lang 已提交
457 458 459 460 461 462 463 464 465 466
    /**
     * Code visual infomation from data after data processing
     *
     * @param {module:echarts/model/Global} ecModel
     * @private
     */
    echartsProto._doVisualCoding = function (ecModel, payload) {
        each(VISUAL_CODING_STAGES, function (stage) {
            each(visualCodingFuncs[stage] || [], function (visualCoding) {
                visualCoding(ecModel, payload);
L
lang 已提交
467
            });
L
tweak  
lang 已提交
468 469
        });
    };
L
lang 已提交
470

L
tweak  
lang 已提交
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
    /**
     * Render each chart and component
     * @private
     */
    echartsProto._doRender = function (ecModel, payload) {
        var api = this._extensionAPI;
        // Render all components
        each(this._componentsList, function (component) {
            var componentModel = component.__model;
            component.render(componentModel, ecModel, api, payload);

            updateZ(componentModel, component);
        }, this);

        each(this._chartsList, function (chart) {
            chart.__keepAlive = false;
        }, this);

        // Render all charts
        ecModel.eachSeries(function (seriesModel, idx) {
491
            var chart = this._chartsMap[seriesModel.getId()];
L
tweak  
lang 已提交
492 493 494 495 496 497
            chart.__keepAlive = true;
            chart.render(seriesModel, ecModel, api, payload);

            updateZ(seriesModel, chart);
        }, this);

L
lang 已提交
498
        // Remove groups of unrendered charts
L
tweak  
lang 已提交
499 500 501 502 503 504
        each(this._chartsList, function (chart) {
            if (!chart.__keepAlive) {
                chart.remove(ecModel, api);
            }
        }, this);
    };
L
lang 已提交
505

L
lang 已提交
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
    var MOUSE_EVENT_NAMES = [
        'click', 'dblclick', 'mouseover', 'mouseout', 'globalout'
    ];
    /**
     * @private
     */
    echartsProto._initEvents = function () {
        var zr = this._zr;
        each(MOUSE_EVENT_NAMES, function (eveName) {
            zr.on(eveName, function (e) {
                var ecModel = this.getModel();
                var el = e.target;
                if (el && el.dataIndex != null) {
                    var hostModel = el.hostModel || ecModel.getSeriesByIndex(
                        el.seriesIndex, true
                    );
                    var params = hostModel && hostModel.getDataParams(el.dataIndex) || {};
                    params.event = e;
                    params.type = eveName;
                    this.trigger(eveName, params);
                }
            }, this);
        }, this);
    };

L
tweak  
lang 已提交
531 532 533 534 535 536 537
    echartsProto.dispose = function () {
        each(this._components, function (component) {
            component.dispose();
        });
        each(this._charts, function (chart) {
            chart.dispose();
        });
L
lang 已提交
538

L
tweak  
lang 已提交
539
        this.zr.dispose();
L
lang 已提交
540 541
    };

L
lang 已提交
542 543
    zrUtil.mixin(ECharts, Eventful);

L
lang 已提交
544 545 546 547 548 549 550 551 552 553 554 555 556 557
    /**
     * @param {module:echarts/model/Series|module:echarts/model/Component} model
     * @param {module:echarts/view/Component|module:echarts/view/Chart} view
     * @return {string}
     */
    function updateZ(model, view) {
        var z = model.get('z');
        var zlevel = model.get('zlevel');
        // Set z and zlevel
        view.group.traverse(function (el) {
            z != null && (el.z = z);
            zlevel != null && (el.zlevel = zlevel);
        });
    }
L
lang 已提交
558 559 560 561
    /**
     * @type {Array.<Function>}
     * @inner
     */
P
pah100 已提交
562 563
    var actions = [];

L
lang 已提交
564 565 566 567 568 569
    /**
     * Map from eventType to actionType
     * @type {Object}
     */
    var eventActionMap = {};

L
lang 已提交
570 571 572 573
    /**
     * @type {Array.<Function>}
     * @inner
     */
574 575
    var layoutFuncs = [];

L
lang 已提交
576 577 578 579 580 581 582
    /**
     * Data processor functions of each stage
     * @type {Array.<Object.<string, Function>>}
     * @inner
     */
    var dataProcessorFuncs = {};

583 584 585 586 587 588
    /**
     * @type {Array.<Function>}
     * @inner
     */
    var optionPreprocessorFuncs = [];

L
lang 已提交
589 590 591 592 593
    /**
     * Visual coding functions of each stage
     * @type {Array.<Object.<string, Function>>}
     * @inner
     */
594
    var visualCodingFuncs = {};
L
lang 已提交
595

L
lang 已提交
596
    /**
L
lang 已提交
597
     * @alias
L
lang 已提交
598
     */
L
tweak  
lang 已提交
599
    var echarts = {};
L
lang 已提交
600

L
tweak  
lang 已提交
601 602 603 604 605 606 607 608
    /**
     * @param {HTMLDomElement} dom
     * @param {Object} [theme]
     * @param {Object} opts
     */
    echarts.init = function (dom, theme, opts) {
        return new ECharts(dom, theme, opts);
    };
L
lang 已提交
609

L
tweak  
lang 已提交
610 611 612 613 614 615 616
    /**
     * Register option preprocessor
     * @param {Function} preprocessorFunc
     */
    echarts.registerPreprocessor = function (preprocessorFunc) {
        optionPreprocessorFuncs.push(preprocessorFunc);
    };
617

L
tweak  
lang 已提交
618 619 620 621 622 623 624 625 626 627 628
    /**
     * @param {string} stage
     * @param {Function} processorFunc
     */
    echarts.registerProcessor = function (stage, processorFunc) {
        if (zrUtil.indexOf(PROCESSOR_STAGES, stage) < 0) {
            throw new Error('stage should be one of ' + PROCESSOR_STAGES);
        }
        var funcs = dataProcessorFuncs[stage] || (dataProcessorFuncs[stage] = []);
        funcs.push(processorFunc);
    };
L
lang 已提交
629

L
tweak  
lang 已提交
630 631 632 633 634 635 636 637 638 639 640
    /**
     * 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 已提交
641 642 643 644
     * @param {string} [actionInfo.event]
     * @param {string} [actionInfo.update]
     * @param {string} [eventName]
     * @param {Function} action
L
tweak  
lang 已提交
645
     */
L
lang 已提交
646 647 648 649 650
    echarts.registerAction = function (actionInfo, eventName, action) {
        if (typeof eventName === 'function') {
            action = eventName;
            eventName = '';
        }
L
tweak  
lang 已提交
651 652
        var actionType = zrUtil.isObject(actionInfo)
            ? actionInfo.type
L
lang 已提交
653 654 655 656
            : ([actionInfo, actionInfo = {
                event: eventName
            }][0]);
        eventName = actionInfo.event;
657

L
tweak  
lang 已提交
658 659 660
        if (!actions[actionType]) {
            actions[actionType] = {action: action, actionInfo: actionInfo};
        }
L
lang 已提交
661
        eventActionMap[eventName] = actionType;
L
tweak  
lang 已提交
662
    };
P
pah100 已提交
663

L
tweak  
lang 已提交
664 665 666 667 668 669 670
    /**
     * @param {string} type
     * @param {*} CoordinateSystem
     */
    echarts.registerCoordinateSystem = function (type, CoordinateSystem) {
        CoordinateSystemManager.register(type, CoordinateSystem);
    };
L
lang 已提交
671

L
tweak  
lang 已提交
672 673 674 675 676
    /**
     * @param {*} layout
     */
    echarts.registerLayout = function (layout, isFactory) {
        // PENDING All functions ?
677 678
        if (zrUtil.indexOf(layoutFuncs, layout) < 0) {
            layoutFuncs.push(layout);
L
tweak  
lang 已提交
679 680
        }
    };
L
lang 已提交
681

L
tweak  
lang 已提交
682 683 684 685 686 687 688 689 690 691 692
    /**
     * @param {string} stage
     * @param {Function} visualCodingFunc
     */
    echarts.registerVisualCoding = function (stage, visualCodingFunc) {
        if (zrUtil.indexOf(VISUAL_CODING_STAGES, stage) < 0) {
            throw new Error('stage should be one of ' + VISUAL_CODING_STAGES);
        }
        var funcs = visualCodingFuncs[stage] || (visualCodingFuncs[stage] = []);
        funcs.push(visualCodingFunc);
    };
L
Update  
lang 已提交
693

L
tweak  
lang 已提交
694
    /**
L
lang 已提交
695
     * @param {echarts/scale/*} scale
L
tweak  
lang 已提交
696 697 698 699
     */
    echarts.registerScale = function (scale) {
        scaleClasses.register(scale);
    };
L
lang 已提交
700

L
tweak  
lang 已提交
701 702 703 704 705 706
    /**
     * @param {Object} opts
     */
    echarts.extendChartView = function (opts) {
        return ChartView.extend(opts);
    };
L
Update  
lang 已提交
707

L
tweak  
lang 已提交
708 709 710 711 712 713
    /**
     * @param {Object} opts
     */
    echarts.extendComponentModel = function (opts) {
        return ComponentModel.extend(opts);
    };
L
Update  
lang 已提交
714

L
tweak  
lang 已提交
715 716 717 718 719 720
    /**
     * @param {Object} opts
     */
    echarts.extendSeriesModel = function (opts) {
        return SeriesModel.extend(opts);
    };
P
pah100 已提交
721

L
tweak  
lang 已提交
722 723 724 725 726
    /**
     * @param {Object} opts
     */
    echarts.extendComponentView = function (opts) {
        return ComponentView.extend(opts);
L
lang 已提交
727 728
    };

L
lang 已提交
729
    echarts.registerVisualCoding('echarts', require('./visual/seriesColor'));
L
lang 已提交
730

731 732
    echarts.registerPreprocessor(require('./preprocessor/backwardCompat'));

L
lang 已提交
733 734
    return echarts;
});