#  Created byMartin.cz
#  Copyright (c) <NAME>. All rights reserved.

import pero


class DrawTest(pero.Graphics):
    """Test case for manually assembled pie chart drawing."""
    
    
    def draw(self, canvas, *args, **kwargs):
        """Draws the test."""
        
        # clear canvas
        canvas.fill(pero.colors.White)
        
        # prepare series
        data = [10, 25, 15, 30, 5, 10, 5]
        total = float(sum(data))
        
        # init glyphs
        wedge = pero.Wedge(
            line_color = "white",
            line_width = 5,
            start_angle_units = pero.ANGLE_DEG,
            end_angle_units = pero.ANGLE_DEG,)
        
        label = pero.Text(
            text_align = pero.TEXT_ALIGN_CENTER,
            text_base = pero.TEXT_BASE_MIDDLE,
            text_color = "white",
            font_size = 16,
            font_weight = pero.FONT_WEIGHT_BOLD)
        
        # calc coordinates
        padding = 15
        width, height = canvas.viewport.wh
        
        wedge.x = 0.5*width
        wedge.y = 0.5*height
        wedge.outer_radius = 0.5*(min(width, height) - 2*padding)
        wedge.inner_radius = 0.5*wedge.outer_radius
        
        label_c = (wedge.x, wedge.y)
        label_x = wedge.x + 0.5*(wedge.outer_radius + wedge.inner_radius)
        label_y = wedge.y
        
        # draw slices
        start_angle = -90
        for i, value in enumerate(data):
            
            # calc angle
            wedge.start_angle = start_angle
            wedge.end_angle = start_angle + 360*value/total
            start_angle = wedge.end_angle
            
            # set color
            wedge.fill_color = pero.colors.Pero[i]
            
            # draw glyph
            wedge.draw(canvas)
            
            # draw label
            label_angle = wedge.start_angle + 0.5*(wedge.end_angle - wedge.start_angle)
            x, y = pero.rotate((label_x, label_y), pero.rads(label_angle), label_c)
            label.draw(canvas, text=str(value), x=x, y=y)


# run test
if __name__ == '__main__':
    pero.debug(DrawTest(), 'show', "Pie Chart", 500, 400)

#  Created byMartin.cz
#  Copyright (c) <NAME>. All rights reserved.

import pero


class DrawTest(pero.Graphics):
    """Test case for manually assembled pie chart drawing."""
    
    
    def draw(self, canvas, *args, **kwargs):
        """Draws the test."""
        
        # clear canvas
        canvas.fill(pero.colors.White)
        
        # prepare series
        data = [10, 25, 15, 30, 5, 10, 5]
        total = float(sum(data))
        
        # init glyphs
        wedge = pero.Wedge(
            line_color = "white",
            line_width = 5,
            start_angle_units = pero.ANGLE_DEG,
            end_angle_units = pero.ANGLE_DEG,)
        
        label = pero.Text(
            text_align = pero.TEXT_ALIGN_CENTER,
            text_base = pero.TEXT_BASE_MIDDLE,
            text_color = "white",
            font_size = 16,
            font_weight = pero.FONT_WEIGHT_BOLD)
        
        # calc coordinates
        padding = 15
        width, height = canvas.viewport.wh
        
        wedge.x = 0.5*width
        wedge.y = 0.5*height
        wedge.outer_radius = 0.5*(min(width, height) - 2*padding)
        wedge.inner_radius = 0.5*wedge.outer_radius
        
        label_c = (wedge.x, wedge.y)
        label_x = wedge.x + 0.5*(wedge.outer_radius + wedge.inner_radius)
        label_y = wedge.y
        
        # draw slices
        start_angle = -90
        for i, value in enumerate(data):
            
            # calc angle
            wedge.start_angle = start_angle
            wedge.end_angle = start_angle + 360*value/total
            start_angle = wedge.end_angle
            
            # set color
            wedge.fill_color = pero.colors.Pero[i]
            
            # draw glyph
            wedge.draw(canvas)
            
            # draw label
            label_angle = wedge.start_angle + 0.5*(wedge.end_angle - wedge.start_angle)
            x, y = pero.rotate((label_x, label_y), pero.rads(label_angle), label_c)
            label.draw(canvas, text=str(value), x=x, y=y)


# run test
if __name__ == '__main__':
    pero.debug(DrawTest(), 'show', "Pie Chart", 500, 400)

#  Created byMartin.cz #  Copyright (c) <NAME>. All rights reserved. Test case for manually assembled pie chart drawing. Draws the test. # clear canvas # prepare series # init glyphs # calc coordinates # draw slices # calc angle # set color # draw glyph # draw label # run test