按x和y缩放强制d3js麻烦

时间:2014-06-26 15:34:35

标签: d3.js

拖动任何节点时,我无法按x和y进行缩放。有没有人遇到同样的麻烦?

有用于强制的线条:

var x = d3.scale.linear()
        .domain([0, defaultParams.maxX])
        .range([0, width]);

var y = d3.scale.linear()
        .domain([0, defaultParams.maxY])
        .range([height, 0]);


var force = d3.layout.force()
        .size([defaultParams.maxX, defaultParams.maxY])
        .charge(-400)
        .linkDistance(5)
        .on("tick", tick);


function tick() {
        link
            .attr("x1", function(d) { return x(d.source.x); })
            .attr("y1", function(d) { return y(d.source.y); })
            .attr("x2", function(d) { return x(d.target.x); })
            .attr("y2", function(d) { return y(d.target.y); });

        node
            .attr("transform", function(d){ return "translate(" + x(d.x) + "," + y(d.y) + ")"; })

}

function dragMove(d) {
    d3.select(this).attr("transform", function(d){ return "translate(" + x(d.x) + "," + y(d.y) + ")"; });
}

0 个答案:

没有答案