User Tools

Site Tools


jordan_aupetit:solution_homework1

Report of Jordan Aupetit and Antoine Laumond

We decided to implement the “icicle plot” by Kruskal and Landwher.

This is our code:

from tulip import *
import time

def main(graph): 
	viewBorderColor =  graph.getColorProperty("viewBorderColor")
	viewBorderWidth =  graph.getDoubleProperty("viewBorderWidth")
	viewColor =  graph.getColorProperty("viewColor")
	viewFont =  graph.getStringProperty("viewFont")
	viewFontSize =  graph.getIntegerProperty("viewFontSize")
	viewLabel =  graph.getStringProperty("viewLabel")
	viewLabelBorderColor =  graph.getColorProperty("viewLabelBorderColor")
	viewLabelBorderWidth =  graph.getDoubleProperty("viewLabelBorderWidth")
	viewLabelColor =  graph.getColorProperty("viewLabelColor")
	viewLabelPosition =  graph.getIntegerProperty("viewLabelPosition")
	viewLayout =  graph.getLayoutProperty("viewLayout")
	viewMetaGraph =  graph.getGraphProperty("viewMetaGraph")
	viewMetric =  graph.getDoubleProperty("viewMetric")
	viewRotation =  graph.getDoubleProperty("viewRotation")
	viewSelection =  graph.getBooleanProperty("viewSelection")
	viewShape =  graph.getIntegerProperty("viewShape")
	viewSize =  graph.getSizeProperty("viewSize")
	viewSrcAnchorShape =  graph.getIntegerProperty("viewSrcAnchorShape")
	viewSrcAnchorSize =  graph.getSizeProperty("viewSrcAnchorSize")
	viewTexture =  graph.getStringProperty("viewTexture")
	viewTgtAnchorShape =  graph.getIntegerProperty("viewTgtAnchorShape")
	viewTgtAnchorSize =  graph.getSizeProperty("viewTgtAnchorSize")


	#### Modifiable ####
	size          = 5
	sleepTime     = 0.3
	animate       = True    # /!\ Desactiver l'animation sous Windows
	initial_color = 55		# Couleur du premier rectangle
	color_stage   = 20		# Difference de couleur entre deux etages
	####################
	
	####################
	depth           = 0
	listNode        = []
	color_threshold = -((255 - initial_color) / color_stage)
	####################

	def changeNode(node, sizeNode, width, x, y, color):
		viewShape[node] = tlp.NodeShape.Square
		baseSize = tlp.Size(sizeNode * width, sizeNode, 1)
		viewSize[node] = baseSize
		viewColor[node] = tlp.Color(initial_color - (color*color_stage), -(color*color_stage), 0)
		viewBorderColor[node] = tlp.Color.Black
		viewBorderWidth[node] = 1
		viewLayout[node] = tlp.Coord(x, y)

	# On recupere le noeud root
	for node in graph.getNodes():
		if len(list(graph.getInNodes(node))) == 0:
			listNode.append([node, size, len(list(graph.getNodes())), 0, 0, depth])
			changeNode(node, size, len(list(graph.getNodes())), 0, 0, 0)


	while listNode:	
		idChild = 0
		nbChild = len(list(graph.getOutNodes(listNode[0][0])))
		depthChild = listNode[0][5] - 1

		if nbChild > 0:
			childWidth = float(listNode[0][2]) / float(nbChild)
		
		# On parcours tous les fils du noeud actuel
		for child in graph.getOutNodes(listNode[0][0]):
			# On prend la position du pere et on ajoute la position du fils
			# On enleve la taille du pere divise par deux et on ajoute
			# la taille du fils divise par 2 pour etre aligne a gauche sur le pere
			childX = listNode[0][3] + (idChild * childWidth * size) - (float(listNode[0][2] * size) / 2) + (float(childWidth * size) / 2)
			
			childY = depthChild * size
			listNode.append([child, size, childWidth, childX, childY, depthChild])
	
			if depthChild < color_threshold:
				changeNode(child, size, childWidth, childX, childY, color_threshold)			
			else:
				changeNode(child, size, childWidth, childX, childY, depthChild)
			
			if animate:
				# /!\ Attention, la fonction sleep freeze Tulip sous windows
				time.sleep(sleepTime)
				updateVisualization()
			
			idChild += 1
			
		# On enleve le noeud que l'on vient de traiter	
		listNode.pop(0)

You can also download the script here : https://drive.google.com/file/d/0B4a6xS3ToC9lbVBESW5RVlR4TW8/view?usp=sharing

General Introduction:


This script provides a visualization of the icicle plot algorithm from any tree.
The script performs a hierarchical path of the tree using a queue to determine the order of the vertices to be processed.
Each vertex will reshape and reposition according of the vertices of upstairs (parent's vertex).
Colorization is a gradient from the roots to the leaves.

Editable parameters:
  • “animate” : When tested on Windows system, the sleep function doesn't make an animation because it freezes the script (tested with 3 computers). The boolean “animate” can cancel the animation and avoid this problem if it's equal to False. No problems seen with Unix system.
  • “sleepTime” is the duration of the sleep function. It's initial value is 0.3. A large value will increase the time between the different phases of the script's animation.
  • “size” determines the size of the root node. It's initial value is 5.
  • “initial_color” determines the luminance of the root's color. A high value will show a lighter root.
  • “color_stage” determines the difference of color intensity between two node floors. A low value is recommended for deep graphs.
Here is an illustration with a complete tree:

(We do not have permission to add files so here are some links.)

http://i.imgur.com/dFf11qX.png

http://i.imgur.com/LpnMUS2.png

Here is an illustration with a random tree:
/net/html/perso/melancon/Visual_Analytics_Course/data/pages/jordan_aupetit/solution_homework1.txt · Last modified: 2014/10/20 08:46 by aupetit