D3 Js force directed graph

169 views
Skip to first unread message

aneesh mj

unread,
Jul 7, 2014, 8:26:10 AM7/7/14
to d3...@googlegroups.com
Hi,

I am using the following force directed example for one of my project.


Here I need something like: - Highlight the paths between "Microsoft" and "Sony".

Is it possible ? if so can anyone help me on this ?

Thanking you.

aneesh mj

unread,
Jul 17, 2014, 8:32:33 AM7/17/14
to d3...@googlegroups.com
Can anyone please help me on this ?

Thanks
Aneesh

Phuoc Do

unread,
Jul 17, 2014, 8:50:28 PM7/17/14
to d3...@googlegroups.com
aneesh,

You can change class of the link:

var link = svg.selectAll(".link")
    .data(force.links())
  .enter().append("line")
    .attr("class", function(l) {
      if (l.source.name === "Microsoft" && l.target.name === "Motorola") {
        return "hilink";
      } else {
        return "link";
      }
    });

and css:

.hilink {
  fill: none;
  stroke: #666;
  stroke-width: 4.5px;
}

Example:


Phuoc Do

aneesh mj

unread,
Jul 22, 2014, 7:35:29 AM7/22/14
to d3...@googlegroups.com
Thanks Phuoc !!

I was looking for an algorithm or a method, which will give me the shortest path between two points and highlight those.

Phuoc Do

unread,
Jul 22, 2014, 12:48:28 PM7/22/14
to d3...@googlegroups.com
aneesh,

That algorithm is not available in d3. d3 force layout doesn't have weight/value on link. So you can't really find shortest path algorithm like Dijkstra.

Phuoc


--
You received this message because you are subscribed to a topic in the Google Groups "d3-js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/d3-js/2ZgSAYkdB_c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Phuoc Do

Dow Street

unread,
Jul 22, 2014, 12:53:29 PM7/22/14
to d3...@googlegroups.com
JSNetworkX might be helpful as part of a solution - looks like there is an implementation of unweighted shortest paths (although I have not used it myself):

http://jsnetworkx.org/index.html
https://github.com/fkling/JSNetworkX/blob/master/jsnx/algorithms/shortest_paths/unweighted.js

R,
Dow
> You received this message because you are subscribed to the Google Groups "d3-js" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages