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

Improve bar layout, legendAction parameters remove legendModel

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