def draw_country_labels(d, country_labels_xy, font_size, colors): for country, position in country_labels_xy.items(): x, y = position[0] * XY_RATIO, position[1] * XY_RATIO words = country.split() offset = 0 grey = "#707070" for i in range(0, len(words), 2): if i + 1 == len(words): d.append(draw.Text(words[i].upper(), font_size, x, y - offset, fill=grey, center=True, stroke='white', stroke_width=0.5)) else: d.append(draw.Text(words[i].upper() + ' ' + words[i+1].upper(), font_size, x, y - offset, fill=grey, center=True, stroke='white', stroke_width=0.5)) offset += 30
def render_text(text, model, target, style=None): style = style_join(style or {}, text.style) assert len(style) > 0 x = N(model[text.anchor_point.x]) y = M(model[text.anchor_point.y], target) target.append( draw.Text(text.text, text.font_size, x, y, center=True, **style))
def draw_text(self, d, text, x, y, text_size, fill="black"): x = int(x) y = int(y) text_size = int(text_size) text = text.strip('"') d.append(draw.Text(text, text_size, x, y, center=0.6)) return d
def draw_keyboard(keyboard_or_index: Union[int, Keyboard]) -> draw.Group: keyboard: Keyboard = keyboards[keyboard_or_index] if isinstance( keyboard_or_index, int) else keyboard_or_index outlines = draw.Group( transform=f"translate({-keyboard.left},{-keyboard.top})") chars = draw.Group(transform="scale(1,-1)") for key in keyboard.values(): outlines.append( draw.Rectangle(key.x, key.y, key.width, key.height, fill='transparent', stroke_width=5, stroke='blue')) if key.code > 0: chars.append( draw.Text(key.char, fontSize=25, x=key.x + key.width / 2, y=-key.y - key.height / 2, center=True)) outlines.append(chars) return outlines
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
def __init__(self, dataSource: TableModel, XColumn: ColumnModel, width: double, height: double, animation: bool, nameFile: str): super().__init__(dataSource, width, height, XColumn, animation) self.widthView = 1000 self.heightView = 1000 self.LabelColumn = XColumn self.colorList = self.dataSourceTableWithoutXcolumn.rowsColors self.listOfLength = list() self.d = draw.Drawing(self.widthView, self.heightView) self.Check = False self.femaleColumn = self.maleColumn = XColumn self.getMaleAndFemaleColumns() self.maleTotal = self.sumColumn(self.maleColumn) self.femaleTotal = self.sumColumn(self.femaleColumn) self.drawlayOut() self.drawText() if self.Check: self.drawMaleAndFemaleStack() self.drawHuman() else: self.drawlayOut() self.d.append( draw.Text( text= "Error: we can't found male or Female column \n. . . Try to check column name", fontSize=40, x=0, y=self.heightView / 2)) self.d.setPixelScale(min(width, height) / 1000) # Set number of pixels per geometry unit #self.d.saveSvg(nameFile + '.svg') self.SVG = self.d.asSvg()
def draw_name(self, n, pred, contig, start, end): self.im.append( draw.Text('{}: {} ({}-{})'.format(pred, contig, start, end), 38, 15 + self.scale / 10, self.imheight - (n * 20 * self.scale - 6 * self.scale), fill='black'))
def draw_line(self, dims, vals, grid_size=10, color='#ffffff'): anim = draw.Drawing(330, 120, origin=(0, 0)) for x in range(dims[0]): group = draw.Group() group.draw( draw.Rectangle( 100 * x + grid_size, # origin x coords grid_size, # origin y coords 100, # grid width 100, # grid height stroke_width=grid_size, # outline size stroke='black', # outline color fill=color)) # fill color string_output = str(vals[x]) font_size = 50 / len(string_output) + 25 group.draw( draw.Text( string_output, font_size, 100 * x + grid_size + font_size / 3 + 2 * len(string_output), # origin x coords grid_size + 2250 / (font_size + 20), # origin y coords center=0)) anim.append(group) return anim
def __init__(self, dataSource: TableModel, XColumn: ColumnModel, width: double, height: double, animation: bool, nameFile: str): super().__init__(dataSource, width, height, XColumn, animation) self.widthView = 1000 self.heightView = 1000 self.LabelColumn = dataSource.columns[0] self.xColumn = XColumn self.colorList = self.dataSourceTableWithoutXcolumn.rowsColors self.listOfLength = list() self.d = draw.Drawing(self.widthView, self.heightView) self.total = self.sumColumn(self.xColumn) self.drawlayOut() if self.xColumn.columnType == enums.ColumnDataType.Measures.value: self.drawStack() self.drawHuman() self.drawText() else: self.d.append( draw.Text(text="Error: Xcolumn is not Measured", fontSize=60, x=50, y=self.heightView / 2)) self.d.setPixelScale(min(width, height) / 1000) # Set number of pixels per geometry unit #self.d.saveSvg(nameFile+'.svg') self.SVG = self.d.asSvg()
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])
def __init__(self, dataSource: TableModel, XColumn: ColumnModel, width: double, height: double, animation: bool, nameFile: str): self.animation = animation self.metaData = list() self.Index =0 self.listOfPercentageValue =dict() self.widthView = 1000 self.heightView = 1000 self.dataSourceTableWithoutXcolumn = dataSource self.xColumn = XColumn self.idOfKeyColumn = 0 self.zeroX = 655.3 self.zeroY = 417.1 self.color = self.dataSourceTableWithoutXcolumn.columnsColors[0] self.latColumn = self.findLatColumn() self.lngColumn = self.findLngColumn() if self.latColumn != self.xColumn and self.lngColumn != self.xColumn : self.listOfLength = list() self.d = draw.Drawing(self.widthView , self.heightView) self.drawlayOut() self.drawMap() self.drawPoint() else: self.d.append(draw.Text(text="Error: you have to select keyCountries in columns", fontSize=60, x=50, y=self.heightView / 2)) self.d.setPixelScale(min(width,height)/1000) # Set number of pixels per geometry unit #self.d.saveSvg(nameFile+'.svg') self.SVG = self.d.asSvg()
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]
def group_with_word(frame, word, i): group = draw.Group() group.append(frame) group.append( draw.Text(str(i) + ': ' + word, fontSize=40, x=10, y=-40, transform='scale(1, -1)')) return group
def drawNetArrow(x, label, sz): global d drawArrow(x + 15, -15, 25, 5, 8) d.append( svg.Text(label, sz, x + 15 + 25 / 2, -15 - 10, center=0.5, fill="black"))
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))
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 render(T, output, image_size, vertices_labels=True, draw_inner_lines=True, face_colors=["lightcoral", "mistyrose", "steelblue"]): d = drawSvg.Drawing(2.1, 2.1, origin="center") d.draw(euclid.shapes.Circle(0, 0, 1), fill="silver") for (i, j), flist in T.face_indices.items(): for face in flist: coords = [T.project(v) for v in face.points] center = T.project(face.center) for k, D in enumerate(face.domain1): if len(D) == 2: P, V = [T.project(p) for p in D] poly = Polygon.fromVertices([P, V, center]) else: P1, V, P2 = [T.project(p) for p in D] poly = Polygon.fromVertices([P1, V, P2, center]) d.draw(poly, fill=face_colors[2 * (i + j) % 3]) if draw_inner_lines: d.draw(poly, fill="papayawhip", hwidth=0.02) for k, D in enumerate(face.domain2): if len(D) == 2: P, V = [T.project(p) for p in D] poly = Polygon.fromVertices([P, V, center]) else: P1, V, P2 = [T.project(p) for p in D] poly = Polygon.fromVertices([P1, V, P2, center]) d.draw(poly, fill=face_colors[2 * (i + j) % 3], opacity=0.3) if draw_inner_lines: d.draw(poly, fill="papayawhip", hwidth=0.02) poly2 = Polygon.fromVertices(coords) d.draw(poly2, fill="#666", hwidth=0.05) if vertices_labels: for i in range(min(100, T.num_vertices)): d.draw( drawSvg.Text(str(i), 0.05, *T.project(T.vertices_coords[i]), center=0.7, fill="yellow")) d.setRenderSize(w=image_size) d.saveSvg(output)
def drawFretNumber(self, d: dsvg.Drawing, x: float, y: float) -> float: fs = self.fretStyle textY = y - fs.fontSize / 4.0 d.append( dsvg.Text(str(self.fretIndex), fs.fontSize, x + fs.circleX, textY, fill=fs.circleStrokeColor, center=False, text_anchor='middle')) return fs.fretWidth
def drawHeading(self, d: dsvg.Drawing, baseNote: str, x: float, y: float) -> float: scaleName = self.subscribers[0].comboBoxScales.currentText() modeName = self.subscribers[0].comboBoxModes.currentText() heading = f"{baseNote} {scaleName}, Mode {modeName}" d.append( dsvg.Text(heading, headingFontSize, x, y, fill=headingColor, center=False, text_anchor='left')) return headingFontSize
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
def Text( self, text: str, fontSize: int, x: float, y: float, col: str, anch: Optional[str] = None, ) -> draw.Text: return draw.Text(text, fontSize, x, self.height - y - fontSize, text_anchor=anch, fill=col)
def draw(self, x=None, y=0, xscale=1.0): # font_family = self.label.font_family if self.offset is not None: offset = self.offset if x is None: x = self.w * xscale d = draw.Group(transform="translate({} {})".format(x, y)) d.append( draw.Text(self.text, self.font_size, self.w, (self.font_size / 2 + offset), font_family='monospace', center=True)) return d
def drawSideLable(self): fontSize = self.widthOfYLabels/8 if( self.widthOfYLabels/8 > (self.heightOfCoordinatePlane/self.quality)/8): fontSize = (self.heightOfCoordinatePlane/self.quality)/8 y = self.heightOfXLabels x = self.widthOfYLabels / 10 for i in range(0, int(self.quality)): num = str(self.listOfLevelXValue[i]) self.metaData.append(num) if (len(num) > 10): num = num[0:8] + "..." t = draw.Text(text=str(num), fontSize=fontSize, x=x,y=self.convertY(self.listOfLevelXValue[i]),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=self.widthView,to=x, repeatCount='1')) self.d.append(t) self.Index += 1
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
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
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_event(d, event): # Monday is 0 and Sunday is 6 start_x_pos = event.start_datetime().weekday() * COL_WIDTH start_y_pos = COL_HEIGHT - (event.start_hour_decimal() - 10) * HOUR_HEIGHT end_y_pos = COL_HEIGHT - (event.end_hour_decimal() - 10) * HOUR_HEIGHT height = event.hour_duration_decimal() * HOUR_HEIGHT rect = draw.Rectangle(start_x_pos, end_y_pos, COL_WIDTH, height, fill=GREEN) text = draw.Text('busy', 10, start_x_pos + 5, start_y_pos - 10, center=0, fill='white') d.append(rect) d.append(text)
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"))
def add_names(self, url, font_size=12, family="Arial", colour="white", x_adj=0, y_adj=0): d = self.d for n in self.tree.traverse(): x_0, y_0 = n.x_coor, n.y_coor p = draw.Text(n.name, font_size, x_0 + x_adj, y_0 + y_adj, center=False, fill=colour, font_family=family) d.append(p) d.saveSvg(url) return (d)
def draw_days(d): for day_num, day_name in enumerate([ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]): x_pos = day_num * COL_WIDTH r = draw.Rectangle(x_pos, COL_HEIGHT, COL_WIDTH, BANNER_HEIGHT, fill='black', stroke='white') t = draw.Text(day_name, 10, x_pos + 5, COL_HEIGHT + 5, center=0, fill='white') d.append(r) d.append(t)