Beispiel #1
0
class Plus(T):
    """Draw a "+"-shaped tick mark. Attribute "fill-style" is ignored."""
    keys = pychart_util.union_dict(
        T.keys, {
            "line_style": (line_style.T, line_style.T(width=1),
                           "The line style of the tick mark.")
        })

    def draw(self, can, x, y):
        # move to the bottom-left corner
        can.line(self.line_style, x - self.size / 1.4, y, x + self.size / 1.4,
                 y)
        can.line(self.line_style, x, y - self.size / 1.4, x,
                 y + self.size / 1.4)
Beispiel #2
0
class X(T):
    """Draw a "X"-shaped tick mark. Attribute "fill-style" is ignored."""
    keys = pychart_util.union_dict(
        T.keys, {
            "line_style": (line_style.T, line_style.T(width=0.7),
                           "The line style of the tick mark")
        })

    def draw(self, can, x, y):
        # move to the bottom-left corner
        x = x - self.size / 2.0
        y = y - self.size / 2.0
        can.line(self.line_style, x, y, x + self.size, y + self.size)
        can.line(self.line_style, x + self.size, y, x, y + self.size)
Beispiel #3
0
class Star(T):
    """Draw a "*". Attribute "fill-style" is ignored."""
    keys = pychart_util.union_dict(
        T.keys, {
            "line_style": (line_style.T, line_style.T(width=1),
                           "The line style of the tick mark.")
        })

    def draw(self, can, x, y):
        # move to the bottom-left corner
        midx = x
        midy = y
        d_len = self.size / 2.0
        r_len = self.size * 1.414 / 2.0
        can.line(self.line_style, x - d_len, y - d_len, x + d_len, y + d_len)
        can.line(self.line_style, x + d_len, y - d_len, x - d_len, y + d_len)
        can.line(self.line_style, midx, y - r_len, midx, y + r_len)
        can.line(self.line_style, x - r_len, midy, x + r_len, midy)
Beispiel #4
0
class X(T):
    keys = pychart_util.union_dict(
        T.keys, {
            "draw_tics_above":
            (IntType, 0,
             "If true, tick lines and labels are drawn above the axis line.")
        })
    __doc__ = axis_doc.doc_x

    ##AUTOMATICALLY GENERATED

    ##END AUTOMATICALLY GENERATED
    def draw_below(self, ar, can):
        self.type_check()
        self.tic_interval = self.tic_interval or ar.x_grid_interval
        y_base = ar.loc[1] + self.offset

        can.line(self.line_style, ar.loc[0], y_base, ar.loc[0] + ar.size[0],
                 y_base)

        tic_dic = {}
        max_tic_height = 0

        for i in ar.x_tic_points(self.tic_interval):
            tic_dic[i] = 1
            ticx = ar.x_pos(i)

            str = "/hC" + pychart_util.apply_format(self.format, (i, ), 0)

            (total_height, base_height) = font.text_height(str)
            max_tic_height = max(max_tic_height, total_height)

            can.line(self.line_style, ticx, y_base, ticx,
                     y_base - self.tic_len)
            can.show(
                ticx + self.tic_label_offset[0],
                y_base - self.tic_len - base_height + self.tic_label_offset[1],
                str)

        if self.minor_tic_interval:
            for i in ar.x_tic_points(self.minor_tic_interval):
                if tic_dic.has_key(i):
                    # a major tic was drawn already.
                    pass
                else:
                    ticx = ar.x_pos(i)
                    can.line(self.line_style, ticx, y_base, ticx,
                             y_base - self.minor_tic_len)

        self.draw_label(ar, can, y_base - self.tic_len - max_tic_height - 10)

    def draw_above(self, ar, can):
        y_base = ar.loc[1] + self.offset

        tic_dic = {}
        max_tic_height = 0

        for i in ar.x_tic_points(self.tic_interval):
            tic_dic[i] = 1
            ticx = ar.x_pos(i)

            str = "/hC" + pychart_util.apply_format(self.format, (i, ), 0)

            (total_height, base_height) = font.text_height(str)
            max_tic_height = max(max_tic_height, total_height)

            can.line(self.line_style, ticx, y_base, ticx,
                     y_base + self.tic_len)
            can.show(
                ticx + self.tic_label_offset[0],
                y_base + self.tic_len + base_height + self.tic_label_offset[1],
                str)

        if self.minor_tic_interval:
            for i in ar.x_tic_points(self.minor_tic_interval):
                if tic_dic.has_key(i):
                    # a major tic was drawn already.
                    pass
                else:
                    ticx = ar.x_pos(i)
                    can.line(self.line_style, ticx, y_base, ticx,
                             y_base + self.minor_tic_len)
        self.draw_label(ar, can, y_base + self.tic_len + max_tic_height + 10)

    def draw_label(self, ar, can, ylabel):
        if self.label == None: return

        str = "/hC/vM" + self.label
        (label_height, base_height) = font.text_height(str)
        xlabel = ar.loc[0] + ar.size[0] / 2.0
        if self.label_offset[0] != None:
            xlabel += self.label_offset[0]
        if self.label_offset[1] != None:
            ylabel += self.label_offset[1]
        can.show(xlabel, ylabel, str)

    def draw(self, ar, can):
        self.type_check()
        self.tic_interval = self.tic_interval or ar.x_grid_interval
        y_base = ar.loc[1] + self.offset
        can.line(self.line_style, ar.loc[0], y_base, ar.loc[0] + ar.size[0],
                 y_base)
        if self.draw_tics_above:
            self.draw_above(ar, can)
        else:
            self.draw_below(ar, can)
Beispiel #5
0
class Y(T):
    __doc__ = axis_doc.doc_y
    keys = pychart_util.union_dict(
        T.keys, {
            "draw_tics_right":
            (IntType, 0,
             "If true, tick lines and labels are drawn right of the axis line."
             )
        })

    def draw_left(self, ar, can):
        x_base = ar.loc[0] + self.offset
        xmin = 999999
        tic_dic = {}
        for i in ar.y_tic_points(self.tic_interval):
            y_tic = ar.y_pos(i)
            tic_dic[i] = 1
            can.line(self.line_style, x_base, y_tic, x_base - self.tic_len,
                     y_tic)
            str = pychart_util.apply_format(self.format, (i, ), 0)
            if self.tic_len > 0: str = "/hR" + str

            tic_height, base_height = font.text_height(str)
            x = x_base - self.tic_len + self.tic_label_offset[0]
            can.show(x, y_tic - tic_height / 2.0 + self.tic_label_offset[1],
                     str)
            xmin = min(xmin, x - font.text_width(str))

        if self.minor_tic_interval:
            for i in ar.y_tic_points(self.minor_tic_interval):
                if tic_dic.has_key(i):
                    # a major tic line was drawn already.
                    pass
                else:
                    y_tic = ar.y_pos(i)
                    can.line(self.line_style, x_base, y_tic,
                             x_base - self.minor_tic_len, y_tic)

        self.draw_label(ar, can, xmin - theme.default_font_size / 2.0)

    def draw_right(self, ar, can):
        x_base = ar.loc[0] + self.offset
        xmax = 0
        tic_dic = {}
        for i in ar.y_tic_points(self.tic_interval):
            y_tic = ar.y_pos(i)
            tic_dic[i] = 1
            can.line(self.line_style, x_base, y_tic, x_base + self.tic_len,
                     y_tic)
            str = pychart_util.apply_format(self.format, (i, ), 0)
            if self.tic_len > 0: str = "/hL" + str

            tic_height, base_height = font.text_height(str)
            x = x_base + self.tic_len + self.tic_label_offset[0]
            can.show(x, y_tic - tic_height / 2.0 + self.tic_label_offset[1],
                     str)
            xmax = max(xmax, x + font.text_width(str))

        if self.minor_tic_interval:
            for i in ar.y_tic_points(self.minor_tic_interval):
                if tic_dic.has_key(i):
                    # a major tic line was drawn already.
                    pass
                else:
                    y_tic = ar.y_pos(i)
                    can.line(self.line_style, x_base, y_tic,
                             x_base + self.minor_tic_len, y_tic)

        self.draw_label(ar, can, xmax + theme.default_font_size)

    def draw_label(self, ar, can, xlabel):
        if self.label == None:
            return
        ylabel = ar.loc[1] + ar.size[1] / 2
        if self.label_offset[0] != None:
            xlabel += self.label_offset[0]
        if self.label_offset[1] != None:
            ylabel += self.label_offset[1]
        can.show(xlabel, ylabel, "/a90/hC" + self.label)

    def draw(self, ar, can):
        self.type_check()
        self.tic_interval = self.tic_interval or ar.y_grid_interval

        x_base = ar.loc[0] + self.offset
        can.line(self.line_style, x_base, ar.loc[1], x_base,
                 ar.loc[1] + ar.size[1])
        if self.draw_tics_right:
            self.draw_right(ar, can)
        else:
            self.draw_left(ar, can)
Beispiel #6
0
class X(T):
    keys = pychart_util.union_dict(
        T.keys, {
            "draw_tics_above":
            (IntType, 0,
             "If true, tick lines and labels are drawn above the axis line."),
            "x_list": (types.ListType, [], "x tic list")
        })
    __doc__ = axis_doc.doc_x

    ##AUTOMATICALLY GENERATED

    ##END AUTOMATICALLY GENERATED
    def draw_tics_and_labels(self, ar, can):
        #assert self.check_integrity()
        y_base = ar.loc[1] + self.offset
        self.tic_interval = self.tic_interval or ar.x_grid_interval

        can.line(self.line_style, ar.loc[0], y_base, ar.loc[0] + ar.size[0],
                 y_base)

        tic_dic = {}
        max_tic_height = 0
        if self.draw_tics_above:
            sign = 1
        else:
            sign = -1
        if self.x_list:
            tic_list = self.x_list
        else:
            tic_list = ar.x_tic_points(self.tic_interval)
        for i in tic_list:
            tic_dic[i] = 1
            ticx = ar.x_pos(i)

            string = "/hC" + pychart_util.apply_format(self.format, (i, ), 0)

            (total_height, base_height) = font.text_height(string)
            max_tic_height = max(max_tic_height, total_height)
            if self.draw_tics_above:
                base_height = 0

            can.line(self.line_style, ticx, y_base, ticx,
                     y_base + sign * self.tic_len)
            can.show(
                ticx + self.tic_label_offset[0], y_base + sign *
                (self.tic_len + base_height) + self.tic_label_offset[1],
                string)

        if self.minor_tic_interval:
            for i in ar.x_tic_points(self.minor_tic_interval):
                if tic_dic.has_key(i):
                    # a major tic was drawn already.
                    pass
                else:
                    ticx = ar.x_pos(i)
                    can.line(self.line_style, ticx, y_base, ticx,
                             y_base + sign * self.minor_tic_len)

        self.draw_label(ar, can,
                        (y_base + sign * (self.tic_len + max_tic_height + 10)))

    def draw_label(self, ar, can, ylabel):
        if self.label == None: return

        string = "/hC/vM" + self.label
        (label_height, base_height) = font.text_height(string)
        xlabel = ar.loc[0] + ar.size[0] / 2.0
        if self.label_offset[0] != None:
            xlabel += self.label_offset[0]
        if self.label_offset[1] != None:
            ylabel += self.label_offset[1]
        can.show(xlabel, ylabel, string)

    def draw(self, ar, can):
        assert self.check_integrity()
        self.tic_interval = self.tic_interval or ar.x_grid_interval
        y_base = ar.loc[1] + self.offset
        can.line(self.line_style, ar.loc[0], y_base, ar.loc[0] + ar.size[0],
                 y_base)
        self.draw_tics_and_labels(ar, can)