def paint(self, canvas, data, axis, axispos): for t in data.ticks: t.temp_v = axis.convert(data, t) t.temp_x_pt, t.temp_y_pt = axispos.vtickpoint_pt(t.temp_v) t.temp_dx, t.temp_dy = axispos.vtickdirection(t.temp_v) maxticklevel, maxlabellevel = tick.maxlevels(data.ticks) labeldist_pt = unit.topt(self.labeldist) # create & align t.temp_labelbox for t in data.ticks: if t.labellevel is not None: labelattrs = attr.selectattrs(self.labelattrs, t.labellevel, maxlabellevel) if labelattrs is not None: labelattrs = self.defaultlabelattrs + labelattrs if self.labeldirection is not None: labelattrs.append( self.labeldirection.trafo(t.temp_dx, t.temp_dy)) if t.labelattrs is not None: labelattrs.extend(t.labelattrs) t.temp_labelbox = canvas.textengine.text_pt( t.temp_x_pt, t.temp_y_pt, t.label, labelattrs) if len(data.ticks) > 1: equaldirection = 1 for t in data.ticks[1:]: if t.temp_dx != data.ticks[ 0].temp_dx or t.temp_dy != data.ticks[0].temp_dy: equaldirection = 0 else: equaldirection = 0 if equaldirection and ( (not data.ticks[0].temp_dx and self.labelvequalize) or (not data.ticks[0].temp_dy and self.labelhequalize)): if self.labelattrs is not None: box.linealignequal_pt([ t.temp_labelbox for t in data.ticks if t.labellevel is not None ], labeldist_pt, -data.ticks[0].temp_dx, -data.ticks[0].temp_dy) else: for t in data.ticks: if t.labellevel is not None and self.labelattrs is not None: t.temp_labelbox.linealign_pt(labeldist_pt, -t.temp_dx, -t.temp_dy) for t in data.ticks: if t.ticklevel is not None and self.tickattrs is not None: tickattrs = attr.selectattrs( self.defaulttickattrs + self.tickattrs, t.ticklevel, maxticklevel) if tickattrs is not None: innerticklength = attr.selectattr(self.innerticklength, t.ticklevel, maxticklevel) outerticklength = attr.selectattr(self.outerticklength, t.ticklevel, maxticklevel) if innerticklength is not None or outerticklength is not None: if innerticklength is None: innerticklength = 0 if outerticklength is None: outerticklength = 0 innerticklength_pt = unit.topt(innerticklength) outerticklength_pt = unit.topt(outerticklength) x1 = t.temp_x_pt + t.temp_dx * innerticklength_pt y1 = t.temp_y_pt + t.temp_dy * innerticklength_pt x2 = t.temp_x_pt - t.temp_dx * outerticklength_pt y2 = t.temp_y_pt - t.temp_dy * outerticklength_pt canvas.layer("ticks").stroke( path.line_pt(x1, y1, x2, y2), tickattrs) if outerticklength_pt > canvas.extent_pt: canvas.extent_pt = outerticklength_pt if -innerticklength_pt > canvas.extent_pt: canvas.extent_pt = -innerticklength_pt if self.gridattrs is not None: gridattrs = attr.selectattrs( self.defaultgridattrs + self.gridattrs, t.ticklevel, maxticklevel) if gridattrs is not None: canvas.layer("grid").stroke(axispos.vgridpath(t.temp_v), gridattrs) if t.labellevel is not None and self.labelattrs is not None: canvas.layer("labels").insert(t.temp_labelbox) canvas.labels.append(t.temp_labelbox) extent_pt = t.temp_labelbox.extent_pt(t.temp_dx, t.temp_dy) + labeldist_pt if extent_pt > canvas.extent_pt: canvas.extent_pt = extent_pt if self.labelattrs is None: canvas.labels = None if self.basepathattrs is not None: canvas.layer("baseline").stroke( axispos.vbasepath(), self.defaultbasepathattrs + self.basepathattrs) # for t in data.ticks: # del t.temp_v # we've inserted those temporary variables ... and do not care any longer about them # del t.temp_x_pt # del t.temp_y_pt # del t.temp_dx # del t.temp_dy # if t.labellevel is not None and self.labelattrs is not None: # del t.temp_labelbox _title.paint(self, canvas, data, axis, axispos)
def paint(self, canvas, data, axis, axispos): for t in data.ticks: t.temp_v = axis.convert(data, t) t.temp_x_pt, t.temp_y_pt = axispos.vtickpoint_pt(t.temp_v) t.temp_dx, t.temp_dy = axispos.vtickdirection(t.temp_v) maxticklevel, maxlabellevel = tick.maxlevels(data.ticks) labeldist_pt = unit.topt(self.labeldist) # create & align t.temp_labelbox for t in data.ticks: if t.labellevel is not None: labelattrs = attr.selectattrs(self.labelattrs, t.labellevel, maxlabellevel) if labelattrs is not None: labelattrs = self.defaultlabelattrs + labelattrs if self.labeldirection is not None: labelattrs.append(self.labeldirection.trafo(t.temp_dx, t.temp_dy)) if t.labelattrs is not None: labelattrs.extend(t.labelattrs) t.temp_labelbox = canvas.texrunner.text_pt(t.temp_x_pt, t.temp_y_pt, t.label, labelattrs) if len(data.ticks) > 1: equaldirection = 1 for t in data.ticks[1:]: if t.temp_dx != data.ticks[0].temp_dx or t.temp_dy != data.ticks[0].temp_dy: equaldirection = 0 else: equaldirection = 0 if equaldirection and ((not data.ticks[0].temp_dx and self.labelvequalize) or (not data.ticks[0].temp_dy and self.labelhequalize)): if self.labelattrs is not None: box.linealignequal_pt([t.temp_labelbox for t in data.ticks if t.labellevel is not None], labeldist_pt, -data.ticks[0].temp_dx, -data.ticks[0].temp_dy) else: for t in data.ticks: if t.labellevel is not None and self.labelattrs is not None: t.temp_labelbox.linealign_pt(labeldist_pt, -t.temp_dx, -t.temp_dy) for t in data.ticks: if t.ticklevel is not None and self.tickattrs is not None: tickattrs = attr.selectattrs(self.defaulttickattrs + self.tickattrs, t.ticklevel, maxticklevel) if tickattrs is not None: innerticklength = attr.selectattr(self.innerticklength, t.ticklevel, maxticklevel) outerticklength = attr.selectattr(self.outerticklength, t.ticklevel, maxticklevel) if innerticklength is not None or outerticklength is not None: if innerticklength is None: innerticklength = 0 if outerticklength is None: outerticklength = 0 innerticklength_pt = unit.topt(innerticklength) outerticklength_pt = unit.topt(outerticklength) x1 = t.temp_x_pt + t.temp_dx * innerticklength_pt y1 = t.temp_y_pt + t.temp_dy * innerticklength_pt x2 = t.temp_x_pt - t.temp_dx * outerticklength_pt y2 = t.temp_y_pt - t.temp_dy * outerticklength_pt canvas.layer("ticks").stroke(path.line_pt(x1, y1, x2, y2), tickattrs) if outerticklength_pt > canvas.extent_pt: canvas.extent_pt = outerticklength_pt if -innerticklength_pt > canvas.extent_pt: canvas.extent_pt = -innerticklength_pt if self.gridattrs is not None: gridattrs = attr.selectattrs(self.defaultgridattrs + self.gridattrs, t.ticklevel, maxticklevel) if gridattrs is not None: canvas.layer("grid").stroke(axispos.vgridpath(t.temp_v), gridattrs) if t.labellevel is not None and self.labelattrs is not None: canvas.layer("labels").insert(t.temp_labelbox) canvas.labels.append(t.temp_labelbox) extent_pt = t.temp_labelbox.extent_pt(t.temp_dx, t.temp_dy) + labeldist_pt if extent_pt > canvas.extent_pt: canvas.extent_pt = extent_pt if self.labelattrs is None: canvas.labels = None if self.basepathattrs is not None: canvas.layer("baseline").stroke(axispos.vbasepath(), self.defaultbasepathattrs + self.basepathattrs) # for t in data.ticks: # del t.temp_v # we've inserted those temporary variables ... and do not care any longer about them # del t.temp_x_pt # del t.temp_y_pt # del t.temp_dx # del t.temp_dy # if t.labellevel is not None and self.labelattrs is not None: # del t.temp_labelbox _title.paint(self, canvas, data, axis, axispos)