Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在SVG路径的中间显示SVG图像_Javascript_Svg_D3.js_Force Layout - Fatal编程技术网

Javascript 在SVG路径的中间显示SVG图像

Javascript 在SVG路径的中间显示SVG图像,javascript,svg,d3.js,force-layout,Javascript,Svg,D3.js,Force Layout,我有一个具有不同大小节点的力定向图。我想在连接两个节点的每个路径中间显示一个自定义图标。从d3示例中,我找到了在节点内显示图像的方法。但是,当我在路径上尝试相同的技术时,图像不会显示 var path = svg.append("svg:g").selectAll("path").data(force.links()); var pathEnter = path.enter().append("svg:path"); pathEnter.attr("class", function(d) {

我有一个具有不同大小节点的力定向图。我想在连接两个节点的每个路径中间显示一个自定义图标。从d3示例中,我找到了在节点内显示图像的方法。但是,当我在路径上尝试相同的技术时,图像不会显示

var path = svg.append("svg:g").selectAll("path").data(force.links());

var pathEnter = path.enter().append("svg:path");

pathEnter.attr("class", function(d) {
    return "link " + d.target.type;
})

pathEnter.append("svg:g").append("image")
    .attr("xlink:href","http://127.0.0.1:8000/static/styles/images/add.png")
    .attr("x",0).attr("y",0).attr("width",12).attr("height", 12)
    .attr("class", "type-icon");

我想在问问题之前我需要多一点耐心。我解决问题的方法是:

var icon = svg.append("svg:g").selectAll("g")
.data(force.links()).enter().append("svg:g");

icon.append("image").attr("xlink:href","imagePath")
  .attr("x", -20)
  .attr("y", -2)
  .attr("width", 12).attr("height", 12)
        .attr("class", "type-icon");
然后在勾号功能中:

        icon.attr("transform", function(d) {
            return "translate(" +((d.target.x+d.source.x)/2) + "," +
                ((d.target.y+d.source.y))/2 + ")";
        });

获取两个节点之间的中心点。

我想在提问之前我需要多一点耐心。我解决问题的方法是:

var icon = svg.append("svg:g").selectAll("g")
.data(force.links()).enter().append("svg:g");

icon.append("image").attr("xlink:href","imagePath")
  .attr("x", -20)
  .attr("y", -2)
  .attr("width", 12).attr("height", 12)
        .attr("class", "type-icon");
然后在勾号功能中:

        icon.attr("transform", function(d) {
            return "translate(" +((d.target.x+d.source.x)/2) + "," +
                ((d.target.y+d.source.y))/2 + ")";
        });
以获取两个节点之间的中心点