未验证 提交 33a2e4b8 编写于 作者: S sushuang 提交者: GitHub

Fix group layout

上级 f83c355f
...@@ -267,7 +267,7 @@ echarts.extendComponentView({ ...@@ -267,7 +267,7 @@ echarts.extendComponentView({
} }
this._lastGraphicModel = graphicModel; this._lastGraphicModel = graphicModel;
this._updateElements(graphicModel, api); this._updateElements(graphicModel);
this._relocate(graphicModel, api); this._relocate(graphicModel, api);
}, },
...@@ -277,7 +277,7 @@ echarts.extendComponentView({ ...@@ -277,7 +277,7 @@ echarts.extendComponentView({
* @private * @private
* @param {Object} graphicModel graphic model * @param {Object} graphicModel graphic model
*/ */
_updateElements: function (graphicModel, api) { _updateElements: function (graphicModel) {
var elOptionsToUpdate = graphicModel.useElOptionsToUpdate(); var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
if (!elOptionsToUpdate) { if (!elOptionsToUpdate) {
...@@ -339,23 +339,8 @@ echarts.extendComponentView({ ...@@ -339,23 +339,8 @@ echarts.extendComponentView({
var el = elMap.get(id); var el = elMap.get(id);
if (el) { if (el) {
var isParentRoot = targetElParent === rootGroup; el.__ecGraphicWidthOption = elOption.width;
var parentWidth = isParentRoot el.__ecGraphicHeightOption = elOption.height;
? api.getWidth()
// Like 'position:absolute' in css, default 0.
: (targetElParent.__ecGraphicWidth || 0);
var parentHeight = isParentRoot
? api.getHeight()
: (targetElParent.__ecGraphicHeight || 0);
var isGroup = el.type === 'group';
el.__ecGraphicWidth = isGroup
? parsePercent(elOption.width, parentWidth)
: parentWidth;
el.__ecGraphicHeight = isGroup
? parsePercent(elOption.height, parentHeight)
: parentHeight;
setEventData(el, graphicModel, elOption); setEventData(el, graphicModel, elOption);
} }
}); });
...@@ -370,7 +355,31 @@ echarts.extendComponentView({ ...@@ -370,7 +355,31 @@ echarts.extendComponentView({
*/ */
_relocate: function (graphicModel, api) { _relocate: function (graphicModel, api) {
var elOptions = graphicModel.option.elements; var elOptions = graphicModel.option.elements;
var rootGroup = this.group;
var elMap = this._elMap; var elMap = this._elMap;
var apiWidth = api.getWidth();
var apiHeight = api.getHeight();
// Top-down to calculate percentage width/height of group
for (var i = 0; i < elOptions.length; i++) {
var elOption = elOptions[i];
var el = elMap.get(elOption.id);
if (!el || !el.isGroup) {
continue;
}
var parentEl = el.parent;
var isParentRoot = parentEl === rootGroup;
// Like 'position:absolut' in css, default 0.
el.__ecGraphicWidth = parsePercent(
el.__ecGraphicWidthOption,
isParentRoot ? apiWidth : parentEl.__ecGraphicWidth
) || 0;
el.__ecGraphicHeight = parsePercent(
el.__ecGraphicHeightOption,
isParentRoot ? apiHeight : parentEl.__ecGraphicHeight
) || 0;
}
// Bottom-up tranvese all elements (consider ec resize) to locate elements. // Bottom-up tranvese all elements (consider ec resize) to locate elements.
for (var i = elOptions.length - 1; i >= 0; i--) { for (var i = elOptions.length - 1; i >= 0; i--) {
...@@ -381,9 +390,15 @@ echarts.extendComponentView({ ...@@ -381,9 +390,15 @@ echarts.extendComponentView({
continue; continue;
} }
var containerInfo = { var parentEl = el.parent;
width: el.__ecGraphicWidth, var containerInfo = parentEl === rootGroup
height: el.__ecGraphicHeight ? {
width: apiWidth,
height: apiHeight
}
: {
width: parentEl.__ecGraphicWidth,
height: parentEl.__ecGraphicHeight
}; };
layoutUtil.positionElement( layoutUtil.positionElement(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册