提交 65c3f366 编写于 作者: L lang

Data model

上级 83224531
......@@ -14,10 +14,10 @@ define(function(require) {
constructor: CoordinateSystemManager,
update: function (option) {
update: function (ecModel) {
this._coordinateSystems = {};
zrUtil.each(coordinateSystemCreators, function (coordinateSystemCreator, type) {
this._coordinateSystems[type] = coordinateSystemCreator.create(option);
this._coordinateSystems[type] = coordinateSystemCreator.create(ecModel);
});
},
......@@ -28,7 +28,11 @@ define(function(require) {
}
},
resize: function () {}
resize: function (ecModel, api) {
zrUtil.each(this._coordinateSystems, function (coordinateSystem) {
coordinateSystem.resize(ecModel, api);
});
}
}
CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
......
define(function(require) {
'use strict';
var zrUtil = require('zrender/core/util');
function getSeriesStackId(seriesModel) {
return seriesModel.get('stack') || '__ec_stack_' + seriesModel.seriesIndex;
}
function BarLayoutGrid() {};
BarLayoutGrid.prototype = {
constructor: BarLayoutGrid,
run: function (ecModel, api) {
var barWidthAndOffset = zrUtil.filter(
this._calBarWidthAndOffset(ecModel.getSeriesByType('bar')),
function (seriesModel) {
return seriesModel.coordinateSystem
&& seriesModel.coordinateSystem.type === 'cartesian2d'
}
);
var lastStackCoords = {};
ecModel.eachSeries(function (seriesModel) {
var data = seriesModel.getData();
var cartesian = seriesModel.coordinateSystem;
var stackId = getSeriesStackId();
var columnLayoutInfo = barWidthAndOffset[cartesian.name][stackId];
var columnOffset = columnLayoutInfo.offset;
var columnWidth = columnLayoutInfo.width;
var projectAxis = columnLayoutInfo.axis;
if (data.type === 'list') {
var coords = cartesian.dataToCoords(data);
lastStackCoords[stackId] = lastStackCoords[stackId] || [];
data.each(function (dataItem, idx) {
var coord = coords[idx];
var lastCoord = lastStackCoords[stackId][idx] || projectAxis.otherCoord;
var x, y, width, height;
if (projectAxis.isHorizontal()) {
x = coord[0] + columnOffset;
y = Math.min(lastCoord, coord[1]);
width = columnWidth;
height = Math.abs(coord[1] - lastCoord);
lastStackCoords[stackId][idx] = y;
}
else {
x = Math.min(lastCoord, coord[0]);
y = coord[1] + columnOffset;
width = Math.abs(coord[0] - lastCoord);
height = columnWidth;
lastStackCoords[stackId][idx] = x;
}
dataItem.layout = {
x: x,
y: x,
width: width,
height: height
};
});
}
}, this);
},
_calBarWidthAndOffset: function (barSeries, api) {
// Columns info on each category axis. Key is cartesian name
var columnsMap = {};
zrUtil.each(barSeries, function (seriesModel, idx) {
var cartesian = seriesModel.coordinateSystem
var categoryAxis = cartesian.getAxesByScale('ordinal')[0];
if (categoryAxis) {
var columnsOnAxis = columnsMap[cartesian.name] || {
remainedWidth: categoryAxis.getBandWidth(true),
autoWidthCount: 0,
categoryGap: '20%',
gap: '30%',
axis: categoryAxis,
stacks: {}
};
var stacks = columnsOnAxis.stacks;
columnsMap[cartesian.name] = columnsOnAxis;
var stackId = getSeriesStackId(seriesModel);
if (! stacks[stackId]) {
columnsOnAxis.autoWidthCount++;
}
stacks[stackId] = stacks[stackId] || {
width: 0,
maxWidth: 0
};
var barWidth = seriesModel.get('barWidth');
var barMaxWidth = seriesModel.get('barMaxWidth');
var barGap = seriesModel.get('barGap');
var barCategoryGap = seriesModel.get('barCategoryGap');
// TODO
if (barWidth && ! stacks[stackId].width) {
barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
stacks[stackId].width = barWidth;
columnsOnAxis.remainedWidth -= barWidth;
}
barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
barGap && (columnsOnAxis.gap = barGap);
barCategoryGap && (columnsOnAxis.categoryGap = barCategoryGap);
}
});
var result = {};
zrUtil.each(columnsMap, function (columnsOnAxis, coordSysName) {
result[coordSysName] = {};
var categoryGap = columnsOnAxis.categoryGap;
var barGapPercent = columnsOnAxis.gap;
var categoryAxis = columnsOnAxis.axis;
var bandWidth = categoryAxis.getBandWidth(true);
if (typeof categoryGap === 'string') {
categoryGap = (parseFloat(categoryGap) / 100) * bandWidth;
}
if (typeof (barGapPercent === 'string')) {
barGapPercent = parseFloat(barGapPercent) / 100;
}
var remainedWidth = columnsOnAxis.remainedWidth;
var autoWidthCount = columnsOnAxis.autoWidthCount;
var autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
autoWidth = Math.max(autoWidth, 0);
// Find if any auto calculated bar exceeded maxBarWidth
zrUtil.each(columnsOnAxis.stacks, function (column, stack) {
var maxWidth = column.maxWidth;
if (! column.width && maxWidth && maxWidth < autoWidth) {
maxWidth = Math.min(maxWidth, remainedWidth);
remainedWidth -= maxWidth;
column.width = maxWidth;
autoWidthCount--;
}
});
// Recalculate width again
autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
autoWidth = Math.max(autoWidth, 0);
zrUtil.each(columnsOnAxis.stacks, function (column) {
if (! column.width) {
column.width = autoWidth;
}
});
var offset = -bandWidth / 2 + categoryGap / 2;
zrUtil.each(columnsOnAxis.stacks, function (column, stackId) {
result[coordSysName][stackId] = result[coordSysName][stackId] || {
offset: offset,
width: column.width,
axis: columnsOnAxis.axis
};
offset += column.width * (1 + barGapPercent);
});
});
return result;
}
};
return BarLayoutGrid;
});
\ No newline at end of file
......@@ -11,22 +11,31 @@ define(function (require) {
render: function (seriesModel, ecModel, api) {
var coordinateSystemType = seriesModel.get('coordinateSystem');
if (coordinateSystemType === 'cartesian') {
if (coordinateSystemType === 'cartesian2d') {
this._renderCartesianBar(seriesModel, ecModel, api);
}
},
_renderCartesianBar: function (series, ecModel, api) {
// Currently only one grid is supported
var grid = api.getCoordinateSystem('grid', 0);
var data = series.getData();
var coords = grid.dataToCoords(
data, series.get('xAxisIndex'), series.get('yAxisIndex')
);
data.each(function (dataItem, idx) {
var coord = coords[idx];
_renderCartesianBar: function (seriesModel, ecModel, api) {
var group = api.createGroup();
seriesModel.getData().each(function (dataItem) {
var layout = dataItem.layout;
dataItem.parent = seriesModel;
var rect = api.createRectangle({
shape: {
x: layout.x,
y: layout.y,
width: layout.width,
height: layout.height
},
style: {
color: dataItem.get('itemStyle.normal.color')
}
});
group.add(rect);
});
}
});
......
......@@ -11,7 +11,7 @@ define(function (require) {
var Axis = require('./CartesianAxis');
function dimAxisMapper(dim) {
return this._axis[dim];
return this._axes[dim];
}
/**
......@@ -19,7 +19,7 @@ define(function (require) {
* @constructor
*/
var Cartesian = function (name) {
this._axis = {};
this._axes = {};
this._dimList = [];
......@@ -46,7 +46,7 @@ define(function (require) {
* @return {module:echarts/coord/Cartesian~Axis}
*/
getAxis: function (dim) {
return this._axis[dim];
return this._axes[dim];
},
/**
......@@ -90,7 +90,7 @@ define(function (require) {
addAxis: function (axis) {
var dim = axis.dim;
this._axis[dim] = axis;
this._axes[dim] = axis;
this._dimList.push(dim);
},
......@@ -120,7 +120,7 @@ define(function (require) {
for (var i = 0; i < dimList.length; i++) {
var dim = dimList[i];
var axis = this._axis[axis];
var axis = this._axes[axis];
output[dim] = axis[method](input[dim]);
}
......
define(function(require) {
'use strict';
var zrUtil = require('zrender/core/util');
var Cartesian = require('./Cartesian');
function Cartesian2D(name) {
Cartesian.call(this, name);
}
Cartesian2D.prototype = {
type: 'cartesian2d',
/**
* Convert series data to coorindates
* @param {module:echarts/data/List} data
* @param {number} [xAxisIndex=0]
* @param {number} [yAxisIndex=0]
* @return {Array}
* Return list of coordinates. For example:
* `[[10, 10], [20, 20], [30, 30]]`
*/
dataToCoords: function (data) {
var xAxis = this.getAxis('x');
var yAxis = this.getAxis('y');
var xAxisCoords = data.mapX(xAxis.dataToCoord, xAxis);
var yAxisCoords = data.mapY(yAxis.dataToCoord, yAxis);
var xIndex = xAxis.isHorizontal() ? 0 : 1;
// If y axis is category axis
var categoryAxis = this.getAxisByScale('ordinal')[0];
if (categoryAxis && categoryAxis.dim === 'y') {
xIndex = 1 - xIndex;
}
return zrUtil.map(xAxisCoords, function (coord, idx) {
var item = [];
item[xIndex] = coord;
item[1 - xIndex] = yAxisCoords[idx];
});
}
};
zrUtil.inherits(Cartesian2D, Cartesian);
return Cartesian2D;
});
\ No newline at end of file
......@@ -6,7 +6,7 @@ define(function(require, factory) {
'use strict';
var zrUtil = require('zrender/core/util');
var Cartesian = require('./Cartesian');
var Cartesian2D = require('./Cartesian2D');
var Axis2D = require('./CartesianAxis2D');
var OrdinalScale = require('../scale/Ordinal');
var IntervalScale = require('../scale/Interval');
......@@ -125,39 +125,6 @@ define(function(require, factory) {
return this._coordsMap[key];
},
/**
* Convert series data to coorindates
* @param {Array} data
* @param {number} [xAxisIndex=0]
* @param {number} [yAxisIndex=0]
* @return {Array}
* Return list of coordinates. For example:
* `[[10, 10], [20, 20], [30, 30]]`
*/
dataToCoords: function (data, xAxisIndex, yAxisIndex) {
xAxisIndex = xAxisIndex || 0;
yAxisIndex = yAxisIndex || 0;
var cartesian = this.getCartesian(xAxisIndex, yAxisIndex);
if (! cartesian) {
// Error
return;
}
var xAxis = cartesian.getAxis('x');
var yAxis = cartesian.getAxis('y');
var xAxisCoords = data.mapX(xAxis.dataToCoord, xAxis);
var yAxisCoords = data.mapY(yAxis.dataToCoord, yAxis);
var xIndex = xAxis.isHorizontal() ? 0 : 1;
return zrUtil.map(xAxisCoords, function (coord, idx) {
var item = [];
item[xIndex] = coord;
item[1 - xIndex] = yAxisCoords[idx];
});
},
/**
* Initialize cartesian coordinate systems
* @private
......@@ -188,7 +155,7 @@ define(function(require, factory) {
ecModel.eachComponent('yAxis', function (yAxisModel, j) {
var key = 'x' + i + 'y' + j;
var cartesian = new Cartesian(key);
var cartesian = new Cartesian2D(key);
this._coordsMap[key] = cartesian;
this._coordsList.push(cartesian);
......@@ -265,7 +232,7 @@ define(function(require, factory) {
ecModel.eachSeries(function (seriesModel, idx) {
var coordinateSystem = seriesModel.get('coordinateSystem');
if (coordinateSystem === 'cartesian') {
if (coordinateSystem === 'cartesian2d') {
var xAxisIndex = seriesModel.get('xAxisIndex');
var yAxisIndex = seriesModel.get('yAxisIndex');
......@@ -282,16 +249,19 @@ define(function(require, factory) {
var data = seriesModel.getData();
if (data.type === 'list') {
var categoryAxis = cartesian.getAxisByScale('ordinal');
if (! categoryAxis || categoryAxis.dim === 'x') {
if (! categoryAxis) {
data.eachY(function (value) {
axisData.y.push(value);
});
}
if (! categoryAxis || categoryAxis.dim === 'y') {
data.eachX(function (value) {
axisData.x.push(value);
});
}
else {
data.eachY(function (value) {
axisData[categoryAxis.dim].push(value);
});
}
}
}
}, this);
......@@ -308,11 +278,18 @@ define(function(require, factory) {
}
};
Grid.create = function (option, api) {
if (option.grid) {
Grid.create = function (ecModel, api) {
if (ecModel.getComponent('grid')) {
var grid = new Grid();
grid.init(option);
grid.resize(option, api);
grid.init(ecModel);
grid.resize(ecModel, api);
// Inject the coordinateSystems into seriesModel
ecModel.eachSeries(function (seriesModel) {
seriesModel.coordinateSystem = grid.getCartesian(
seriesModel.get('xAxisIndex'), seriesModel.get('yAxisIndex')
);
});
}
}
......
......@@ -6,10 +6,11 @@
*/
define(function(require) {
var util = require('zrender/tool/util');
'use strict';
var util = require('zrender/core/util');
var Model = require('../model/Model');
/**
* @alias module:echarts/data/Graph
* @constructor
......@@ -48,39 +49,40 @@ define(function(require) {
/**
* 添加一个新的节点
* @param {string} id 节点名称
* @param {*} [data] 存储的数据
* @param {*} [option] 存储的数据
*/
Graph.prototype.addNode = function (id, data) {
if (this._nodesMap[id]) {
return this._nodesMap[id];
Graph.prototype.addNode = function (option) {
var name = option.name;
if (this._nodesMap[name]) {
return this._nodesMap[name];
}
var node = new Graph.Node(id, data);
var node = new Graph.Node(option);
this.nodes.push(node);
this._nodesMap[id] = node;
this._nodesMap[name] = node;
return node;
};
/**
* 获取节点
* @param {string} id
* @param {string} name
* @return {module:echarts/data/Graph~Node}
*/
Graph.prototype.getNodeById = function (id) {
return this._nodesMap[id];
Graph.prototype.getNodeByName = function (name) {
return this._nodesMap[name];
};
/**
* 添加边
* @param {string|module:echarts/data/Graph~Node} n1
* @param {string|module:echarts/data/Graph~Node} n2
* @param {*} data
* @param {*} option
* @return {module:echarts/data/Graph~Edge}
*/
Graph.prototype.addEdge = function (n1, n2, data) {
Graph.prototype.addEdge = function (n1, n2, option) {
if (typeof(n1) == 'string') {
n1 = this._nodesMap[n1];
}
......@@ -91,12 +93,14 @@ define(function(require) {
return;
}
var key = n1.id + '-' + n2.id;
var key = n1.name + '-' + n2.name;
if (this._edgesMap[key]) {
return this._edgesMap[key];
}
var edge = new Graph.Edge(n1, n2, data);
var edge = new Graph.Edge(option);
edge.node1 = n1;
edge.node2 = n2;
if (this._directed) {
n1.outEdges.push(edge);
......@@ -120,7 +124,7 @@ define(function(require) {
Graph.prototype.removeEdge = function (edge) {
var n1 = edge.node1;
var n2 = edge.node2;
var key = n1.id + '-' + n2.id;
var key = n1.name + '-' + n2.name;
if (this._directed) {
n1.outEdges.splice(util.indexOf(n1.outEdges, edge), 1);
n2.inEdges.splice(util.indexOf(n2.inEdges, edge), 1);
......@@ -142,10 +146,10 @@ define(function(require) {
*/
Graph.prototype.getEdge = function (n1, n2) {
if (typeof(n1) !== 'string') {
n1 = n1.id;
n1 = n1.name;
}
if (typeof(n2) !== 'string') {
n2 = n2.id;
n2 = n2.name;
}
if (this._directed) {
......@@ -168,7 +172,7 @@ define(function(require) {
}
}
delete this._nodesMap[node.id];
delete this._nodesMap[node.name];
this.nodes.splice(util.indexOf(this.nodes, node), 1);
for (var i = 0; i < this.edges.length;) {
......@@ -313,80 +317,74 @@ define(function(require) {
Graph.prototype.clone = function () {
var graph = new Graph(this._directed);
for (var i = 0; i < this.nodes.length; i++) {
graph.addNode(this.nodes[i].id, this.nodes[i].data);
graph.addNode(this.nodes[i].name, this.nodes[i].data);
}
for (var i = 0; i < this.edges.length; i++) {
var e = this.edges[i];
graph.addEdge(e.node1.id, e.node2.id, e.data);
graph.addEdge(e.node1.name, e.node2.name, e.data);
}
return graph;
};
/**
* 图节点
* @alias module:echarts/data/Graph~Node
* @param {string} id
* @param {*} [data]
*/
var Node = function(id, data) {
/**
* 节点名称
* @type {string}
*/
this.id = id;
/**
* 节点存储的数据
* @type {*}
*/
this.data = data || null;
/**
* 入边,只在有向图上有效
* @type {Array.<module:echarts/data/Graph~Edge>}
*/
this.inEdges = [];
/**
* 出边,只在有向图上有效
* @type {Array.<module:echarts/data/Graph~Edge>}
*/
this.outEdges = [];
/**
* 邻接边
* @type {Array.<module:echarts/data/Graph~Edge>}
*/
this.edges = [];
};
/**
* 度
* @return {number}
*/
Node.prototype.degree = function () {
return this.edges.length;
};
var Node = Model.extend({
init: function (option) {
/**
* 节点名称
* @type {string}
*/
this.name = option.name || '';
/**
* 节点存储的数据
* @type {*}
*/
this.$option = option || null;
/**
* 入边,只在有向图上有效
* @type {Array.<module:echarts/data/Graph~Edge>}
*/
this.inEdges = [];
/**
* 出边,只在有向图上有效
* @type {Array.<module:echarts/data/Graph~Edge>}
*/
this.outEdges = [];
/**
* 邻接边
* @type {Array.<module:echarts/data/Graph~Edge>}
*/
this.edges = [];
},
/**
* 入度,只在有向图上有效
* @return {number}
*/
Node.prototype.inDegree = function () {
return this.inEdges.length;
};
/**
* 度
* @return {number}
*/
degree: function () {
return this.edges.length;
},
/**
* 出度,只在有向图上有效
* @return {number}
*/
Node.prototype.outDegree = function () {
return this.outEdges.length;
};
/**
* 入度,只在有向图上有效
* @return {number}
*/
inDegree: function () {
return this.inEdges.length;
},
/**
* 获取数据项
* @return {number}
*/
Node.prototype.getValue = function () {
return this.data.value;
};
/**
* 出度,只在有向图上有效
* @return {number}
*/
outDegree: function () {
return this.outEdges.length;
}
});
/**
* 图边
......@@ -395,24 +393,24 @@ define(function(require) {
* @param {module:echarts/data/Graph~Node} node2
* @param {extra} data
*/
var Edge = function(node1, node2, data) {
var Edge = Model.extend({
/**
* 节点1,如果是有向图则为源节点
* @type {module:echarts/data/Graph~Node}
*/
this.node1 = node1;
node1: null,
/**
* 节点2,如果是有向图则为目标节点
* @type {module:echarts/data/Graph~Node}
*/
this.node2 = node2;
node2: null,
/**
* 边存储的数据
* @type {*}
*/
this.data = data || null;
};
init: function (option) {
this.$option = option;
}
});
Graph.Node = Node;
Graph.Edge = Edge;
......@@ -428,13 +426,13 @@ define(function(require) {
* 4| x x x x x
* 5| x x x x x
* ```
* 节点的行列总和会被写到`node.data.value`
* 对于有向图会计算每一行的和写到`node.data.outValue`,
* 计算每一列的和写到`node.data.inValue`。
* 边的权重会被然后写到`edge.data.weight`。
* 节点的行列总和会被写到`node.$option.value`
* 对于有向图会计算每一行的和写到`node.$option.outValue`,
* 计算每一列的和写到`node.$option.inValue`。
* 边的权重会被然后写到`edge.$option.weight`。
*
* @method module:echarts/data/Graph.fromMatrix
* @param {Array.<Object>} nodesData 节点信息,必须有`id`属性, 会保存到`node.data`中
* @param {Array.<Object>} nodesData 节点信息,必须有`name`属性, 会保存到`node.data`中
* @param {Array} matrix 邻接矩阵
* @param {boolean} directed 是否是有向图
* @return {module:echarts/data/Graph}
......@@ -445,7 +443,7 @@ define(function(require) {
|| (matrix[0].length !== matrix.length)
|| (nodesData.length !== matrix.length)
) {
// Not a valid data
// Not a valname data
return;
}
......@@ -453,23 +451,23 @@ define(function(require) {
var graph = new Graph(directed);
for (var i = 0; i < size; i++) {
var node = graph.addNode(nodesData[i].id, nodesData[i]);
var node = graph.addNode(nodesData[i].name, nodesData[i]);
// TODO
// node.data已经有value的情况
node.data.value = 0;
node.$option.value = 0;
if (directed) {
node.data.outValue = node.data.inValue = 0;
node.$option.outValue = node.$option.inValue = 0;
}
}
for (var i = 0; i < size; i++) {
for (var j = 0; j < size; j++) {
var item = matrix[i][j];
if (directed) {
graph.nodes[i].data.outValue += item;
graph.nodes[j].data.inValue += item;
graph.nodes[i].$option.outValue += item;
graph.nodes[j].$option.inValue += item;
}
graph.nodes[i].data.value += item;
graph.nodes[j].data.value += item;
graph.nodes[i].$option.value += item;
graph.nodes[j].$option.value += item;
}
}
......@@ -482,11 +480,11 @@ define(function(require) {
var n1 = graph.nodes[i];
var n2 = graph.nodes[j];
var edge = graph.addEdge(n1, n2, {});
edge.data.weight = item;
edge.$option.weight = item;
if (i !== j) {
if (directed && matrix[j][i]) {
var inEdge = graph.addEdge(n2, n1, {});
inEdge.data.weight = matrix[j][i];
inEdge.$option.weight = matrix[j][i];
}
}
}
......
......@@ -2,6 +2,7 @@ define(function(require) {
'use strict';
var zrUtil = require('zrender/core/util');
var Model = require('../model/Model');
function createArrayIterWithDepth(maxDepth, properties, cb, context, iterType) {
// Simple optimization to avoid read the undefined value in properties array
......@@ -26,12 +27,86 @@ define(function(require) {
}
}
var Entry = Model.extend({
layout: null,
init: function (option) {
this.name = option.name || '';
this.$option = option;
this._value = option.value === null ? option : option.value
this.rawIndex = 0;
},
/**
* Get x of single data item.
* @return {number}
*/
getX: function () {
// Use idx as x if data is 1d
// Usually when xAxis is category axis
return this.dimension === 1 ? this.rawIndex : this._value[0];
},
setX: function (x) {
if (this.dimension > 1) {
this._value[0] = x;
}
},
/**
* Get y of single data item.
* @return {number}
*/
getY: function () {
if (this.dimension > 1) {
return this._value[1];
}
else {
// Value is a single number if data is 1d
return this._value;
}
},
setY: function (y) {
if (this.dimension > 1) {
this._value[1] = y;
}
else {
this._value = y;
}
},
getZ: function () {
if (this.dimension > 2) {
return this._value[2];
}
},
setZ: function (z) {
if (this.dimension > 2) {
this._value[2] = z;
}
},
getValue: function () {
return this._value[this.dimension];
},
setValue: function (value) {
this._value[this.dimensino] = value
}
});
function List() {
this.elements = this.elements || [];
this.dataDimension = 2;
// Depth and properties is useful in nested Array.
// For example in eventRiver, data structure is a nested 2d array as following
// [{evolution: []}, {evolution: []}]
......@@ -90,88 +165,13 @@ define(function(require) {
},
getItemByName: function (name) {
var elements = this.elements;
for (var i = 0; i < elements.length; i++) {
if (elements[i].name === name) {
return elements[i];
}
}
},
/**
* Get x of single data item.
* can be overwritten
* @param {*} item
* @param {number} idx
* @return {number}
*/
getX: function (item, idx) {
// Use idx as x if data is 1d
// Usually when xAxis is category axis
return this.dataDimension === 1 ? idx : item.value[0];
},
setX: function (item, x) {
if (this.dataDimension > 1) {
item.value[0] = x;
}
},
/**
* Get y of single data item.
* can be overwritten
* @param {*} item
* @return {number}
*/
getY: function (item) {
if (this.dataDimension > 1) {
return item.value[1];
}
else {
// Value is a single number if data is 1d
return item.value;
}
},
setY: function (item, y) {
if (this.dataDimension > 1) {
item.value[1] = y;
}
else {
item.value = y;
}
},
/**
* Get z of single data item.
* can be overwritten
* @param {*} item
* @return {number}
*/
getZ: function (item) {
if (this.dataDimension > 2) {
return item.value[2];
}
},
setZ: function (item, z) {
if (this.dataDimension > 2) {
item.value[2] = z;
}
},
/**
* Get value of single data item.
* can be overwritten
* @param {*} item
* @return {number}
*/
getValue: function (item) {
// PENDING
return item.value[this.dataDimension];
},
setValue: function (item, z) {
item.value[this.dataDimension] = z;
// var elements = this.elements;
// for (var i = 0; i < elements.length; i++) {
// if (elements[i].name === name) {
// return elements[i];
// }
// }
// TODO
},
clone: function () {
......@@ -183,25 +183,23 @@ define(function(require) {
zrUtil.each(['each', 'map', 'filter'], function (iterType) {
List.prototype[iterType + name] = function (cb, context) {
this[iterType](function (item, idx) {
return cb && cb.call(context || this, this['get' + name](item, idx));
return cb && cb.call(context || this, item['get' + name](idx));
}, context);
};
});
});
List.fromArray = function (data) {
List.fromArray = function (data, dimension) {
var list = new List();
// Normalize data
list.elements = zrUtil.map(data, function (dataItem) {
if (dataItem !== Object(dataItem)) {
return {
value: dataItem
};
}
return dataItem;
var entry = new Entry(dataItem);
entry.dimension = dimension;
});
return list;
}
};
List.Entry = Entry;
return List;
});
\ No newline at end of file
......@@ -10,6 +10,9 @@ define(function(require) {
seriesIndex: 0,
// coodinateSystem will be injected in the echarts/CoordinateSystem
coordinateSystem: null,
init: function (seriesOption) {
this.name = seriesOption.name;
......
define(function(require) {
'use strict';
var zrUtil = require('zrender/core/util');
// Process axis to add the default properties
return require('./Processor').extend({
type: 'axisDefault',
optionChanged: function (optionModel) {
var xAxesList = optionModel.get('xAxis');
var yAxesList = optionModel.get('yAxis');
if (xAxesList && ! (xAxesList instanceof Array)) {
xAxesList = [xAxesList];
}
if (yAxesList && ! (yAxesList instanceof Array)) {
yAxesList = [yAxesList];
}
// Find if any axis has position make the x axis vertical orientation
var isXHorizontal = true;
var position;
var xAxesLen = xAxesList.length;
var yAxesLen = yAxesList.length;
for (var i = 0; i < xAxesLen; i++) {
// Merge
var xAxis = xAxesList[i];
// If has vertical x axis
position = xAxis.position;
if (position === 'left' || position === 'right') {
isXHorizontal = false;
break;
}
}
if (isXHorizontal) {
// If has horizontal y axis
for (var i = 0; i < yAxesLen; i++) {
position = yAxesList[i].position;
if (position === 'top' || position === 'bottom') {
isXHorizontal = false;
break;
}
}
}
var gridPositionOccupied = {
left: false,
top: false,
bottom: false,
right: false
};
function processAxesSingleDim(name, axisList) {
for (var i = 0; i < axisList.length; i++) {
var axis = axisList[i];
var position = axis.position;
if (name === 'x') {
// X Axis is default category
axis.type = axis.type || 'category';
}
else {
// Y Axis is default value
axis.type = axis.type || 'value';
}
// Merge from option with specified type
zrUtil.merge(xAxis, optionModel.get(axis.type + 'Axis'));
// Default axis position:
// x axis on the bottom and y axis on the left
if (
(name === 'x' && isXHorizontal)
|| (name === 'y' && ! isXHorizontal)
) {
position = gridPositionOccupied.bottom ?
'top ' : 'bottom';
}
else {
position = gridPositionOccupied.left ?
'right ' : 'left';
}
axis.position = position;
// Take the position on the grid
gridPositionOccupied[position] = true;
}
}
processAxesSingleDim('x', xAxesList);
processAxesSingleDim('y', yAxesList);
optionModel.set('xAxis', xAxesList);
optionModel.set('yAxis', yAxesList);
}
});
});
\ No newline at end of file
......@@ -2,22 +2,7 @@ define(function(require) {
'use strict';
var AxisRangeFilter = require('./Processor').extend({
return function (ecModel) {
type: 'axisRangeFilter',
optionChanged: function (option) {
},
syncState: function () {
},
process: function () {
}
});
return AxisRangeFilter;
};
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册