简体   繁体   English

如何在d3.js中为选定的边和顶点创建轮廓?

[英]How to create an outline for selected edges and vertices in d3.js?

I am trying to create a visual effect as in the following drawing: http://imageshack.us/photo/my-images/52/97003573.png/ [that a selected amount of vertices and edges connecting them will be surrounded by an outline] I would appreciate any code examples how to do this as I am new to SVG and graphics through javascript in general. 我正在尝试创建如下图所示的视觉效果: http : //imageshack.us/photo/my-images/52/97003573.png/ [选定数量的顶点和连接它们的边将被包围。概述]我将不胜感激任何代码示例如何执行此操作,因为我一般都是通过javascript来接触SVG和图形的。 Thanks 谢谢

I was able to accomplish this by adding two more sets of very thick 'link' lines, with stroke-linecap values of "round", that can be extended to your selected lines in a similar fashion. 通过添加两套非常粗的“链接”线(具有笔画线帽值“ round”)可以完成此操作,这些线可以以类似的方式扩展到您选择的线。

连结图片

var linkoutline = svg.selectAll(".outline")  
    .data(json.links)
  .enter().append("svg:line")
    .attr("class","outline")
    .style("stroke","red")
    .style("stroke-width",20)
    .style("stroke-linecap","round");
var linkback = svg.selectAll(".backline")
    .data(json.links)
  .enter().append("svg:line")
    .attr("class","backline")
    .style("stroke","white")
    .style("stroke-width",18)
    .style("stroke-linecap","round");

See an updated jsfiddle of this at http://jsfiddle.net/s2f8L/8/ . http://jsfiddle.net/s2f8L/8/上查看更新的jsfiddle。 This can be extended to your selected lines in a similar fashion 可以类似的方式将其扩展到您选择的行

Is it that hard to do a selectAll based on id or class? 基于id或class进行selectAll很难吗? You could add shadows using CSS after that as SVG and CSS both offer support for something like this. 之后,您可以使用CSS添加阴影,因为SVG和CSS都提供了对此类功能的支持。

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

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