示例#1
0
 def vcap_pt(self, coordinate, length_pt, vx, vy):
     """returns an error cap path for a given coordinate, lengths and
     point in graph coordinates"""
     if coordinate == 0:
         return path.line_pt(self.xpos_pt + vx*self.width_pt - 0.5*length_pt,
                             self.ypos_pt + vy*self.height_pt,
                             self.xpos_pt + vx*self.width_pt + 0.5*length_pt,
                             self.ypos_pt + vy*self.height_pt)
     elif coordinate == 1:
         return path.line_pt(self.xpos_pt + vx*self.width_pt,
                             self.ypos_pt + vy*self.height_pt - 0.5*length_pt,
                             self.xpos_pt + vx*self.width_pt,
                             self.ypos_pt + vy*self.height_pt + 0.5*length_pt)
     else:
         raise ValueError("direction invalid")
示例#2
0
 def vcap_pt(self, coordinate, length_pt, vx, vy):
     """returns an error cap path for a given coordinate, lengths and
     point in graph coordinates"""
     if coordinate == 0:
         return path.line_pt(
             self.xpos_pt + vx * self.width_pt - 0.5 * length_pt,
             self.ypos_pt + vy * self.height_pt,
             self.xpos_pt + vx * self.width_pt + 0.5 * length_pt,
             self.ypos_pt + vy * self.height_pt)
     elif coordinate == 1:
         return path.line_pt(
             self.xpos_pt + vx * self.width_pt,
             self.ypos_pt + vy * self.height_pt - 0.5 * length_pt,
             self.xpos_pt + vx * self.width_pt,
             self.ypos_pt + vy * self.height_pt + 0.5 * length_pt)
     else:
         raise ValueError("direction invalid")
示例#3
0
 def vbasepath(self, v1=None, v2=None):
     if v1 is None:
         v1 = 0
     if v2 is None:
         v2 = 1
     x1_pt, y1_pt = self.vtickpoint_pt(v1)
     x2_pt, y2_pt = self.vtickpoint_pt(v2)
     return path.line_pt(x1_pt, y1_pt, x2_pt, y2_pt)
示例#4
0
 def vgeodesic(self, vx1, vy1, vx2, vy2):
     """returns a geodesic path between two points in graph coordinates"""
     if self.flipped:
         vx1, vy1 = vy1, vx1
         vx2, vy2 = vy2, vx2
     return path.line_pt(self.xpos_pt + vx1*self.width_pt,
                         self.ypos_pt + vy1*self.height_pt,
                         self.xpos_pt + vx2*self.width_pt,
                         self.ypos_pt + vy2*self.height_pt)
示例#5
0
 def vbasepath(self, v1=None, v2=None):
     if v1 is None:
         v1 = 0
     if v2 is None:
         v2 = 1
     return path.line_pt((1-v1)*self.x1_pt+v1*self.x2_pt,
                         (1-v1)*self.y1_pt+v1*self.y2_pt,
                         (1-v2)*self.x1_pt+v2*self.x2_pt,
                         (1-v2)*self.y1_pt+v2*self.y2_pt)
示例#6
0
 def vgeodesic(self, vx1, vy1, vz1, vx2, vy2, vz2):
     """returns a geodesic path between two points in graph coordinates"""
     return path.line_pt(*(self.vpos_pt(vx1, vy1, vz1) + self.vpos_pt(vx2, vy2, vz2)))
示例#7
0
 def yvgridpath(self, vy):
     return path.line_pt(self.xpos_pt, self.ypos_pt + vy*self.height_pt,
                         self.xpos_pt + self.width_pt, self.ypos_pt + vy*self.height_pt)
示例#8
0
 def xvgridpath(self, vx):
     return path.line_pt(self.xpos_pt + vx*self.width_pt, self.ypos_pt,
                         self.xpos_pt + vx*self.width_pt, self.ypos_pt + self.height_pt)
示例#9
0
 def vgeodesic(self, vx1, vy1, vz1, vx2, vy2, vz2):
     """returns a geodesic path between two points in graph coordinates"""
     return path.line_pt(*(self.vpos_pt(vx1, vy1, vz1) +
                           self.vpos_pt(vx2, vy2, vz2)))
示例#10
0
 def yvgridpath(self, vy):
     return path.line_pt(self.xpos_pt, self.ypos_pt + vy * self.height_pt,
                         self.xpos_pt + self.width_pt,
                         self.ypos_pt + vy * self.height_pt)
示例#11
0
 def xvgridpath(self, vx):
     return path.line_pt(self.xpos_pt + vx * self.width_pt, self.ypos_pt,
                         self.xpos_pt + vx * self.width_pt,
                         self.ypos_pt + self.height_pt)
示例#12
0
 def vgeodesic(self, vx1, vy1, vx2, vy2):
     """returns a geodesic path between two points in graph coordinates"""
     return path.line_pt(self.xpos_pt + vx1 * self.width_pt,
                         self.ypos_pt + vy1 * self.height_pt,
                         self.xpos_pt + vx2 * self.width_pt,
                         self.ypos_pt + vy2 * self.height_pt)
示例#13
0
文件: painter.py 项目: atal2003/test
 def paint(self, canvas, data, axis, positioner):
     namepos = []
     for name in data.names:
         subaxis = data.subaxes[name]
         v = subaxis.vmin + self.namepos * (subaxis.vmax - subaxis.vmin)
         x, y = positioner.vtickpoint_pt(v)
         dx, dy = positioner.vtickdirection(v)
         namepos.append((v, x, y, dx, dy))
     nameboxes = []
     if self.nameattrs is not None:
         for (v, x, y, dx, dy), name in zip(namepos, data.names):
             nameattrs = self.defaultnameattrs + self.nameattrs
             if self.namedirection is not None:
                 nameattrs.append(self.namedirection.trafo(dx, dy))
             nameboxes.append(
                 canvas.textengine.text_pt(x, y, str(name), nameattrs))
     labeldist_pt = canvas.extent_pt + unit.topt(self.namedist)
     if len(namepos) > 1:
         equaldirection = 1
         for np in namepos[1:]:
             if np[3] != namepos[0][3] or np[4] != namepos[0][4]:
                 equaldirection = 0
     else:
         equaldirection = 0
     if equaldirection and ((not namepos[0][3] and self.namevequalize) or
                            (not namepos[0][4] and self.namehequalize)):
         box.linealignequal_pt(nameboxes, labeldist_pt, -namepos[0][3],
                               -namepos[0][4])
     else:
         for namebox, np in zip(nameboxes, namepos):
             namebox.linealign_pt(labeldist_pt, -np[3], -np[4])
     if self.basepathattrs is not None:
         p = positioner.vbasepath()
         if p is not None:
             canvas.layer("baseline").stroke(
                 p, self.defaultbasepathattrs + self.basepathattrs)
     if (self.tickattrs is not None
             and (self.innerticklength is not None
                  or self.outerticklength is not None)):
         if self.innerticklength is not None:
             innerticklength_pt = unit.topt(self.innerticklength)
             if canvas.extent_pt < -innerticklength_pt:
                 canvas.extent_pt = -innerticklength_pt
         elif self.outerticklength is not None:
             innerticklength_pt = 0
         if self.outerticklength is not None:
             outerticklength_pt = unit.topt(self.outerticklength)
             if canvas.extent_pt < outerticklength_pt:
                 canvas.extent_pt = outerticklength_pt
         elif innerticklength_pt is not None:
             outerticklength_pt = 0
         for v in [data.subaxes[name].vminover
                   for name in data.names] + [1]:
             x, y = positioner.vtickpoint_pt(v)
             dx, dy = positioner.vtickdirection(v)
             x1 = x + dx * innerticklength_pt
             y1 = y + dy * innerticklength_pt
             x2 = x - dx * outerticklength_pt
             y2 = y - dy * outerticklength_pt
             canvas.layer("ticks").stroke(
                 path.line_pt(x1, y1, x2, y2),
                 self.defaulttickattrs + self.tickattrs)
     for (v, x, y, dx, dy), namebox in zip(namepos, nameboxes):
         newextent_pt = namebox.extent_pt(dx, dy) + labeldist_pt
         if canvas.extent_pt < newextent_pt:
             canvas.extent_pt = newextent_pt
     for namebox in nameboxes:
         canvas.layer("labels").insert(namebox)
     _title.paint(self, canvas, data, axis, positioner)
示例#14
0
文件: painter.py 项目: atal2003/test
    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)
示例#15
0
 def paint(self, canvas, data, axis, positioner):
     namepos = []
     for name in data.names:
         subaxis = data.subaxes[name]
         v = subaxis.vmin + self.namepos * (subaxis.vmax - subaxis.vmin)
         x, y = positioner.vtickpoint_pt(v)
         dx, dy = positioner.vtickdirection(v)
         namepos.append((v, x, y, dx, dy))
     nameboxes = []
     if self.nameattrs is not None:
         for (v, x, y, dx, dy), name in zip(namepos, data.names):
             nameattrs = self.defaultnameattrs + self.nameattrs
             if self.namedirection is not None:
                 nameattrs.append(self.namedirection.trafo(dx, dy))
             nameboxes.append(canvas.texrunner.text_pt(x, y, str(name), nameattrs))
     labeldist_pt = canvas.extent_pt + unit.topt(self.namedist)
     if len(namepos) > 1:
         equaldirection = 1
         for np in namepos[1:]:
             if np[3] != namepos[0][3] or np[4] != namepos[0][4]:
                 equaldirection = 0
     else:
         equaldirection = 0
     if equaldirection and ((not namepos[0][3] and self.namevequalize) or
                            (not namepos[0][4] and self.namehequalize)):
         box.linealignequal_pt(nameboxes, labeldist_pt, -namepos[0][3], -namepos[0][4])
     else:
         for namebox, np in zip(nameboxes, namepos):
             namebox.linealign_pt(labeldist_pt, -np[3], -np[4])
     if self.basepathattrs is not None:
         p = positioner.vbasepath()
         if p is not None:
             canvas.layer("baseline").stroke(p, self.defaultbasepathattrs + self.basepathattrs)
     if ( self.tickattrs is not None and
          (self.innerticklength is not None or self.outerticklength is not None) ):
         if self.innerticklength is not None:
             innerticklength_pt = unit.topt(self.innerticklength)
             if canvas.extent_pt < -innerticklength_pt:
                 canvas.extent_pt = -innerticklength_pt
         elif self.outerticklength is not None:
             innerticklength_pt = 0
         if self.outerticklength is not None:
             outerticklength_pt = unit.topt(self.outerticklength)
             if canvas.extent_pt < outerticklength_pt:
                 canvas.extent_pt = outerticklength_pt
         elif innerticklength_pt is not None:
             outerticklength_pt = 0
         for v in [data.subaxes[name].vminover for name in data.names] + [1]:
             x, y = positioner.vtickpoint_pt(v)
             dx, dy = positioner.vtickdirection(v)
             x1 = x + dx * innerticklength_pt
             y1 = y + dy * innerticklength_pt
             x2 = x - dx * outerticklength_pt
             y2 = y - dy * outerticklength_pt
             canvas.layer("ticks").stroke(path.line_pt(x1, y1, x2, y2), self.defaulttickattrs + self.tickattrs)
     for (v, x, y, dx, dy), namebox in zip(namepos, nameboxes):
         newextent_pt = namebox.extent_pt(dx, dy) + labeldist_pt
         if canvas.extent_pt < newextent_pt:
             canvas.extent_pt = newextent_pt
     for namebox in nameboxes:
         canvas.layer("labels").insert(namebox)
     _title.paint(self, canvas, data, axis, positioner)
示例#16
0
    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)