Graphic visualization

I am looking for a way to visualize a graph built in Spark Graphx. As far as I know, Graphx has no visualization methods, so I need to export data from Graphx to another graph library, but I'm stuck here. I came across this site: https://lintool.imtqy.com/warcbase-docs/Spark-Network-Analysis/ but this did not help. Which library should I use and how to export the graph.

+5
source share
2 answers

So you can do something like this

def toGexf[VD,ED](g:Graph[VD,ED]) : String = { "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<gexf xmlns=\"http://www.gexf.net/1.2draft\" version=\"1.2\">\n" + " <graph mode=\"static\" defaultedgetype=\"directed\">\n" + " <nodes>\n" + g.vertices.map(v => " <node id=\"" + v._1 + "\" label=\"" + v._2 + "\" />\n").collect.mkString + " </nodes>\n" + " <edges>\n" + g.edges.map(e => " <edge source=\"" + e.srcId + "\" target=\"" + e.dstId + "\" label=\"" + e.attr + "\" />\n").collect.mkString + " </edges>\n" + " </graph>\n" + "</gexf>" } 
  1. Use the GEXF plugin in linkurious.js to download the file

Example: http://gregroberts.imtqy.com

enter image description here

+6
source

You can use Gephi or d3 from Zeppelin . Check out D3.js In Action by Elijah Meeks and Spark GraphX in Action by Michael S. Malak

Release zeppelin in scala and js , borrowed from grapxInAction :

 import org.apache.spark.graphx._ import scala.reflect.ClassTag def drawGraph[VD:ClassTag,ED:ClassTag](g:Graph[VD,ED]) = { val u = java.util.UUID.randomUUID val v = g.vertices.collect.map(_._1) println("""%html <div id='a""" + u + """' style='width:960px; height:500px'></div> <style> .node circle { fill: gray; } .node text { font: 10px sans-serif; text-anchor: middle; fill: white; } line.link { stroke: gray; stroke-width: 1.5px; } </style> <script src="//d3js.org/d3.v3.min.js"></script> <script> .var width = 960, height = 500; var svg = d3.select("#a""" + u + """").append("svg") .attr("width", width).attr("height", height); var nodes = [""" + v.map("{id:" + _ + "}").mkString(",") + """]; var links = [""" + g.edges.collect.map( e => "{source:nodes[" + v.indexWhere(_ == e.srcId) + "],target:nodes[" + v.indexWhere(_ == e.dstId) + "]}").mkString(",") + """]; var link = svg.selectAll(".link").data(links); link.enter().insert("line", ".node").attr("class", "link"); var node = svg.selectAll(".node").data(nodes); var nodeEnter = node.enter().append("g").attr("class", "node") nodeEnter.append("circle").attr("r", 8); nodeEnter.append("text").attr("dy", "0.35em") .text(function(d) { return d.id; }); d3.layout.force().linkDistance(50).charge(-200).chargeDistance(300) .friction(0.95).linkStrength(0.5).size([width, height]) .on("tick", function() { link.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.target.x; }) .attr("y2", function(d) { return d.target.y; }); node.attr("transform", function(d) { return "translate(" + dx + "," + dy + ")"; }); }).nodes(nodes).links(links).start(); </script> """) } 
+1
source

All Articles