D3.js 凸面外壳不使用缩放/平移
我试图包括@bumbeishvili的凸包实现( )进入我的自定义d3力,但不幸的是,在平移或缩放后,我无法更新凸面外壳…有什么想法吗 这里是小提琴: 由于一个节点可能是多个组的一部分,并且此信息不在节点中,而是在链接中,所以实现会有一点变化D3.js 凸面外壳不使用缩放/平移,d3.js,force-layout,convex-hull,D3.js,Force Layout,Convex Hull,我试图包括@bumbeishvili的凸包实现( )进入我的自定义d3力,但不幸的是,在平移或缩放后,我无法更新凸面外壳…有什么想法吗 这里是小提琴: 由于一个节点可能是多个组的一部分,并且此信息不在节点中,而是在链接中,所以实现会有一点变化 function updateGroups(links, paths) { subgraphs.forEach(function (subgraph) { var path = paths.filter(function (d) {
function updateGroups(links, paths) {
subgraphs.forEach(function (subgraph) {
var path = paths.filter(function (d) {
return d == subgraph;
}).attr('transform', 'scale(1) translate(0,0)')
.attr('d', function (d) {
polygon = polygonGenerator(subgraph, links);
centroid = d3.polygonCentroid(polygon);
// to scale the shape properly around its points:
// move the 'g' element to the centroid point, translate
// all the path around the center of the 'g' and then
// we can scale the 'g' element properly
return valueline(
polygon.map(function (point) {
return [point[0] - centroid[0], point[1] - centroid[1]];
})
);
});
d3.select(path.node().parentNode).attr('transform', 'translate(' + centroid[0] + ',' + (centroid[1]) + ') scale(' + scaleFactor + ')');
});
}
提前感谢您不需要对路径进行单独的缩放。很可能它无法在一个图形中进行2次缩放(一次捕捉并处理鼠标事件) 删除对
路径的缩放[第629行]
//paths.call(d3.zoom()
// .scaleExtent([minZoom, maxZoom])
// .on("zoom", zoomed));
然后将路径
组置于将缩放变换应用到[第404行]的组下方。(不在svg
下方)
groups = g.append('g').attr('class', 'groups');