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: tooltip pickup error when width is not equal #6738

Open
wants to merge 3 commits into
base: v5
Choose a base branch
from

Conversation

BQXBQX
Copy link
Contributor

@BQXBQX BQXBQX commented Apr 3, 2025

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Apr 3, 2025

现在逻辑修改为三种情况:
先按照 domain 拿到所有满足的 elements

  1. 如果 elements 的数量大于 1,对所有满足 domain 的进行一次就近查找。
  2. 如果 elements 的数量等于 1,直接返回这个找到的。
  3. 如果没找到,走兜底逻辑,对所有 elements 进行就近查找。
 let target;
 const domainX = getDomainXByPoint(mouse, scaleX, coordinate);
 const targets = elements.filter((d) => d.__data__.title === domainX);

 // the domainX have multiple targets, we need to find the closest one. case: mockGroupInterval.
 if (targets.length > 1) {
     const search = bisector(xof).center;
     const i = search(targets, abstractX);
     target = targets[i];
 }
 // if the domainX have only one target, we can return it directly.
 else if (targets.length === 1) {
     target = targets[0];
 }
 // when can not get the target from the domainX, we need to find the closest one as the default target.
 else {
     const search = bisector(xof).center;
     const i = search(elements, abstractX);
     target = elements[i];
 }

@coveralls
Copy link

Pull Request Test Coverage Report for Build 14239491881

Details

  • 29 of 29 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.009%) to 86.777%

Totals Coverage Status
Change from base Build 14239476232: 0.009%
Covered Lines: 10744
Relevant Lines: 12000

💛 - Coveralls

@interstellarmt
Copy link
Contributor

这个查找逻辑对于未经过 flexX转换的标记会有什么影响吗

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Apr 3, 2025

这个查找逻辑对于未经过 flexX转换的标记会有什么影响吗

可能会,逻辑处理变化了一下,原来是根据就近原则找到最近的,再判断其 domainX 是否正确,现在是找到对应的 domainX,之后进行上面的三个判断,再判断 domainX 是否正确(因为有可能进入兜底情况,所以最后判断逻辑不能删除)。我单测过了一遍,都没有问题。

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Apr 3, 2025

我觉得在使用 flexX 转换后,所有的 就近原则 的逻辑都必须删除或者作为最后的兜底逻辑,因为 flexX 会导致 x轴bandwidth 长度无法确定,tooltip 拾取时如果还是就近拾取必然拾取错误。

就是类似下面这种逻辑:

const search = bisector(xof).center;
const i = search(elements, abstractX);
target = elements[i];

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Apr 3, 2025

还有一个点是 seriesTooltip 的拾取逻辑我觉得可以复用一下 tooltip 的拾取逻辑,这样拾取逻辑更新时,可以只更新一处。

@interstellarmt
Copy link
Contributor

可以看下能不能提一个公共的逻辑出来,这样后续好维护

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Apr 7, 2025

在优化时,我遇到了一个问题,就是当 axis 设置为 false 时,title 和 domainX 无法正确对应,这时的 title 为 y 轴的值,我尝试通过数据项 value 进行比较,但是无法得到哪个数据通道才是 y 轴的 value,感觉无法比较 😭

image

复现 demo: tooltip-alphabetIntervalTitle

@interstellarmt
Copy link
Contributor

跟axis是否为false应该没关系,是这里自定义了tooltip的title,这种情况下是否得特殊处理
image

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Apr 8, 2025

跟axis是否为false应该没关系,是这里自定义了tooltip的title,这种情况下是否得特殊处理 image

嗯,是的,应该进行特殊处理,但是感觉 element 上面除了 title 没有其他的有效信息可以对 domainX 进行特殊判断了,信息比较少,是不是需要加字段呢?🤔

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Apr 9, 2025

我尝试用 x 值匹配试一试,感觉用 title 定位还是不准确的

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Apr 9, 2025

image 使用 x 轴进行比较时,会遇到新的问题,ratio 的值是错误的,导致 x 值无法正确计算。从感官上来看图表,感觉 ratio 是一个动态的值,但是 scale 拿到的 ratio 是固定的,导致 x 计算错误,无法正确捕获 tooltip 😭。(case: stateAgesIntervalScrollbar)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants