当前位置: 首页>>代码示例>>Python>>正文


Python Vertex.pos方法代码示例

本文整理汇总了Python中graph.Vertex.pos方法的典型用法代码示例。如果您正苦于以下问题:Python Vertex.pos方法的具体用法?Python Vertex.pos怎么用?Python Vertex.pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graph.Vertex的用法示例。


在下文中一共展示了Vertex.pos方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import pos [as 别名]

#.........这里部分代码省略.........
        #
        # Extension - we allow node IDs of type String as well as
        # integer.
        #
        if not isinstance(vxbranch.data['id'][0].data, (int, GMLString)):
            raise ImportError, ("GML format error: node ID '%s' of "
                                "unsupportedtype" % (vxbranch.data['id'][0].data))

        id = str(vxbranch.data['id'][0].data)
        if id in vertexIndex:
            # Duplicate vertex
            if yesall_duplicate_vert or yestoall:
                continue
            if queryCallback:
                result = queryCallback("Duplicate vertex detected: id %s" % (id))
                if result == CustomButtonDialog.ID['Yes']:
                    continue
                elif result == CustomButtonDialog.ID['Yes to similar errors']:
                    yesall_duplicate_vert = True
                    continue
                elif result == CustomButtonDialog.ID['Yes to all errors']:
                    yestoall = True
                    continue
                else:
                    raise ImportError, "Import aborted."
            else:
                raise ImportError, "Duplicate vertex detected: id %s" % (id)

        v = Vertex(id=id)

        if 'label' in vxbranch.data:
            v.name = str(vxbranch.data['label'][0].data)
        if 'graphics' in vxbranch.data:
            pos = list(v.pos)
            rad = v.radius
            color = list(v.color)
            grbranch = vxbranch.data['graphics'][0].data

            if 'x' in grbranch.data:
                pos[X_AXIS] = float(grbranch.data['x'][0].data)
            if 'y' in grbranch.data:
                pos[Y_AXIS] = float(grbranch.data['y'][0].data)
            if 'z' in grbranch.data:
                pos[Z_AXIS] = float(grbranch.data['z'][0].data)
            if 'w' in grbranch.data:
                radius = float(grbranch.data['w'][0].data)
            if 'h' in grbranch.data:
                radius = max(radius, float(grbranch.data['h'][0].data))
            if 'd' in grbranch.data:
                radius = max(radius, float(grbranch.data['d'][0].data))
            if 'fill' in grbranch.data:
                fail = False
                fillstr = grbranch.data['fill'][0].data
                if not isinstance(fillstr, GMLString):
                    fail = True
                    fail = "fill must be a String"
                elif not len(str(fillstr)) > 0:
                    fail = "fill string too short"
                elif str(fillstr)[0] != '#':
                    # Named color
                    try:
                        color = colorByName(str(fillstr))
                    except UnknownColor:
                        fail = "unrecognized named color"
                else:
                    # Hex color
开发者ID:ulethHCI,项目名称:GLuskap,代码行数:70,代码来源:gml.py

示例2: load

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import pos [as 别名]
def load(graph, fobj, queryCallback=None, warningCallback=None):
    """Load .gv or .dot file

    Arguments:
    graph -- the graph to be created from the loaded file
    fobj -- a file object of the DOT file to be read
    queryCallback -- function to display a default query dialog (default None)
    warningCallback -- function to display a default warning dialog
                       (default None)

    """

    # Set global variables to in DOTGraph for automatically replacing
    # attributes of duplicate nodes and edges
    global _yestoall_nodes
    global _yestoall_edges
    _yestoall_nodes = None
    _yestoall_edges = None

    try:
        dotgraph = DOTGraph(Stream(fobj), queryCallback=queryCallback,
                            warningCallback=warningCallback)
    except EOF:
        raise ImportError, "Premature end of file"
    except Unbalanced:
        raise ImportError, "Unbalanced delimiters in file"

    # Boolean variables to control if the rest of the import errors are handled
    # automatically
    yestoall = False
    yesall_color = False
    yesall_degenerate_edge = False

    def getColor(color):
        """Retun an RGB float triple of a color string. Return False if invalid

        Arguments:
        color -- a string representing a color
        """

        # Hex color
        if color[0] == '#' and len(color) == 7:
            fillstr = color
            r = fillstr[1:3]
            g = fillstr[3:5]
            b = fillstr[5:7]
            try:
                color = [x / 255.0 for x in (int(r, 16), int(g, 16), int(b, 16))]
                return color
            except:
                return False

        # HSV float triple
        elif ',' in color or ' ' in color:
            color = color.replace(" ", "").split(',', 3)
            try:
                color = [float(x) for x in color]
                color = colorsys.hsv_to_rgb(color[0], color[1], color[2])
                return color
            except:
                return False
        # X11 Color Name
        else:
            try:
                color = colorByName(color)
                return color
            except UnknownColor:
                return False

    # Add all the vertices in the dotgraph to the context graph
    for vertex, attributes in dotgraph.nodes.items():
        v = Vertex(id=vertex)
        if 'label' in attributes:
            v.name = attributes['label']
        if 'width' in attributes:
            v.radius = float(attributes['width'])
        if 'pos' in attributes:
            # remove ! and spaces, then split numbers
            pos = attributes['pos'][:-1].replace(" ", "").split(',', 3)
            if len(pos) < 3:
                pos.append(0.0)
            v.pos = (float(pos[0]), float(pos[1]), float(pos[2]))
        if 'color' in attributes:
            color = getColor(attributes['color'])
            if color != False:
                v.color = tuple(color)
            elif not yesall_color and not yestoall:
                # Invalid color
                if queryCallback:
                    result = queryCallback("Invalid vertex color %s for %s. "
                                           "Assign default color?" %
                                           (attributes['color'], vertex), True)
                    if result == CustomButtonDialog.ID['Yes']:
                        pass
                    elif result == CustomButtonDialog.ID['Yes to similar errors']:
                        yesall_color = True
                    elif result == CustomButtonDialog.ID['Yes to all errors']:
                        yestoall = True
                    else:
                        raise ImportError, "Import aborted."
#.........这里部分代码省略.........
开发者ID:ulethHCI,项目名称:GLuskap,代码行数:103,代码来源:dot.py

示例3: load

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import pos [as 别名]
def load(graph, fobj, queryCallback=None, warningCallback=None):
    """ Load a TLP file and create a graph from it

    Arguments:
    graph -- the graph to be created from the loaded file
    fobj -- a file object of the TLP file to be read
    queryCallback -- function to display a default query dialog (default None)
    warningCallback -- function to display a default warning dialog
                       (default None)
    
    """

    try:
        tlpgraph = TLPGraph(Stream(fobj))
    except Unbalanced:
        raise ImportError, "Unbalanced delimiters in file"
    except TypeMismatch:
        raise ImportError, "Unintelligible value in file"
    except EOF:
        raise ImportError, "Premature end of file"

    # Boolean variables to control if the rest of the import errors are handled
    # automatically
    yestoall = False
    yesall_duplicate_edge = False
    yesall_degenerate_edge = False
    yesall_nonexist_vert = False

    # Make vertices and apply properties
    for vertex, properties in tlpgraph.nodes.items():
        v = Vertex(vertex)
        if "viewLabel" in properties:
            v.name = properties["viewLabel"]
        if "viewLayout" in properties:
            pos = string_to_tuple(properties["viewLayout"])
            v.pos = tuple([float(x) for x in pos])
        if "viewSize" in properties:
            v.radius = float(string_to_tuple(properties["viewSize"])[0])
        if "viewColor" in properties:
            color = string_to_tuple(properties["viewColor"])[:3]
            v.color = tuple([float(x) / 255 for x in color])
        graph.addVertex(v)

    # Make edges and apply properties
    edges = tlpgraph.edges.values()
    edges.extend(tlpgraph.lost_edges)
    for properties in edges:

        source = properties["source"]
        target = properties["target"]

        # Raise an error if edge is degenerate, or source or target vertices
        # are non existent. Automatically handle errors if yes all is selected
        if source == target:
            # Degenerate Edge
            if yesall_degenerate_edge or yestoall:
                continue
            if queryCallback:
                result = queryCallback("Degenerate edge detected: %s -> %s" % (source, target))
                if result == CustomButtonDialog.ID["Yes"]:
                    continue
                elif result == CustomButtonDialog.ID["Yes to similar errors"]:
                    yesall_degenerate_edge = True
                    continue
                elif result == CustomButtonDialog.ID["Yes to all errors"]:
                    yestoall = True
                    continue
                else:
                    raise ImportError, "Import aborted."
            else:
                raise ImportError("Degenerate edge detected: %s -> %s" % (source, target))
        if source not in tlpgraph.nodes.keys():
            # Nonexistent vertex
            if yesall_nonexist_vert or yestoall:
                continue
            if queryCallback:
                result = queryCallback("Edge specifies nonexistent " "source vertex %s" % (source))
                if result == CustomButtonDialog.ID["Yes"]:
                    continue
                elif result == CustomButtonDialog.ID["Yes to similar errors"]:
                    yesall_nonexist_vert = True
                    continue
                elif result == CustomButtonDialog.ID["Yes to all errors"]:
                    yestoall = True
                    continue
                else:
                    raise ImportError, "Import aborted."
            else:
                raise ImportError, ("Edge specifies nonexistent source vertex" " %s" % (source))
        if target not in tlpgraph.nodes.keys():
            # Nonexistent vertex
            if yesall_nonexist_vert or yestoall:
                continue
            if queryCallback:
                result = queryCallback("Edge specifies nonexistent " "target vertex %s" % (target))
                if result == CustomButtonDialog.ID["Yes"]:
                    continue
                elif result == CustomButtonDialog.ID["Yes to similar errors"]:
                    yesall_nonexist_vert = True
                    continue
#.........这里部分代码省略.........
开发者ID:ulethHCI,项目名称:GLuskap,代码行数:103,代码来源:tlp.py

示例4: load

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import pos [as 别名]

#.........这里部分代码省略.........
            if len(fillstr) == 7:
                r = fillstr[1:3]
                g = fillstr[3:5]
                b = fillstr[5:7]
            elif len(fillstr) == 4:
                r = fillstr[1]
                g = fillstr[2]
                b = fillstr[3]
            else:
                fail = "fill must be of form '#fff' or '#ffffff'"
            if not fail:
                color = [x / 255.0 for x in (int(r, 16), int(g, 16), int(b, 16))]
                v.color = tuple(color)
            elif fail and not yesall_color and not yestoall:
                if queryCallback:
                    result = queryCallback("Invalid vertex fill color (%s): id "
                                           "%s, fill '%s' \n\nUse default color"
                                           "and continue?" %
                                           (fail, id, fillstr), override=True)
                    if result == CustomButtonDialog.ID['Yes']:
                        pass
                    elif result == CustomButtonDialog.ID['Yes to similar errors']:
                        yesall_color = True
                    elif result == CustomButtonDialog.ID['Yes to all errors']:
                        yestoall = True
                    else:
                        raise ImportError, "Import aborted."
                else:
                    raise ImportError, ("Invalid vertex fill color (%s): id %s, "
                                        "fill '%s'" % (fail, id, fillstr))

        # Determine the position of each vertex
        if 'x' in vertAttrs or 'y' in vertAttrs or 'z' in vertAttrs:
            pos = [0.0, 0.0, 0.0]
            if 'x' in vertAttrs and (isinstance(vertAttrs['x'], float) or
                                         isinstance(vertAttrs['x'], int)):
                pos[0] = pos[0] + vertAttrs['x']
            if 'y' in vertAttrs and (isinstance(vertAttrs['y'], float) or
                                         isinstance(vertAttrs['y'], int)):
                pos[1] = pos[1] + vertAttrs['y']
            if 'z' in vertAttrs and (isinstance(vertAttrs['z'], float) or
                                         isinstance(vertAttrs['z'], int)):
                pos[2] = pos[2] + vertAttrs['z']

            v.pos = tuple(pos)

        # Accept either radius or size for the radius of a vertex
        if 'radius' in vertAttrs:
            v.radius = vertAttrs['radius']
        elif 'size' in vertAttrs:
            v.radius = vertAttrs['size']
        # Accept either name or label for the label of a vertex
        if 'name' in vertAttrs:
            v.name = vertAttrs['name']
        elif 'label' in vertAttrs:
            v.name = vertAttrs['label']
        graph.addVertex(v)
        vertexIndex[v.id] = v

    # Read edges
    for edgeNode in graphNode.getElementsByTagName('edge'):
        edgeAttrs = dict(
            [(str(a), str(b)) for a, b in edgeNode.attributes.items()]
        )
        # Create a dict edgeAttrs that maps edge attributes to their values
        for dataNode in edgeNode.getElementsByTagName('data'):
开发者ID:ulethHCI,项目名称:GLuskap,代码行数:70,代码来源:graphml.py


注:本文中的graph.Vertex.pos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。