Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update to latest @antv/g #5702

Merged
merged 15 commits into from May 15, 2024
Merged

fix: update to latest @antv/g #5702

merged 15 commits into from May 15, 2024

Conversation

xiaoiver
Copy link
Contributor

@xiaoiver xiaoiver commented May 7, 2024

  • Update to latest @antv/component@2.x which supports string marker in Category items.
  • anchor attribute is removed. But we can modify path in symbols instead, an offset of half width is applied.
/**
 * ▷
 */
export const triangle: SymbolFactor = (width: number, height: number) => {
// before
  return [['M', 0, 0], ['L', width, -height / 2], ['L', width, height / 2], ['Z']];
// after
  return [['M', -width / 2, 0], ['L', width / 2, -height / 2], ['L', width / 2, height / 2], ['Z']];
};
  • Since x/y/z are removed from Group CustomElement and Mesh, we should use transform: 'translate3d()' instead. For example, after calculating layout for each nodes:
// before
dataToUpdate.nodes.push({ id: id as ID, style: { x, y, z } });
// after
dataToUpdate.nodes.push({ id: id as ID, style: { transform: `translate3d(${x}, ${y}, ${z})` } });

Another example in base combo:

protected getComboStyle(attributes: Required<S>) {
// before
    return { x, y, zIndex };
// after
    return { transform: `translate(${x}, ${y})`, zIndex };
}

And there are also no more redundant and non-standard attributes like x/y for <g> in the generated SVGs.

// before
<g id="label" fill="none" transform="matrix(1,0,0,1,254,31.25)" x="254" y="31.25"></g>
// after
<g id="label" fill="none" transform="matrix(1,0,0,1,254,31.25)"></g>

Checklist:

  • element nodes
  • element edges
  • element port
  • layout
  • behavior
  • animation
  • plugin

@xiaoiver xiaoiver changed the title fix: update to latest @antv/g [WIP] fix: update to latest @antv/g May 7, 2024
@xiaoiver
Copy link
Contributor Author

xiaoiver commented May 11, 2024

layoutDendrogramTb 例子文本朝向有问题,应该是把 rotate transform 覆盖了:

截屏2024-05-11 上午10 02 12

@Aarebecca
Copy link
Contributor

layoutDendrogramTb 例子文本朝向有问题,应该是把 rotate transform 覆盖了:

截屏2024-05-11 上午10 02 12

这种可能需要合并 transform 属性(而不是替换),会有潜在问题吗

@xiaoiver
Copy link
Contributor Author

xiaoiver commented May 13, 2024

这种可能需要合并 transform 属性(而不是替换),会有潜在问题吗

SVG 的 <g> 其实只有 transform 属性可用,所以如果我们允许用户直接传 transform 到一个 Group 或者 CustomElement 上,那肯定会覆盖的。上面那个问题我修复的方式是,把 x/y 体现在 transform 的 translate 部分,如果用户传的 transform 不包含 translate,那就没问题,比如上面例子中的 rotate。

但我觉得更好的做法是把 x/y 当作 CustomElement 的自定义属性,由它的各个子元素消费(例如子元素 把它赋值给自身的 cx/cy 属性,子元素 赋给自身的 x/y 属性这样),这样就可以和父元素的 transform 分离开,自然就不存在覆盖问题了。

我现在也在尝试往这个方向改,会修改到 getGraphicStyle 这个方法,放开 x/y/z 这些原本被过滤掉的属性,继续往子元素下传递。以 Circle 类型的 node 为例:

protected getKeyStyle(attributes: Required<CircleStyleProps>): GCircleStyleProps {
  const keyStyle = super.getKeyStyle(attributes);
  const { x = 0, y = 0, z = 0 } = keyStyle;
  return { ...keyStyle, r: Math.min(...this.getSize(attributes)) / 2, cx: x, cy: y, cz: z };
}

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g

@xiaoiver
Copy link
Contributor Author

目前只剩下 animation 这部分例子截图待生成。

@xiaoiver xiaoiver changed the title [WIP] fix: update to latest @antv/g fix: update to latest @antv/g May 14, 2024
@xiaoiver
Copy link
Contributor Author

xiaoiver commented May 14, 2024

2000 circle nodes(icon + text)
render + layout 耗时 710 -> 640ms

截屏2024-05-14 下午7 28 48 截屏2024-05-14 下午7 28 36

数据流这部分应该还有一些优化空间:

截屏2024-05-14 下午7 31 29

@Aarebecca Aarebecca merged commit 36e39e5 into v5 May 15, 2024
3 checks passed
@Aarebecca Aarebecca deleted the fix-latest branch May 15, 2024 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants