相关疑难解决方法(0)

在节点边缘上对齐标记D3强制布局

我正在尝试实现d3力布局,无法弄清楚如何以正确的方式定位链接的标记.

这是我到目前为止所得到的:

var links = force_data.force_directed_data.links;

        var nodes = {};

        // Compute the distinct nodes from the links.
        links.forEach(function (link) {
            link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
            link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
        });

        console.log(nodes);

        var width = 1000,
            height = 1000;

        var force = d3.layout.force()
            .nodes(d3.values(nodes))
            .links(links)
            .size([width, height])
            .linkDistance(300)
            .charge(-120)
            .friction(0.9)
            .on("tick", tick)
            .start();

        var svg = d3.select("#force-graph").append("svg")
            .attr("width", width)
            .attr("height", height);

        // Per-type markers, as they don't inherit styles.
        svg.append("defs").selectAll("marker")
            .data(["dominating"])
            .enter().append("marker")
            .attr("id", …
Run Code Online (Sandbox Code Playgroud)

javascript d3.js force-layout

7
推荐指数
1
解决办法
2537
查看次数

标签 统计

d3.js ×1

force-layout ×1

javascript ×1