Skip to content

Commit

Permalink
Merge pull request #17007 from apache/fix/graphic
Browse files Browse the repository at this point in the history
fix(graphic): fix some options may be unexpectedly reset on update
  • Loading branch information
plainheart authored May 16, 2022
2 parents 84b9578 + ffc7429 commit 5cf53e2
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 27 deletions.
4 changes: 3 additions & 1 deletion src/component/graphic/GraphicModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ export class GraphicComponentModel extends ComponentModel<GraphicComponentOption
result.push(option);

const children = option.children;
if (option.type === 'group' && children) {
// here we don't judge if option.type is `group`
// when new option doesn't provide `type`, it will cause that the children can't be updated.
if (children && children.length) {
this._flatten(children, result, option);
}
// Deleting for JSON output, and for not affecting group creation.
Expand Down
49 changes: 26 additions & 23 deletions src/component/graphic/GraphicView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,40 +440,43 @@ function updateCommonAttrs(
defaultZlevel: number
) {
if (!el.isGroup) {
const elDisplayable = el as Displayable;
elDisplayable.cursor = zrUtil.retrieve2(
(elOption as GraphicComponentDisplayableOption).cursor,
Displayable.prototype.cursor
);
// We should not support configure z and zlevel in the element level.
// But seems we didn't limit it previously. So here still use it to avoid breaking.
elDisplayable.z = zrUtil.retrieve2(
(elOption as GraphicComponentDisplayableOption).z,
defaultZ || 0
);
elDisplayable.zlevel = zrUtil.retrieve2(
(elOption as GraphicComponentDisplayableOption).zlevel,
defaultZlevel || 0
);
// z2 must not be null/undefined, otherwise sort error may occur.
const optZ2 = (elOption as GraphicComponentDisplayableOption).z2;
optZ2 != null && (elDisplayable.z2 = optZ2 || 0);
zrUtil.each([
['cursor', Displayable.prototype.cursor],
// We should not support configure z and zlevel in the element level.
// But seems we didn't limit it previously. So here still use it to avoid breaking.
['zlevel', defaultZlevel || 0],
['z', defaultZ || 0],
// z2 must not be null/undefined, otherwise sort error may occur.
['z2', 0]
], item => {
const prop = item[0] as any;
if (zrUtil.hasOwn(elOption, prop)) {
(el as any)[prop] = zrUtil.retrieve2(
(elOption as any)[prop],
item[1]
);
}
else if ((el as any)[prop] == null) {
(el as any)[prop] = item[1];
}
});
}

zrUtil.each(zrUtil.keys(elOption), key => {
const val = (elOption as any)[key];
// Assign event handlers.
// PENDING: should enumerate all event names or use pattern matching?
if (key.indexOf('on') === 0 && zrUtil.isFunction(val)) {
(el as any)[key] = val;
if (key.indexOf('on') === 0) {
const val = (elOption as any)[key];
(el as any)[key] = zrUtil.isFunction(val) ? val : null;
}
});
el.draggable = elOption.draggable;
if (zrUtil.hasOwn(elOption, 'draggable')) {
el.draggable = elOption.draggable;
}

// Other attributes
elOption.name != null && (el.name = elOption.name);
elOption.id != null && ((el as any).id = elOption.id);

}
// Remove unnecessary props to avoid potential problems.
function getCleanedElOption(
Expand Down
105 changes: 102 additions & 3 deletions test/graphic-cases.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/runTest/actions/__meta__.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/runTest/actions/graphic-cases.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5cf53e2

Please sign in to comment.