Пример #1
0
def main(path):

    df = pd.read_csv('{}/wire_locations.csv'.format(path), header=0)
    df *= 1000  # converting to mm
    
    wire_locations = np.array(df['z'])   
    wire_radius = df.iloc[0, -1]  # wire radius converted to mm 
    former_radius = df.iloc[0, 0] + wire_radius  # radius of coil former
    inner_radius = df.iloc[0, -3]  # center of inner wire position
    
    drawing = draw.Drawing(2.1*former_radius, 2.1*wire_locations[-1], origin='center')

    #  draws wire grooves
    wire_groups = np.split(wire_locations, np.where(np.diff(wire_locations) > 2.5*wire_radius)[0]+1)  # finds bundled wire groups
    for group in wire_groups:
        groove(drawing, group, former_radius, inner_radius, wire_radius)

    drawing.setRenderSize(w=5000)
    drawing.saveSvg('{}/grooves.svg'.format(path))

    #  draws wires on previous drawing
    for wire in wire_locations:
        for turn in df.iloc[0, :-1]:
            drawing.append(draw.Circle(turn, wire, wire_radius,
                           fill='none', stroke_width=0.01, stroke='black'))

    drawing.setRenderSize(w=5000)
    drawing.saveSvg('{}/grooves_and_wires.svg'.format(path))
def draw_via_pads(d, via_list, factor):
    for via_name, via in via_list:
        via_x = float(via.x) * factor
        via_y = float(via.y) * factor

        via_length = float(via.length) * factor
        via_width = float(via.width) * factor

        via_drill = float(via.drill) * factor

        rotation = str.format("translate({1}, {2}) rotate({0}) ",
                              str(-via.rotation), str(via_x), str(-via_y))

        color = "lightgreen"
        d.append(
            draw.Rectangle(-via_width / 2,
                           -via_drill / 2 - 0.25 * factor,
                           via_width,
                           via_length,
                           fill=color,
                           stroke_width=1,
                           stroke="black",
                           opacity="0.7",
                           transform=rotation,
                           rx=via_width / 2,
                           ry=via_width / 2))
        d.append(
            draw.Circle(via_x,
                        via_y,
                        via_drill / 2,
                        fill="orange",
                        stroke_width=1,
                        stroke="black",
                        opacity="0.7"))
Пример #3
0
def render_circle(circle, model, target, style=None):
    style = style_join(style or {}, circle.style)
    assert len(style) > 0
    x = N(model[circle.x])
    y = M(model[circle.y], target)
    r = N(model[circle.radius])
    target.append(draw.Circle(x, y, r, **style))
Пример #4
0
def render(circles, data, size, highlight=[], output='circles.svg'):
    d = draw.Drawing(size, size, origin='center')
    d.append(draw.Rectangle(
        -size / 2,
        -size / 2,
        size,
        size,
        fill='white',
    ))

    for i, item in enumerate(zip(circles, data)):
        circle = item[0]

        if item[1][1] > 0:
            color = '#3b3b3b'
        else:
            if item[1][0] and item[1][0] in highlight:
                color = '#ffff00'
            else:
                color = '#84ab3f'

        d.append(
            draw.Circle(
                *circle,
                fill=color,
                amount=item[1][1],
                person=html.escape(item[1][0]),
                target=html.escape(item[1][2]) if len(item[1]) >= 4 else '',
                description=html.escape(item[1][3])
                if len(item[1]) >= 4 else '',
            ))

    d.saveSvg(output)
Пример #5
0
 def drawText(self):
     oldstartPoint = 0
     startX = 0
     length = 0
     if self.xColumn.columnType == enums.ColumnDataType.Measures.value:
         for cell, cell2, i in zip(self.LabelColumn.cells,
                                   self.xColumn.cells,
                                   range(0, len(self.LabelColumn.cells))):
             if (type(cell2.value) != str):
                 if (i != 0):
                     length += 1
                     startX += oldstartPoint
                     height = self.getLength(double(cell2.value))
                     oldstartPoint = height
                     text = str(cell.value) + ": " + str(
                         self.percentageOfValue(double(
                             cell2.value)))[0:4] + "%"
                     self.d.append(
                         draw.Circle(self.widthView - 300,
                                     length * 80 + 50,
                                     20,
                                     fill=self.colorList[i - 1],
                                     fill_opacity=0.5,
                                     stroke_width=0))
                     self.d.append(
                         draw.Text(text=str(text),
                                   fontSize=30,
                                   x=self.widthView - 250,
                                   y=length * 80 + 50,
                                   Class=str(self.Index),
                                   id=self.Index))
                     self.metaData.append(text)
                     self.Index += 1
Пример #6
0
 def draw_harbours(self, harbour_list):
     for col, row, adj_tiles, harbour_type in harbour_list:
         c_x, c_y = self._get_hexagon_coords(col, row)
         t = draw.Text(harbour_type,
                       42,
                       c_x,
                       -c_y,
                       center=True,
                       stroke="lime")
         c = draw.Circle(c_x, -c_y, r=32, fill="white", stroke="black")
         n = set(
             chain.from_iterable([(a, b) for _, _, type, a, b in adj_tiles
                                  if not type == 'harbour']))
         # 0 = 90° theta, 1= 30*,  2 = -30°, 3 = - 90°
         for corner in n:
             theta = 90 - corner * 60
             e_x = int(self.HALF_TILE *
                       np.math.cos(np.math.radians(theta)) + c_x)
             e_y = int(self.HALF_TILE *
                       np.math.sin(np.math.radians(theta)) + c_y)
             line = draw.Line(c_x, -c_y, e_x, -e_y, **{
                 "stroke": "red",
                 "stroke-width": "5px"
             })
             self.drawing.extend([line])
         self.drawing.extend([c, t])
Пример #7
0
    def generateDot(self):
        #determine angle
        angle = 2 * np.pi * rand.random()

        #determine the distance from the center
        #distance must place the whole dot within the canvas
        #should have greater likelihood to place near the center as controlled by some kind of parameter
        multiplier = abs(rand.gauss(0, 0.2))
        if multiplier > 1:
            multiplier = 1
        magnitude = multiplier * ((self.canvasWidth / 2) - self.dotRadius -
                                  (self.boxThickness / 2))

        #convert to cartesian
        (cx, cy) = pol2cart(magnitude, angle)

        #adjust bounds
        self.adjustBounds(cx, cy)

        #create circle
        return draw.Circle(cx,
                           cy,
                           self.dotRadius,
                           fill=self.dotColor,
                           stroke_width=0)
Пример #8
0
    def drawCircle(self, d, x, y, r, fill="f", pen=5):
        pen = int(pen)
        if fill == "f":
            kwargs = {"fill_opacity": 0}
        elif fill == "F":
            kwargs = {"fill": self.STROKE_COLOR}
        else:
            kwargs = {"fill_opacity": 0}

        x = int(x)
        y = int(y)
        r = int(r)

        d.append(
            draw.Circle(x,
                        y,
                        r,
                        stroke_width=pen,
                        stroke=self.STROKE_COLOR,
                        **kwargs))

        v_list = [(x, y + r), (x, y - r), (x + r, y), (x - r, y)]

        self.update_svg_boundary(v_list)

        return d
Пример #9
0
    def DrawCells(self,
                  url,
                  stroke="red",
                  stroke_width=1,
                  radius=3,
                  inter_distance=2,
                  fill="transparent",
                  draw_h=True,
                  h_line_width=1,
                  draw_out=False):

        spacing = self.width / (self.n_leaves + 1)
        width = self.width
        height = self.height
        d = self.d

        #d.append(draw.Circle(150, 100, radius, stroke_width=2, stroke='white', stroke_dasharray="5,5", fill="transparent"))
        #d.append(draw.Ellipse(150, 100, 80, 60, stroke_width=3, stroke='white', fill ="transparent"))

        for n in self.tree.traverse():
            # Inner tree, vertical lines
            x_0, y_0, y_1 = n.x_coor, n.y_coor, self._y_scaling(n.dist)

            n_cells = int(y_1 / ((radius * 2) + inter_distance))

            for i in range(n_cells):
                d.append(
                    draw.Circle(x_0,
                                y_0 + (inter_distance * i) + (i * radius * 2) +
                                inter_distance,
                                radius,
                                stroke_width=stroke_width,
                                stroke=stroke,
                                fill=fill))
                if draw_out:
                    if i == 0:
                        continue
                    p = draw.Path(stroke_width=stroke_width,
                                  stroke=stroke,
                                  fill="none")
                    p.M(
                        x_0, y_0 + (inter_distance * i) + (i * radius * 2) +
                        inter_distance).l(-radius * 3, -radius * 3)
                    d.append(p)

            if draw_h:
                if not n.is_leaf():
                    c1, c2 = n.get_children()
                    # Horizontal lines
                    # Inner Tree
                    p = draw.Path(stroke=stroke,
                                  stroke_width=h_line_width,
                                  fill='none')
                    p.M(c1.x_coor, n.y_coor).L(c2.x_coor, n.y_coor)
                    d.append(p)

        d.setRenderSize(h=self.height)
        d.saveSvg(url)
        return (d)
Пример #10
0
 def _draw_number(self, x, y, val):
     text = draw.Text(str(val), self.FONT_SIZE, x, -(y), center=True)
     circle = draw.Circle(x,
                          -(y + 4),
                          r=self.FONT_SIZE * 0.75,
                          fill="beige",
                          stroke="black")
     return [circle, text]
Пример #11
0
    def __init__(self):
        """반지름이 1인 원을 생성하고, group하나를 만든다."""
        self.image_size = 500
        self.d = draw.Drawing(2, 2, origin='center')  # viewbox(-1, -1, 2, 2)
        self.d.setRenderSize(self.image_size)
        self.d.append(draw.Circle(0, 0, 1, fill='orange'))

        group = draw.Group()
        self.d.append(group)
Пример #12
0
def draw_number(drawing,
                viewport,
                number,
                number_offset,
                number_total,
                recursion_depth=0):
    if number == 1:
        drawing.append(
            draw.Circle(viewport.cx,
                        viewport.cy,
                        viewport.scale,
                        fill=col(number_offset / number_total),
                        stroke_width=0.25,
                        stroke='black'))
        return

    n = largest_prime_factor(number)

    alpha = tau / n

    # calculate the major circle radius
    R = viewport.scale

    if recursion_depth > 0:
        R *= 0.95  # add some padding between intermediate levels

    # calculate the minor circle radius
    r = R - R / (
        1 + math.sin(alpha / 2)
    )  # small circle radius needed to form a ring of circles inscribed in R
    d = R - r

    # special case for repeated 2-factors to eliminate excessive padding
    if n == 2 and number > 2:
        r *= 1.25

    #if n == number: # optional: shade the inside of the smallest prime factor
    #    e = math.cos(alpha/2) * d
    #    drawing.append(draw.Circle(viewport.cx, viewport.cy, e, fill = '#eee'))

    for i in range(n):
        angle = (viewport.angle + i / n * tau) % tau
        v = Viewport()
        # rotate the viewport
        v.cx, v.cy = viewport.cx + d * math.cos(
            angle), viewport.cy + d * math.sin(angle)
        v.scale = r
        v.angle = angle
        if n == 2:
            # special case 90° rotation to make repeated factors 2 tile in both directions (can probably be generalized)
            v.angle += tau / 4

        # recursion – cycle colors except for the last grouping (unless it's a prime)
        draw_number(
            drawing, v, number // n, number_offset +
            (recursion_depth == 0 or n != number) * i * number // n,
            number_total, recursion_depth + 1)
def draw_frame(t):
    d = draw.Drawing(2, 5.00, origin=(-1, -1.05))
    d.setRenderSize(h=150)
    d.append(draw.Rectangle(-4, -4, 8, 10, fill='white'))
    d.append(draw.Rectangle(-1, -1.00, 8, 1.05, fill='brown'))
    t = (t + 1) % 2 - 1
    y = 4 - t**2 * 4
    d.append(draw.Circle(0, y, 1, fill='lime'))
    return d
Пример #14
0
 def draw_ball(self, p, radius):
     c = draw.Circle(
         p.x,
         p.y,
         radius,
         fill='pink',
         fill_opacity=.25,
         stroke_width=.5,
         stroke='black',
     )
     context.append(c)
Пример #15
0
 def drawCircle(self):
     colorList = self.generateRandomColorsList(len(self.firstColumn.cells))
     xCenter = self.xCenter
     yCenter = self.yCenter
     r = self.r
     oldEndangle = 0
     endAngle = 0
     length = 0
     for cell, cell2, i in zip(self.firstColumn.cells,
                               self.secondColumn.cells,
                               range(0, len(self.firstColumn.cells))):
         if (type(cell2.value) != str):
             if (i != 0):
                 length += 1
                 startangle = oldEndangle
                 endAngle += self.getAngle(double(cell2.value))
                 oldEndangle = endAngle
                 radiansconversion = np.pi / 180.
                 xstartpoint = xCenter + r * np.cos(
                     startangle * radiansconversion)
                 ystartpoint = yCenter - r * np.sin(
                     startangle * radiansconversion)
                 xendpoint = xCenter + r * np.cos(
                     endAngle * radiansconversion)
                 yendpoint = yCenter - r * np.sin(
                     endAngle * radiansconversion)
                 large_arc_flag = 0
                 if endAngle - startangle > 180: large_arc_flag = 1
                 M = ("M %s %s" % (xstartpoint, ystartpoint))
                 a = ("A %s %s 0 %s 0 %s %s" %
                      (r, r, large_arc_flag, xendpoint, yendpoint))
                 L = ("L %s %s" % (xCenter, yCenter))
                 p = draw.Path(stroke_width=10,
                               stroke="white",
                               fill=colorList[i - 1],
                               fill_opacity=0.5,
                               d=M + a + L)
                 p.Z()
                 self.d.append(p)
                 text = str(cell.value) + ": " + str(
                     self.percentageOfValue(double(cell2.value)))[0:4] + "%"
                 self.d.append(
                     draw.Circle(self.widthView + 100,
                                 length * 80,
                                 20,
                                 fill=colorList[i - 1],
                                 fill_opacity=0.5,
                                 stroke_width=0))
                 self.d.append(
                     draw.Text(text=str(text),
                               fontSize=30,
                               x=self.widthView + 150,
                               y=length * 80 - 10))
Пример #16
0
    def drawColmunsColorList(self, colors: List[str]):
        if((self.widthView / (len(self.dataSourceTableWithoutXcolumn.columns) + 1)) / 15 <(self.heightView / (len(self.dataSourceTableWithoutXcolumn.columns) + 1)) / 15):
          fontSize = (self.widthView / (len(self.dataSourceTableWithoutXcolumn.columns) + 1)) / 15
        else:
          fontSize = (self.heightView / (len(self.dataSourceTableWithoutXcolumn.columns) + 1)) / 15
        add = self.widthView / 50
        num = "X:" + str(self.xColumn.name)
        if (len(str(num)) > 10):
            num = num[0:8] + "..."
        self.metaData.append("X:" + str(self.xColumn.name))
        self.Index += 1
        c = draw.Circle(add, self.heightOfXLabels / 4 +(fontSize / 2), fontSize / 2, fill="black", stroke_width=0,stroke='black',fill_opacity=1)
        t =draw.Text(text=str(num), fontSize=fontSize, x=add + (fontSize * 2),y=self.heightOfXLabels / 4 + (fontSize / 3),style="font-size : " + str(fontSize),Class=str(self.Index),id=str(self.Index))
        if self.animation:
          t.appendAnim(draw.Animate('x', str((self.Index / 20) ) + 's', from_or_values=0, to=add + (fontSize * 2),repeatCount='1'))
          c.appendAnim(draw.Animate('cx', str((self.Index / 20) - 0.1) + 's', from_or_values=0, to=add + (fontSize * 2),repeatCount='1'))
        self.d.append(t)
        self.d.append(c)
        add += self.widthView / (len(self.dataSourceTableWithoutXcolumn.columns) + 3)


        columnCounter = 0
        for column in self.dataSourceTableWithoutXcolumn.columns:
          if column !=self.xColumn:
            if column.columnType == enums.ColumnDataType.Measures.value:
                num = column.name
                if (len(str(num)) > 10):
                    num = num[0:8] + "..."
                self.metaData.append(num)
                c = draw.Circle(add, self.heightOfXLabels / 4 + (fontSize / 2), fontSize / 2, fill=colors[columnCounter],stroke_width=0,stroke='black')
                t = draw.Text(text=str(num), fontSize=fontSize, x=add + (fontSize * 2),y=self.heightOfXLabels / 4 + (fontSize / 3),style="font-size : " +str(fontSize),Class=str(self.Index),id=str(self.Index))
                if self.animation:
                  t.appendAnim(draw.Animate('x', str((self.Index / 20) ) + 's', from_or_values=0, to=add + (fontSize * 2),repeatCount='1'))
                  c.appendAnim(draw.Animate('cx', str((self.Index / 20) - 0.1) + 's', from_or_values=0, to=add + (fontSize * 2),repeatCount='1'))
                  c.appendAnim(draw.Animate('r', '3.2s', from_or_values=fontSize, to=abs(fontSize / 2), repeatCount='1'))
                self.d.append(t)
                self.d.append(c)
                add += self.widthView / (len(self.dataSourceTableWithoutXcolumn.columns) + 3)
                self.Index += 1
          columnCounter += 1
def draw_legend(d):
    d.append(draw.Circle(250, 320, 20, fill="yellow", stroke="orange"))
    d.append(
        draw.Line(0,
                  0,
                  0,
                  200,
                  stroke_width=2,
                  stroke="red",
                  fill="yellow",
                  transform="translate(250, -320) rotate(-80)"))

    d.append(draw.Circle(550, 320, 20, fill="yellow", stroke="orange"))
    d.append(
        draw.Line(0,
                  -100,
                  0,
                  100,
                  stroke_width=2,
                  stroke="green",
                  fill="yellow",
                  transform="translate(550, -320) rotate(-30)"))
def draw_component_positions(filename, drawing, bottom_layer=False):
    file = open(filename, 'r')
    offset_x, offset_y, *temp = file.readline().replace(',', '.').split('|')
    file.readline()  # Skip empty line
    for entry in file:
        name, tele_id, x, y, rotation = entry.replace(',', '.').rstrip().split('|')
        x = float(x) + float(offset_x)
        y = float(y) + float(offset_y)
        x = x * factor
        y = y * factor

        if bottom_layer:
            y = output_image_height - y
            rotation = int(rotation) + 180

        drawing.append(
                draw.Circle(x, y, 0.3 * factor, fill="yellow"))
        rotation_transform = str.format(
                "translate({1}, {2}) rotate({0}) ", str(-int(rotation)), str(x), str(-y))

        drawing.append(
                draw.Line(0, 0, 0, 1 * factor, stroke="red", stroke_width=2, transform=rotation_transform))

        if name in part_package:
            package = part_package[name]
            if package in first_pads:
                pad_position = first_pads[package]
                pad_x = pad_position[0] * factor
                pad_y = pad_position[1] * factor

                angle_rad = radians(int(rotation))
                rot_x = pad_x * math.cos(angle_rad) - pad_y * math.sin(angle_rad)
                rot_y = pad_x * math.sin(angle_rad) + pad_y * math.cos(angle_rad)

                rotation_transform = str.format(
                        "translate({1}, {2}) rotate({0})", str(-int(rotation)), str(x), str(-y))
                drawing.append(draw.Circle(pad_x, pad_y, 0.2 * factor, fill="blue", transform=rotation_transform))
                drawing.append(
                        draw.Text(name, 1 * factor, x - rot_x, y + rot_y, stroke="#444444", fill="lightgreen"))
Пример #19
0
 def drawPoint(self):
   i =1
   for x,y,data in zip(self.lngColumn.cells[1:],self.latColumn.cells[1:],self.xColumn.cells[1:]):
     text = self.xColumn.name + ":" + str(data.value)
     for column in self.dataSourceTableWithoutXcolumn.columns:
       text += '  '+'<br/>' +column.name + ":" + str(column.cells[i].value)
     c = draw.Circle(self.convertX(x.value)+self.zeroX,self.convertY(y.value)+self.zeroY, 0.9 , fill="green", stroke_width=0, stroke='green',Class=self.Index,fill_opacity=1, transform="translate(-163.3,-120.8) ")
     if self.animation:
       c.appendAnim(draw.Animate('r', '3.2s', from_or_values=15, to=abs(1), repeatCount='1'))
       c.appendAnim(draw.Animate('cx', '2s', from_or_values=0, to=abs(self.convertX(x.value)+self.zeroX), repeatCount='1'))
     self.d.append(c)
     self.metaData.append(text)
     self.Index += 1
     i += 1
Пример #20
0
    def drawCircle(self):

        xcenter = self.xCenter
        ycenter = self.yCenter
        r = self.r
        Y = -self.yCenter
        length = -1
        for cell, cell2, i in zip(self.firstColumn.cells, self.secondColumn.cells,
                                  range(0, len(self.firstColumn.cells))):
            if (type(cell2.value) != str):
                if (i != 0):
                    length += 1
                    startangle = 0
                    endangle = self.getAngle(double(cell2.value))
                    radiansconversion = np.pi / 180.
                    xstartpoint = xcenter + r * np.cos(startangle * radiansconversion)
                    ystartpoint = ycenter - r * np.sin(startangle * radiansconversion)
                    xendpoint = xcenter + r * np.cos(endangle * radiansconversion)
                    yendpoint = ycenter - r * np.sin(endangle * radiansconversion)
                    large_arc_flag = 0
                    if endangle - startangle > 180: large_arc_flag = 1
                    M = ("M %s %s" % (xstartpoint, ystartpoint))
                    a = ("A %s %s 0 %s 0 %s %s" % (r, r, large_arc_flag, xendpoint, yendpoint))
                    L = ("L %s %s" % (xcenter, ycenter))
                    p = draw.Path(stroke_width=10, stroke="white", fill=self.colorList[i - 1], fill_opacity=1,
                                  d=M + a + L,Class=str(self.Index),id=self.Index)


                    p.Z()
                    self.d.append(p)
                    text = str(self.firstColumn.cells[i - len(self.firstColumn.cells)].value) + ": " + str(
                        self.percentageOfValue(cell2.value))[0:4] + "%"
                    self.metaData.append(text)
                    r -= self.r / len(self.firstColumn.cells)
                    c=draw.Circle(-ycenter, xcenter, r, fill="white", fill_opacity=1,
                                    stroke="white", stroke_width=10)
                    if self.animation:
                      c.appendAnim(draw.Animate('r', '0.35s', from_or_values=0, to=r, repeatCount='1'))
                    self.d.append(c)
                    t =draw.Text(text=str(text), fontSize=30, x=str((length * 55 + 8) - 50), y=Y -50, style="font-size : "+str(30),
                                            transform="rotate(90," + str(self.xCenter - 40) + "," + str(
                                                -length * 55 + 8) + ")",Class=str(self.Index),id=self.Index
                                            ,Style="font-size : " + str(10))

                    if self.animation:
                      t.appendAnim(draw.Animate('x', str(length/4)+'s', from_or_values=0, to=(length * 55 + 8) - 50, repeatCount='1'))
                    self.d.append(t)
                    self.Index += 1
                    Y -= ((self.r / len(self.firstColumn.cells)) / 100)-10
Пример #21
0
    def show(self):
        d = draw.Drawing(1.4, 1.4, origin='center')

        d.append(
            draw.Circle(0,
                        0,
                        0.5,
                        stroke_width='0.005',
                        stroke=self.color,
                        fill_opacity='0.0'))

        for region in self.regions:
            d.append(region.draw(self.length))

        d.setRenderSize(self.size)
        return d
Пример #22
0
 def drawXPointsWithXValueSteps(self):
     add = self.widthOfYLabels
     for cell, i in zip(self.xColumn.cells[0:], range(1, len(self.xColumn.cells))):
         add += self.xUnit
         num = self.xColumn.cells[i].value
         self.metaData.append(str(num))
         if (len(str(num)) > 10):
             num = num[0:8] + "..."
         self.d.append(
             draw.Circle(add, self.heightOfXLabels, self.xUnit / 35, fill="black", stroke_width=0, stroke='black'))
         self.d.append(
             draw.Text(text=str(num), fontSize=self.heightOfXLabels /10, x=add ,
                       y=self.heightOfXLabels /1.29,
                       id=str(self.Index),Class=str(self.Index),
                       style="font-size : " + str(self.heightOfXLabels / 10),
                       transform="rotate(90," + str(add ) + "," + str(-self.heightOfXLabels / 1.29) + ")"))
         self.Index += 1
Пример #23
0
 def draw(self, x=0, y=0, xscale=1.0):
     h = self.h
     a = self.x * xscale
     b = (self.x + self.w) * xscale
     x = x * xscale
     r = h / 2
     font_size = h * 0.55
     arrow_size = 7
     if self.direction >= 0:
         line_start = a
         arrow_end = b
         arrow_start = max(arrow_end - arrow_size, line_start)
     else:
         line_start = b
         arrow_end = a
         arrow_start = min(arrow_end + arrow_size, line_start)
     centre = (a + b) / 2
     arrow_y = h / 2 + self.elevation * r
     group = draw.Group(transform="translate({} {})".format(x, y))
     group.append(
         draw.Line(line_start,
                   arrow_y,
                   arrow_start,
                   arrow_y,
                   stroke='black'))
     group.append(
         draw.Circle(centre, h / 2, r, fill='ivory', stroke='black'))
     group.append(
         draw.Lines(arrow_end,
                    arrow_y,
                    arrow_start,
                    arrow_y + arrow_size / 2,
                    arrow_start,
                    arrow_y - arrow_size / 2,
                    arrow_end,
                    arrow_y,
                    fill='black'))
     group.append(
         draw.Text(self.label,
                   font_size,
                   centre,
                   h / 2,
                   text_anchor='middle',
                   dy="0.35em"))
     return group
Пример #24
0
 def drawText(self):
     h = 40
     i = 1
     for cell in self.xColumn.cells[1:]:
         self.d.append(
             draw.Circle(self.widthView - 230,
                         h,
                         20,
                         fill=self.colorList[i - 1],
                         fill_opacity=0.5,
                         stroke_width=0))
         self.d.append(
             draw.Text(text=str(cell.value),
                       fontSize=30,
                       x=self.widthView - 200,
                       y=h))
         h += 60
         i += 1
def draw_smd_pads(d, smd_list, factor):
    for pad_name, pad in smd_list:
        pad_x = float(pad.x) * factor
        pad_y = float(pad.y) * factor

        pad_width = float(pad.width) * factor
        pad_length = float(pad.length) * factor

        # rotation=str.format(
        #    "translate({0}, {1})", str(pad_x), str(-pad_y))
        rotation = str.format("translate({1}, {2}) rotate({0})",
                              str(-pad.rotation), str(pad_x), str(-pad_y))

        fill_color = "lightskyblue"

        d.append(
            draw.Rectangle(-pad_width / 2,
                           -pad_length / 2,
                           pad_width,
                           pad_length,
                           stroke_width=1,
                           stroke="black",
                           fill=fill_color,
                           transform=rotation))

        # Draw midpoint
        color = "red"  # if item.rotation != 45 else "yellow"
        radius = pad_width / 2 if pad_width < pad_length else pad_length / 2
        d.append(
            draw.Circle(pad_x,
                        pad_y,
                        radius / 2,
                        fill=color,
                        stroke_width=1,
                        stroke="black"))
        d.append(
            draw.Text(pad_name,
                      30,
                      pad_x,
                      pad_y,
                      fill="yellow",
                      stroke="orange"))
Пример #26
0
    def drawNote(self, d: dsvg.Drawing, x: float, y: float) -> float:
        fs = self.fretStyle
        if self.individualMarked:
            textY = y - fs.fontSize / 4.0
            d.append(
                dsvg.Circle(x + fs.circleX,
                            y,
                            fs.radius,
                            fill=fs.circleFillColor,
                            stroke_width=2,
                            stroke=fs.circleStrokeColor))

            d.append(
                dsvg.Text(self.noteName,
                          fs.fontSize,
                          x + fs.circleX,
                          textY,
                          fill=fs.circleStrokeColor,
                          center=False,
                          text_anchor='middle'))
        return fs.fretWidth
Пример #27
0
    def drawPointsOfValuesInDataSourceTableWithoutXColumn(self, colors: List[str]):
        columnCounter = 0
        for column in self.dataSourceTableWithoutXcolumn.columns:
          if column.columnType == enums.ColumnDataType.Measures.value:
            if (column != self.xColumn):
                add = self.widthOfYLabels
                for cell, i in zip(column.cells, range(0, len(self.xColumn.cells))):
                    if (i != 0):
                        add += self.xUnit
                        self.metaData.append("(" + str(self.xColumn.cells[i].value) + "," + str(cell.value) + ")")
                        c = draw.Circle(add, self.convertY(double(cell.value)), self.xUnit / 25,
                                                  fill=colors[columnCounter],
                                                  stroke_width=0,Class=str(self.Index),
                                                  stroke=colors[columnCounter], id=(self.Index))
                        if self.animation:
                          c.appendAnim(draw.Animate('cx', '2s', from_or_values=0, to=abs(add),repeatCount='1'))
                          c.appendAnim(
                            draw.Animate('r', '3.2s', from_or_values=(self.xUnit / 25)*2, to=abs(self.xUnit / 25), repeatCount='1'))
                        self.d.append(c)
                        self.Index += 1

          columnCounter += 1
Пример #28
0
def draw_svg(json_articles, width, height, colors, sizes, country_font_size=30, directory=None):
    """
    Given a json of cleaned articles (popularity score scaled), calculate the country label positions and draw the entire svg
    """
    drawing = draw.Drawing(width, height, origin="center")
    draw_dash_boundary(directory + '/boundary.csv', drawing)
    draw_elevation(directory + '/elevation.csv', drawing)

    for v in json_articles.values():
        # Draw each article
        title = v["Article"]
        x = v["x"] * XY_RATIO
        y = v["y"] * XY_RATIO  # The original x, y are too small to visualize
        country = v["Country"]
        size = sizes[v['Article']]  # Augment the font_size and circle size correspondingly
        drawing.append(draw.Circle(x, y, size, **{ 'fill' : colors[country], 'fill-opacity' : 0.6 }))
        if size > 0.2:
            adjusted_x, adjusted_y = x - 0.5*len(title)*XY_RATIO, y - 0.5*size
            drawing.append(draw.Text(title, int(size), adjusted_x, adjusted_y))
    # Draw country labels
    country_labels_xy = get_country_labels_xy(json_articles)
    draw_country_labels(drawing, country_labels_xy, country_font_size, colors)
    return drawing
Пример #29
0
def drawSigil(points, canvas, color='white'): # draw sigil from coordinate list

    # setup sigil
    dash = svg.Marker(-0.5, -0.5, 0.5, 0.5, scale=5, orient='auto') # define line to terminate the sigil
    dash.append(svg.Line(-0., -0.5, 0., 0.5, stroke_width=0.2, stroke=color))
    dot = svg.Marker(-0.8, -0.5, 0.5, 0.5, scale=5, orient='auto') # define circle to start the sigil
    dot.append(svg.Circle(-0.3, 0.0, 0.3, stroke_width=0.2, stroke=color, fill='none'))
    p = svg.Path(stroke_width=7, stroke=color, fill='none', marker_start=dot, marker_end=dash)

    # draw sigil
    for point in points:
        if points.index(point) == 0:
            originX = point[0]
            originY = point[1]
            p.M(originX, originY)
        else:
            x = point[0] - originX # abs. to rel. coords
            y = point[1] - originY # abs. to rel. coords
            p.l(x, y) # draw
            originX = point[0]
            originY = point[1]

    # add to canvas
    canvas.append(p)
Пример #30
0
 def render(self, dpi=96, background=None):
     # self.printState()
     # TODO: implement polyline
     d = draw.Drawing(self.diameter, self.diameter, origin='center')
     radius = self.diameter / 2.0
     if background is not None:
         d.append(
             draw.Rectangle(-radius,
                            -radius,
                            self.diameter,
                            self.diameter,
                            fill=background))
     d.append(
         draw.Circle(0,
                     0,
                     radius,
                     stroke='black',
                     stroke_width=5,
                     stroke_opacity=1,
                     fill='none'))
     for i in range(self.n_pins - 1, 0, -1):
         for j in range(0, i):
             for yarn in self.state[i][j]:
                 endPoint = self._get_point(i)
                 startPoint = self._get_point(j)
                 d.append(
                     draw.Line(startPoint.x,
                               startPoint.y,
                               endPoint.x,
                               endPoint.y,
                               stroke_width=yarn.width,
                               stroke=yarn.color,
                               stroke_opacity=0.4,
                               fill='none'))
     d.setPixelScale(dpi * 0.393701 / 10)
     return d