提交 5da7fb4f 编写于 作者: L lang

Daily update

上级 65c3f366
......@@ -176,5 +176,7 @@ define(function(require) {
}
};
require('../../echarts').registerLayout(BarLayoutGrid);
return BarLayoutGrid;
});
\ No newline at end of file
......@@ -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;
}
});
......
......@@ -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
......@@ -7,6 +7,7 @@ define(function (require) {
type: 'legend',
render: function (ecModel, api) {
var legendModel = ecModel.getComponent('legend');
}
});
});
\ No newline at end of file
{
}
\ No newline at end of file
......@@ -293,5 +293,7 @@ define(function(require, factory) {
}
}
require('../../CoordinateSystem').register('grid', Grid);
return Grid;
});
\ No newline at end of file
......@@ -25,12 +25,24 @@ define(function(require) {
this._directed = directed || false;
/**
* @type {Array}
* @type {Array.<module:echarts/data/Graph~Node>}
*/
this.nodes = [];
/**
* @type {Array.<module:echarts/data/Graph~Edge>}
*/
this.edges = [];
/**
* @type {Object.<string, module:echarts/data/Graph~Node>}
* @private
*/
this._nodesMap = {};
/**
* @type {Object.<string, module:echarts/data/Graph~Edge>}
* @private
*/
this._edgesMap = {};
};
......
......@@ -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;
......
......@@ -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.<module:echarts/data/Tree~TreeNode>}
*/
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.<module:echarts/data/Tree~TreeNode>}
* @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.<Object>} 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;
......
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
/**
* 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.<module:echarts/model/Series>}
*/
getSeriesAll: function () {
return this._series;
},
eachSeries: function (cb, context) {
zrUtil.each(this._series, cb, context);
},
......
/**
* @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
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册