[英]position a tooltip over a table cell with translate() in d3.js
我正在从 json 数据和 d3 创建一个表,如下所示: https : //jsfiddle.net/rpardee/ku3q6txw/41/
我正在使用带有 d3.mouse() 的 mouseenter 来获取鼠标指针的 x,y 坐标,但需要将从 .mouse() 返回的坐标转换为可以输入到 translate() 中的像素位置,以便正确放置工具提示。 到目前为止,我的挥杆导致:
// Move the tooltip over to where the mouse pointer is
// There has *got* to be a better way of doing this.
const coords = d3.mouse(this);
const xpos = table._groups[0][0].clientWidth - coords[0] ;
const ypos = table._groups[0][0].clientHeight - coords[1] ; ;
imp_tooltip.style("transform", `translate(${xpos}px, ${ypos}px)`) ;
这很接近,但还不够接近。
我猜我可以设置一个 d3.scaleLinear() 来进行这个翻译,但是我在试图弄清楚要向那个人的 .domain() 和 range() 方法中输入什么内容时遇到了困难。
有人可以给我一个线索吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.