Beispiel #1
0
 def _get_font_style(self, size, anchor, dash_array):
     style = StyleBuilder()
     style.setStrokeDashArray(dash_array)
     style.setFontFamily(fontfamily="Verdana")
     style.setFontSize("%dpx" % size)
     style.setTextAnchor(anchor)
     return style
Beispiel #2
0
 def _get_font_style(self, size, anchor, dash_array):
     style = StyleBuilder()
     style.setStrokeDashArray(dash_array)
     style.setFontFamily(fontfamily="Verdana")
     style.setFontSize("%dpx" % size)
     style.setTextAnchor(anchor)
     return style
def draw_tree(width, height):
    global nameStyle

    nameStyle = StyleBuilder()
    nameStyle.setFontFamily(fontfamily=dc.nameFont)
    nameStyle.setFontSize("%spt" % dc.nameFontSize)
    nameStyle.setTextAnchor("left")
    nameStyle = nameStyle.getStyle()

    svg = Svg(width=width, height=height)

    # draw nodes

    for depth in depthToNames:
        for name in depthToNames[depth]:
            node = nameToNode[name]
            draw_node(svg, node, name)

    # draw branches

    for depth in depthToNames:
        for name in depthToNames[depth]:
            node = nameToNode[name]
            isLeaf = (node.children == [])
            if (isLeaf): continue

            numChildren = len(node.children)
            for (i, child) in enumerate(node.children):
                rootFrac = 0.4 + (0.2 * i) / (numChildren - 1)
                sinkFrac = 0.5

                if (orientation == "T2B"):
                    (rootX, rootY) = (node.x + rootFrac * dc.nodeWdt,
                                      node.y + dc.nodeHgt)
                    (sinkX, sinkY) = (child.x + sinkFrac * dc.nodeWdt, child.y)
                    draw_vert_branch(svg, "%s_branch_%d" % (name, i), rootX,
                                     rootY, sinkX, sinkY)
                else:  # if (orientation == "L2R"):
                    (rootX, rootY) = (node.x + dc.nodeWdt,
                                      node.y + rootFrac * dc.nodeHgt)
                    (sinkX, sinkY) = (child.x, child.y + sinkFrac * dc.nodeHgt)
                    draw_horz_branch(svg, "%s_branch_%d" % (name, i), rootX,
                                     rootY, sinkX, sinkY)

    return svg
Beispiel #4
0
    def genLabels(self):
        labels = G()
        labelStyle = StyleBuilder()
        labelStyle.setTextAnchor('middle')
        labelStyle.setFontSize(10)
        lineStyle = StyleBuilder()
        lineStyle.setStroke('#a9a9a9')
        dimLabelA = str(self.dimA) + ' nm'
        dimLabelB = str(self.dimB) + ' nm'
        # horizontal label
        cornerHL = self.view.getTopLeft()
        cornerHR = self.view.getTopRight()

        hLabelStart = [cornerHL[0], cornerHL[1] + 5]
        hLabelEnd = [cornerHR[0], cornerHR[1] + 5]

        hLine = Line(hLabelStart[0], hLabelStart[1], hLabelEnd[0], hLabelEnd[1])
        hLabel = Text(dimLabelA, (hLabelStart[0] + hLabelEnd[0])/2, hLabelEnd[1] + 20)
        hLine.set_style(lineStyle.getStyle())
        hLabel.set_style(labelStyle.getStyle())

        cornerVL = self.view.getTopLeft()
        cornerVR = self.view.getBottomLeft()

        vLabelStart = [cornerVL[0] - 5, cornerVL[1]]
        vLabelEnd = [cornerVR[0] - 5, cornerVR[1]]

        vLine = Line(vLabelStart[0], vLabelStart[1], vLabelEnd[0], vLabelEnd[1])
        vLabel = Text(dimLabelB, vLabelEnd[0] - 30, (vLabelStart[1] + vLabelEnd[1])/2)
        vLine.set_style(lineStyle.getStyle())
        vLabel.set_style(labelStyle.getStyle())
        labels.addElement(hLine)
        labels.addElement(hLabel)
        labels.addElement(vLine)
        labels.addElement(vLabel)

        #center = [self.gridCoord[0] + self.dimA*SCALING_FACTOR/2, self.gridCoord[1] + self.dimB*SCALING_FACTOR + LABEL_SHIFT]
        #dimLabel = str(self.dimA) + 'nm x ' +str(self.dimB) + 'nm'
        #labels = Text(dimLabel, center[0], center[1])
        #labels.set_style(labelStyle.getStyle())
        return labels
Beispiel #5
0
    def genLabels(self):

        labels = G()
        labelStyle = StyleBuilder()
        labelStyle.setTextAnchor('middle')
        labelStyle.setFontSize(10)
        lineStyle = StyleBuilder()
        lineStyle.setStroke('#a9a9a9')
        dimLabelA = str(self.x/SCALING_FACTOR) + ' nm'
        dimLabelB = str(self.z/SCALING_FACTOR) + ' nm'
        # horizontal label
        cornerHL = self.hCSlice.getTopLeft()
        cornerHR = self.hCSlice.getTopRight()

        hLabelStart = [cornerHL[0], cornerHL[1] + 5]
        hLabelEnd = [cornerHR[0], cornerHR[1] + 5]

        hLine = Line(hLabelStart[0], hLabelStart[1], hLabelEnd[0], hLabelEnd[1])
        hLabel = Text(dimLabelA, (hLabelStart[0] + hLabelEnd[0])/2, hLabelEnd[1] + 20)
        hLine.set_style(lineStyle.getStyle())
        hLabel.set_style(labelStyle.getStyle())

        cornerVL = self.hCSlice.getTopLeft()
        cornerVR = self.hCSlice.getBottomLeft()

        vLabelStart = [cornerVL[0] - 5, cornerVL[1]]
        vLabelEnd = [cornerVR[0] - 5, cornerVR[1]]

        vLine = Line(vLabelStart[0], vLabelStart[1], vLabelEnd[0], vLabelEnd[1])
        vLabel = Text(dimLabelB, vLabelEnd[0] - 30, (vLabelStart[1] + vLabelEnd[1])/2)
        vLine.set_style(lineStyle.getStyle())
        vLabel.set_style(labelStyle.getStyle())
        labels.addElement(hLine)
        labels.addElement(hLabel)
        labels.addElement(vLine)
        labels.addElement(vLabel)
        return labels
def draw_tree():
    if (dc.nameFontSize < 16):
        scale = dc.nameFontSize / 16.0
        nameCapsHgt = dc.nameCapsHgt * scale
        nameDescHgt = dc.nameDescHgt * scale
        nameFontLineHgt = dc.nameFontLineHgt * scale

    nameStyle = StyleBuilder()
    nameStyle.setFontFamily(fontfamily=dc.nameFont)
    nameStyle.setFontSize("%spt" % dc.nameFontSize)
    nameStyle.setTextAnchor("left")
    nameStyle = nameStyle.getStyle()

    svg = Svg()

    # draw nodes

    for depth in depthToNames:
        for name in depthToNames[depth]:
            node = nameToNode[name]
            isLeaf = (node.left == None)

            yLine = node.y + nameCapsHgt + 1

            ob = SvgRect(node.x,
                         node.y,
                         dc.nodeWidth,
                         dc.nodeHeight,
                         id="%s_box" % name)
            ob.set_stroke(dc.lineColor)
            ob.set_stroke_width(dc.lineThickness)
            if (isLeaf): ob.set_fill(dc.leafFillColor)
            else: ob.set_fill(dc.nodeFillColor)
            svg.addElement(ob)

            ob = SvgText("%s" % name, node.x + 1, yLine, id="%s_name" % node)
            ob.set_style(nameStyle)
            svg.addElement(ob)
            yLine += nameFontLineHgt

            if (hasattr(node, "bitsUnion")):
                ob = SvgText("U:" +
                             bits_to_string(node.numBits, node.bitsUnion),
                             node.x + 1,
                             yLine,
                             id="%s_Bunion" % node)
                ob.set_style(nameStyle)
                svg.addElement(ob)
            yLine += nameFontLineHgt

            if (hasattr(node, "bitsIntersection")):
                ob = SvgText(
                    "I:" + bits_to_string(node.numBits, node.bitsIntersection),
                    node.x + 1,
                    yLine,
                    id="%s_Bintersection" % node)
                ob.set_style(nameStyle)
                svg.addElement(ob)
            yLine += nameFontLineHgt

            if (hasattr(node, "bitsAll")):
                ob = SvgText("A:" + bits_to_string(node.numBits, node.bitsAll),
                             node.x + 1,
                             yLine,
                             id="%s_Ball" % node)
                ob.set_style(nameStyle)
                svg.addElement(ob)
            yLine += nameFontLineHgt

            if (hasattr(node, "bitsSome")):
                ob = SvgText("S:" +
                             bits_to_string(node.numBits, node.bitsSome),
                             node.x + 1,
                             yLine,
                             id="%s_Bsome" % node)
                ob.set_style(nameStyle)
                svg.addElement(ob)
            yLine += nameFontLineHgt

    # draw branches

    for depth in depthToNames:
        for name in depthToNames[depth]:
            node = nameToNode[name]
            if (node.left == None): continue

            (leftStartX, leftStartY) = (node.x + 0.4 * dc.nodeWidth,
                                        node.y + dc.nodeHeight)
            (rightStartX, rightStartY) = (node.x + 0.6 * dc.nodeWidth,
                                          node.y + dc.nodeHeight)
            (leftEndX, leftEndY) = (node.left.x + 0.5 * dc.nodeWidth,
                                    node.right.y)
            (rightEndX, rightEndY) = (node.right.x + 0.5 * dc.nodeWidth,
                                      node.right.y)

            draw_branch(svg, "%s_left_branch" % node, leftStartX, leftStartY,
                        leftEndX, leftEndY)
            draw_branch(svg, "%s_right_branch" % node, rightStartX,
                        rightStartY, rightEndX, rightEndY)

    return svg