예제 #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)
예제 #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
    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)
예제 #4
0
    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)
예제 #5
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)
예제 #6
0
    def draw(self, ar, can, 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."""

        rect_size = self.get_rect_size()
        line_len = self.get_line_len()
        
        nr_lines = len(self.label.split("\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:
            can.rectangle(self.line_style, self.fill_style,
                             x_tick, y_center - rect_size/2.0,
                             x_tick + rect_size,
                             y_center + rect_size/2.0)
        elif self.line_style != None:
            can.line(self.line_style, x_tick, y_center,
                     x_tick + line_len, y_center)
            if self.tick_mark != None:
                self.tick_mark.draw(can, x_tick + line_len/2.0, y_center)
        elif self.tick_mark != None:
            self.tick_mark.draw(can, x_tick, y_center)
            
        can.show(x_label, y, self.label)
예제 #7
0
파일: axis.py 프로젝트: Scemoon/lpts
    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)
            string = pychart_util.apply_format(self.format, (i,), 0)
            if self.tic_len > 0: string = "/hL" + string

            tic_height, base_height = font.text_height(string)
            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],
                     string)
            xmax = max(xmax, x + font.text_width(string))
            
        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)
예제 #8
0
 def get_dimension(self):
     x = self.loc[0] - self.left_fudge
     y = self.loc[1] - self.bottom_fudge
     width = font.text_width(self.text) + self.right_fudge + self.left_fudge
     height = (font.text_height(
         self.text))[0] + self.top_fudge + self.bottom_fudge
     return (x, y, width, height)
예제 #9
0
    def draw(self, ar, can, 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."""

        rect_size = self.get_rect_size()
        line_len = self.get_line_len()

        nr_lines = len(self.label.split("\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:
            can.rectangle(self.line_style, self.fill_style, x_tick,
                          y_center - rect_size / 2.0, x_tick + rect_size,
                          y_center + rect_size / 2.0)
        elif self.line_style != None:
            can.line(self.line_style, x_tick, y_center, x_tick + line_len,
                     y_center)
            if self.tick_mark != None:
                self.tick_mark.draw(can, x_tick + line_len / 2.0, y_center)
        elif self.tick_mark != None:
            self.tick_mark.draw(can, x_tick, y_center)

        can.show(x_label, y, self.label)
예제 #10
0
    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)
예제 #11
0
파일: axis.py 프로젝트: Scemoon/lpts
 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)
예제 #12
0
    def draw(self, can=None):
        if can == None:
            can = canvas.default_canvas()
        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
            can.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':
            can.show(x, y, self.text)
        elif halign == 'C':
            can.show(x + text_width / 2.0, y, self.text)
        elif halign == 'R':
            can.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), can)
예제 #13
0
    def draw(self, can = None):
        if can == None:
            can = canvas.default_canvas()
        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
            can.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':
            can.show(x, y, self.text)
        elif halign == 'C':
            can.show(x+text_width/2.0, y, self.text)
        elif halign == 'R':
            can.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), can)
예제 #14
0
파일: axis.py 프로젝트: zhyh329/lpts
    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)))
예제 #15
0
파일: axis.py 프로젝트: Scemoon/lpts
    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)))
예제 #16
0
파일: axis.py 프로젝트: luke202001/tpch-kit
    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)
예제 #17
0
파일: axis.py 프로젝트: BasilN/LED_Project
   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)
예제 #18
0
 def height(self):
     h = font.text_height(self.label)[0]
     return h
예제 #19
0
 def get_dimension(self):
     x = self.loc[0] - self.left_fudge
     y = self.loc[1] - self.bottom_fudge
     width = font.text_width(self.text) + self.right_fudge + self.left_fudge
     height = (font.text_height(self.text))[0] + self.top_fudge + self.bottom_fudge
     return (x, y, width, height)
예제 #20
0
파일: text_box.py 프로젝트: luowy/xtc
    def draw(self, can = None):
        if can == None:
            can = canvas.default_canvas()
        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:
            if self.callout == False:
                width = text_width+self.left_fudge+self.right_fudge
                height = text_height+self.bottom_fudge+self.top_fudge
                can.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)
            else:
                width = text_width+self.left_fudge+self.right_fudge
                height = text_height+self.bottom_fudge+self.top_fudge

                cx = x + self.callout_shift
                cy = y
                csize = self.callout_size

                x1 = x-self.left_fudge
                y1 = y-self.bottom_fudge
                x2 = x-self.left_fudge+width
                y2 = y-self.bottom_fudge+height

                p0 = (cx,y1-csize)
                p1 = (cx-csize,y1)
                p2 = (cx+csize,y1)

                px0,py0 = p0
                px1,py1 = p1
                px2,py2 = p2

                can.polygon(None, self.fill_style,
                            [p0, p1, p2])

                can.line(self.line_style, px0, py0, px1, py1)
                can.line(self.line_style, px0, py0, px2, py2)

                can.round_rectangle(None, 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)

                can.line(self.line_style, x2, y1, x2, y2)
                can.line(self.line_style, x2, y2, x1, y2)
                can.line(self.line_style, x1, y2, x1, y1)
                can.line(self.line_style, x1, y1, px1, y1)
                can.line(self.line_style, px2, y1, x2, y1)



        if halign == 'L':
            can.show(x, y, self.text)
        elif halign == 'C':
            can.show(x+text_width/2.0, y, self.text)
        elif halign == 'R':
            can.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), can)
예제 #21
0
파일: axis.py 프로젝트: luke202001/tpch-kit
    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)
예제 #22
0
 def height(self):
     h = font.text_height(self.label)[0]
     return h
예제 #23
0
파일: axis.py 프로젝트: BasilN/LED_Project
    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)