简体   繁体   English

用D3和Leaflet重复SVG

[英]Repeating SVG with D3 and Leaflet

So I am starting another d3 project. 所以我开始另一个d3项目。 This project includes rendering a static network graph in D3 on a LeafletJS canvas (to allow standardized zoom/pan controls across our other visualizations). 该项目包括在LeafletJS画布上在D3中渲染静态网络图(以允许跨我们的其他可视化进行标准化缩放/平移控制)。 The problem with this network is that it needs to wrap around the x-axis (ex: a node on the right may be connected to a node on the left). 这个网络的问题是它需要环绕x轴(例如:右边的节点可能连接到左边的节点)。 I want to be able to pan seamlessly across multiple instances of this same graph, but I'm not sure what the best approach to this problem is. 我希望能够在同一图表的多个实例之间无缝平移,但我不确定这个问题的最佳方法是什么。

My best idea so far is to render two identical copies of the visualization and position them one after the other...Then use Leaflet's worldCopyJump to let one visualization render while the user is panning across the other. 到目前为止,我最好的想法是渲染两个相同的可视化副本并将它们一个接一个地定位......然后使用Leaflet的worldCopyJump让一个可视化渲染,同时用户在另一个平移。 Obviously though, with one instance of the visualization needing 1500+ SVG objects, this may not be the best approach. 显然,有一个可视化实例需要1500多个SVG对象,这可能不是最好的方法。

So U may not need exact code, but could someone help me think of a solid approach? 所以你可能不需要确切的代码,但有人可以帮助我想出一个可靠的方法吗? I'll be glad to provide more details if necessary. 如有必要,我很乐意提供更多细节。

The clean but complicated way to avoid duplicating the network graph is to update the coordinates of the network graph's nodes based on the canvas' pan position, as well as add temporary duplicates on the other side when necessary (when a link intersects the graph's boundaries). 避免重复网络图的干净但复杂的方法是根据画布的平移位置更新网络图节点的坐标,并在必要时(当链接与图的边界相交时)在另一侧添加临时副本。 The first part of the problem is simpler. 问题的第一部分更简单。 Based on the following example: 基于以下示例:

http://bl.ocks.org/jose187/4733747 http://bl.ocks.org/jose187/4733747

You can update the simple transform: 您可以更新简单转换:

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

To work with the pan position that you can pass along to your d3 update code (code that runs on a canvas pan event so that the pan position may be calculated and passed along): 要使用可以传递给d3更新代码的平移位置(在画布平移事件上运行的代码,以便可以计算并传递平移位置):

var transform = function(d, canvasPanX) {
    // figure out if the point in question is off the canvas and
    // reposition it to a visible position
};

The temporary duplicates seem much more difficult to implement, but it may help to place duplicate geometry in a separate svg group so you can wipe it out easily and start fresh after each pan. 临时副本似乎更难实现,但它可能有助于将重复的几何体放在单独的svg组中,这样您就可以轻松地将其擦除并在每次平移后重新开始。

I understand that my suggestions are very high level - let me know what you think so I can think about it further, as well as if it would help if I tried to fill in more details. 我知道我的建议非常高级 - 让我知道你的想法,以便我可以进一步思考,以及如果我试图填写更多细节会有所帮助。

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

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