def create_graph(p_node,s): completed_nodes = [] uncomplete_nodes = [] global g g = Graph() p = p_node parent_follower = s.pAll[p_node].follower parent_node_name = s.pAll[p_node].id g.add_node(id=str(parent_node_name),radius = 5,stroke = color(1, 0, 0.25, 1),text = color(1)) print parent_node_name,"--->",parent_follower for i in range(len(parent_follower)): g.add_node(id=str(parent_follower[i]), radius = 5, stroke = color(1), text = color(1)) completed_nodes.append(parent_node_name) # Random edges. for i in range(len(parent_follower)): node1 = str(parent_node_name) node2 = str(parent_follower[i]) uncomplete_nodes.append(parent_follower[i]) g.add_edge(node1, node2, length = 500.0, weight = random(), stroke = color(1, 0, 0.25, 1)) print "-"*50 print "Completed_Nodes ",completed_nodes print "Uncomplete_Nodes ",uncomplete_nodes ##New Round while len(uncomplete_nodes) <> 0: node1 = uncomplete_nodes[0] changed_node = node_convert(node1,s) follower_list = s.pAll[changed_node].follower for i in follower_list: if i not in completed_nodes: node_1 = str(node1) node2 = str(i) print node_1,"--->",i uncomplete_nodes.append(i) g.add_node(id=str(i),radius = 5,stroke = color(1, 0, 0.25, 1),text = color(1)) g.add_edge(node_1,node2, length = 50.0, stroke = color(1), weight = random()) completed_nodes.append(node1) del uncomplete_nodes[0] ## New Round ## for I in range(len(parent_follower)): ## ## p_node = s.pAll[p].follower[I] ## parent_name = p_node ## ## p_node = node_convert(p_node,s) ## p_links = s.pAll[p_node].follower ## ## p_node = parent_name #change ## ## print parent_name,"-->",p_links ## ## r = rd.choice([x * 0.01 for x in range(0,100)]) #rd.choice([0,51,255]) #rd.randint(10,200) ## green = rd.choice([x * 0.01 for x in range(0,100)]) #rd.choice([255,128,255]) #rd.randint(0,100) ## b = rd.choice([x * 0.01 for x in range(0,100)]) #rd.choice([128,0,255]) #rd.randint(0,200) ## ## if len(p_links) <> 0: ## ## for i in range(len(p_links)): ## node1 = str(parent_name) ## ## bul = True ## if p_links[i] not in s.pAll[p].follower: #Not a parent follower ## ## for j in range (I): #Loop to check another sibling's follower ## ## sibling = s.pAll[p].follower[j] ## sibling = node_convert(sibling,s) ## ## if p_links[i] in s.pAll[sibling].follower: ## ## bul = True #Controlling Parameter ## ## if bul: ## g.add_node(id=str(p_links[i]),radius = 5,stroke = color(r, green, b, 1),text = color(1)) ## node2 = str(p_links[i]) ## g.add_edge(node1, node2, ## length = 50.0, ## weight = random(), ## stroke = color(r, green, b, 1)) # Two handy tricks to prettify the layout: # 1) Nodes with a higher weight (i.e. incoming traffic) appear bigger. for node in g.nodes: node.radius = 5#node.radius + node.radius*node.weight # 2) Nodes with only one connection ("leaf" nodes) have a shorter connection. for node in g.nodes: if len(node.edges) == 1: node.edges[0].length = 0.5 g.prune(depth=0) # Remove orphaned nodes with no connections. g.distance = 25 # Overall spacing between nodes. g.layout.force = 0.01 # Strength of the attractive & repulsive force. g.layout.repulsion = 5 # Repulsion radius. dragged = None
radius = 6, stroke = color(0), text = color(.3,.6,.9)) index += 1 # Random edges. for n in range(0,len(abo)-1): node1 = g.nodes[n] node1.text = Text(abo[n], font="Droid Serif", fontsize=5, fontweight=BOLD) node2 = g.nodes[n+1] g.add_edge(node1, node2, length = 1.0, weight = 1.0, stroke = color(.7,.1,.1)) #g.prune(depth=0) # Remove orphaned nodes with no connections. g.distance = 5 # Overall spacing between nodes. g.layout.force = 0.01 # Strength of the attractive & repulsive force. g.layout.repulsion = 15 # Repulsion radius. dragged = None def draw(canvas): canvas.clear() background(1) translate(250, 250) # With directed=True, edges have an arrowhead indicating the direction of the connection. # With weighted=True, Node.centrality is indicated by a shadow under high-traffic nodes. # With weighted=0.0-1.0, indicates nodes whose centrality > the given threshold. # This requires some extra calculations. g.draw(weighted=False, directed=True)
def create_graph(p_node, s): global g g = Graph() p = p_node temp = s.pAll[p_node].follower g.add_node(id=str(p_node), radius=5, stroke=color(1, 0, 0.25, 1), text=color(1)) for i in range(len(temp)): #100 g.add_node(id=str(temp[i]), radius=5, stroke=color(1), text=color(1)) # Random edges. p_links = s.pAll[p_node].follower for i in range(len(p_links)): node1 = str(p_node) #choice(g.nodes) node2 = str(p_links[i]) #choice(g.nodes) g.add_edge(node1, node2, length=500.0, weight=random(), stroke=color(1, 0, 0.25, 1)) #New Round for I in range(len(temp)): p_node = s.pAll[p].follower[I] #0 p_links = s.pAll[p_node].follower #print [x * 0.01 for x in range(0,100)] r = rd.choice([x * 0.01 for x in range(0, 100) ]) #rd.choice([0,51,255]) #rd.randint(10,200) green = rd.choice([x * 0.01 for x in range(0, 100) ]) #rd.choice([255,128,255]) #rd.randint(0,100) b = rd.choice([x * 0.01 for x in range(0, 100) ]) #rd.choice([128,0,255]) #rd.randint(0,200) #print r,green,b for i in range(len(p_links)): node1 = str(p_node) #choice(g.nodes) bul = True if p_links[i] not in s.pAll[p].follower: #Not a parent follower for j in range(I): #Loop to check another sibling's follower sibling = s.pAll[p].follower[j] if p_links[i] in s.pAll[sibling].follower: bul = False if bul: g.add_node(id=str(p_links[i]), radius=5, stroke=color(r, green, b, 1), text=color(1)) node2 = str(p_links[i]) #choice(g.nodes) g.add_edge(node1, node2, length=50.0, weight=random(), stroke=color(r, green, b, 1)) # Two handy tricks to prettify the layout: # 1) Nodes with a higher weight (i.e. incoming traffic) appear bigger. for node in g.nodes: node.radius = 5 #node.radius + node.radius*node.weight # 2) Nodes with only one connection ("leaf" nodes) have a shorter connection. for node in g.nodes: if len(node.edges) == 1: node.edges[0].length = 0.5 g.prune(depth=0) # Remove orphaned nodes with no connections. g.distance = 15 # Overall spacing between nodes. g.layout.force = 0.01 # Strength of the attractive & repulsive force. g.layout.repulsion = 5 # Repulsion radius. dragged = None
for i in range(75): node1 = choice(g.nodes) node2 = choice(g.nodes) g.add_edge(node1, node2, length=1.0, weight=random(), stroke=color(0)) # Two handy tricks to prettify the layout: # 1) Nodes with a higher weight (i.e. incoming traffic) appear bigger. for node in g.nodes: node.radius = node.radius + node.radius * node.weight # 2) Nodes with only one connection ("leaf" nodes) have a shorter connection. for node in g.nodes: if len(node.edges) == 1: node.edges[0].length *= 0.1 g.prune(depth=0) # Remove orphaned nodes with no connections. g.distance = 10 # Overall spacing between nodes. g.layout.force = 0.01 # Strength of the attractive & repulsive force. g.layout.repulsion = 15 # Repulsion radius. dragged = None def draw(canvas): canvas.clear() background(1) translate(250, 250) # With directed=True, edges have an arrowhead indicating the direction of the connection. # With weighted=True, Node.centrality is indicated by a shadow under high-traffic nodes. # With weighted=0.0-1.0, indicates nodes whose centrality > the given threshold.
def create_graph(p_node, s): completed_nodes = [] uncomplete_nodes = [] global g g = Graph() p = p_node temp = s.pAll[p_node].follower g.add_node(id=str(p_node), radius=5, stroke=color(1, 0, 0.25, 1), text=color(1)) ## print "-"*50 ## print "parent_node ",p_node ## print "parent follower ",temp for i in range(len(temp)): #100 g.add_node(id=str(temp[i]), radius=5, stroke=color(1), text=color(1)) completed_nodes.append(p_node) # Random edges. p_links = s.pAll[p_node].follower for i in range(len(p_links)): node1 = str(p_node) #choice(g.nodes) node2 = str(p_links[i]) #choice(g.nodes) uncomplete_nodes.append(p_links[i]) g.add_edge(node1, node2, length=500.0, weight=random(), stroke=color(1, 0, 0.25, 1)) ## print "-"*50 ## print "Completed_Nodes ",completed_nodes ## print "Uncomplete_Nodes ",uncomplete_nodes while len(uncomplete_nodes) <> 0: node1 = uncomplete_nodes[0] follower_list = s.pAll[node1].follower ## print "node1 which became parent ",node1 for i in follower_list: if i not in completed_nodes: node_1 = str(node1) node2 = str(i) print node_1, "--->", i uncomplete_nodes.append(i) g.add_node(id=str(i), radius=5, stroke=color(1, 0, 0.25, 1), text=color(1)) g.add_edge(node_1, node2, length=50.0, stroke=color(1), weight=random()) completed_nodes.append(node1) del uncomplete_nodes[0] ## print "Completed_Nodes ",completed_nodes ## print "Uncomplete_Nodes ",uncomplete_nodes #New Round ## for I in range(len(temp)): ## ## p_node = s.pAll[p].follower[I] #0 ## p_links = s.pAll[p_node].follower ## ## print "Sibling Node ",p_node ## print "Sibling Follower ",p_links ## ## #print [x * 0.01 for x in range(0,100)] ## r = rd.choice([x * 0.01 for x in range(0,100)])#rd.choice([0,51,255]) #rd.randint(10,200) ## green = rd.choice([x * 0.01 for x in range(0,100)]) #rd.choice([255,128,255]) #rd.randint(0,100) ## b = rd.choice([x * 0.01 for x in range(0,100)]) #rd.choice([128,0,255]) #rd.randint(0,200) ## ## #print r,green,b ## ## for i in range(len(p_links)): ## node1 = str(p_node)#choice(g.nodes) ## ## bul = True ## if p_links[i] not in s.pAll[p].follower: #Not a parent follower ## ## for j in range (I): #Loop to check another sibling's follower ## ## sibling = s.pAll[p].follower[j] ## ## if p_links[i] in s.pAll[sibling].follower: ## ## bul = False ## ## if bul: ## g.add_node(id=str(p_links[i]),radius = 5,stroke = color(r, green, b, 1),text = color(1)) ## node2 = str(p_links[i])#choice(g.nodes) ## g.add_edge(node1, node2, ## length = 50.0, ## weight = random(), ## stroke = color(r, green, b, 1)) ## # Two handy tricks to prettify the layout: # 1) Nodes with a higher weight (i.e. incoming traffic) appear bigger. for node in g.nodes: node.radius = 5 #node.radius + node.radius*node.weight # 2) Nodes with only one connection ("leaf" nodes) have a shorter connection. for node in g.nodes: if len(node.edges) == 1: node.edges[0].length = 0.5 g.prune(depth=0) # Remove orphaned nodes with no connections. g.distance = 15 # Overall spacing between nodes. g.layout.force = 0.01 # Strength of the attractive & repulsive force. g.layout.repulsion = 5 # Repulsion radius. dragged = None
def create_graph(p_node,s): global g g = Graph() p = p_node temp = s.pAll[p_node].follower g.add_node(id=str(p_node),radius = 5,stroke = color(1, 0, 0.25, 1),text = color(1)) for i in range(len(temp)):#100 g.add_node(id=str(temp[i]), radius = 5, stroke = color(1), text = color(1)) # Random edges. p_links = s.pAll[p_node].follower for i in range(len(p_links)): node1 = str(p_node)#choice(g.nodes) node2 = str(p_links[i])#choice(g.nodes) g.add_edge(node1, node2, length = 500.0, weight = random(), stroke = color(1, 0, 0.25, 1)) #New Round for I in range(len(temp)): p_node = s.pAll[p].follower[I] #0 p_links = s.pAll[p_node].follower #print [x * 0.01 for x in range(0,100)] r = rd.choice([x * 0.01 for x in range(0,100)])#rd.choice([0,51,255]) #rd.randint(10,200) green = rd.choice([x * 0.01 for x in range(0,100)]) #rd.choice([255,128,255]) #rd.randint(0,100) b = rd.choice([x * 0.01 for x in range(0,100)]) #rd.choice([128,0,255]) #rd.randint(0,200) #print r,green,b for i in range(len(p_links)): node1 = str(p_node)#choice(g.nodes) bul = True if p_links[i] not in s.pAll[p].follower: #Not a parent follower for j in range (I): #Loop to check another sibling's follower sibling = s.pAll[p].follower[j] if p_links[i] in s.pAll[sibling].follower: bul = False if bul: g.add_node(id=str(p_links[i]),radius = 5,stroke = color(r, green, b, 1),text = color(1)) node2 = str(p_links[i])#choice(g.nodes) g.add_edge(node1, node2, length = 50.0, weight = random(), stroke = color(r, green, b, 1)) # Two handy tricks to prettify the layout: # 1) Nodes with a higher weight (i.e. incoming traffic) appear bigger. for node in g.nodes: node.radius = 5#node.radius + node.radius*node.weight # 2) Nodes with only one connection ("leaf" nodes) have a shorter connection. for node in g.nodes: if len(node.edges) == 1: node.edges[0].length = 0.5 g.prune(depth=0) # Remove orphaned nodes with no connections. g.distance = 15 # Overall spacing between nodes. g.layout.force = 0.01 # Strength of the attractive & repulsive force. g.layout.repulsion = 5 # Repulsion radius. dragged = None