Esempio n. 1
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)
Esempio n. 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)
Esempio n. 3
0
    def draw(self, ar):

        # Draw the line
        canvas.clip(ar.loc[0], ar.loc[1],
                ar.loc[0] + ar.size[0],
                ar.loc[1] + ar.size[1])
        if self.line_style:
            points = []
            for pair in self.data:
                points.append((ar.x_pos(pair[self.xcol]), ar.y_pos(pair[self.ycol])))
            canvas.lines(self.line_style, points)
        canvas.endclip()
        
        # Draw tick marks and error bars
        canvas.clip(ar.loc[0] - 10, ar.loc[1] - 10,
                ar.loc[0] + ar.size[0] + 10,
                ar.loc[1] + ar.size[1] + 10)
        for pair in self.data:
            x = pair[self.xcol]
            y = pair[self.ycol]
            x_pos = ar.x_pos(x)
            y_pos = ar.y_pos(y)

            if self.error_bar:
                plus = pair[self.y_error_plus_col or self.y_error_minus_col]
                minus = pair[self.y_error_minus_col or self.y_error_plus_col]
                if self.y_qerror_minus_col or self.y_qerror_plus_col:
                    q_plus = pair[self.y_qerror_minus_col or self.y_qerror_plus_col]
                    q_minus = pair[self.y_qerror_plus_col or self.y_qerror_minus_col]
                    self.error_bar.draw((x_pos, y_pos),
                                       ar.y_pos(y - minus),
                                       ar.y_pos(y + plus),
                                       ar.y_pos(y - q_minus),
                                       ar.y_pos(y + q_plus))
                else:
                    self.error_bar.draw((x_pos, y_pos),
                                        ar.y_pos(y - minus),
                                        ar.y_pos(y + plus))
                    
            if self.tick_mark:
                self.tick_mark.draw(x_pos, y_pos)
            if self.data_label_format:
                canvas.show(x_pos + self.data_label_offset[0],
                            y_pos + self.data_label_offset[1],
                            "/hC" + pychart_util.apply_format(self.data_label_format, (x, y), 1))

        canvas.endclip()
Esempio n. 4
0
   def draw(self, ar):
      self.type_check()
      self.tic_interval = self.tic_interval or ar.y_grid_interval
      x_base = ar.loc[0] + self.offset

      canvas.line(self.line_style, x_base, ar.loc[1],
                  x_base, ar.loc[1]+ar.size[1])
      
      xmin = x_base + ar.size[0] # somebigvalue
      tic_dic = {}
      for i in ar.y_tic_points(self.tic_interval):
         y_tic = ar.y_pos(i)
         tic_dic[i] = 1
         canvas.line(self.line_style, x_base, y_tic,
                     x_base - self.tic_len, y_tic)
         tic_label = pychart_util.apply_format(self.format, (i,), 0)
         x = x_base - self.tic_len + self.tic_label_offset[0]
         if self.tic_len > 0:
            tic_label = "/hR" + tic_label
            
         tic_height, base_height = font.text_height(tic_label)
         canvas.show(x, y_tic - tic_height/2.0 + self.tic_label_offset[1],
		     tic_label)
         xmin = min(xmin, x - font.text_width(tic_label))
      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 was drawn already.
               pass
            else:
               y_tic = ar.y_pos(i)
               canvas.line(self.line_style, x_base, y_tic,
                           x_base - self.minor_tic_len, y_tic)
               
      if self.label != None:
         xlabel = xmin - theme.default_font_size/2.0
         ylabel = ar.loc[1] + ar.size[1] / 2
         if self.label_offset[0] != None:
            xlabel = xlabel + self.label_offset[0]
         if self.label_offset[1] != None:
            ylabel = ylabel + self.label_offset[1]
         canvas.show(xlabel, ylabel, "/a90/hC" + self.label)
Esempio n. 5
0
    def draw(self, ar):
        self.type_check()
        self.tic_interval = self.tic_interval or ar.y_grid_interval
        x_base = ar.loc[0] + self.offset

        canvas.line(self.line_style, x_base, ar.loc[1], x_base,
                    ar.loc[1] + ar.size[1])

        xmin = x_base + ar.size[0]  # somebigvalue
        tic_dic = {}
        for i in ar.y_tic_points(self.tic_interval):
            y_tic = ar.y_pos(i)
            tic_dic[i] = 1
            canvas.line(self.line_style, x_base, y_tic, x_base - self.tic_len,
                        y_tic)
            tic_label = pychart_util.apply_format(self.format, (i, ), 0)
            x = x_base - self.tic_len + self.tic_label_offset[0]
            if self.tic_len > 0:
                tic_label = "/hR" + tic_label

            tic_height, base_height = font.text_height(tic_label)
            canvas.show(x, y_tic - tic_height / 2.0 + self.tic_label_offset[1],
                        tic_label)
            xmin = min(xmin, x - font.text_width(tic_label))
        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 was drawn already.
                    pass
                else:
                    y_tic = ar.y_pos(i)
                    canvas.line(self.line_style, x_base, y_tic,
                                x_base - self.minor_tic_len, y_tic)

        if self.label != None:
            xlabel = xmin - theme.default_font_size / 2.0
            ylabel = ar.loc[1] + ar.size[1] / 2
            if self.label_offset[0] != None:
                xlabel = xlabel + self.label_offset[0]
            if self.label_offset[1] != None:
                ylabel = ylabel + self.label_offset[1]
            canvas.show(xlabel, ylabel, "/a90/hC" + self.label)
Esempio n. 6
0
    def draw(self, ar, x_tick, x_label, y):
        """Draw a legend entry. X_TICK and X_LABEL are the X location \
        (in points) of where the sample and label are drawn."""

        nr_lines = len(string.split(self.label, "\n"))
        text_height = font.text_height(self.label)[0]
        line_height = text_height / float(nr_lines)
        y_center = y + text_height - line_height / 1.5

        if self.fill_style != None:
            canvas.rectangle(self.line_style, self.fill_style, x_tick,
                             y_center - self.rect_size / 2.0,
                             x_tick + self.rect_size,
                             y_center + self.rect_size / 2.0)
        elif self.line_style != None:
            canvas.line(self.line_style, x_tick, y_center,
                        x_tick + self.line_len, y_center)
            if self.tick_mark != None:
                self.tick_mark.draw(x_tick + self.line_len / 2.0, y_center)
        elif self.tick_mark != None:
            self.tick_mark.draw(x_tick, y_center)

        canvas.show(x_label, y, self.label)
Esempio n. 7
0
 def draw(self, ar, x_tick, x_label, y):
     """Draw a legend entry. X_TICK and X_LABEL are the X location \
     (in points) of where the sample and label are drawn."""
     
     nr_lines = len(string.split(self.label, "\n"))
     text_height = font.text_height(self.label)[0]
     line_height = text_height / float(nr_lines)
     y_center = y + text_height - line_height/1.5
         
     if self.fill_style != None:
         canvas.rectangle(self.line_style, self.fill_style,
                          x_tick, y_center - self.rect_size/2.0,
                          x_tick + self.rect_size,
                          y_center + self.rect_size/2.0)
     elif self.line_style != None:
         canvas.line(self.line_style, x_tick, y_center,
                     x_tick + self.line_len, y_center)
         if self.tick_mark != None:
             self.tick_mark.draw(x_tick + self.line_len/2.0, y_center)
     elif self.tick_mark != None:
         self.tick_mark.draw(x_tick, y_center)
         
     canvas.show(x_label, y, self.label)
Esempio n. 8
0
    def draw_vertical(self, ar):
        for pair in self.data:
            xval = pair[self.bcol]
            yval = pair[self.hcol]

            ybot = 0
            if self.stack_on:
                ybot = self.stack_on.get_value(xval)
                yval = yval + ybot

            totalWidth = (self.width+self.cluster_sep) * self.cluster[1] - self.cluster_sep
            firstX = ar.x_pos(xval) - totalWidth/2.0
            thisX = firstX + (self.width+self.cluster_sep) * self.cluster[0] - self.cluster_sep

            canvas.rectangle(self.line_style, self.fill_style,
                             thisX, ar.y_pos(ybot), thisX+self.width, 
                             ar.y_pos(yval))

            if self.error_bar:
                plus = pair[self.error_minus_col or self.error_plus_col]
                minus = pair[self.error_plus_col or self.error_minus_col]
                qplus = 0
                qminus = 0
                if self.qerror_minus_col or self.qerror_plus_col:
                    qplus = pair[self.qerror_minus_col or self.qerror_plus_col]
                    qminus = pair[self.qerror_plus_col or self.qerror_minus_col]
                self.error_bar.draw((thisX+self.width/2.0, ar.y_pos(yval)),
                                    ar.y_pos(yval - qminus),
                                    ar.y_pos(yval + qplus),
                                    ar.y_pos(yval - minus),
                                    ar.y_pos(yval + plus))
                    
            if self.data_label_format:
                canvas.show(thisX + self.width/2.0 + self.data_label_offset[0],
                            ar.y_pos(yval) + self.data_label_offset[1],
                            "/hC" + pychart_util.apply_format(self.data_label_format, (pair[self.bcol], pair[self.hcol]), 1))
Esempio n. 9
0
    def draw(self):
        x = self.loc[0]
        y = self.loc[1]
        text_width = font.text_width(self.text)
        text_height = font.text_height(self.text)[0]
        (halign, valign, angle) = font.get_align(self.text)

        if self.line_style or self.fill_style:
            width = text_width + self.left_fudge + self.right_fudge
            height = text_height + self.bottom_fudge + self.top_fudge
            canvas.round_rectangle(self.line_style, self.fill_style,
                                   x - self.left_fudge, y - self.bottom_fudge,
                                   x - self.left_fudge + width,
                                   y - self.bottom_fudge + height, self.radius,
                                   self.shadow)

        if halign == 'L':
            canvas.show(x, y, self.text)
        elif halign == 'C':
            canvas.show(x + text_width / 2.0, y, self.text)
        elif halign == 'R':
            canvas.show(x + text_width, y, self.text)
        else:
            raise Exception, "Unsupported alignment (" + halign + ")"

        # draw arrows
        for t in self.arrows:
            (tipLoc, tail, arrow) = t
            if tail:
                (x, y, width, height) = self.get_dimension()
                origin = [x, y]
                for ch in tail:
                    if ch == 'l':
                        origin[0] = x
                    elif ch == 'c':
                        origin[0] = x + width / 2.0
                    elif ch == 'r':
                        origin[0] = x + width
                    elif ch == 'b':
                        origin[1] = y
                    elif ch == 'm':
                        origin[1] = y + height / 2.0
                    elif ch == 't':
                        origin[1] = y + height
                    else:
                        raise ValueError, tail + ": unknown tail location spec."
            else:
                origin = self.choose_end_point(tipLoc[0], tipLoc[1])

            arrow.draw((origin, tipLoc))
Esempio n. 10
0
    def draw(self):
        x = self.loc[0]
        y = self.loc[1]
        text_width = font.text_width(self.text)
        text_height = font.text_height(self.text)[0]
        (halign, valign, angle) = font.get_align(self.text)
        
        if self.line_style or self.fill_style:
            width = text_width+self.left_fudge+self.right_fudge
            height = text_height+self.bottom_fudge+self.top_fudge
            canvas.round_rectangle(self.line_style, self.fill_style,
                                   x-self.left_fudge, y-self.bottom_fudge,
                                   x-self.left_fudge+width, y-self.bottom_fudge+height,
                                   self.radius, self.shadow)

        if halign == 'L':
            canvas.show(x, y, self.text)
        elif halign == 'C':
            canvas.show(x+text_width/2.0, y, self.text)
        elif halign == 'R':
            canvas.show(x+text_width, y, self.text)
        else:
            raise Exception, "Unsupported alignment (" + halign + ")"

        # draw arrows
        for t in self.arrows:
            (tipLoc, tail, arrow) = t
            if tail:
                (x, y, width, height) = self.get_dimension()
                origin = [x, y]
                for ch in tail:
                    if ch == 'l':
                        origin[0] = x
                    elif ch == 'c':
                        origin[0] = x+width/2.0
                    elif ch == 'r':
                        origin[0] = x+width
                    elif ch == 'b':
                        origin[1] = y
                    elif ch == 'm':
                        origin[1] = y+height/2.0
                    elif ch == 't':
                        origin[1] = y+height
                    else:
                        raise ValueError, tail +  ": unknown tail location spec."
            else:
                origin = self.choose_end_point(tipLoc[0], tipLoc[1])
                
            arrow.draw((origin, tipLoc))
Esempio n. 11
0
File: train.py Progetto: reusee/ILTE
def main():
  app = QApplication(sys.argv)
  canvas = Canvas()
  canvas.show()
  sys.exit(app.exec_())
Esempio n. 12
0
    def draw(self, ar):
        self.type_check()
        self.tic_interval = self.tic_interval or ar.x_grid_interval
        y_base = ar.loc[1] + self.offset
      
        canvas.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)

            canvas.line(self.line_style, ticx, y_base, ticx, y_base-self.tic_len)
            canvas.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)
                    canvas.line(self.line_style, ticx, y_base, ticx,
                                y_base-self.minor_tic_len)

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

        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)

            canvas.line(self.line_style, ticx, y_base, ticx, y_base-self.tic_len)
            canvas.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)
                    canvas.line(self.line_style, ticx, y_base, ticx,
                                y_base-self.minor_tic_len)

        if self.label != None:
            str = "/hC/vM" + self.label
            (label_height, base_height) = font.text_height(str)
            if self.label_offset[0] != None:
                xlabel = ar.loc[0] + self.label_offset[0]
            else:
                xlabel = ar.loc[0] + ar.size[0]/2.0
            if self.label_offset[1] != None:
                ylabel = y_base + self.label_offset[1]
            else:
                ylabel = y_base - self.tic_len - max_tic_height - 10
            canvas.show(xlabel, ylabel, str)
Esempio n. 13
0
    def draw(self, ar):
        self.type_check()
        self.tic_interval = self.tic_interval or ar.x_grid_interval
        y_base = ar.loc[1] + self.offset

        canvas.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)

            canvas.line(self.line_style, ticx, y_base, ticx,
                        y_base - self.tic_len)
            canvas.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)
                    canvas.line(self.line_style, ticx, y_base, ticx,
                                y_base - self.minor_tic_len)

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

        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)

            canvas.line(self.line_style, ticx, y_base, ticx,
                        y_base - self.tic_len)
            canvas.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)
                    canvas.line(self.line_style, ticx, y_base, ticx,
                                y_base - self.minor_tic_len)

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