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
Resize  
lang 已提交
96 97 98

        // In case some people write `window.onresize = chart.resize`
        this.resize = zrUtil.bind(this.resize, this);
L
lang 已提交
99
    }
L
lang 已提交
100

L
tweak  
lang 已提交
101
    var echartsProto = ECharts.prototype;
L
lang 已提交
102

L
tweak  
lang 已提交
103 104 105
    echartsProto.getDom = function () {
        return this._dom;
    };
L
lang 已提交
106

L
tweak  
lang 已提交
107 108 109
    echartsProto.getZr = function () {
        return this._zr;
    };
L
lang 已提交
110

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

L
tweak  
lang 已提交
115 116 117
        each(optionPreprocessorFuncs, function (preProcess) {
            preProcess(option);
        });
L
lang 已提交
118

L
tweak  
lang 已提交
119 120 121 122 123 124 125 126 127
        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 已提交
128

L
tweak  
lang 已提交
129
        this._prepareComponents(ecModel);
L
lang 已提交
130

L
tweak  
lang 已提交
131
        this._prepareCharts(ecModel);
L
lang 已提交
132

L
tweak  
lang 已提交
133
        this.update();
L
lang 已提交
134

L
tweak  
lang 已提交
135 136
        refreshImmediately && this._zr.refreshImmediately();
    };
L
lang 已提交
137

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

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

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

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

L
tweak  
lang 已提交
165
        var ecModel = this._model;
L
lang 已提交
166

L
tweak  
lang 已提交
167
        ecModel.restoreData();
L
lang 已提交
168

L
tweak  
lang 已提交
169 170 171
        // 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 已提交
172

L
tweak  
lang 已提交
173
        this._processData(ecModel);
L
lang 已提交
174

L
tweak  
lang 已提交
175
        this._stackSeriesData(ecModel);
L
lang 已提交
176

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

L
tweak  
lang 已提交
179
        this._doLayout(ecModel, payload);
180

L
tweak  
lang 已提交
181
        this._doVisualCoding(ecModel, payload);
182

L
tweak  
lang 已提交
183
        this._doRender(ecModel, payload);
184

L
tweak  
lang 已提交
185 186 187 188 189 190 191 192
        // 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 已提交
193
            }
L
tweak  
lang 已提交
194 195
        }
        backgroundColor && (this._dom.style.backgroundColor = backgroundColor);
L
lang 已提交
196

L
lang 已提交
197
        // console.time && console.timeEnd('update');
L
tweak  
lang 已提交
198
    };
199

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

L
tweak  
lang 已提交
207
        this._doLayout(ecModel, payload);
208

L
tweak  
lang 已提交
209
        this._doVisualCoding(ecModel, payload);
210

L
tweak  
lang 已提交
211 212
        this._invokeUpdateMethod('updateView', ecModel, payload);
    };
213

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

L
tweak  
lang 已提交
220
        this._doVisualCoding(ecModel, payload);
221

L
tweak  
lang 已提交
222 223
        this._invokeUpdateMethod('updateVisual', ecModel, payload);
    };
224

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

L
tweak  
lang 已提交
231
        this._doLayout(ecModel, payload);
232

L
tweak  
lang 已提交
233 234
        this._invokeUpdateMethod('updateLayout', ecModel, payload);
    };
L
lang 已提交
235

L
Resize  
lang 已提交
236 237 238
    /**
     * Resize the chart
     */
L
tweak  
lang 已提交
239
    echartsProto.resize = function () {
L
Resize  
lang 已提交
240
        this._zr.resize();
L
tweak  
lang 已提交
241 242
        this.update();
    };
P
pah100 已提交
243

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

L
tweak  
lang 已提交
254 255 256 257 258 259 260 261 262
    /**
     * @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 已提交
263 264
            var actionInfo = actionWrap.actionInfo;
            var updateMethod = actionInfo.update || 'update';
L
tweak  
lang 已提交
265 266
            actionWrap.action(payload, this._model);
            updateMethod !== 'none' && this[updateMethod](payload);
L
lang 已提交
267 268 269 270 271 272

            // 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 已提交
273 274
        }
    };
275

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

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

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

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

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

L
tweak  
lang 已提交
299
    };
L
lang 已提交
300

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

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

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

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

            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 已提交
330 331
                }
                else {
L
tweak  
lang 已提交
332
                    // Error
L
lang 已提交
333
                }
334
            }
L
lang 已提交
335

L
tweak  
lang 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
            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 已提交
353

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

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

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

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

373
            var id = componentModel.getId();
L
tweak  
lang 已提交
374 375 376 377 378 379 380 381 382 383 384 385 386 387
            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 已提交
388
                }
389
            }
L
tweak  
lang 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
            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 已提交
409

L
tweak  
lang 已提交
410 411 412 413 414 415 416 417 418 419
    /**
     * 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 已提交
420
            });
L
tweak  
lang 已提交
421 422
        });
    };
L
lang 已提交
423

L
tweak  
lang 已提交
424 425 426 427 428 429 430 431 432 433 434 435
    /**
     * @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 已提交
436
                }
L
tweak  
lang 已提交
437 438 439 440
                stackedDataMap[stack] = data;
            }
        });
    };
L
lang 已提交
441

L
tweak  
lang 已提交
442
    /**
L
lang 已提交
443
     * Layout before each chart render there series, after visual coding and data processing
L
tweak  
lang 已提交
444 445 446 447 448 449 450 451 452 453
     *
     * @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 已提交
454

L
tweak  
lang 已提交
455 456 457 458 459 460 461 462 463 464
    /**
     * 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 已提交
465
            });
L
tweak  
lang 已提交
466 467
        });
    };
L
lang 已提交
468

L
tweak  
lang 已提交
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
    /**
     * 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) {
489
            var chart = this._chartsMap[seriesModel.getId()];
L
tweak  
lang 已提交
490 491 492 493 494 495
            chart.__keepAlive = true;
            chart.render(seriesModel, ecModel, api, payload);

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

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

L
lang 已提交
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
    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 已提交
529 530 531 532 533 534 535
    echartsProto.dispose = function () {
        each(this._components, function (component) {
            component.dispose();
        });
        each(this._charts, function (chart) {
            chart.dispose();
        });
L
lang 已提交
536

L
tweak  
lang 已提交
537
        this.zr.dispose();
L
lang 已提交
538 539
    };

L
lang 已提交
540 541
    zrUtil.mixin(ECharts, Eventful);

L
lang 已提交
542 543 544 545 546 547 548 549 550 551 552 553 554 555
    /**
     * @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 已提交
556 557 558 559
    /**
     * @type {Array.<Function>}
     * @inner
     */
P
pah100 已提交
560 561
    var actions = [];

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

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

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

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

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

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

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

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

L
tweak  
lang 已提交
616 617 618 619 620 621 622 623 624 625 626
    /**
     * @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 已提交
627

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

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

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

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

L
tweak  
lang 已提交
680 681 682 683 684 685 686 687 688 689 690
    /**
     * @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 已提交
691

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

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

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

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

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

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

729 730
    echarts.registerPreprocessor(require('./preprocessor/backwardCompat'));

L
lang 已提交
731 732
    return echarts;
});