antvis/G6

边文字旋转问题 #4515

auuunya posted onGitHub

Describe the bug

let radian = Math.atan((startPoint.y - endPoint.y) / ((startPoint.x - endPoint.x))); startLabel.rotateAtStart(radian); 根据这个斜率方法设置自定义边上的文字旋转,文字在边的中点做自我旋转 image image image

Your Example Website or App

rt

Steps to Reproduce the Bug or Issue

rt.

Expected behavior

rt.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response


边的 labelCfg 配置 autoRotate: true 可以自动旋转的。你这里原始需求是什么呢?

posted by Yanyan-Wang almost 2 years ago

在自定义边里面 只有一个update方法,两个节点之间可能有多条边,所以需要文字跟随便旋转,但是使用斜率的话 边上的文字就自我旋转, 在update里面设置labelCfg 无效

posted by auuunya almost 2 years ago

labelCfg 是配置在 graph 的 defaultEdge 或者边数据里面的。你的情况给个在线复现 demo 看看?

posted by Yanyan-Wang almost 2 years ago

labelCfg 是配置在 graph 的 defaultEdge 或者边数据里面的。你的情况给个在线复现 demo 看看?

https://codesandbox.io/s/bold-flower-mevdjo?file=/index.js 类似于这样,只使用了registerEdge的update方法,但是好像在这里无法定义文字跟着边旋转,即便是使用math计算出来的,拖动节点 边上的文字就自己旋转

posted by auuunya almost 2 years ago

你好,该问题解决了吗?

posted by Anthony081105 about 1 year ago

你好,该问题解决了吗?

使用默认的边做了默认autoratote:true,然后尽量不去在边上做自定义, 如果要自定义边文字的话你就得自己写旋转方法了,

posted by auuunya about 1 year ago

Fund this Issue

$0.00
Funded

Pull requests