def paint(self, canvas, data, axis, axispos): if self.breaklinesattrs is not None: breaklinesdist_pt = unit.topt(self.breaklinesdist) breaklineslength_pt = unit.topt(self.breaklineslength) breaklinesextent_pt = (0.5*breaklinesdist_pt*math.fabs(self.cos) + 0.5*breaklineslength_pt*math.fabs(self.sin)) if canvas.extent_pt < breaklinesextent_pt: canvas.extent_pt = breaklinesextent_pt for v in [data.subaxes[name].vminover for name in data.names[1:]]: # use a tangent of the basepath (this is independent of the tickdirection) p = axispos.vbasepath(v, None).normpath() breakline = p.tangent(0, length=self.breaklineslength) widthline = p.tangent(0, length=self.breaklinesdist).transformed(trafomodule.rotate(self.breaklinesangle+90, *breakline.atbegin())) # XXX Uiiii tocenter = map(lambda x: 0.5*(x[0]-x[1]), zip(breakline.atbegin(), breakline.atend())) towidth = map(lambda x: 0.5*(x[0]-x[1]), zip(widthline.atbegin(), widthline.atend())) breakline = breakline.transformed(trafomodule.translate(*tocenter).rotated(self.breaklinesangle, *breakline.atbegin())) breakline1 = breakline.transformed(trafomodule.translate(*towidth)) breakline2 = breakline.transformed(trafomodule.translate(-towidth[0], -towidth[1])) canvas.layer("baseline").fill(path.path(path.moveto_pt(*breakline1.atbegin_pt()), path.lineto_pt(*breakline1.atend_pt()), path.lineto_pt(*breakline2.atend_pt()), path.lineto_pt(*breakline2.atbegin_pt()), path.closepath()), [color.gray.white]) canvas.layer("baseline").stroke(breakline1, self.defaultbreaklinesattrs + self.breaklinesattrs) canvas.layer("baseline").stroke(breakline2, self.defaultbreaklinesattrs + self.breaklinesattrs) _title.paint(self, canvas, data, axis, axispos)
def __init__(self, elems, epsilon=None): """elems should contain metapost knots or links""" if epsilon is None: epsilon = _epsilon knots = [] is_closed = True for i, elem in enumerate(elems): if isinstance(elem, _link): elem.set_knots(elems[i - 1], elems[(i + 1) % len(elems)]) elif isinstance(elem, _knot): knots.append(elem) if elem.ltype == mp_endpoint or elem.rtype == mp_endpoint: is_closed = False # link the knots among each other for i in range(len(knots)): knots[i - 1].next = knots[i] # determine the control points mp_make_choices(knots[0], epsilon) pathmodule.path.__init__(self) # build up the path do_moveto = True do_lineto = False do_curveto = False prev = None for i, elem in enumerate(elems): if isinstance(elem, _link): do_moveto = False if isinstance(elem, line): do_lineto, do_curveto = True, False else: do_lineto, do_curveto = False, True elif isinstance(elem, _knot): if do_moveto: self.append(pathmodule.moveto_pt(elem.x_pt, elem.y_pt)) if do_lineto: self.append(pathmodule.lineto_pt(elem.x_pt, elem.y_pt)) elif do_curveto: self.append( pathmodule.curveto_pt(prev.rx_pt, prev.ry_pt, elem.lx_pt, elem.ly_pt, elem.x_pt, elem.y_pt)) do_moveto = True do_lineto = False do_curveto = False prev = elem # close the path if necessary if knots[0].ltype == mp_explicit: elem = knots[0] if do_lineto and is_closed: self.append(pathmodule.closepath()) elif do_curveto: self.append( pathmodule.curveto_pt(prev.rx_pt, prev.ry_pt, elem.lx_pt, elem.ly_pt, elem.x_pt, elem.y_pt)) if is_closed: self.append(pathmodule.closepath())
def paint(self, canvas, data, axis, axispos): if self.breaklinesattrs is not None: breaklinesdist_pt = unit.topt(self.breaklinesdist) breaklineslength_pt = unit.topt(self.breaklineslength) breaklinesextent_pt = (0.5*breaklinesdist_pt*math.fabs(self.cos) + 0.5*breaklineslength_pt*math.fabs(self.sin)) if canvas.extent_pt < breaklinesextent_pt: canvas.extent_pt = breaklinesextent_pt for v in [data.subaxes[name].vminover for name in data.names[1:]]: # use a tangent of the basepath (this is independent of the tickdirection) p = axispos.vbasepath(v, None).normpath() breakline = p.tangent(0, length=self.breaklineslength) widthline = p.tangent(0, length=self.breaklinesdist).transformed(trafomodule.rotate(self.breaklinesangle+90, *breakline.atbegin())) # XXX Uiiii tocenter = map(lambda x: 0.5*(x[0]-x[1]), zip(breakline.atbegin(), breakline.atend())) towidth = map(lambda x: 0.5*(x[0]-x[1]), zip(widthline.atbegin(), widthline.atend())) breakline = breakline.transformed(trafomodule.translate(*tocenter).rotated(self.breaklinesangle, *breakline.atbegin())) breakline1 = breakline.transformed(trafomodule.translate(*towidth)) breakline2 = breakline.transformed(trafomodule.translate(-towidth[0], -towidth[1])) canvas.fill(path.path(path.moveto_pt(*breakline1.atbegin_pt()), path.lineto_pt(*breakline1.atend_pt()), path.lineto_pt(*breakline2.atend_pt()), path.lineto_pt(*breakline2.atbegin_pt()), path.closepath()), [color.gray.white]) canvas.stroke(breakline1, self.defaultbreaklinesattrs + self.breaklinesattrs) canvas.stroke(breakline2, self.defaultbreaklinesattrs + self.breaklinesattrs) _title.paint(self, canvas, data, axis, axispos)
def updatepath(self, path, trafo, context): sbx = context.t1stack.pop(0) wx = context.t1stack.pop(0) path.append(moveto_pt(*trafo.apply_pt(sbx, 0))) context.x = sbx context.y = 0 context.wx = wx context.wy = 0
def __init__(self, elems, epsilon=None): """elems should contain metapost knots or links""" if epsilon is None: epsilon = _epsilon knots = [] is_closed = True for i, elem in enumerate(elems): if isinstance(elem, _link): elem.set_knots(elems[i-1], elems[(i+1)%len(elems)]) elif isinstance(elem, _knot): knots.append(elem) if elem.ltype == mp_endpoint or elem.rtype == mp_endpoint: is_closed = False # link the knots among each other for i in range(len(knots)): knots[i-1].next = knots[i] # determine the control points mp_make_choices(knots[0], epsilon) pathmodule.path.__init__(self) # build up the path do_moveto = True do_lineto = False do_curveto = False prev = None for i, elem in enumerate(elems): if isinstance(elem, _link): do_moveto = False if isinstance(elem, line): do_lineto, do_curveto = True, False else: do_lineto, do_curveto = False, True elif isinstance(elem, _knot): if do_moveto: self.append(pathmodule.moveto_pt(elem.x_pt, elem.y_pt)) if do_lineto: self.append(pathmodule.lineto_pt(elem.x_pt, elem.y_pt)) elif do_curveto: self.append(pathmodule.curveto_pt(prev.rx_pt, prev.ry_pt, elem.lx_pt, elem.ly_pt, elem.x_pt, elem.y_pt)) do_moveto = True do_lineto = False do_curveto = False prev = elem # close the path if necessary if knots[0].ltype == mp_explicit: elem = knots[0] if do_lineto and is_closed: self.append(pathmodule.closepath()) elif do_curveto: self.append(pathmodule.curveto_pt(prev.rx_pt, prev.ry_pt, elem.lx_pt, elem.ly_pt, elem.x_pt, elem.y_pt)) if is_closed: self.append(pathmodule.closepath())
def zvgridpath(self, vz): return path.path(path.moveto_pt(*self.vpos_pt(0, 0, vz)), path.lineto_pt(*self.vpos_pt(1, 0, vz)), path.lineto_pt(*self.vpos_pt(1, 1, vz)), path.lineto_pt(*self.vpos_pt(0, 1, vz)), path.closepath())
def yvgridpath(self, vy): return path.path(path.moveto_pt(*self.vpos_pt(0, vy, 0)), path.lineto_pt(*self.vpos_pt(1, vy, 0)), path.lineto_pt(*self.vpos_pt(1, vy, 1)), path.lineto_pt(*self.vpos_pt(0, vy, 1)), path.closepath())
def xvgridpath(self, vx): return path.path(path.moveto_pt(*self.vpos_pt(vx, 0, 0)), path.lineto_pt(*self.vpos_pt(vx, 1, 0)), path.lineto_pt(*self.vpos_pt(vx, 1, 1)), path.lineto_pt(*self.vpos_pt(vx, 0, 1)), path.closepath())
def updatepath(self, path, trafo, context): dy = context.t1stack.pop(0) path.append(moveto_pt(*trafo.apply_pt(context.x, context.y + dy))) context.y += dy
def updatepath(self, path, trafo, context): path.append(closepath()) # The closepath in T1 is different from PostScripts in that it does # *not* modify the current position; hence we need to add an additional # moveto here ... path.append(moveto_pt(*trafo.apply_pt(context.x, context.y)))
def updatepath(self, path, trafo, context): x = context.t1stack.pop(0) y = context.t1stack.pop(0) path.append(moveto_pt(*trafo.apply_pt(x, y))) context.x = x context.y = y