-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathpie.py
More file actions
36 lines (26 loc) · 889 Bytes
/
pie.py
File metadata and controls
36 lines (26 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from decimal import Decimal
from typing import Literal, List
from matplotlib.axes import Axes
from pydantic import BaseModel, Field
from .base import Chart, ChartType
from ..utils.rounding import dynamic_round
class PieData(BaseModel):
label: str
angle: float
radius: float
class PieChart(Chart):
type: Literal[ChartType.PIE] = ChartType.PIE
elements: List[PieData] = Field(default_factory=list)
def _extract_info(self, ax: Axes) -> None:
super()._extract_info(ax)
for wedge in ax.patches:
pie_data = PieData(
label=wedge.get_label(),
angle=abs(
dynamic_round(
Decimal(float(wedge.theta2)) - Decimal(float(wedge.theta1))
)
),
radius=wedge.r,
)
self.elements.append(pie_data)