Exemplo n.º 1
0
    def render(self, svg, x, y):
        stroke_width = self.conf.connection.thickness

        shape_builder = ShapeBuilder()
        connect_y = y + self.connect_y
        bottom_y = y + self.content.height + 10

        tmp = 0

        if isinstance(self.content.children[0], QuantityAbove):
            t = self.content.height - self.content.children[0].content.height
            tmp = t / 2
        elif isinstance(self.content.children[0], Sequence):
            if isinstance(self.content.children[0].children[0], QuantityAbove):
                t = self.content.height - self.content.children[0].children[0].content.height
                tmp = t / 2

        self.content.render(svg, x + 20, y - tmp)

        path_data = "m {0},{1} c 10,0 10,{3} {2},{3}".format(x, connect_y, 20, bottom_y - connect_y)
        svg.addElement(path(path_data, stroke = "black", fill = "none", stroke_width=stroke_width))
        path_data = "m {0},{1} c 10,0 10,{3} {2},{3}".format(x + 20 + self.content.width, bottom_y, 20, connect_y - bottom_y)
        svg.addElement(path(path_data, stroke = "black", fill = "none", stroke_width=stroke_width))

        Line(10, 0, self.conf, arrow=True).render(svg, x + 20 + self.content.width / 2, bottom_y)
        l = shape_builder.createLine(x + 20, bottom_y, x + 20 + self.content.width, bottom_y, strokewidth=stroke_width)
        svg.addElement(l)
        l = shape_builder.createLine(x, connect_y, x + 20, connect_y, strokewidth=stroke_width)
        svg.addElement(l)
        l = shape_builder.createLine(x + 20 + self.content.width, connect_y, x + 20 + self.content.width + 20, connect_y, strokewidth=stroke_width)
        svg.addElement(l)
Exemplo n.º 2
0
Arquivo: svg.py Projeto: ncqgm/gnumed
 def _calc_clip_path(self, rect):
     rx, ry, width, height = rect
     if rx < 0:
         width += rx
         rx = 0
     pathId = "path%d_%d_%d" % (rx, ry, width)
     p = path(pathData="M %d %d H %d V %d H %d" %
              (rx, ry + height, rx + width, ry, rx))
     return pathId, p
Exemplo n.º 3
0
 def _calc_clip_path(self, rect):
     rx, ry, width, height = rect
     if rx < 0:
         width += rx
         rx = 0
     pathId = "path%d_%d_%d" % (rx, ry, width)
     p = path(pathData="M %d %d H %d V %d H %d" %
              (rx, ry + height, rx + width, ry, rx))
     return pathId, p
Exemplo n.º 4
0
    def render(self, svg, x, y):
        self.content.render(svg, x + 20, y + 20)

        stroke_width = self.conf.connection.thickness

        connect_y = y + self.connect_y
        above_y = connect_y - self.content.height_above - 10
        path_data = "m {0},{1} c -10,0 -10,{3} 0,{3}".format(x + 20, connect_y, 20, above_y - connect_y)
        svg.addElement(path(path_data, stroke = "black", fill = "none", stroke_width=stroke_width))
        path_data = "m {0},{1} c 10,0 10,{3} 0,{3}".format(x + 20 + self.content.width, above_y, 20, connect_y - above_y)
        svg.addElement(path(path_data, stroke = "black", fill = "none", stroke_width=stroke_width))
        shape_builder = ShapeBuilder()
        Line(0, 0, self.conf, arrow=True).render(svg, x + 25 + self.content.width / 2, above_y)
        l = shape_builder.createLine(x + 20, above_y, x + 20 + self.content.width, above_y, strokewidth=stroke_width)
        svg.addElement(l)
        l = shape_builder.createLine(x, connect_y, x + 20, connect_y, strokewidth=stroke_width)
        svg.addElement(l)
        l = shape_builder.createLine(x + 20 + self.content.width, connect_y, x + 20 + self.content.width + 20, connect_y, strokewidth=stroke_width)
        svg.addElement(l)
Exemplo n.º 5
0
    def render(self, svg, x, y):
        stroke_width = self.conf.connection.thickness
        shape_builder = ShapeBuilder()
        start_x = x
        start_y = y + self.connect_y
        end_x = x + self.content_width + 20

        x += 20
        for child in self.children:
            child.render(svg, x, y)

            l = shape_builder.createLine(x + child.width, y + child.connect_y, x + self.content_width, y + child.connect_y, strokewidth=stroke_width)
            svg.addElement(l)
            path_data = "m {0},{1} c {2},0 0,{3} {2},{3}".format(start_x, start_y, 20, y + child.connect_y - start_y)
            svg.addElement(path(path_data, stroke = "black", fill="none", stroke_width=stroke_width))
            path_data = "m {0},{1} c {2},0 0,{3} {2},{3}".format(end_x, y + child.connect_y, 20, start_y - (y + child.connect_y))
            svg.addElement(path(path_data, stroke = "black", fill="none", stroke_width=stroke_width))

            y += child.height + self.padding
Exemplo n.º 6
0
    def __init__(self, name='right-arrow', width=5):
        self.width = width

        BaseElement.__init__(self, 'marker')
        self._attributes['id'] = name
        self._attributes['viewBox'] = '0 0 20 20'
        self._attributes['refX'] = '0'
        self._attributes['refY'] = '10'
        self._attributes['orient'] = 'auto'
        self._attributes['markerUnits'] = 'strokeWidth'
        self._attributes['markerWidth'] = width
        self._attributes['markerHeight'] = 2 * width
        self.addElement(path("M 0 0 L 20 10 L 0 20 z"))
Exemplo n.º 7
0
 def draw_content(self, elem):
     # Create a new group
     grp = g()
     grp.setAttribute('id', 'scalebar')
     # Find the amount of available width
     bbox = self.map_container.bbox
     step_length = (float(self.step) * self.factor)
     c = [[bbox[0], 0], [bbox[0] + step_length, 0]]
     px = self.map_container.geo_to_local_coords(c)
     step_px = abs(px[1][0] - px[0][0])
     nsteps = int(floor(float(self.width) / step_px))
     # Draw the horizontal line
     l = path(pathData="M %f %f L %f %f" % (
         mm_to_px(self.x), mm_to_px(self.y + self.height),
         mm_to_px(self.x + nsteps*step_px), mm_to_px(self.y + self.height)
     ), style=StyleBuilder({'stroke': 'black', 'stroke-width': 0.3}).getStyle())
     grp.addElement(l)
     # Draw the vertical lines and write the text
     # textsize = int(re.findall('([0-9]+)',
     #             self.style.style_dict.get('font-size', "12")
     #         )[0])
     for i in range(nsteps+1):
         l = path(pathData="M %f %f L %f %f" % (
             mm_to_px(self.x + i*step_px), mm_to_px(self.y + self.height),
             mm_to_px(self.x + i*step_px), mm_to_px(self.y + self.height - 3)
         ), style=StyleBuilder({'stroke': 'black', 'stroke-width': 0.3}).getStyle())
         grp.addElement(l)
         content = str(i*self.step)
         if i == nsteps: content += ' ' + self.unit
         t = text(
             content=content, 
             x=mm_to_px(self.x + i*step_px), y=mm_to_px(self.y + self.height - 5)
         )
         t.set_style(self.style.getStyle())
         grp.addElement(t)
     elem.addElement(grp)
Exemplo n.º 8
0
def arc_curve(x,y, x2,y2, curve_angle=45, width=10, color=RED_3,
              cap_def=None):
    """clockwise curve.
    Note that you need to create cap_def"""
    p = path(pathData='M {0},{1}'.format(x,y))
    # M is move absolute
    angle = slope_angle(x,y, x2,y2)
    mid_x, mid_y = middle(x,y, x2,y2)
    rx = ry = distance(x,y,x2,y2)
    #p.appendCubicShorthandCurveToPath(x2,y2)
    p.appendArcToPath(rx, ry, x2, y2, relative=False)
    style = 'fill:{0};stroke-width:{1};stroke:{2};stroke-linecap:round'.format(ALPHA, width, color)
    if cap_def:
        p.set_marker_end('url(#{0})'.format(cap_def))
        #style += ';marker-end;url(#{0})'.format(cap_def)
    p.set_style(style)
    return [p]
Exemplo n.º 9
0
    def chair(self, id_attr, color_1, color_2):
        head = ShapeBuilder().createCircle(30, 25, 20, stroke='black', strokewidth=5.0, fill=color_1)
        head.set_class('head')
        body = path(pathData="M 19.264266,38.267870 C 12.892238,41.659428 9.0221978,48.396703 6.6126745,55.405840 L 51.476471,55.405840 C 49.270169,48.545436 45.682644,41.911786 39.811885,38.267870 C 33.901416,38.010889 26.459633,38.267870 19.264266,38.267870 z ")
        body.set_style('stroke-width:5.0;stroke:black;fill:%s;' % color_2)
        body.set_class('body')

        th = TransformBuilder()
        th.setScaling('0.8', '0.8')

        group = g()
        group.addElement(body)
        group.addElement(head)
        group.set_id(id_attr)
        group.set_transform(th.getTransform())

        return group
Exemplo n.º 10
0
def arc_curve(x,
              y,
              x2,
              y2,
              curve_angle=45,
              width=10,
              color=RED_3,
              cap_def=None):
    """clockwise curve.
    Note that you need to create cap_def"""
    p = path(pathData='M {0},{1}'.format(x, y))
    # M is move absolute
    angle = slope_angle(x, y, x2, y2)
    mid_x, mid_y = middle(x, y, x2, y2)
    rx = ry = distance(x, y, x2, y2)
    #p.appendCubicShorthandCurveToPath(x2,y2)
    p.appendArcToPath(rx, ry, x2, y2, relative=False)
    style = 'fill:{0};stroke-width:{1};stroke:{2};stroke-linecap:round'.format(
        ALPHA, width, color)
    if cap_def:
        p.set_marker_end('url(#{0})'.format(cap_def))
        #style += ';marker-end;url(#{0})'.format(cap_def)
    p.set_style(style)
    return [p]
def get_svgdoc(paths,
               rxn_nodes,
               labels,
               font_size,
               font_family,
               height,
               width,
               easy_edit=True,
               vonda_compatible=False):
    """ Assemble svg document (easy_edit version, easily editable in inkscape)"""

    # create svg document
    doc = svg()
    doc.set_height(height)
    doc.set_width(width)
    # add marker defenitions
    defs = TextContent("""
	<defs>
	  <marker id="product" markerWidth="6" markerHeight="6" refX="0.75" refY="2.5" orient="auto" markerUnits="strokeWidth">
		<path d="M1,1 Q3,2.5 1,4 L4,2.5 z " stroke-linejoin="round" stroke-linecap="round" stroke="#000" stroke-width="0.5" fill="#000"/>
	  </marker>
	  <marker id="substrate" markerWidth="6" markerHeight="6" refX="0.75" refY="2.5" orient="auto" markerUnits="strokeWidth">
		<circle cx="2.6" cy="2.5" r="1.1" fill="#000"/>
	  </marker>
	</defs>
	""")
    doc.addElement(defs)

    # add paths
    for p in paths:
        pth = path(paths[p]['d'])
        if vonda_compatible:
            pth.set_id(str(p[0]))
        elif easy_edit:
            pth.set_id('path_{}{}'.format(*p))
        else:
            pth.set_id(str(p))
        pth.set_style(paths[p]['style'])
        doc.addElement(pth)

    # add labels
    for n in labels:
        x = labels[n]['x']
        y = labels[n]['y']
        txt = text(labels[n]['text'], x, y)
        txt.set_id(str(n))
        txt.set_font_family(font_family)
        txt.set_font_size(font_size)
        doc.addElement(txt)

    # add reaction nodes
    for c in rxn_nodes:
        x = rxn_nodes[c]['x']
        y = rxn_nodes[c]['y']
        crc = circle(x, y, 5)
        crc.set_id(c)
        crc.set_style('fill:#999999')
        doc.addElement(crc)

        # add reaction value placeholders
        if easy_edit:
            txt = text('-0.0e+00', x + 10, y + 4)
            txt.set_id('rval_' + c)
            txt.set_font_family(font_family)
            txt.set_font_size(8)
            doc.addElement(txt)

    return doc