D3.js文本周围类似箭头的路径
我想重现这个美丽的箭头状,由于源代码无法访问,我问自己: 如何为工具提示正文创建适合覆盖文本块的背景路径 我是否必须创建文本元素,然后通过getBoundingClientRect计算宽度,并将宽度插入自定义路径 编辑:刚刚在bostock的非小型js中找到了解决方案D3.js文本周围类似箭头的路径,d3.js,D3.js,我想重现这个美丽的箭头状,由于源代码无法访问,我问自己: 如何为工具提示正文创建适合覆盖文本块的背景路径 我是否必须创建文本元素,然后通过getBoundingClientRect计算宽度,并将宽度插入自定义路径 编辑:刚刚在bostock的非小型js中找到了解决方案 var tooltipRect = tooltipContent.node().getBoundingClientRect(), tooltipWidth = tooltipRect.width, tooltipH
var tooltipRect = tooltipContent.node().getBoundingClientRect(),
tooltipWidth = tooltipRect.width,
tooltipHeight = tooltipRect.height;
tooltipPath
.attr("width", tooltipWidth)
.attr("height", tooltipHeight + 6)
.select("path")
.attr("d", "M0,0"
+ "H" + tooltipWidth
+ "v" + tooltipHeight
+ "H" + (tooltipWidth / 2 + 6)
+ "l-6,6"
+ "l-6,-6"
+ "H0"
+ "z");
tooltipOverlay
.style("left", (d.x + margin.left - tooltipWidth / 2) + "px")
.style("top", (d.y + margin.top - tooltipHeight - 6) + "px");
如果您使用SVG,这听起来像是一种方法。@chrispie-您能告诉我们非精简代码在哪里吗?@VividD-我找到了它