简体   繁体   English

调整相对于foreignObject节点的标记位置?

[英]Adjust the marker position relative to foreignObject node?

Here is my current fiddle . 这是我目前的小提琴 I'm using foreignObjects to define custom icons for nodes (the fiddle is just using a ? but locally I'm using font-awesome icons). 我正在使用foreignObjects为节点定义自定义图标(小提琴只是使用?,但在本地使用的是超棒的字体图标)。 This works great, however the problem is that the arrows on the paths point to the top-left corner of the element. 这很好用,但是问题是路径上的箭头指向元素的左上角。 I've tried changing toying with many of the existing parameters and have looked through the API documentation but am unable to find a solution. 我尝试使用许多现有参数更改玩具,并查看了API文档,但找不到解决方案。 I'm guessing I could do some complicated math in the code below, but I'm hoping for a parameter that can set some sort of radius for the end of the path. 我猜想我可以在下面的代码中做一些复杂的数学运算,但是我希望有一个参数可以为路径的末端设置某种半径。

function linkArc(d) {
  var dx = d.target.x - d.source.x,
      dy = d.target.y - d.source.y,
      dr = Math.sqrt(dx * dx + dy * dy);
  return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
}

The only documentation I found on paths was geo-paths. 我在路径上找到的唯一文档是地理位置路径。 I tried using pointRadius anyway but it didn't seem to do anything at all. 无论如何,我都尝试使用pointRadius,但它似乎根本没有做任何事情。 Here is the path definition: 这是路径定义:

var path = svg.append("g").selectAll("path")
    .data(force.links())
    .enter().append("path")
    .attr("class", function (d) { return "link " + d.type; })
    .attr("marker-end", function (d) { return "url(#" + d.type + ")"; });

You can use the transform attribute to adjust the position: 您可以使用transform属性来调整位置:

var path = svg.append("g").selectAll("path")
  .data(force.links())
  .enter().append("path")
  .attr("transform", "translate(10,10)")
  .attr("class", function (d) { return "link " + d.type; })
  .attr("marker-end", function (d) { return "url(#" + d.type + ")"; });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM