Beispiel #1
0
 def svg(self) -> str:
     shape = _person(self.x + self.width / 4, self.y, self.width / 2, self.height, self.svg_attrs)
     y0 = self.y - 32  # FIXME
     text_attrs = SvgAttrs({
         'text.text-anchor': 'middle',
         **self.svg_attrs
     })
     text = self.text.svg(self.cx, y0, text_attrs)
     return '<g {style}>{shape}{text}</g>'.format(style=_style(self.svg_attrs), shape=shape, text=text)
Beispiel #2
0
 def svg(self) -> str:
     tx, ty = self.cx, self.cy
     x1, y1, x2, y2 = self.x1, self.y1, self.x2, self.y2
     shape = _arrow(x1, y1, x2, y2, self.svg_attrs)
     # text_kwargs = {'text-anchor': 'middle', **self.kwargs}
     text_kwargs = self.svg_attrs
     v = _Vector2d(x1, y1, x2, y2).normalize()
     if v.dy > 0:
         v = v.rotate(-90).multiple(20)
     else:
         v = v.rotate(90).multiple(20)
     text = self.text.svg(tx + v.dx, ty + v.dy, text_kwargs)
     return '<g {style}>{shape}{text}</g>'.format(style=_style(self.svg_attrs), shape=shape, text=text)
Beispiel #3
0
def _rect(cx, cy, width, height, kwargs):
    x = cx - (width // 2)
    y = cy - (height // 2)
    style = _style({
        'fill': 'none',
        'stroke': 'black',
        **kwargs
    })
    return """
    <rect
    x="{x}"
    y="{y}"
    width="{width}"
    height="{height}"
    {style}
    />
    """.format(x=x, y=y, width=width, height=height, style=style)
Beispiel #4
0
def _person(x, y, width, height, kwargs):
    cx = x + width / 2
    xx = x + width
    yy = y + height
    cr = height // 5
    rx = cr
    ry = cr
    style = _style({
        'fill': 'none',
        'stroke': 'black',
        **kwargs
    })
    return """
    <path
    d="
    M {cxr},{yum}
    C {cxr},{yud}
      {cxl},{yud}
      {cxl},{yum}
    M {cxr},{yum}
    C {cxr},{yuu}
      {cxl},{yuu}
      {cxl},{yum}
    M{cx},{y1}
    L{cx},{y3}
    M{xl},{y2}
    L{xr},{y2}
    M{cx},{y3}
    L{xl},{yy}
    M{cx},{y3}
    L{xr},{yy}
    "
    {style}
    />
    """.format(
        cxr=cx - cr, cxl=cx + cr,
        yuu=y - cr / 3, yum=y + cr, yud=y + 2 * cr + cr / 3,  # FIXME
        xl=x, y0=y,
        xr=xx, yy=yy,
        y1=y + cr * 2, y2=y + cr * 3, y3=cr * 4 + y,
        cx=cx, cy=y + cr,
        rx=rx, ry=ry,
        xa=(cx - rx), xb=(cx + rx),
        style=style
    )
Beispiel #5
0
def _cylinder(cx, cy, width, height, kwargs):
    curve = 8 + (width * 1.2) // 20  # FIXME
    xl = cx - (width // 2)
    xr = cx + (width // 2)
    yum = cy - (height // 2)
    yuu = yum - curve
    yud = yum + curve
    ydm = cy + (height // 2)
    ydd = ydm + curve
    style = _style({
        'fill': 'none',
        'stroke': 'black',
        **kwargs
    })
    return """
    <path
    d="
    M {xr},{yum}
    C {xr},{yud}
      {xl},{yud}
      {xl},{yum}
    M {xr},{yum}
    C {xr},{yuu}
      {xl},{yuu}
      {xl},{yum}
    M {xr},{yum}
    L {xr},{ydm}
    C {xr},{ydd}
      {xl},{ydd}
      {xl},{ydm}
    L {xl},{yum}
    "
    {style}
    />
    """.format(
        xl=xl,
        xr=xr,
        yuu=yuu,
        yum=yum,
        yud=yud,
        ydm=ydm,
        ydd=ydd,
        style=style
    )
Beispiel #6
0
def _arrow(x1, y1, x2, y2, kwargs):
    def rotate_base(deg, pump):
        v1 = _Vector2d(x1, y1, x2, y2).normalize().multiple(pump).rotate(deg).negate()
        return v1.move(x2, y2)

    va = rotate_base(27, 27)
    vb = rotate_base(-27, 27)
    style = _style({
        'stroke': 'black',
        'stroke-width': '3',
        **kwargs
    })
    return """
    <path d="
    M {x1} {y1}
    L {x2} {y2}
    M {xa} {ya}
    L {x2} {y2}
    M {xb} {yb}
    L {x2} {y2}
    " {style}></path>
    """.format(x1=x1, y1=y1, x2=x2, y2=y2, xa=va.x2, ya=va.y2, xb=vb.x2, yb=vb.y2, style=style)
Beispiel #7
0
 def svg(self) -> str:
     x, y, cx, cy, w, h = self.x, self.y, self.cx, self.cy, self.width, self.height
     shape = _rect(cx, cy, w, h, self.svg_attrs)
     text = self.text.svg(x + self.padding.left, y + self.padding.top, self.svg_attrs)
     return '<g {style}>{shape}{text}</g>'.format(style=_style(self.svg_attrs), shape=shape, text=text)