User Tools

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

Voir la portion de cours sur l'indice DOI.

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]):
                self.__fadeOut__(node)
            elif (not self.visible[node]) and updateVis[node]:
                self.__fadeIn__(node)
            elif self.visible[node] and updateVis[node]:
                self.__fadeIn__(node)
            else:
                self.__fadeOut__(node)
 
            self.visible[node] = updateVis[node]
 
    def __fadeOut__(self, node):
        c = tlp.Color(0, 0, 255, 255)
        self.color[node] = c
        if __name__ == '__main__':
            updateVisualization()
        return True
 
    def __fadeIn__(self, node):
        c = tlp.Color(255, 0, 0, 255)
        self.color[node] = c
        if __name__ == '__main__':
            updateVisualization()
        return True
 
def main(graph):
    furnas = Furnas(graph)
    tree_sel = furnas.tree.getLocalBooleanProperty('DOI_selection')
    furnas.performDOI(4, tree_sel)
/net/html/perso/melancon/Visual_Analytics_Course/data/pages/chicoutimi_2016/doi_de_furnas.txt · Last modified: 2016/05/26 21:52 by melancon