In [7]:
import sys
if sys.version_info[0] == 3:
from imp import reload
from tulip import tlp
import tulipnb
reload(tulipnb)
import random
def getRandomFontAwesomeIcon():
iconKeys = vars(tlp.TulipFontAwesome).keys()
while 1:
attName = random.choice(list(iconKeys))
attr = getattr(tlp.TulipFontAwesome, attName)
if not attName.startswith('_') and type(attr) == str:
return attr
def getRandomColor():
r = int(random.random()*255)
g = int(random.random()*255)
b = int(random.random()*255)
return tlp.Color(r, g, b)
In [8]:
graph = tlp.importGraph('Grid Approximation')
graph.applySizeAlgorithm('Auto Sizing')
for n in graph.getNodes():
values = {'viewShape': tlp.NodeShape.FontAwesomeIcon,
'viewColor' : getRandomColor(),
'viewIcon' : getRandomFontAwesomeIcon()}
graph.setNodePropertiesValues(n, values)
tulipnb.display(graph)
In [9]:
import string
graph = tlp.importGraph('Grid')
for n in graph.getNodes():
values = {'viewShape': tlp.NodeShape.FontAwesomeIcon,
'viewColor' : getRandomColor(),
'viewLabel': ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(5)),
'viewLabelColor': tlp.Color.Blue,
'viewIcon' : getRandomFontAwesomeIcon()}
graph.setNodePropertiesValues(n, values)
tulipnb.display(graph)
In [10]:
# need to import the tulipgui module in order to load the 'File System Directory' import plugin
# (as it depends on Qt)
from tulipgui import *
import os
# get the root directory of the Python Standard Libraries
pythonStdLibPath = os.path.dirname(os.__file__)
# call the 'File System Directory' import plugin from Tulip
# importing the tree structure of a file system
params = tlp.getDefaultPluginParameters('File System Directory')
params['directory color'] = tlp.Color.Blue
params['other color'] = tlp.Color.Red
params['dir::directory'] = pythonStdLibPath
graph = tlp.importGraph('File System Directory', params)
# compute an anonymous graph double property that will store node degrees
degree = tlp.DoubleProperty(graph)
degreeParams = tlp.getDefaultPluginParameters('Degree')
graph.applyDoubleAlgorithm('Degree', degree, degreeParams)
# create a heat map color scale
heatMap = tlp.ColorScale([tlp.Color.Green, tlp.Color.Black, tlp.Color.Red])
# linearly map node degrees to colors using the 'Color Mapping' plugin from Tulip
# using the heat map color scale
colorMappingParams = tlp.getDefaultPluginParameters('Color Mapping', graph)
colorMappingParams['input property'] = degree
colorMappingParams['colorScale'] = heatMap
colorMappingParams['type'] = 'logarithmic'
graph.applyColorAlgorithm('Color Mapping', colorMappingParams)
# apply the 'Bubble Tree' graph layout plugin from Tulip
graph.applyLayoutAlgorithm('Bubble Tree')
# compute quadratic bezier shapes for edges
curveEdgeParams = tlp.getDefaultPluginParameters('Curve edges', graph)
curveEdgeParams['curve type'] = 'QuadraticDiscrete'
graph.applyAlgorithm('Curve edges', curveEdgeParams)
graph['viewLabelColor'].setAllNodeValue(tlp.Color.Black)
tulipnb.display(graph)
In [11]:
graph = tlp.importGraph('Grid Approximation')
graph.applyAlgorithm('Voronoi diagram')
voronoi = graph.getSubGraph('Voronoi')
original = graph.getSubGraph('Original graph')
for e in original.getEdges():
graph['viewColor'][e] = tlp.Color.Red
for n in voronoi.getNodes():
graph['viewColor'][n] = tlp.Color.Blue
for e in voronoi.getEdges():
graph['viewColor'][e] = tlp.Color.Blue
tulipnb.display(graph)
In [ ]: