From 5da7fb4f9e9c422543a39e44de844a458367d9a0 Mon Sep 17 00:00:00 2001 From: lang Date: Mon, 17 Aug 2015 00:25:02 +0800 Subject: [PATCH] Daily update --- src/chart/bar/BarLayoutGrid.js | 2 + src/chart/bar/BarSeries.js | 3 +- src/chart/pie/PieSeries.js | 2 +- src/component/legend/LegendView.js | 1 + src/config.js | 3 - src/coord/cartesian/Grid.js | 2 + src/data/Graph.js | 14 +- src/data/List.js | 65 +++++--- src/data/Tree.js | 234 +++++++++++++++-------------- src/echarts.js | 68 ++++++--- src/model/Global.js | 22 ++- src/model/Model.js | 36 +++-- src/processor/seriesStack.js | 5 +- 13 files changed, 288 insertions(+), 169 deletions(-) delete mode 100644 src/config.js diff --git a/src/chart/bar/BarLayoutGrid.js b/src/chart/bar/BarLayoutGrid.js index 3febce04d..33e06a962 100644 --- a/src/chart/bar/BarLayoutGrid.js +++ b/src/chart/bar/BarLayoutGrid.js @@ -176,5 +176,7 @@ define(function(require) { } }; + require('../../echarts').registerLayout(BarLayoutGrid); + return BarLayoutGrid; }); \ No newline at end of file diff --git a/src/chart/bar/BarSeries.js b/src/chart/bar/BarSeries.js index e2b67ba5e..7be286745 100644 --- a/src/chart/bar/BarSeries.js +++ b/src/chart/bar/BarSeries.js @@ -9,8 +9,7 @@ define(function(require) { type: 'bar', getInitialData: function (option) { - var list = List.fromArray(option.data); - list.dataDimension = 1; + var list = List.fromArray(option.data, this, 1); return list; } }); diff --git a/src/chart/pie/PieSeries.js b/src/chart/pie/PieSeries.js index 0a8ed011e..b7fa7ae72 100644 --- a/src/chart/pie/PieSeries.js +++ b/src/chart/pie/PieSeries.js @@ -9,7 +9,7 @@ define(function(require) { type: 'pie', getInitialData: function (option) { - return List.fromArray(option.data); + return List.fromArray(option.data, this, 1); } }); }); \ No newline at end of file diff --git a/src/component/legend/LegendView.js b/src/component/legend/LegendView.js index 2e9155d73..85dee4a94 100644 --- a/src/component/legend/LegendView.js +++ b/src/component/legend/LegendView.js @@ -7,6 +7,7 @@ define(function (require) { type: 'legend', render: function (ecModel, api) { + var legendModel = ecModel.getComponent('legend'); } }); }); \ No newline at end of file diff --git a/src/config.js b/src/config.js deleted file mode 100644 index 544b7b4dd..000000000 --- a/src/config.js +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} \ No newline at end of file diff --git a/src/coord/cartesian/Grid.js b/src/coord/cartesian/Grid.js index 0dcc43fb9..e0ad1b98b 100644 --- a/src/coord/cartesian/Grid.js +++ b/src/coord/cartesian/Grid.js @@ -293,5 +293,7 @@ define(function(require, factory) { } } + require('../../CoordinateSystem').register('grid', Grid); + return Grid; }); \ No newline at end of file diff --git a/src/data/Graph.js b/src/data/Graph.js index b4ab7b54b..59332c89a 100644 --- a/src/data/Graph.js +++ b/src/data/Graph.js @@ -25,12 +25,24 @@ define(function(require) { this._directed = directed || false; /** - * @type {Array} + * @type {Array.} */ this.nodes = []; + + /** + * @type {Array.} + */ this.edges = []; + /** + * @type {Object.} + * @private + */ this._nodesMap = {}; + /** + * @type {Object.} + * @private + */ this._edgesMap = {}; }; diff --git a/src/data/List.js b/src/data/List.js index ac209806f..54fcb478e 100644 --- a/src/data/List.js +++ b/src/data/List.js @@ -11,17 +11,15 @@ define(function(require) { if (depth === maxDepth) { return zrUtil[iterType](array, cb, context); } - else { - if (array) { - var property = properties[i]; - for (var i = 0; i < array.length; i++) { - var item = array[i]; - // Access property of each item - if (nestedProperties && property && item) { - item = item[property]; - } - array[i] = eachAxis(item, depth); + else if (array) { + var property = properties[depth]; + for (var i = 0; i < array.length; i++) { + var item = array[i]; + // Access property of each item + if (nestedProperties && property && item) { + item = item[property]; } + array[i] = eachAxis(item, depth); } } } @@ -31,20 +29,32 @@ define(function(require) { layout: null, - init: function (option) { - + init: function (option, parent, dataIndex) { + + /** + * @type {string} + * @memeberOf module:echarts/data/List~Entry + * @public + */ this.name = option.name || ''; this.$option = option; + /** + * @type {number|Array} + * @memeberOf module:echarts/data/List~Entry + * @private + */ this._value = option.value === null ? option : option.value - this.rawIndex = 0; + /** + * @private + * @readOnly + */ + this.rawIndex = dataIndex || 0; }, - /** - * Get x of single data item. * @return {number} */ getX: function () { @@ -53,6 +63,9 @@ define(function(require) { return this.dimension === 1 ? this.rawIndex : this._value[0]; }, + /** + * @param {number} x + */ setX: function (x) { if (this.dimension > 1) { this._value[0] = x; @@ -60,7 +73,6 @@ define(function(require) { }, /** - * Get y of single data item. * @return {number} */ getY: function () { @@ -73,6 +85,9 @@ define(function(require) { } }, + /** + * @param {number} y + */ setY: function (y) { if (this.dimension > 1) { this._value[1] = y; @@ -82,22 +97,34 @@ define(function(require) { } }, + /** + * @return {number} + */ getZ: function () { if (this.dimension > 2) { return this._value[2]; } }, + /** + * @param {number} z + */ setZ: function (z) { if (this.dimension > 2) { this._value[2] = z; } }, + /** + * @return {number} + */ getValue: function () { return this._value[this.dimension]; }, + /** + * @param {number} value + */ setValue: function (value) { this._value[this.dimensino] = value } @@ -189,11 +216,11 @@ define(function(require) { }); }); - List.fromArray = function (data, dimension) { + List.fromArray = function (data, dimension, parentModel) { var list = new List(); // Normalize data - list.elements = zrUtil.map(data, function (dataItem) { - var entry = new Entry(dataItem); + list.elements = zrUtil.map(data, function (dataItem, index) { + var entry = new Entry(dataItem, parentModel, index); entry.dimension = dimension; }); return list; diff --git a/src/data/Tree.js b/src/data/Tree.js index 96c4d8ee4..1c1c085bd 100644 --- a/src/data/Tree.js +++ b/src/data/Tree.js @@ -7,128 +7,138 @@ define(function(require) { var zrUtil = require('zrender/tool/util'); + var Model = require('../model/Model'); /** * @constructor module:echarts/data/Tree~TreeNode - * @param {string} id Node ID - * @param {Object} [data] + * @param {Object} option */ - function TreeNode(id, data) { - /** - * @type {string} - */ - this.id = id; - /** - * 节点的深度 - * @type {number} - */ - this.depth = 0; - /** - * 以当前节点为根节点的子树的高度 - * @type {number} - */ - this.height = 0; - /** - * 子节点列表 - * @type {Array.} - */ - this.children = []; - - /** - * @type {module:echarts/data/Tree~TreeNode} - */ - this.parent = null; + var TreeNode = Model.extend({ + + init: function (option) { + /** + * @type {string} + * @memberOf {module:echarts/data/Tree~TreeNode} + * @readOnly + */ + this.name = option.name || ''; + /** + * 节点的深度 + * @type {number} + * @readOnly + */ + this.depth = 0; + /** + * 以当前节点为根节点的子树的高度 + * @type {number} + * @readOnly + */ + this.height = 0; + + /** + * @type {module:echarts/data/Tree~TreeNode} + * @readOnly + */ + this.parentNode = null; + + /** + * 存储的用户数据 + * @type {Object} + */ + this.$option = option || null; + + /** + * 子节点列表 + * @type {Array.} + * @readOnly + */ + this.children = []; + }, /** - * 存储的用户数据 - * @type {Object} - */ - this.data = data || null; - } - - /** - * 添加子节点 - * @param {module:echarts/data/Tree~TreeNode} child - */ - TreeNode.prototype.add = function (child) { - var children = this.children; - if (child.parent === this) { - return; - } - - children.push(child); - child.parent = this; - }; + * 添加子节点 + * @param {module:echarts/data/Tree~TreeNode} child + */ + add: function (child) { + var children = this.children; + if (child.parentNode === this) { + return; + } - /** - * 移除子节点 - * @param {module:echarts/data/Tree~TreeNode} child - */ - TreeNode.prototype.remove = function (child) { - var children = this.children; - var idx = zrUtil.indexOf(children, child); - if (idx >= 0) { - children.splice(idx, 1); - child.parent = null; - } - }; + children.push(child); + child.parentNode = this; + }, - /** - * 遍历当前节点及其所有子节点 - * @param {Function} cb - * @param {Object} [context] - */ - TreeNode.prototype.eachNode = function (cb, context) { - cb.call(context, this); + /** + * 移除子节点 + * @param {module:echarts/data/Tree~TreeNode} child + */ + remove: function (child) { + var children = this.children; + var idx = zrUtil.indexOf(children, child); + if (idx >= 0) { + children.splice(idx, 1); + child.parentNode = null; + } + }, - for (var i = 0; i < this.children.length; i++) { - this.children[i].eachNode(cb, context); - } - }; + /** + * 遍历当前节点及其所有子节点 + * @param {Function} cb + * @param {Object} [context] + */ + eachNode: function (cb, context) { + cb.call(context, this); + + for (var i = 0; i < this.children.length; i++) { + this.children[i].eachNode(cb, context); + } + }, - /** - * 更新当前树及所有子树的高度和深度 - * @param {number} depth - */ - TreeNode.prototype.updateDepthAndHeight = function (depth) { - var height = 0; - this.depth = depth; - for (var i = 0; i < this.children.length; i++) { - var child = this.children[i]; - child.updateDepthAndHeight(depth + 1); - if (child.height > height) { - height = child.height; + /** + * 更新当前树及所有子树的高度和深度 + * @param {number} depth + */ + updateDepthAndHeight: function (depth) { + var height = 0; + this.depth = depth; + for (var i = 0; i < this.children.length; i++) { + var child = this.children[i]; + child.updateDepthAndHeight(depth + 1); + if (child.height > height) { + height = child.height; + } } - } - this.height = height + 1; - }; + this.height = height + 1; + }, - /** - * @param {string} id - * @return module:echarts/data/Tree~TreeNode - */ - TreeNode.prototype.getNodeById = function (id) { - if (this.id === id) { - return this; - } - for (var i = 0; i < this.children.length; i++) { - var res = this.children[i].getNodeById(id); - if (res) { - return res; + /** + * @param {string} name + * @return module:echarts/data/Tree~TreeNode + */ + getNodeByName: function (name) { + if (this.name === name) { + return this; + } + for (var i = 0; i < this.children.length; i++) { + var res = this.children[i].getNodeByName(name); + if (res) { + return res; + } } } - }; + }); /** * @constructor * @alias module:echarts/data/Tree - * @param {string} id + * @param {string} name */ - function Tree(id) { + function Tree(name) { /** * @type {module:echarts/data/Tree~TreeNode} */ - this.root = new TreeNode(id); + this.root = new TreeNode(name); } Tree.prototype.type = 'tree'; @@ -144,44 +154,44 @@ define(function(require) { /** * 生成子树 - * @param {string} id 子树根节点 id + * @param {string} name 子树根节点 name * @return {module:echarts/data/Tree} */ - Tree.prototype.getSubTree = function(id) { - var root = this.getNodeById(id); + Tree.prototype.getSubTree = function(name) { + var root = this.getNodeByName(name); if (root) { - var tree = new Tree(root.id); + var tree = new Tree(root.name); tree.root = root; return tree; } }; /** - * @param {string} id + * @param {string} name * @return module:echarts/data/Tree~TreeNode */ - Tree.prototype.getNodeById = function (id) { - return this.root.getNodeById(id); + Tree.prototype.getNodeByName = function (name) { + return this.root.getNodeByName(name); }; /** * 从 option 里的 data 数据构建树 - * @param {string} id + * @param {string} name * @param {Array.} data * @return module:echarts/data/Tree */ - Tree.fromOptionData = function (id, data) { - var tree = new Tree(id); + Tree.fromOptionData = function (name, data) { + var tree = new Tree(name); var rootNode = tree.root; // Root node rootNode.data = { - name: id, + name: name, children: data }; function buildHierarchy(dataNode, parentNode) { - var node = new TreeNode(dataNode.name, dataNode); + var node = new TreeNode(dataNode); parentNode.add(node); // 遍历添加子节点 var children = dataNode.children; diff --git a/src/echarts.js b/src/echarts.js index f1f58aa89..6aa1265b5 100644 --- a/src/echarts.js +++ b/src/echarts.js @@ -1,6 +1,6 @@ define(function (require) { - var config = require('./config'); + var defaultOption = require('./config'); var GlobalModel = require('./model/Global'); var zrUtil = require('zrender/core/util'); var Chart = require('./chart/Chart'); @@ -10,8 +10,6 @@ define(function (require) { var zrender = require('zrender'); - var processors = []; - /** * @module echarts~ECharts */ @@ -33,6 +31,10 @@ define(function (require) { this._extensionAPI = new ExtensionAPI(this); this._coordinateSystem = new CoordinateSystemManager(); + + this._layouts = zrUtil.map(layoutClasses, function (Layout) { + return new Layout(); + }); }; ECharts.prototype = { @@ -41,11 +43,11 @@ define(function (require) { return this._zr; }, - setOption: function (rawOption, merge) { - rawOption = zrUtil.clone(rawOption); - zrUtil.merge(rawOption, this._theme); + setOption: function (option, merge) { + option = zrUtil.clone(option); + zrUtil.merge(option, this._theme); - var ecModel = new GlobalModel(rawOption); + var ecModel = new GlobalModel(option); // Add series index ecModel.eachSeries(function (series, seriesIndex) { @@ -70,17 +72,33 @@ define(function (require) { }, updateImmediately: function () { - this._model.restore(); + var ecModel = this._model; + + ecModel.restore(); - this._processData(this._model); + this._processData(ecModel); - this._coordinateSystem.update(this._model); + this._coordinateSystem.update(ecModel); - this._doRender(this._model); + this._doLayout(ecModel); + + this._doRender(ecModel); }, resize: function () { - this._coordinateSystem.resize(this._model, this._extensionAPI); + var ecModel = this._model; + + this._coordinateSystem.resize(ecModel, this._extensionAPI); + + this._doLayout(ecModel); + + this._doRender(ecModel); + }, + + _doLayout: function (model) { + zrUtil.each(this._layouts, function (layout) { + layout.run(model); + }); }, _prepareCharts: function (ecModel) { @@ -146,7 +164,7 @@ define(function (require) { }, _processData: function (ecModel) { - zrUtil.each(processors, function (processor) { + zrUtil.each(processorList, function (processor) { processor(ecModel); }); }, @@ -181,6 +199,10 @@ define(function (require) { }; + var processorList = []; + + var layoutClasses = []; + /** * @module echarts */ @@ -190,19 +212,29 @@ define(function (require) { return new ECharts(dom, theme); }, - registreProcessor: function (Processor) { - + registerProcessor: function (processor) { + if (zrUtil.indexOf(processorList, processor) < 0) { + processorList.push(processor); + } }, registerCoordinateSystem: function (type, CoordinateSystem) { + CoordinateSystemManager.register(type, CoordinateSystem); + }, + + registerLayout: function (layout) { + if (zrUtil.indexOf(layoutClasses, layout) < 0) { + layoutClasses.push(layout); + } + }, + + registerVisualCoding: function () { } }; - echarts.registreProcessor(require('./processor/AxisDefault')); - - echarts.registreProcessor(require('./processor/SeriesFilter')); + echarts.registerProcessor(require('./processor/seriesFilter')); return echarts; }); \ No newline at end of file diff --git a/src/model/Global.js b/src/model/Global.js index 9d1b77121..c7831eeaf 100644 --- a/src/model/Global.js +++ b/src/model/Global.js @@ -1,3 +1,9 @@ +/** + * ECharts global model + * + * @module {echarts/model/Global} + */ + define(function (require) { var zrUtil = require('zrender/core/util'); @@ -6,6 +12,9 @@ define(function (require) { var SeriesModel = require('./SeriesModel'); var ComponentModel = require('./Component/Model'); + /** + * @alias module:echarts/model/Global + */ var GlobalModel = Model.extend({ constructor: GlobalModel, @@ -108,10 +117,21 @@ define(function (require) { }); }, - getSeriesAll: function (seriesIndex) { + /** + * @param {number} seriesIndex + * @return {module:echarts/model/Series} + */ + getSeries: function (seriesIndex) { return this._series[seriesIndex]; }, + /** + * @return {Array.} + */ + getSeriesAll: function () { + return this._series; + }, + eachSeries: function (cb, context) { zrUtil.each(this._series, cb, context); }, diff --git a/src/model/Model.js b/src/model/Model.js index 1538322ee..cd45b6813 100644 --- a/src/model/Model.js +++ b/src/model/Model.js @@ -1,20 +1,38 @@ +/** + * @module echarts/model/Model + */ define(function (require) { var zrUtil = require('zrender/core/util'); - function Model(option, parent) { + /** + * @alias module:echarts/model/Model + * @constructor + */ + function Model(option, parentModel) { - this.parent = parent || null; + /** + * @type {module:echarts/model/Model} + */ + this.parentModel = parentModel || null; + /** + * @type {Object} + * @readOnly + */ this.$option = {}; - this.init(option); + this.init.apply(this, arguments); } Model.prototype = { constructor: Model, + /** + * Model 的初始化函数 + * @param {Object} option + */ init: function (option) { this.$option = option; }, @@ -26,6 +44,10 @@ define(function (require) { zrUtil.merge(this.$option, option); }, + /** + * @param {string} path + * @return {*} + */ get: function (path) { if (typeof path == 'string') { path = path.split('.'); @@ -37,16 +59,12 @@ define(function (require) { break; } } - if (obj == null && this.parent) { - return this.parent.get(path); + if (obj == null && this.parentModel) { + return this.parentModel.get(path); } return obj; }, - getOption: function () { - return this.$option; - }, - restore: function () {}, // Pending diff --git a/src/processor/seriesStack.js b/src/processor/seriesStack.js index 8e3feb2fd..91b951016 100644 --- a/src/processor/seriesStack.js +++ b/src/processor/seriesStack.js @@ -5,10 +5,9 @@ define(function() { var stackedMap = {}; option.eachSeries(function (series) { var data = series.getData(); + var stack = series.get('stack'); - if (data.type === 'list' && data.dataDimension === 1) { - - var id = series.get('name') + '_' + series.get('name'); + if (stack && data.type === 'list') { data.eachY(function (y, idx) { stackedMap[idx] = stackedMap[idx] || 0; -- GitLab