コード例 #1
0
    def DrawActual(self, x, y, border=False):
        current = 0
        font_size = 10

        canv_utils.WriteText(self.canv,
                             "Actual",
                             x=x + 35,
                             y=y + 70,
                             rot=-0,
                             font_size=15)
        for i in range(len(self.data)):
            height = self.height * (self.data.iloc[i].actual / 100)
            text_vloc = -(y - (self.height * self.TextPos[i]))
            center_of_graph = -(y - current) + (height / 2)

            canv_utils.DrawLine(self.canv, (x - font_size - 18, text_vloc),
                                (x, center_of_graph),
                                color=self.Colors[i])
            canv_utils.WriteText(self.canv,
                                 self.data.iloc[i].range,
                                 x=x - font_size - 20,
                                 y=text_vloc,
                                 rot=-0,
                                 font_size=font_size)

            # canv_utils.DrawLine(self.canv, (x + self.width, center_of_graph),
            #                     (x + font_size + self.width + 18, text_vloc), color=self.Colors[i])
            # canv_utils.WriteLeftAlignedText(self.canv, self.data.iloc[i].category, x=x + font_size + self.width + 20,
            #                                 y=text_vloc, rot=-0, font_size=font_size)

            canv_utils.DrawRectangle(self.canv, (x, -(y - current)),
                                     (self.width, height),
                                     fill=1,
                                     stroke=0,
                                     color=self.Colors[i])
            current += height
コード例 #2
0
    def DrawNormalRange(self, txt="Normal Range"):
        rangeLow = canv_utils.Point2Pixel(self.Stats['yAxis']['min'],
                                          self.Stats['yAxis']['max'], 0,
                                          self.height, self.NormalRange[0])
        rangeHigh = canv_utils.Point2Pixel(self.Stats['yAxis']['min'],
                                           self.Stats['yAxis']['max'], 0,
                                           self.height, self.NormalRange[1])

        self.canv.saveState()
        clr = np.array([3, 125, 80, 125]) / 255
        self.canv.setStrokeColor(Color(*clr))
        w, h = canv_utils.GetFontWidhHeight(txt, self.canv._fontname,
                                            self.canv._fontsize)
        self.canv.setLineWidth(2)  # small lines
        self.canv.line(0, rangeLow, self.width + h, rangeLow)
        self.canv.line(0, rangeHigh, self.width + h, rangeHigh)

        diff = abs(rangeLow - rangeHigh)

        fontSize = min(
            10, max(5, int(diff * 0.12))
        )  # Calculating Suitable Font Size between 7-12 according to Range Difference

        self.canv.setFontSize(fontSize)
        w, h = canv_utils.GetFontWidhHeight(txt, self.canv._fontname,
                                            self.canv._fontsize)
        y = rangeLow + (diff - w) / 2
        canv_utils.WriteText(self.canv, txt, x=self.width + h, y=y, rot=-90)
        self.canv.setFontSize(8)
        w, h = canv_utils.GetFontWidhHeight(txt, self.canv._fontname,
                                            self.canv._fontsize)
        canv_utils.WriteText(self.canv, self.NormalRange[0],
                             self.width + (h * 4), rangeLow - (h / 2))
        canv_utils.WriteText(self.canv, self.NormalRange[1],
                             self.width + (h * 4), rangeHigh - (h / 2))
        self.canv.restoreState()
コード例 #3
0
    def DrawTarget(self, x, y):
        current = 0
        font_size = 10

        canv_utils.WriteText(self.canv,
                             "Target",
                             x=x + 35,
                             y=y + 70,
                             rot=-0,
                             font_size=15)
        for i in range(len(self.data)):
            height = self.height * (self.data.iloc[i].target /
                                    self.Stats['target']['sum'])
            text_vloc = -(y - (self.height * self.TextPos[i]))
            center_of_graph = -(y - current) + (height / 2)

            # canv_utils.DrawLine(self.canv, (x - font_size - 18, text_vloc), (x, center_of_graph), color=self.Colors[i])
            # canv_utils.WriteText(self.canv, self.data.iloc[i].range, x=x - font_size - 20, y=text_vloc,
            #                      rot=-0, font_size=font_size)

            canv_utils.DrawLine(self.canv, (x + self.width, center_of_graph),
                                (x + font_size + self.width + 18, text_vloc),
                                color=self.Colors[i])
            canv_utils.WriteLeftAlignedText(self.canv,
                                            self.data.iloc[i].category,
                                            x=x + font_size + self.width + 20,
                                            y=text_vloc,
                                            rot=-0,
                                            font_size=font_size)

            canv_utils.DrawRectangle(self.canv, (x, -(y - current)),
                                     (self.width, height),
                                     fill=1,
                                     stroke=0,
                                     color=self.Colors[i])
            current += height
コード例 #4
0
    def draw(self):
        """
        Draw the shape, text, etc
        """
        self.Figure(grid=True)
        area = self.Stats['xAxis']['major_size']
        padding = 0.07
        center_space = 0.07
        padding_size = padding * area
        center_size = center_space * area
        bar_size = (area - (padding_size * 2 + center_size)) / 2

        self.canv.saveState()
        self.canv.setFontSize(8)
        self.canv.setFillColorRGB(0.2, 0.2, 0.2, 1.0)
        for i in range(len(self.data)):
            data_row = self.data.iloc[i]
            actual = canv_utils.Point2Pixel(0, self.Stats['yAxis']['max'], 0,
                                            self.height,
                                            max(data_row.actual, 0.2))
            target = canv_utils.Point2Pixel(0, self.Stats['yAxis']['max'], 0,
                                            self.height,
                                            max(data_row.target, 0.2))
            xy = (padding_size + area * i, 0)
            wh = (bar_size, actual)

            xy2 = (padding_size + center_size + bar_size + area * i, 0)
            wh2 = (bar_size, target)

            # print("XY: ", xy)
            # print("WH: ", wh)
            # print("bar_size: ", bar_size, "padding_size: ", padding_size, "center_size",  center_size)
            # Actual Bar
            w_txt, h_txt = canv_utils.GetFontWidhHeight(
                f"A: {data_row.actual}%", self.canv._fontname,
                self.canv._fontsize)
            canv_utils.DrawRectangle(self.canv,
                                     xy,
                                     wh,
                                     fill=1,
                                     color=self.Colors[i],
                                     stroke=0)
            canv_utils.WriteText(self.canv,
                                 f"A: {data_row.actual}%",
                                 xy[0] + wh[0] / 2 + w_txt / 2,
                                 wh[1] / 2,
                                 rot=0)

            # Target Bar
            w_txt, h_txt = canv_utils.GetFontWidhHeight(
                f"T: {data_row.target}%", self.canv._fontname,
                self.canv._fontsize)
            canv_utils.DrawRectangle(self.canv,
                                     xy2,
                                     wh2,
                                     fill=1,
                                     color=self.Colors[i],
                                     stroke=0)
            canv_utils.WriteText(self.canv,
                                 f"T: {data_row.target}%",
                                 xy2[0] + wh2[0] / 2 + w_txt / 2,
                                 wh2[1] / 2,
                                 rot=0)

        self.canv.restoreState()
コード例 #5
0
    def DrawWeeks(self, grid=True):
        weeks = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

        for wk in weeks:
            canv_utils.WriteText(self.canv, wk, 0, 0)