def makePathDefs(self) -> Defs: """ Creates Defs object for reusable `Insertion` and `Skip` elements. """ _BW, _BH = self._base_width, self._base_height _hBW, _hBH = _BW/2, _BH/2 _67BW, _67BH = _BW/1.5, _BH/1.5 p = Path() p.appendMoveToPath(_hBW, _hBH) p.appendQuadraticCurveToPath(-_67BW, -_BH, 0, -_BH) p.appendQuadraticCurveToPath(_67BW, 0, 0, _BH) p.set_stroke_linecap("round") g_insertion = G() g_insertion.setAttribute('id', "insertion") g_insertion.addElement(p) d = 0.5 # small delta to compensate for round endcap line1 = Line(d, d, _BW-d, _BH-d, style="stroke:#cc0000; stroke-width:2") line2 = Line(_BW-d, d, d, _BH-d, style="stroke:#cc0000; stroke-width:2") line1.set_stroke_linecap("round") line2.set_stroke_linecap("round") g_skip = G() g_skip.setAttribute('id', "skip") g_skip.addElement(line1) g_skip.addElement(line2) path_defs = Defs() path_defs.addElement(g_insertion) path_defs.addElement(g_skip) return path_defs
def drawFrontFacePair(topCorners, bottomCorners, color): pointList = [] pointList2 = [] output = G() YZStyle1 = StyleBuilder() #YZStyle1.setStroke('black') #YZStyle1.setStrokeWidth(1.5) YZStyle1.setFilling(color) YZStyle1.setFillOpacity(0.75) YZStyle2 = StyleBuilder() YZStyle2.setStroke('black') YZStyle2.setStrokeWidth(0.5) YZStyle2.setFillOpacity(0.75) YZStyle2.setFilling('#ffffff') pointList.append(strPathStart(topCorners[1])) pointList.append(strPathPoint(topCorners[2])) pointList.append(strPathPoint(bottomCorners[2])) pointList.append(strPathPoint(bottomCorners[1])) svgCode1 = pGram(pointList) pointList2.append(strPathStart(topCorners[0])) pointList2.append(strPathPoint(topCorners[3])) pointList2.append(strPathPoint(bottomCorners[3])) pointList2.append(strPathPoint(bottomCorners[0])) svgCode2 = pGram(pointList2) frontFace = Path(svgCode1) frontFace.set_style(YZStyle1.getStyle()) backFace = Path(svgCode2) backFace.set_style(YZStyle2.getStyle()) output.addElement(backFace) output.addElement(frontFace) return output
def drawSideFacePair(topCorners, bottomCorners, color): pointList = [] pointList2 = [] output = G() XYStyle1 = StyleBuilder() #XYStyle1.setStroke('black') #XYStyle1.setStrokeWidth(1.5) XYStyle1.setFilling(color) #XYStyle1.setFillOpacity(0.8) XYStyle2 = StyleBuilder() XYStyle2.setStroke(color) XYStyle2.setStrokeWidth(0.5) XYStyle2.setFilling(color) pointList.append(strPathStart(topCorners[2])) pointList.append(strPathPoint(topCorners[3])) pointList.append(strPathPoint(bottomCorners[3])) pointList.append(strPathPoint(bottomCorners[2])) svgCode1 = pGram(pointList) pointList2.append(strPathStart(topCorners[0])) pointList2.append(strPathPoint(topCorners[1])) pointList2.append(strPathPoint(bottomCorners[1])) pointList2.append(strPathPoint(bottomCorners[0])) svgCode2 = pGram(pointList2) rightFace = Path(svgCode1) rightFace.set_style(XYStyle1.getStyle()) leftFace = Path(svgCode2) leftFace.set_style(XYStyle2.getStyle()) output.addElement(leftFace) output.addElement(rightFace) return output
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
def draw_branch(svg, id, xs, ys, xe, ye): svgPath = ["M%f,%f" % (xs, ys)] svgPath += ["C%f,%f %f,%f %f,%f" % (xs, ye, xe, ys, xe, ye)] ob = SvgPath(pathData=" ".join(svgPath), id=id) ob.set_stroke_width(dc.branchThickness) ob.set_stroke(dc.branchColor) ob.set_fill("none") svg.addElement(ob)
def makePathOligosGroup(self) -> G: id_coords = self.mapIdnumsToYcoords() oligo_list = self.cn_doc.getOligoList() _BW = self._base_width _BH = self._base_height _pX = self.PATH_X_PADDING + self._path_radius_scaled*3 + _BW/2 g = G() g.setAttribute('id', "Oligos") i = 0 for color, is_circular, strands in oligo_list: prev_id, prev5, prev3, prevX, prevY = None, None, None, 0, 0 path_lines = [] if is_circular: strands.append(strands[0]) for id_num, idx5, idx3, isfwd, _ in strands: x = _pX + idx5*_BW if idx5 < idx3: # top strand y = id_coords[id_num] - _BH/2 else: y = id_coords[id_num] + _BH/2 dx = (idx3-idx5)*_BW if prev_id is not None and id_num != prev_id: # c dx1 dy1, dx2 dy2, dx dy if isfwd: x1 = x + abs(y-prevY)*0.03 else: x1 = x - abs(y-prevY)*0.03 y1 = (y+prevY)/2 path_lines.append("Q %s %s, %s %s" % (x1, y1, x, y)) path_lines.append("h %s" % dx) else: path_lines.append("M %s, %s h %s" % (x, y, dx)) prev_id, prev5, prev3, prevX, prevY = id_num, idx5, idx3, x, y p = Path(" ".join(path_lines)) oligo_style = 'fill:none; stroke:%s; stroke-width:2' % color p.set_style(oligo_style) p.setAttribute('id', "oligo_%s" % i) p.setAttribute("stroke-linejoin", "round") i += 1 g.addElement(p) return g
def makePathGridlinesGroup(self) -> G: size = self.cn_doc.max_vhelix_length _BW = self._base_width _BH = self._base_height g = G() g.setAttribute('id', "GridLines") for i in range(len(self.cn_doc.vh_order)): id_num = self.cn_doc.vh_order[i] x = self.PATH_X_PADDING + self._path_radius_scaled*3 y = self.PATH_Y_PADDING + self._path_vh_margin*i h_lines = " ".join("M %s,%s h %s" % (x, y-_BH+j*_BH, _BW*size) for j in range(3)) v_lines = " ".join("M %s,%s v %s" % (x+j*_BW, y-_BH, _BH*2) for j in range(int(size)+1)) p = Path(h_lines + " " + v_lines) grid_style = 'fill:none; stroke:#666666; stroke-width:0.25' p.set_style(grid_style) p.setAttribute('id', "grid_"+self.cn_doc.vh_props['name'][id_num]) g.addElement(p) return g