Пример #1
0
    def generateGraphvizMap(self):
        """Generate graph source code for GraphViz.
        """
        storage = self.getStorage()
        catalog = getToolByName(self, 'portal_catalog')

        kws = [kw_res.getObject() for kw_res in catalog.searchResults(portal_type='Keyword')]

        dot = KeywordGraph(self.getGVFont(), self.getRelFont(), self.getFocusNodeShape(), self.getFocusNodeColor(), self.getFocusNodeFontColor(), self.getFocusNodeFontSize(), self.getFirstNodeShape(), self.getFirstNodeColor(), self.getFirstNodeFontColor(), self.getFirstNodeFontSize(), self.getSecondNodeShape(), self.getSecondNodeColor(), self.getSecondNodeFontColor(), self.getSecondNodeFontSize(), self.getEdgeShape(), self.getEdgeColor(), self.getEdgeFontColor(), self.getEdgeFontSize())

        if kws:
            dot.graphHeader(kws[0])

        for node in kws:
            dot.firstLevelNode(node)
            rels = node.getRelations()
            for rel in rels:
                  obs = node.getReferences(rel)
                  try:
                    obs.remove(self)
                  except ValueError: # self not in list
                    pass
                  for cnode in obs:
                    dot.relation(node, cnode, rel)

        dot.graphFooter()

        return dot.getValue()
Пример #2
0
    def generateGraph(self, levels=2):
        """Generate graph source code for GraphViz.
        """
        ctool = getToolByName(self, 'portal_classification')
        forth = ctool.getForth()
        back = ctool.getBack()

        innernodes = self.findDependent(1, exact=True) # level 1 keywords
        outernodes = self.findDependent(2, exact=True) # level 2 keywords


        dot = KeywordGraph(ctool.getGVFont(), ctool.getRelFont(), ctool.getFocusNodeShape(), ctool.getFocusNodeColor(), ctool.getFocusNodeFontColor(), ctool.getFocusNodeFontSize(), ctool.getFirstNodeShape(), ctool.getFirstNodeColor(), ctool.getFirstNodeFontColor(), ctool.getFirstNodeFontSize(), ctool.getSecondNodeShape(), ctool.getSecondNodeColor(), ctool.getSecondNodeFontColor(), ctool.getSecondNodeFontSize(), ctool.getEdgeShape(), ctool.getEdgeColor(), ctool.getEdgeFontColor(), ctool.getEdgeFontSize())

        dot.graphHeader(self)

        ### Graph nodes
        dot.focusNode(self)

        for node in innernodes:
            dot.firstLevelNode(node)

        for node in outernodes:
            dot.secondLevelNode(node)

        ### relationships

        # from central node
        if forth == '1':
         for rel in self.getRelations():
            obs = self.getReferences(rel)
            for cnode in obs:
                dot.relation(self, cnode, rel)
        if back == '1':
         for backrel in self.getBackRelations():
            obsback = self.getBackReferences(backrel)
            for cnode in obsback:
                dot.relation(cnode, self, backrel)


        # from innernodes w/o back to central
        if forth == '1':
         for node in innernodes:
            rels = node.getRelations()
            for rel in rels:
                obs = node.getReferences(rel)
                try:
                    obs.remove(self)
                except ValueError: # self not in list
                    pass

                for cnode in obs:
                    dot.relation(node, cnode, rel)

        if back == '1':
         for node in innernodes:
            relsback = node.getBackRelations()
            for backrel in relsback:
                obsback = node.getBackReferences(backrel)
                try:
                    obsback.remove(self)
                except ValueError: # self not in list
                    pass

                for cnode in obsback:
                    dot.relation(cnode, node, backrel)

        dot.graphFooter()

        return dot.getValue()