Exemple #1
0
 def rateticks(self, axis, ticks, density):
     """rates ticks by the number of ticks, subticks, labels etc.
     - takes into account the number of ticks, subticks, labels
       etc. and the coverage of the axis range by the ticks
     - when there are no ticks of a level or there was not rater
       given in the constructor for a level, the level is just
       ignored
     - the method returns the sum of the rating results divided
       by the sum of the weights of the raters
     - within the rating, all ticks with a higher level are
       considered as ticks for a given level"""
     maxticklevel, maxlabellevel = tick.maxlevels(ticks)
     numticks = [0]*maxticklevel
     numlabels = [0]*maxlabellevel
     for t in ticks:
         if t.ticklevel is not None:
             for level in range(t.ticklevel, maxticklevel):
                 numticks[level] += 1
         if t.labellevel is not None:
             for level in range(t.labellevel, maxlabellevel):
                 numlabels[level] += 1
     rate = 0
     weight = 0
     for numtick, rater in zip(numticks, self.ticks):
         rate += rater.rate(numtick, density)
         weight += rater.weight
     for numlabel, rater in zip(numlabels, self.labels):
         rate += rater.rate(numlabel, density)
         weight += rater.weight
     return rate/weight
Exemple #2
0
 def rateticks(self, axis, ticks, density):
     """rates ticks by the number of ticks, subticks, labels etc.
     - takes into account the number of ticks, subticks, labels
       etc. and the coverage of the axis range by the ticks
     - when there are no ticks of a level or there was not rater
       given in the constructor for a level, the level is just
       ignored
     - the method returns the sum of the rating results divided
       by the sum of the weights of the raters
     - within the rating, all ticks with a higher level are
       considered as ticks for a given level"""
     maxticklevel, maxlabellevel = tick.maxlevels(ticks)
     numticks = [0] * maxticklevel
     numlabels = [0] * maxlabellevel
     for t in ticks:
         if t.ticklevel is not None:
             for level in range(t.ticklevel, maxticklevel):
                 numticks[level] += 1
         if t.labellevel is not None:
             for level in range(t.labellevel, maxlabellevel):
                 numlabels[level] += 1
     rate = 0
     weight = 0
     for numtick, rater in zip(numticks, self.ticks):
         rate += rater.rate(numtick, density)
         weight += rater.weight
     for numlabel, rater in zip(numlabels, self.labels):
         rate += rater.rate(numlabel, density)
         weight += rater.weight
     return rate / weight
Exemple #3
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.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)
Exemple #4
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)