예제 #1
0
    def draw(self):
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        box = shapes.Rect(self.x + 1,
                          self.y + 1,
                          s - 2,
                          s - 2,
                          fillColor=self.fillColor,
                          strokeColor=self.strokeColor,
                          strokeWidth=0.6)
        g.add(box)

        s += self._oversize

        crossLine1 = shapes.Line(self.x + (s * 0.15) - self._oversize,
                                 self.y + (s * 0.15) - self._oversize,
                                 self.x + (s * 0.85),
                                 self.y + (s * 0.85),
                                 fillColor=self.crossColor,
                                 strokeColor=self.crossColor,
                                 strokeWidth=self.crosswidth)
        g.add(crossLine1)

        crossLine2 = shapes.Line(self.x + (s * 0.15) - self._oversize,
                                 self.y + (s * 0.85),
                                 self.x + (s * 0.85),
                                 self.y + (s * 0.15) - self._oversize,
                                 fillColor=self.crossColor,
                                 strokeColor=self.crossColor,
                                 strokeWidth=self.crosswidth)
        g.add(crossLine2)

        return g
예제 #2
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        # crossbox specific bits
        box = shapes.Rect(self.x + 1,
                          self.y + 1,
                          s - 2,
                          s - 2,
                          fillColor=self.fillColor,
                          strokeColor=self.strokeColor,
                          strokeWidth=2)
        g.add(box)

        crossLine1 = shapes.Line(self.x + (s * 0.15),
                                 self.y + (s * 0.15),
                                 self.x + (s * 0.85),
                                 self.y + (s * 0.85),
                                 fillColor=self.crossColor,
                                 strokeColor=self.crossColor,
                                 strokeWidth=self.crosswidth)
        g.add(crossLine1)

        crossLine2 = shapes.Line(self.x + (s * 0.15),
                                 self.y + (s * 0.85),
                                 self.x + (s * 0.85),
                                 self.y + (s * 0.15),
                                 fillColor=self.crossColor,
                                 strokeColor=self.crossColor,
                                 strokeWidth=self.crosswidth)
        g.add(crossLine2)

        return g
예제 #3
0
    def draw(self):
        """ returns a group of shapes
        """
        g = shapes.Group()

        #overall border and fill
        if self.borderStrokeColor or self.fillColor: # adds border and filling color
            rect = shapes.Rect(self.x, self.y, self.width, self.height)
            rect.fillColor = self.fillColor
            rect.strokeColor = self.borderStrokeColor
            rect.strokeWidth = self.borderStrokeWidth
            g.add(rect)

        #special case - for an empty table we want to avoid divide-by-zero
        data = self.preProcessData(self.data)
        rows = len(self.data)
        cols = len(self.data[0])
        #print "(rows,cols)=(%s, %s)"%(rows,cols)
        row_step = self.height / float(rows)
        col_step = self.width / float(cols)
        #print "(row_step,col_step)=(%s, %s)"%(row_step,col_step)
        # draw the grid
        if self.horizontalDividerStrokeColor:
            for i in range(rows): # make horizontal lines
                x1 = self.x
                x2 = self.x + self.width
                y = self.y + row_step*i
                #print 'line (%s, %s), (%s, %s)'%(x1, y, x2, y)
                line = shapes.Line(x1, y, x2, y)
                line.strokeDashArray = self.dividerDashArray
                line.strokeWidth = self.horizontalDividerStrokeWidth
                line.strokeColor = self.horizontalDividerStrokeColor
                g.add(line)
        if self.verticalDividerStrokeColor:
            for i in range(cols): # make vertical lines
                x = self.x+col_step*i
                y1 = self.y
                y2 = self.y + self.height
                #print 'line (%s, %s), (%s, %s)'%(x, y1, x, y2)
                line = shapes.Line(x, y1, x, y2)
                line.strokeDashArray = self.dividerDashArray
                line.strokeWidth = self.verticalDividerStrokeWidth
                line.strokeColor = self.verticalDividerStrokeColor
                g.add(line)

        # since we plot data from down up, we reverse the list
        self.data.reverse()
        for (j, row) in enumerate(self.data):
            y = self.y + j*row_step + 0.5*row_step - 0.5 * self.fontSize
            for (i, datum) in enumerate(row):
                if datum:
                    x = self.x + i*col_step + 0.5*col_step
                    s = shapes.String(x, y, str(datum), textAnchor=self.textAnchor)
                    s.fontName = self.fontName
                    s.fontSize = self.fontSize
                    s.fillColor = self.fontColor
                    g.add(s)
        return g
예제 #4
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()


        # floppy disk specific bits
        diskBody = shapes.Rect(x=self.x, y=self.y+(s/100), width=s, height=s-(s/100),
               fillColor = self.diskColor,
               strokeColor = None,
               strokeWidth=0)
        g.add(diskBody)

        label = shapes.Rect(x=self.x+(s*0.1), y=(self.y+s)-(s*0.5), width=s*0.8, height=s*0.48,
               fillColor = colors.whitesmoke,
               strokeColor = None,
               strokeWidth=0)
        g.add(label)

        labelsplash = shapes.Rect(x=self.x+(s*0.1), y=(self.y+s)-(s*0.1), width=s*0.8, height=s*0.08,
               fillColor = colors.royalblue,
               strokeColor = None,
               strokeWidth=0)
        g.add(labelsplash)


        line1 = shapes.Line(x1=self.x+(s*0.15), y1=self.y+(0.6*s), x2=self.x+(s*0.85), y2=self.y+(0.6*s),
               fillColor = colors.black,
               strokeColor = colors.black,
               strokeWidth=0)
        g.add(line1)

        line2 = shapes.Line(x1=self.x+(s*0.15), y1=self.y+(0.7*s), x2=self.x+(s*0.85), y2=self.y+(0.7*s),
               fillColor = colors.black,
               strokeColor = colors.black,
               strokeWidth=0)
        g.add(line2)

        line3 = shapes.Line(x1=self.x+(s*0.15), y1=self.y+(0.8*s), x2=self.x+(s*0.85), y2=self.y+(0.8*s),
               fillColor = colors.black,
               strokeColor = colors.black,
               strokeWidth=0)
        g.add(line3)

        metalcover = shapes.Rect(x=self.x+(s*0.2), y=(self.y), width=s*0.5, height=s*0.35,
               fillColor = colors.silver,
               strokeColor = None,
               strokeWidth=0)
        g.add(metalcover)

        coverslot = shapes.Rect(x=self.x+(s*0.28), y=(self.y)+(s*0.035), width=s*0.12, height=s*0.28,
               fillColor = self.diskColor,
               strokeColor = None,
               strokeWidth=0)
        g.add(coverslot)

        return g
예제 #5
0
    def drawLine(self,
                 x1,
                 y1,
                 x2,
                 y2,
                 color=None,
                 width=None,
                 dash=None,
                 **kwargs):
        "Draw a straight line between x1,y1 and x2,y2."
        # set color...
        if color:
            if color == transparent:
                return
        elif self.defaultLineColor == transparent:
            return
        else:
            color = self.defaultLineColor
        color = colorToRL(color)
        if width:
            w = width
        else:
            w = self.defaultLineWidth

        self.drawing.add(
            shapes.Line(x1,
                        self.fixY(y1),
                        x2,
                        self.fixY(y2),
                        strokeColor=color,
                        strokeWidth=w,
                        strokeDashArray=dash))
        return
예제 #6
0
 def aLine(x0, y0, x1, y1):
     if candleKind != 'vertical':
         x0, y0 = y0, x0
         x1, y1 = y1, x1
     G(
         shapes.Line(x0,
                     y0,
                     x1,
                     y1,
                     strokeWidth=strokeWidth,
                     strokeColor=strokeColor,
                     strokeDashArray=strokeDashArray))
예제 #7
0
def draw_label(label, width, height, part):
    # The coordinate begins on lower left, use width and height together
    # with fontsize (although in points and not mm) to align the shapes.

    # In partkeepr I'm using a hierarchy exactly similar to
    # http://octopart.com/search, the lines here represent a part with
    # the longest (end node) in that hierarchy. You can use  these as a
    # static test to see if the label is correct

    # label.add(shapes.String(5, height-5, "Clock Generators, PLLs, Frequency Synthesizers", fontName="Consolas Bold", fontSize=10))
    # label.add(shapes.String(10, height-15, "MOSFETs", fontName="Consolas Bold", fontSize=10))
    # label.add(shapes.String(10, height-45, "Lattice Semiconductor", fontName="Consolas Bold", fontSize=13))
    # label.add(shapes.String(10, height-60, "LC4064V-75TN100C", fontName="Consolas Bold", fontSize=13))
    # label.add(shapes.Rect(width-50, height-55, 40, 20, strokeWidth=1, fillColor=None))
    # label.add(shapes.String(width-45, height-48, "#4444", fontName="Consolas Bold", fontSize=11))
    # label.add(shapes.Line(10, height-75, width-10,height-75, strokeWidth=1))

    label.add(
        shapes.String(10,
                      height - 15,
                      part["category"],
                      fontName="Consolas Bold",
                      fontSize=10))
    label.add(
        shapes.String(10,
                      height - 45,
                      part["name"],
                      fontName="Consolas Bold",
                      fontSize=13))
    label.add(
        shapes.String(10,
                      height - 60,
                      part["description"],
                      fontName="Consolas Bold",
                      fontSize=10))
    label.add(
        shapes.Line(10, height - 75, width - 10, height - 75, strokeWidth=1))
    label.add(
        shapes.Rect(width - 50,
                    height - 43,
                    40,
                    20,
                    strokeWidth=1,
                    fillColor=None))
    label.add(
        shapes.String(width - 46,
                      height - 36,
                      part["id36"],
                      fontName="Consolas Bold",
                      fontSize=10))
예제 #8
0
 def testLine(self):
     s = shapes.Line(10, 20, 30, 40)
     assert s.getBounds() == (10, 20, 30, 40)
예제 #9
0
 def _draw_line(self, fromX, fromY, toX, toY, color=blue):
     l = shapes.Line(fromX * mm, fromY * mm, toX * mm, toY * mm)
     l.strokeColor = color
     l.strokeWidth = self.strokeWidth
     return l
예제 #10
0
def draw(tree, opts):
    for attr in opts.visible:
        tree.set_render_attr(attr, "visible", 1, 1)

    leaves = tree.leaves()

    maxdepth = max([leaf.depth for leaf in leaves])
    width = opts.unitwidth * maxdepth

    set_terminal_ypos(tree)
    calc_internal_ypos(tree)

    maxleaf = leaves[-1]
    maxy = maxleaf.y
    minleaf = leaves[0]
    miny = minleaf.y

    height = sum([x.get_height() for x in leaves])

    max_labelwidth = max(
        [ pdfmetrics.stringWidth(str(l.tiplabel),
                                 l.render_info["tiplabel"]["font"],
                                 l.calc_tiplabel_font_size()) \
          + (l.render_info["tiplabel"]["x_offset"] * l.baseheight)
          for l in leaves ]
        )

    #unitwidth = (height*((avail_w-max_labelwidth)/avail_h)) / maxdepth

    calc_xpos(tree, maxdepth, opts.unitwidth)
    for i in range(10):
        smooth_xpos(tree)

    ## tree.translate(tree.calc_strokewidth()/2.0,
    ##                tree.calc_tiplabel_font_size()/2.0)

    ## width = (maxdepth * unitwidth) + \
    ##         max_labelwidth + (tree.calc_strokewidth() * 0.5)
    #width *= 1.2

    # if fill: width = avail_w

    if opts.lengths_are_support:

        def func(n):
            if n.length is not None:
                n.support = n.length
                n.length = None
                if not n.children:
                    n.support = None

        tree.foreach(func)

    if opts.thicken is not None:

        def func(n):
            try:
                if n.support >= opts.thicken:
                    n.thicken = 1
            except AttributeError:
                pass

        tree.foreach(func)

    if opts.draw_phylogram:
        if opts.scale:
            brlen_transform = opts.scale
        else:
            brlen_transform = (maxdepth * opts.unitwidth) * \
                              1.0/max([l.calc_length_to_root() for l in leaves])
        scale_branches(tree, brlen_transform)
        if opts.verbose:
            print "%s: brlen_transform=%s" % (opts.outfile, brlen_transform)

        # draw scalebar
        max_length_to_root = max([n.calc_length_to_root() for n in leaves])
        max_x = max([n.x for n in leaves])
        scalebar = shapes.Group()
        font_size = tree.calc_tiplabel_font_size() * 0.9
        ##         scalebar.add(shapes.String(max_x, tree.baseheight-font_size*(1.0/3.0),
        ##                                    " %g" % max_length_to_root,
        ##                                    textAnchor="start", fontSize=font_size))
        scalebar.add(
            shapes.String(tree.x,
                          1,
                          "0.0",
                          textAnchor="middle",
                          fontSize=font_size))
        scalebar.add(
            shapes.Line(tree.x,
                        tree.baseheight,
                        max_x,
                        tree.baseheight,
                        strokeColor=colors.black,
                        strokeWidth=1.0))
        scalebar.add(
            shapes.Line(tree.x,
                        tree.baseheight * 1.2,
                        tree.x,
                        tree.baseheight * 0.8,
                        strokeColor=colors.black,
                        strokeWidth=1.0))
        scalebar.add(
            shapes.Line(max_x,
                        tree.baseheight * 1.2,
                        max_x,
                        tree.baseheight * 0.8,
                        strokeColor=colors.black,
                        strokeWidth=1.0))

        interval = 10**(math.floor(math.log10(float(max_length_to_root))))
        nintervals = int(math.modf(max_length_to_root / interval)[1])
        if nintervals == 1:
            interval = interval / 4.0
        x = interval
        while x < max_length_to_root:
            scalebar.add(
                shapes.Line(x * brlen_transform,
                            tree.baseheight * 1.2,
                            x * brlen_transform,
                            tree.baseheight * 0.8,
                            strokeColor=colors.black,
                            strokeWidth=0.5))
            scalebar.add(
                shapes.String(x * brlen_transform,
                              1,
                              str(x),
                              textAnchor="middle",
                              fontSize=font_size))
            x += interval

        height += tree.baseheight * 3
        tree.translate(0, tree.baseheight * 3)
        tree.drawables.append(scalebar)

    font_size = tree.calc_tiplabel_font_size()
    if opts.title:
        title = shapes.Group()
        title.add(
            shapes.String(0,
                          tree.x + height + font_size * 2,
                          opts.title,
                          fontSize=font_size))
        now = datetime.datetime.now().ctime()
        title.add(
            shapes.String(width + max_labelwidth,
                          tree.x + height + font_size * 2,
                          now,
                          fontSize=font_size,
                          textAnchor="end"))
        tree.drawables.append(title)
        height += font_size * 2

    #print list(tree.iternodes())[0].draw().getBounds()
    ## boxes = [ n.draw().getBounds() for n in tree.iternodes() ]
    ## minx = min([ b[0] for b in boxes ])
    ## maxx = max([ b[2] for b in boxes ])
    ## miny = min([ b[1] for b in boxes ])
    ## maxy = max([ b[3] for b in boxes ])
    ## tree.translate(dx=-minx,dy=-miny)
    ## boxes = [ n.draw().getBounds() for n in tree.iternodes() ]
    ## minx = min([ b[0] for b in boxes ])
    ## maxx = max([ b[2] for b in boxes ])
    ## miny = min([ b[1] for b in boxes ])
    ## maxy = max([ b[3] for b in boxes ])
    ## width = maxx; height = maxy

    drawing = shapes.Drawing(width, height)
    for node in tree.iternodes():
        ## x1, y1, x2, y2 = node.getBounds()
        ## if x2 > width:
        ##     print node.tiplabel, x2
        drawing.add(node.draw())

    x1, y1, x2, y2 = drawing.getBounds()
    drawing.width = x2 - x1
    drawing.height = y2 - y1
    return drawing
예제 #11
0
        def draw_label(label, width, height, obj):
            print obj
            try:
                fillColor = obj['fillColor']
            except KeyError:
                fillColor = 'black'

            kwargs = {
                'fontName': 'Helvetica',
                'fontSize': 10,
                'textAnchor': 'middle',
                'fillColor': fillColor
            }

            if obj['typ'] == 'water restriction':
                kwargs = {
                    'fontName': 'Helvetica',
                    'fontSize': 10,
                    'textAnchor': 'middle',
                    'fillColor': fillColor
                }

                ## Header
                label.add(
                    shapes.String(
                        width * .5, height - 10,
                        "WATER RESTRICTED -- Cage %s" % obj['cage_name'],
                        **kwargs))

                label.add(
                    shapes.String(width * .5, height - 20,
                                  "BRUNO LAB   AAAY8462   UNI: CCR2137",
                                  **kwargs))

                label.add(
                    shapes.Line(width * .02,
                                height - 22,
                                width * .98,
                                height - 22,
                                strokeColor=fillColor))

                ## Each mouse
                xy_l = [(.2, -32), (.5, -32), (.8, -32), (.2, -42), (.5, -42),
                        (.8, -42)]

                for mouse, headplate, xy in zip(obj['mice'], obj['headplates'],
                                                xy_l):
                    label.add(
                        shapes.String(width * xy[0], height + xy[1],
                                      '%s - %s' % (mouse, headplate),
                                      **kwargs))

            elif obj['typ'] == 'cage':
                kwargs = {
                    'fontName': 'Helvetica',
                    'fontSize': 10,
                    'textAnchor': 'start',
                    'fillColor': fillColor
                }

                ## Header
                label.add(
                    shapes.String(width * .5,
                                  height - 10,
                                  "Cage: %s" % obj['cage_name'],
                                  fontName='Helvetica',
                                  fontSize=10,
                                  fillColor=fillColor,
                                  textAnchor='middle'))

                ## Each mouse
                xy_l = [(.1, -20), (.6, -20), (.1, -30), (.6, -30), (.1, -40)]

                for mouse, full_name, genotype, headplate, xy in zip(
                        obj['mice'], obj['full_names'], obj['genotypes'],
                        obj['headplates'], xy_l):

                    label.add(
                        shapes.String(
                            width * xy[0], height + xy[1],
                            '%s - %s - %s' % (mouse, headplate, full_name),
                            **kwargs))