Graphx Visualization

Saygın Doğu picture Saygın Doğu · Aug 3, 2016 · Viewed 8.6k times · Source

I am looking for a way to visualize the graph constructed in Spark's Graphx. As far as I know Graphx doesn't have any visualization methods so I need to export the data from Graphx to another graph library, but I am stuck here. I ran into this website: https://lintool.github.io/warcbase-docs/Spark-Network-Analysis/ but it didn't help. Which library I should use and how to export the graph.

Answer

oluies picture oluies · Oct 5, 2016

So you can do something like this

  1. Save to gexf (graph interchange format) Code from Manning | Spark GraphX in Action
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 load the file

Example: http://gregroberts.github.io

enter image description here