コード例 #1
0
def init():
    global line_style_itr
    line_styles = object_set.T()
    for org_style in line_style.standards.objs:
        style = line_style.T(width = default_width, color = org_style.color,
                             dash = org_style.dash)
        line_styles.add(style)

    line_style_itr = line_styles.iterate()
コード例 #2
0
    def draw(self, ar, can):
        center = self.center
        if not center:
            center = (ar.loc[0] + ar.size[0]/2.0,
                            ar.loc[1] + ar.size[1]/2.0)
        base_radius = self.base_radius # the maximum radius of a wedge
        if not base_radius:
            base_radius = min(ar.size[0]/2.0, ar.size[1]/2.0) #* 0.8

        sector_decrement = 1./(len(self.data)*2) * self.sector_width # each following sector diagram will have its sector width decremented by half this amount (in degrees)
        i = 0
        for dataset in self.data:
            cur_angle = self.start_angle
            if self.sector_centred:
                cur_angle -= self.sector_width/2.
            fill = self.fill_styles[i]
            x_center = center[0]
            y_center = center[1]

            if not i: # draw directions around sector diagram once off
                dir_offset = base_radius + (self.dir_offset or base_radius * 0.04)
                directions = ['N', 'E', 'S', 'W']
                angle = self.start_angle

                can.ellipsis(line_style.T(color=color.black, width=0.3, dash=line_style.dash1), None,
                             x_center, y_center, base_radius, 1,
                             0, 360) #

                for d in directions:
                    x_label, y_label = pychart_util.rotate(dir_offset, 0, angle) # coords for bottom left corner of box
                    tw = font.text_width(d)
                    half = 1/3. # normal arithmetic does not seem to apply to these text_box objects...
                    if (angle == 0): # east
                        y_label -= font.text_height(d)[0]*half # move down half
                    elif (angle == -180): # west
                        y_label -= font.text_height(d)[0]*half # move down half
                        x_label -= font.text_width(d) # move left full
                    elif (angle == 90): # north
                        x_label -= font.text_height(d)[0]*half # move left half
                    elif (angle == -90): # south
                        y_label -= font.text_height(d)[0]*.8 # move down (couldn't figure out how to set this dynamically so I fudged...)
                        x_label -= font.text_height(d)[0]*half # move left half
                    canvas.show(x_label + x_center, y_label + y_center, d)
                    angle -= 360/len(directions)

            for val in dataset[self.data_col]: # now draw the sectors
                radius = base_radius*val # scale the radius
                start = cur_angle-self.sector_width+i*sector_decrement
                stop = cur_angle-i*sector_decrement # these may seem confusing, but remember that we need to go counterclockwise

                can.ellipsis(self.line_style, fill,
                             x_center, y_center, radius, 1, start, stop, self.shadow) 
                cur_angle = (cur_angle - self.sector_width) % 360 # we want to go in anticlockwise direction (North, West, South, etc. as in meteorology)
            i = (i + 1) % len(self.fill_styles)
コード例 #3
0
ファイル: tick_mark.py プロジェクト: glosoftgroup/odoo-sample
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)
コード例 #4
0
ファイル: tick_mark.py プロジェクト: glosoftgroup/odoo-sample
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)
コード例 #5
0
ファイル: tick_mark.py プロジェクト: glosoftgroup/odoo-sample
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)
コード例 #6
0
class error_bar6(T):
    __doc__ = error_bar_doc.doc_6
    keys = {
        "line_style": (line_style.T, line_style.default, ""),
        "fill_style": (fill_style.T, fill_style.gray70, ""),
        "center_line_style": (line_style.T, line_style.T(width=0.5), ""),
        "box_width": (UnitType, 4, ""),
    }

    ##AUTOMATICALLY GENERATED

    ##END AUTOMATICALLY GENERATED
    def draw(self, can, loc, min, max, qmin=None, qmax=None):
        x = loc[0]
        y = loc[1]

        can.rectangle(self.line_style, self.fill_style,
                      x - self.box_width / 2.0, min, x + self.box_width / 2.0,
                      max)
        can.line(self.center_line_style, x - self.box_width / 2.0,
                 (min + max) / 2.0, x + self.box_width / 2.0,
                 (min + max) / 2.0)
コード例 #7
0

def _intern(a):
    global standards
    standards.add(a)
    return a


a0 = _intern(T(head_style=0))
a1 = _intern(T(head_style=1))
a2 = _intern(T(head_style=2))
a3 = _intern(T(head_style=3))
gray0 = _intern(
    T(head_style=0,
      head_color=color.gray50,
      line_style=line_style.T(color=color.gray50)))
gray1 = _intern(
    T(head_style=1,
      head_color=color.gray50,
      line_style=line_style.T(color=color.gray50)))
gray2 = _intern(
    T(head_style=2,
      head_color=color.gray50,
      line_style=line_style.T(color=color.gray50)))
gray3 = _intern(
    T(head_style=3,
      head_color=color.gray50,
      line_style=line_style.T(color=color.gray50)))

fat0 = _intern(
    T(head_style=0,
コード例 #8
0
ファイル: fill_style.py プロジェクト: luke202001/tpch-kit
    return style


def __intern_grayscale(style):
    global color_standards, gray_standards
    gray_standards.add(style)
    return style


#black = __intern_both(Plain(bgcolor=color.gray_scale(0.0), line_style=None))

#
# Fill styles for grayscale charts.
#
gray70 = __intern_grayscale(Plain(bgcolor=color.gray70, line_style=None))
diag = __intern_grayscale(Diag(line_style=line_style.T(cap_style=2)))
gray30 = __intern_grayscale(Plain(bgcolor=color.gray30, line_style=None))
rdiag = __intern_grayscale(Rdiag(line_style=line_style.T(cap_style=2)))
gray10 = __intern_grayscale(Plain(bgcolor=color.gray10, line_style=None))
diag2 = __intern_grayscale(
    Diag(line_style=line_style.T(width=3, cap_style=2), line_interval=6))
white = __intern_grayscale(
    Plain(bgcolor=color.gray_scale(1.0), line_style=None))
rdiag2 = __intern_grayscale(
    Rdiag(line_style=line_style.T(width=3, cap_style=2), line_interval=6))
vert = __intern_grayscale(Vert())
diag3 = __intern_grayscale(
    Diag(line_style=line_style.T(width=3, color=color.gray50, cap_style=2),
         line_interval=6))
gray50 = __intern_grayscale(Plain(bgcolor=color.gray50, line_style=None))
horiz = __intern_grayscale(Horiz())
コード例 #9
0
def _intern_grayscale(style):
    global color_standards, grayscale_standards    
    grayscale_standards.add(style)
    return style

black = _intern_both(Plain(bgcolor=color.gray_scale(0.0), line_style=None))

red = _intern_color(Plain(bgcolor=color.red))
darkseagreen = _intern_color(Plain(bgcolor=color.darkseagreen))
blue = _intern_color(Plain(bgcolor=color.blue))
aquamarine1 = _intern_color(Plain(bgcolor=color.aquamarine1))
gray70 = _intern_both(Plain(bgcolor=color.gray70, line_style=None))
brown = _intern_color(Plain(bgcolor=color.brown))
darkorchid = _intern_color(Plain(bgcolor=color.darkorchid))    
diag = _intern_both(Diag(line_style=line_style.T(cap_style=2)))
green = _intern_color(Plain(bgcolor=color.green))
gray50 = _intern_both(Plain(bgcolor=color.gray50, line_style=None))
white = _intern_both(Plain(bgcolor=color.gray_scale(1.0), line_style=None))
goldenrod = _intern_color(Plain(bgcolor=color.goldenrod))
rdiag = _intern_both(Rdiag(line_style=line_style.T(cap_style=2)))
vert = _intern_both(Vert(line_interval=1.8))

gray30 = _intern_both(Plain(bgcolor=color.gray30, line_style=None))
gray20 = _intern_both(Plain(bgcolor=color.gray20, line_style=None))
gray10 = _intern_both(Plain(bgcolor=color.gray10, line_style=None))
diag2 = _intern_both(Diag(line_style=line_style.T(width=3, cap_style=2),
                      line_interval=6))
rdiag2 = _intern_both(Rdiag(line_style=line_style.T(width=3, cap_style=2),
                        line_interval=6))
yellow = _intern_color(Plain(bgcolor=color.yellow))
コード例 #10
0
ファイル: rose_plot.py プロジェクト: glosoftgroup/odoo-sample
class T(chart_object.T):
    """Plots sector diagram which can be superimposed on one another.
    Sector diagrams are also known as wind roses"""
    keys = {
        "start_angle": (NumberType, 90, ""),  # top of chart (north)
        "center": (CoordType, None, ""),
        "base_radius": (NumberType, None, ""),
        "line_style": (line_style.T, line_style.T(color=color.black,
                                                  width=0.3), ""),
        "fill_styles": (list, fill_style.standards.list()[:],
                        """The fill style of each item. The length of the
                         list should be equal to the length of the data.
                         """),
        "sector_centred":
        (int, 1,
         """Bool indicating whether the sectors should be centred on each sector_width(e.g. on 0)"""
         ),
        "dir_offset":
        (UnitType, None,
         """The distance between the directions and the outermost circle. Defaults fine for most cases"""
         ),
        "data": (AnyType, None, pychart_util.data_desc),
        "label_col":
        (int, 0,
         """The column, within "data", from which the labels of items are retrieved."""
         ),
        "data_col":
        (int, 1,
         """ The column, within "data", from which the data values are retrieved."""
         ),
        "dir_line_style": (line_style.T, None, ""),
        "dir_fill_style": (fill_style.T, fill_style.default, ""),
        "shadow": (ShadowType, None, pychart_util.shadow_desc),
        "sector_width": (int, None, ""),  # automatically generated
    }

    def __init__(self, colour=True, **args):
        chart_object.T.init(self, args)
        if colour:
            # the theme.color flag does not seem to affect the fill_style.standards,
            #besides, I want the first two colors to resemble those of gnuplot's postscript terminal
            self.fill_styles = [
                fill_style.Plain(bgcolor=color.red),
                fill_style.Plain(bgcolor=color.green),
                fill_style.Plain(bgcolor=color.blue),
                fill_style.Plain(bgcolor=color.magenta)
            ]

    def check_integrity(self):
        nSectors = len(self.data[0][self.data_col])
        if (360 % nSectors != 0):
            raise Exception('Length of dataset ' + str(nSectors) +
                            ' not a divisor of 360 degrees!')
        for dataset in self.data:
            length = len(dataset[self.data_col])
            if length != nSectors:
                raise Exception('Lengths of datasets given is different!')
            for val in dataset[self.data_col]:
                if (val < 0) | (val > 1):
                    raise Exception('Data value ' + str(val) +
                                    ' not between 0 and 1!')
        self.sector_width = 360 / nSectors
        chart_object.T.check_integrity(self)

    def get_data_range(self, which):
        return (0, 1)

    def get_legend_entry(self):
        legends = []
        i = 0
        for dataset in self.data:
            fill = self.fill_styles[i]
            i = (i + 1) % len(self.fill_styles)
            legends.append(
                legend.Entry(line_style=self.line_style,
                             fill_style=fill,
                             label=dataset[self.label_col]))
        return legends

    def draw(self, ar, can):
        center = self.center
        if not center:
            center = (ar.loc[0] + ar.size[0] / 2.0,
                      ar.loc[1] + ar.size[1] / 2.0)
        base_radius = self.base_radius  # the maximum radius of a wedge
        if not base_radius:
            base_radius = min(ar.size[0] / 2.0, ar.size[1] / 2.0)  #* 0.8

        sector_decrement = 1. / (
            len(self.data) * 2
        ) * self.sector_width  # each following sector diagram will have its sector width decremented by half this amount (in degrees)
        i = 0
        for dataset in self.data:
            cur_angle = self.start_angle
            if self.sector_centred:
                cur_angle -= self.sector_width / 2.
            fill = self.fill_styles[i]
            x_center = center[0]
            y_center = center[1]

            if not i:  # draw directions around sector diagram once off
                dir_offset = base_radius + (self.dir_offset
                                            or base_radius * 0.04)
                directions = ['N', 'E', 'S', 'W']
                angle = self.start_angle

                can.ellipsis(
                    line_style.T(color=color.black,
                                 width=0.3,
                                 dash=line_style.dash1), None, x_center,
                    y_center, base_radius, 1, 0, 360)  #

                for d in directions:
                    x_label, y_label = pychart_util.rotate(
                        dir_offset, 0,
                        angle)  # coords for bottom left corner of box
                    tw = font.text_width(d)
                    half = 1 / 3.  # normal arithmetic does not seem to apply to these text_box objects...
                    if (angle == 0):  # east
                        y_label -= font.text_height(
                            d)[0] * half  # move down half
                    elif (angle == -180):  # west
                        y_label -= font.text_height(
                            d)[0] * half  # move down half
                        x_label -= font.text_width(d)  # move left full
                    elif (angle == 90):  # north
                        x_label -= font.text_height(
                            d)[0] * half  # move left half
                    elif (angle == -90):  # south
                        y_label -= font.text_height(
                            d
                        )[0] * .8  # move down (couldn't figure out how to set this dynamically so I fudged...)
                        x_label -= font.text_height(
                            d)[0] * half  # move left half
                    canvas.show(x_label + x_center, y_label + y_center, d)
                    angle -= 360 / len(directions)

            for val in dataset[self.data_col]:  # now draw the sectors
                radius = base_radius * val  # scale the radius
                start = cur_angle - self.sector_width + i * sector_decrement
                stop = cur_angle - i * sector_decrement  # these may seem confusing, but remember that we need to go counterclockwise

                can.ellipsis(self.line_style, fill, x_center, y_center, radius,
                             1, start, stop, self.shadow)
                cur_angle = (
                    cur_angle - self.sector_width
                ) % 360  # we want to go in anticlockwise direction (North, West, South, etc. as in meteorology)
            i = (i + 1) % len(self.fill_styles)