#!/bin/env python

from pylab import *
from graph_tool.all import *

seed(40)

# get a small graph with some hubs
g = price_network(300)

# get the betweenness centrality
bv, be = betweenness(GraphView(g, directed=False))

# transform values so that they correspond to vertex size and edge thickness
bv.a = bv.a / bv.a.max() * 20 + 5
be.a = be.a / be.a.max() * 4 + 1.5
ms = be.copy()
ms.a *= 3

# get the positions using arf_layout
seed(43)
w = g.new_edge_property("double")
for e in g.edges():
    w[e] = 0.5 / (0.1 * abs(bv[e.source()] - bv[e.target()]) + 1)

pos = arf_layout(g, pos=sfdp_layout(g),
                 max_iter=10000, a=30, d=0.3, weight=w)

# draw the graph
graph_draw(g, pos=pos, bg_color=[1, 1, 1, 0],
           vertex_fill_color="#450000",
           vertex_color="#707070",
           vertex_pen_width=2,
           vertex_size=bv,
           edge_color="#707070",
           edge_pen_width=be,
           edge_marker_size=ms,
           edge_control_points=[0.3, 0.1, 0.7, 0.1],
           output_size=(400, 400),
           output="network.png")