提交 4ed2b265 编写于 作者: L lang

Improve bar layout, legendAction parameters remove legendModel

上级 d8d34c3a
......@@ -181,7 +181,8 @@ define(function(require) {
},
style: {
lineWidth: tickLineWidth
}
},
silent: true
})));
}
var tickEl = api.mergePath(tickLines, {
......@@ -356,7 +357,8 @@ define(function(require) {
},
style: {
lineWidth: lineWidth
}
},
silent: true
})));
}
......@@ -427,7 +429,8 @@ define(function(require) {
y: y,
width: width,
height: height
}
},
silent: true
}));
prevX = x + width;
......
define(function (require) {
var zrUtil = require('zrender/core/util');
var numberUtil = require('../../util/number');
var symbolCreator = require('../../util/symbol');
function createSelectActionDispatcher(uid, seriesName, api) {
api.dispatch({
type: 'legendToggleSelect',
from: uid,
seriesName: seriesName
});
}
return require('../../echarts').extendComponentView({
type: 'legend',
......@@ -65,14 +74,9 @@ define(function (require) {
group.add(legendSymbol);
group.add(text);
legendSymbol.on('click', function () {
api.dispatch({
type: 'legendSelected',
from: this.uid,
legendModel: legendModel,
seriesName: seriesName
});
}, this);
var onClick = zrUtil.curry(createSelectActionDispatcher, this.uid, seriesName, api);
legendSymbol.on('click', onClick, this);
text.on('click', onClick, this);
}, this);
var groupRect = group.getBoundingRect();
......
......@@ -5,8 +5,17 @@ define(function(require) {
var echarts = require('../../echarts');
echarts.registerAction('legendSelected', function (event, ecModel) {
event.legendModel.toggleSelected(event.seriesName);
/**
* @event legendToggleSelect
* @type {Object}
* @property {string} type 'legendToggleSelect'
* @property {string} [from]
* @property {string} seriesName
*/
echarts.registerAction('legendToggleSelect', function (event, ecModel) {
// Update all legend components
ecModel.eachComponent('legend', function (legendModel) {
legendModel && legendModel.toggleSelected(event.seriesName);
});
});
});
\ No newline at end of file
......@@ -142,8 +142,10 @@ define(function(require) {
var valueAxis = cartesian.getOtherAxis(columnLayoutInfo.axis);
if (data.type === 'list') {
var valueAxisStart = valueAxis.getExtent()[0];
var coords = cartesian.dataToCoords(data);
lastStackCoords[stackId] = lastStackCoords[stackId] || [];
data.each(function (dataItem, dataIndex) {
var value = dataItem.getValue(true);
......@@ -153,22 +155,24 @@ define(function(require) {
}
var coord = coords[dataIndex];
var lastCoord = lastStackCoords[stackId][dataIndex] || valueAxis.dataToCoord(0);
var lastCoord = lastStackCoords[stackId][dataIndex] || valueAxisStart;
var x, y, width, height;
if (valueAxis.isHorizontal()) {
x = Math.min(lastCoord, coord[0]);
y = coord[1] + columnOffset;
width = Math.abs(coord[0] - lastCoord);
height = columnWidth;
lastStackCoords[stackId][dataIndex] = x;
lastCoord += coord[0] - lastCoord;
}
else {
x = coord[0] + columnOffset;
y = Math.min(lastCoord, coord[1]);
width = columnWidth;
height = Math.abs(coord[1] - lastCoord);
lastStackCoords[stackId][dataIndex] = y;
lastCoord += coord[1] - lastCoord;
}
lastStackCoords[stackId][dataIndex] = lastCoord;
dataItem.layout = {
x: x,
y: y,
......
......@@ -2,8 +2,11 @@
* ECharts global model
*
* @module {echarts/model/Global}
*
*/
// FIXME Filter 后 series 是否能够被 getComponent 或者 getComponenentById 获取?
define(function (require) {
var zrUtil = require('zrender/core/util');
......@@ -42,6 +45,12 @@ define(function (require) {
*/
this._componentsMap = {};
/**
* @type {Object.<string, module:echarts/model/Model>}
* @private
*/
this._componentsIdMap = {};
/**
* @type {Object.<string, module:echarts/model/Model>}
* @private
......@@ -88,7 +97,6 @@ define(function (require) {
var option = this.option;
var componentsMap = this._componentsMap;
var components = this._components;
var componentTypes = [];
// 如果不存在对应的 component model 则直接 merge
......@@ -140,7 +148,10 @@ define(function (require) {
this._getComponentsByTypes(dependencies), i
);
componentsMap[componentType][i] = componentModel;
components.push(componentModel);
// Merge option is incremental
this._components.push(componentModel);
this._componentsIdMap[componentModel.uid] = componentModel;
}
}
}, this);
......@@ -159,6 +170,8 @@ define(function (require) {
},
/**
* @param {string} type
* @param {number} [idx=0]
* @return {module:echarts/model/Component}
*/
getComponent: function (type, idx) {
......@@ -168,6 +181,14 @@ define(function (require) {
}
},
/**
* @param {string} uid
* @return {module:echarts/model/Component}
*/
getComponentById: function (uid) {
return this._componentsIdMap[uid];
},
/**
* @param {string} type
* @param {Function} cb
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册