-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat: add tooltip data to tooltip event callback #6529
Conversation
@@ -1095,6 +1096,7 @@ export function tooltip( | |||
...event, | |||
nativeEvent: true, | |||
data: { | |||
...data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 data 是什么结构的,拍平了放里面会不会乱?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moayuisuda 单测已经修复:#6508 。可以重新 rebase 一下目标分支,在提交一下。 |
3768589
to
7f20967
Compare
Pull Request Test Coverage Report for Build 12196381001Details
💛 - Coveralls |
@moayuisuda 可以麻烦写一下伪代码,如果有了这个之后,是怎么实现自己的业务逻辑的? |
const Tooltip = forwardRef(({ data }, ref) => {
const [lock, setLock] = useState(false);
useImperativeHandle(ref, () => ({
lock: () => setLock(true),
unlock: () => setLock(false),
}));
return (
<div className={classnames(lock && "lock")}>
<h2>{data.title}</h2>
<ul>
{data.items.map((item) => (
<Item data={item} />
))}
</ul>
</div>
);
});
function renderTooltip(data, ref) {
ReactDom.render(<Tooltip data={data} ref={ref} />, tooltipContainer);
}
function App() {
const tooltipRef = useRef();
useEffect(() => {
plot.on("tooltip:show", (data) => renderTooltip(data, tooltipRef));
plot.on("plot:click", tooltipRef.current.lock);
});
} |
@moayuisuda 看你的例子是希望自定义 tooltip 的渲染内容?如果是这样的话可以通过如下 API 实现: chart.interaction('tooltip', {
render: (event, data) => {
return ReactDom.render(<Tooltip data={data}>, tooltipContainer);
},
}); 参考这个例子。 |
@pearmini 之前尝试过,但是这样写会有g2本来的tooltip。因为我们业务的tooltip有锁定,多选对比功能,现在是完全用react来重新实现的。当然如果g2原生能够支持tooltip点击锁定逻辑,我也就不用绕这么大的弯子了 |
@hustcc 我记得你是添加了 tooltip 锁定的功能的? |
内置只有 enterable 功能,没有业务中的锁定。 |
之前的 data 是没有 title 和 items 是吧? |
Checklist
npm test
passesDescription of change