# Visual Analytics Course

### Site Tools

chicoutimi_2016:doi_de_furnas

# Visual Analytics Course

Instructor: Guy Melançon (email: Guy dot Melancon at labri dot fr)

## Chicoutimi Summer 2016 roadmap / May 3, 3pm course

### DOI de Furnas

Cet algorithme calcule la valeur DOI des sommets en fonction d'un focus. Le graphe doit êtr eun arbre, le focus choisi par défaut (si pas de sélection) est la racine de l'arbre.

Furnas.py
'''
Created on 28 mars 2012

@author: melancon
'''

from tulip import *

class Furnas:
'''
implements Furnas' original DOI function
with accompanying animation function
most functions require that one node be selected in the tree
'''

def __init__(self, tree):
'''
Constructor
'''
self.tree = tree
self.root = self.tree.getSource()
self.API = self.tree.getDoubleProperty('API')
#self.__API__(self.root, 0)
self.Dist2Focus = self.tree.getIntegerProperty('Dist2Focus')
self.DOI = self.tree.getDoubleProperty('DOI')
self.visible = self.tree.getBooleanProperty('visible')
self.visible.setAllNodeValue(True)
self.color = self.tree.getColorProperty('viewColor')

def __API__(self, node, value):
tlp.maxDistance(self.tree, self.root, self.API, tlp.UNDIRECTED)
m = self.API.getNodeMax()
for n in self.tree.getNodes():
self.API[n] = self.API[n] - m
return True

def __getFocusNode__(self):
viewSelection = self.tree.getBooleanProperty('viewSelection')
for node in self.tree.getNodes():
if viewSelection[node]:
return node
# return root when no node selected
return self.tree.getSource()

def __DOI__(self):
focus = self.__getFocusNode__()
tlp.maxDistance(self.tree, focus, self.Dist2Focus, tlp.UNDIRECTED)
for node in self.tree.getNodes():
self.DOI[node] = self.API[node] - self.Dist2Focus[node]

def performDOI(self, layer, selectionProperty):
'''
grabs all node having DOI less than or equal to layer
displays them and hides all others
'''
focus = self.__getFocusNode__()
self.__DOI__()
updateVis = self.tree.getBooleanProperty('updateVis')
for node in self.tree.getNodes():
if self.DOI[node] >= self.DOI[focus] - layer:
updateVis[node] = True
selectionProperty[node] = True
else:
updateVis[node] = False
selectionProperty[node] = False

for node in self.tree.getNodes():
if self.visible[node] and (not updateVis[node]):
elif (not self.visible[node]) and updateVis[node]:
elif self.visible[node] and updateVis[node]:
else:

self.visible[node] = updateVis[node]

c = tlp.Color(0, 0, 255, 255)
self.color[node] = c
if __name__ == '__main__':
updateVisualization()
return True

furnas.performDOI(4, tree_sel)