Esempio n. 1
0
    def draw(self, ar, can):

        # Draw the line

        clipbox = theme.adjust_bounding_box([ar.loc[0], ar.loc[1],
                                             ar.loc[0] + ar.size[0],
                                             ar.loc[1] + ar.size[1]]);
        
        can.clip(clipbox[0],clipbox[1],clipbox[2],clipbox[3])
        if self.line_style:
            points = []
            for pair in self.data:
                yval = pychart_util.get_sample_val(pair, self.ycol)
                xval = pair[self.xcol]
                if None not in (xval, yval):
                    points.append((ar.x_pos(xval), ar.y_pos(yval)))
            can.lines(self.line_style, points)
        can.endclip()
        
        # Draw tick marks and error bars
        can.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 = pychart_util.get_sample_val(pair, self.ycol)
            if None in (x, y): continue
            
            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_plus_col or self.y_qerror_minus_col]
                    q_minus = pair[self.y_qerror_minus_col or self.y_qerror_plus_col]
                    if None not in (minus,plus,q_minus,q_plus):
                        self.error_bar.draw(can, (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:
                    if None not in (minus,plus): #PDS
                        self.error_bar.draw(can, (x_pos, y_pos),
                                            ar.y_pos(y - minus),
                                            ar.y_pos(y + plus))
                        
            if self.tick_mark:
                self.tick_mark.draw(can, x_pos, y_pos)
            if self.data_label_format:
                can.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))

        can.endclip()
Esempio n. 2
0
    def draw(self, ar, can):

        # Draw the line

        clipbox = theme.adjust_bounding_box([ar.loc[0], ar.loc[1], ar.loc[0] + ar.size[0], ar.loc[1] + ar.size[1]])

        can.clip(clipbox[0], clipbox[1], clipbox[2], clipbox[3])
        if self.line_style:
            points = []
            for pair in self.data:
                yval = pychart_util.get_sample_val(pair, self.ycol)
                xval = pair[self.xcol]
                if None not in (xval, yval):
                    points.append((ar.x_pos(xval), ar.y_pos(yval)))
            can.lines(self.line_style, points)
        can.endclip()

        # Draw tick marks and error bars
        can.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 = pychart_util.get_sample_val(pair, self.ycol)
            if None in (x, y):
                continue

            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_plus_col or self.y_qerror_minus_col]
                    q_minus = pair[self.y_qerror_minus_col or self.y_qerror_plus_col]
                    if None not in (minus, plus, q_minus, q_plus):
                        self.error_bar.draw(
                            can,
                            (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:
                    if None not in (minus, plus):  # PDS
                        self.error_bar.draw(can, (x_pos, y_pos), ar.y_pos(y - minus), ar.y_pos(y + plus))

            if self.tick_mark:
                self.tick_mark.draw(can, x_pos, y_pos)
            if self.data_label_format:
                can.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),
                )

        can.endclip()
    def draw_vertical(self, ar, can):
        for pair in self.data:
            xval = pair[self.bcol]
            yvals = pychart_util.get_sample_val(pair, self.hcol)

            if None in (xval, yvals): continue

            ybot = 0

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

            cury = yvals[0]
            n = 0

            for yval in yvals[1:]:
                (line_style, fill_style) = self.get_style(n)
                can.rectangle(line_style, fill_style, this_x, ar.y_pos(cury),
                              this_x + self.width, ar.y_pos(cury + yval))
                cury += yval
                n += 1

                if self.data_label_format:
                    can.show(
                        this_x + self.width / 2.0 + self.data_label_offset[0],
                        ar.y_pos(cury) + self.data_label_offset[1],
                        "/hC" + pychart_util.apply_format(
                            self.data_label_format,
                            (pair[self.bcol], pair[self.hcol]), 1))
    def draw_vertical(self, ar, can):
        for pair in self.data:
            xval = pair[self.bcol]
            yvals = pychart_util.get_sample_val(pair, self.hcol)
            
            if None in (xval, yvals): continue

            ybot = 0
            
            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

            cury = yvals[0]
            n = 0
            
            for yval in yvals[1:]:
                (line_style, fill_style) = self.get_style(n)
                can.rectangle(line_style, fill_style,
                              thisX, ar.y_pos(cury), thisX+self.width, 
                              ar.y_pos(cury + yval))
                cury += yval
                n += 1
                
                if self.data_label_format:
                    can.show(thisX + self.width/2.0 + self.data_label_offset[0],
                             ar.y_pos(cury) + self.data_label_offset[1],
                             "/hC" + pychart_util.apply_format(self.data_label_format, (pair[self.bcol], pair[self.hcol]), 1))
Esempio n. 5
0
    def draw_horizontal(self, ar, can):
        for pair in self.data:
            yval = pair[self.bcol]
            xval = pychart_util.get_sample_val(pair, self.hcol)

            if None in (xval, yval): continue

            xbot = 0
            if self.stack_on:
                xbot = self.stack_on.get_value(yval)
                xval += xbot
            totalWidth = self.get_bar_width(ar, self.cluster[1])
            firstY = ar.y_pos(yval) - totalWidth / 2.0
            thisY = firstY + self.get_bar_width(ar, self.cluster[0])

            can.rectangle(self.line_style, self.fill_style, ar.x_pos(xbot),
                          thisY, ar.x_pos(xval), thisY + self.width)

            if self.data_label_format:
                can.show(
                    ar.x_pos(xval) + self.data_label_offset[0],
                    thisY + self.width / 2.0 + self.data_label_offset[1],
                    "/vM/hL" + pychart_util.apply_format(
                        self.data_label_format,
                        (pair[self.bcol], pair[self.hcol]), 1))
    def draw_horizontal(self, ar, can):
        for pair in self.data:
            yval = pair[self.bcol]
            xvals = pychart_util.get_sample_val(pair, self.hcol)

            if None in (xvals, yval): continue

            totalWidth = (self.width+self.cluster_sep) * self.cluster[1] - self.cluster_sep
            firstY = ar.y_pos(yval) - totalWidth/2.0
            thisY = firstY + (self.width+self.cluster_sep) * self.cluster[0] - self.cluster_sep

            curx = xvals[0]
            n = 0
            for xval in xvals[1:]:
                line_style, fill_style = self.get_style(n)
                can.rectangle(line_style, fill_style,
                              ar.x_pos(curx), thisY,
                              ar.x_pos(xval), thisY+self.width)
                curx = xval
                n += 1
Esempio n. 7
0
    def draw_vertical(self, ar, can):
        for pair in self.data:
            xval = pair[self.bcol]
            yval = pychart_util.get_sample_val(pair, self.hcol)

            if None in (xval, yval): continue

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

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

            can.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]
                if None not in (plus, minus, qplus, qminus):
                    self.error_bar.draw(
                        can, (thisX + self.width / 2.0, ar.y_pos(yval)),
                        ar.y_pos(yval - minus), ar.y_pos(yval + plus),
                        ar.y_pos(yval - qminus), ar.y_pos(yval + qplus))

            if self.data_label_format:
                can.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))
    def draw_horizontal(self, ar, can):
        for pair in self.data:
            yval = pair[self.bcol]
            xvals = pychart_util.get_sample_val(pair, self.hcol)

            if None in (xvals, yval): continue

            totalWidth = (self.width + self.cluster_sep
                          ) * self.cluster[1] - self.cluster_sep
            first_y = ar.y_pos(yval) - totalWidth / 2.0
            this_y = first_y + (self.width + self.cluster_sep
                                ) * self.cluster[0] - self.cluster_sep

            curx = xvals[0]
            n = 0
            for xval in xvals[1:]:
                line_style, fill_style = self.get_style(n)
                can.rectangle(line_style, fill_style, ar.x_pos(curx), this_y,
                              ar.x_pos(curx + xval), this_y + self.width)
                curx += xval
                n += 1
Esempio n. 9
0
    def draw_vertical(self, ar, can):
        for pair in self.data:
            xval = pair[self.bcol]
            yval = pychart_util.get_sample_val(pair, self.hcol)
            
            if None in (xval, yval): continue

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

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

            can.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]
                if None not in (plus, minus, qplus, qminus): 
                    self.error_bar.draw(can, (thisX+self.width/2.0, ar.y_pos(yval)),
                                        ar.y_pos(yval - minus),
                                        ar.y_pos(yval + plus),
                                        ar.y_pos(yval - qminus),
                                        ar.y_pos(yval + qplus))
                    
            if self.data_label_format:
                can.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. 10
0
    def draw_horizontal(self, ar, can):
        for pair in self.data:
            yval = pair[self.bcol]
            xval = pychart_util.get_sample_val(pair, self.hcol)

            if None in (xval, yval): continue

            xbot = 0
            if self.stack_on:
                xbot = self.stack_on.get_value(yval)
                xval += xbot
            totalWidth = self.get_bar_width(ar, self.cluster[1])
            firstY = ar.y_pos(yval) - totalWidth/2.0
            thisY = firstY + self.get_bar_width(ar, self.cluster[0])
            
            can.rectangle(self.line_style, self.fill_style,
                          ar.x_pos(xbot), thisY,
                          ar.x_pos(xval), thisY+self.width)

            if self.data_label_format:
                can.show(ar.x_pos(xval) + self.data_label_offset[0],
		            thisY + self.width/2.0 + self.data_label_offset[1],
                            "/vM/hL" + pychart_util.apply_format(self.data_label_format, (pair[self.bcol], pair[self.hcol]), 1))
Esempio n. 11
0
    def draw(self, ar, can):
        
        prevPair = None

        xmin=999999
        xmax=-999999
        ymin=999999
        ymax=-999999

        # Draw the boundary in a single stroke.
        can.gsave()
        can.newpath()
        for pair in self.data:
            x = pair[self.xcol]
            y = pychart_util.get_sample_val(pair, self.max_col)
            if y == None:
                continue
            
            xmin = min(xmin, ar.x_pos(x))
            xmax = max(xmax, ar.x_pos(x))
            ymin = min(ymin, ar.y_pos(y))
            ymax = max(ymax, ar.y_pos(y))
            if prevPair != None:
                can.lineto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
            else:
                can.moveto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
            prevPair = pair

        for i in range(len(self.data)-1, -1, -1):
            pair = self.data[i]
            x = pair[self.xcol]
            y = pychart_util.get_sample_val(pair, self.min_col)
            if None in (x, y):
                continue

            xmin = min(xmin, ar.x_pos(x))
            xmax = max(xmax, ar.x_pos(x))
            ymin = min(ymin, ar.y_pos(y))
            ymax = max(ymax, ar.y_pos(y))
            can.lineto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
        can.closepath()

        # create a clip region, and fill it.
        can.clip_sub()
        can.fill_with_pattern(self.fill_style, xmin, ymin, xmax, ymax)
        can.grestore()

        if self.line_style: 
            # draw the boundary.
            prevPair = None
            can.newpath()
            can.set_line_style(self.line_style)
            for pair in self.data:
                x = pair[self.xcol]
                y = pychart_util.get_sample_val(pair, self.min_col)
                if None in (x, y):
                    continue

                if prevPair != None:
                    can.lineto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
                else:
                    can.moveto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
                prevPair = pair
            can.stroke()

            prevPair = None
            can.newpath()
            can.set_line_style(self.line_style)
            for pair in self.data:
                x = pair[self.xcol]
                y = pychart_util.get_sample_val(pair, self.max_col)
                if y == None:
                    continue

                if prevPair != None:
                    can.lineto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
                else:
                    can.moveto(xscale(ar.x_pos(x)), yscale(ar.y_pos(y)))
                prevPair = pair
            can.stroke()