flet-charts 0.2.0.dev13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of flet-charts might be problematic. Click here for more details.

Files changed (38) hide show
  1. flet_charts/__init__.py +35 -0
  2. flet_charts/bar_chart.py +237 -0
  3. flet_charts/bar_chart_group.py +33 -0
  4. flet_charts/bar_chart_rod.py +111 -0
  5. flet_charts/bar_chart_rod_stack_item.py +31 -0
  6. flet_charts/chart_axis.py +64 -0
  7. flet_charts/line_chart.py +251 -0
  8. flet_charts/line_chart_data.py +140 -0
  9. flet_charts/line_chart_data_point.py +85 -0
  10. flet_charts/matplotlib_chart.py +64 -0
  11. flet_charts/pie_chart.py +89 -0
  12. flet_charts/pie_chart_section.py +89 -0
  13. flet_charts/plotly_chart.py +56 -0
  14. flet_charts/scatter_chart.py +218 -0
  15. flet_charts/scatter_chart_spot.py +102 -0
  16. flet_charts/types.py +288 -0
  17. flet_charts-0.2.0.dev13.dist-info/METADATA +69 -0
  18. flet_charts-0.2.0.dev13.dist-info/RECORD +38 -0
  19. flet_charts-0.2.0.dev13.dist-info/WHEEL +5 -0
  20. flet_charts-0.2.0.dev13.dist-info/licenses/LICENSE +201 -0
  21. flet_charts-0.2.0.dev13.dist-info/top_level.txt +2 -0
  22. flutter/flet_charts/CHANGELOG.md +3 -0
  23. flutter/flet_charts/LICENSE +201 -0
  24. flutter/flet_charts/README.md +3 -0
  25. flutter/flet_charts/analysis_options.yaml +5 -0
  26. flutter/flet_charts/lib/flet_charts.dart +3 -0
  27. flutter/flet_charts/lib/src/bar_chart.dart +95 -0
  28. flutter/flet_charts/lib/src/extension.dart +25 -0
  29. flutter/flet_charts/lib/src/line_chart.dart +236 -0
  30. flutter/flet_charts/lib/src/pie_chart.dart +71 -0
  31. flutter/flet_charts/lib/src/scatter_chart.dart +140 -0
  32. flutter/flet_charts/lib/src/utils/bar_chart.dart +177 -0
  33. flutter/flet_charts/lib/src/utils/charts.dart +173 -0
  34. flutter/flet_charts/lib/src/utils/line_chart.dart +208 -0
  35. flutter/flet_charts/lib/src/utils/pie_chart.dart +56 -0
  36. flutter/flet_charts/lib/src/utils/scatter_chart.dart +85 -0
  37. flutter/flet_charts/pubspec.lock +776 -0
  38. flutter/flet_charts/pubspec.yaml +24 -0
@@ -0,0 +1,251 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import Any, Optional
3
+
4
+ import flet as ft
5
+
6
+ from .chart_axis import ChartAxis
7
+ from .line_chart_data import LineChartData
8
+ from .types import ChartEventType, ChartGridLines
9
+
10
+ __all__ = [
11
+ "LineChart",
12
+ "LineChartEvent",
13
+ "LineChartEventSpot",
14
+ "LineChartTooltip",
15
+ ]
16
+
17
+
18
+ @dataclass
19
+ class LineChartEventSpot:
20
+ bar_index: int
21
+ """
22
+ The line's index or `-1` if no line was hovered.
23
+ """
24
+
25
+ spot_index: int
26
+ """
27
+ The line's point index or `-1` if no point was hovered.
28
+ """
29
+
30
+
31
+ @dataclass
32
+ class LineChartEvent(ft.Event[ft.EventControlType]):
33
+ type: ChartEventType
34
+ """
35
+ The type of event that occured.
36
+ """
37
+
38
+ spots: list[LineChartEventSpot]
39
+ """
40
+ Spots on which the event occurred.
41
+ """
42
+
43
+
44
+ @dataclass
45
+ class LineChartTooltip:
46
+ """Configuration of the tooltip for [`LineChart`][(p).]s."""
47
+
48
+ bgcolor: ft.ColorValue = "#FF607D8B"
49
+ """
50
+ Background [color](https://flet.dev/docs/reference/colors) of tooltip.
51
+ """
52
+
53
+ border_radius: Optional[ft.BorderRadiusValue] = None
54
+ """
55
+ The tooltip's border radius.
56
+ """
57
+
58
+ margin: ft.Number = 16
59
+ """
60
+ Applies a bottom margin for showing tooltip on top of rods.
61
+ """
62
+
63
+ padding: ft.PaddingValue = field(
64
+ default_factory=lambda: ft.Padding.symmetric(vertical=8, horizontal=16)
65
+ )
66
+ """
67
+ Applies a padding for showing contents inside the tooltip.
68
+
69
+ Value is of type [`PaddingValue`](https://flet.dev/docs/reference/types/aliases#paddingvalue).
70
+ """
71
+
72
+ max_width: ft.Number = 120
73
+ """
74
+ Restricts the tooltip's width.
75
+ """
76
+
77
+ rotate_angle: ft.Number = 0.0
78
+ """
79
+ The tooltip's rotation angle in degrees.
80
+ """
81
+
82
+ horizontal_offset: ft.Number = 0.0
83
+ """
84
+ Applies horizontal offset for showing tooltip.
85
+ """
86
+
87
+ border_side: ft.BorderSide = field(default_factory=lambda: ft.BorderSide.none())
88
+ """
89
+ The tooltip's border side.
90
+ """
91
+
92
+ fit_inside_horizontally: bool = False
93
+ """
94
+ Forces the tooltip to shift horizontally inside the chart, if overflow happens.
95
+ """
96
+
97
+ fit_inside_vertically: bool = False
98
+ """
99
+ Forces the tooltip to shift vertically inside the chart, if overflow happens.
100
+ """
101
+
102
+ show_on_top_of_chart_box_area: bool = False
103
+ """
104
+ Whether to force the tooltip container to top of the line.
105
+ """
106
+
107
+
108
+ @ft.control("LineChart")
109
+ class LineChart(ft.ConstrainedControl):
110
+ """
111
+ Draws a line chart.
112
+
113
+ ![Overview](assets/line-chart/diagram.svg)
114
+ """
115
+
116
+ data_series: list[LineChartData] = field(default_factory=list)
117
+ """
118
+ A list of [`LineChartData`][(p).]
119
+ controls drawn as separate lines on a chart.
120
+ """
121
+
122
+ animation: ft.AnimationValue = field(
123
+ default_factory=lambda: ft.Animation(
124
+ duration=ft.Duration(milliseconds=150), curve=ft.AnimationCurve.LINEAR
125
+ )
126
+ )
127
+ """
128
+ Controls chart implicit animation.
129
+
130
+ Value is of type [`AnimationValue`](https://flet.dev/docs/reference/types/animationvalue).
131
+ """
132
+
133
+ interactive: bool = True
134
+ """
135
+ Enables automatic tooltips and points highlighting when hovering over the chart.
136
+ """
137
+
138
+ point_line_start: Optional[ft.Number] = None
139
+ """
140
+ The start of the vertical line drawn under the selected point.
141
+
142
+ Defaults to chart's bottom edge.
143
+ """
144
+
145
+ point_line_end: Optional[ft.Number] = None
146
+ """
147
+ The end of the vertical line drawn at selected point position.
148
+
149
+ Defaults to data point's `y` value.
150
+ """
151
+
152
+ bgcolor: Optional[ft.ColorValue] = None
153
+ """
154
+ Background [color](https://flet.dev/docs/reference/colors) of the chart.
155
+ """
156
+
157
+ border: Optional[ft.Border] = None
158
+ """
159
+ The border around the chart.
160
+
161
+ Value is of type [`Border`](https://flet.dev/docs/reference/types/border).
162
+ """
163
+
164
+ horizontal_grid_lines: Optional[ChartGridLines] = None
165
+ """
166
+ Controls drawing of chart's horizontal lines.
167
+
168
+ Value is of type [`ChartGridLines`][(p).].
169
+ """
170
+
171
+ vertical_grid_lines: Optional[ChartGridLines] = None
172
+ """
173
+ Controls drawing of chart's vertical lines.
174
+
175
+ Value is of type [`ChartGridLines`][(p).].
176
+ """
177
+
178
+ left_axis: ChartAxis = field(default_factory=lambda: ChartAxis(label_size=44))
179
+ """
180
+ Defines the appearance of the left axis, its title and labels.
181
+
182
+ Value is of type [`ChartAxis`][(p).].
183
+ """
184
+
185
+ top_axis: ChartAxis = field(default_factory=lambda: ChartAxis(label_size=30))
186
+ """
187
+ Defines the appearance of the top axis, its title and labels.
188
+
189
+ Value is of type [`ChartAxis`][(p).].
190
+ """
191
+
192
+ right_axis: ChartAxis = field(default_factory=lambda: ChartAxis(label_size=44))
193
+ """
194
+ Defines the appearance of the right axis, its title and labels.
195
+
196
+ Value is of type [`ChartAxis`][(p).].
197
+ """
198
+
199
+ bottom_axis: ChartAxis = field(default_factory=lambda: ChartAxis(label_size=30))
200
+ """
201
+ Defines the appearance of the bottom axis, its title and labels.
202
+
203
+ Value is of type [`ChartAxis`][(p).].
204
+ """
205
+
206
+ baseline_x: Optional[ft.Number] = None
207
+ """
208
+ Baseline value for X axis.
209
+ """
210
+
211
+ min_x: Optional[ft.Number] = None
212
+ """
213
+ Defines the minimum displayed value for X axis.
214
+ """
215
+
216
+ max_x: Optional[ft.Number] = None
217
+ """
218
+ Defines the maximum displayed value for X axis.
219
+ """
220
+
221
+ baseline_y: Optional[ft.Number] = None
222
+ """
223
+ Baseline value for Y axis.
224
+ """
225
+
226
+ min_y: Optional[ft.Number] = None
227
+ """
228
+ Defines the minimum displayed value for Y axis.
229
+ """
230
+
231
+ max_y: Optional[ft.Number] = None
232
+ """
233
+ Defines the maximum displayed value for Y axis.
234
+ """
235
+
236
+ tooltip: LineChartTooltip = field(default_factory=lambda: LineChartTooltip())
237
+ """
238
+ The tooltip configuration for this chart.
239
+ """
240
+
241
+ on_event: ft.OptionalEventHandler[LineChartEvent["LineChart"]] = None
242
+ """
243
+ Fires when a chart line is hovered or clicked.
244
+
245
+ Value is of type [`LineChartEvent`][(p).].
246
+ """
247
+
248
+ def __post_init__(self, ref: Optional[ft.Ref[Any]]):
249
+ super().__post_init__(ref)
250
+ self._internals["skip_properties"] = ["tooltip"]
251
+ self._internals["skip_inherited_notifier"] = True
@@ -0,0 +1,140 @@
1
+ from dataclasses import field
2
+ from typing import Optional, Union
3
+
4
+ import flet as ft
5
+
6
+ from .line_chart_data_point import LineChartDataPoint
7
+ from .types import ChartPointLine, ChartPointShape
8
+
9
+ __all__ = ["LineChartData"]
10
+
11
+
12
+ @ft.control("LineChartData")
13
+ class LineChartData(ft.BaseControl):
14
+ points: list[LineChartDataPoint] = field(default_factory=list)
15
+ """
16
+ A list of points (dots) of [`LineChartDataPoint`][(p).]
17
+ type representing a single chart line.
18
+ """
19
+
20
+ curved: bool = False
21
+ """
22
+ Set to `True` to draw chart line as a curve.
23
+ """
24
+
25
+ color: ft.ColorValue = ft.Colors.CYAN
26
+ """
27
+ A [color](https://flet.dev/docs/reference/colors) of chart line.
28
+ """
29
+
30
+ gradient: Optional[ft.Gradient] = None
31
+ """
32
+ Gradient to draw line's background.
33
+
34
+ Value is of type [`Gradient`](https://flet.dev/docs/reference/types/gradient).
35
+ """
36
+
37
+ stroke_width: ft.Number = 2.0
38
+ """
39
+ The width of a chart line.
40
+ """
41
+
42
+ rounded_stroke_cap: bool = False
43
+ """
44
+ Whether to draw rounded line caps.
45
+ """
46
+
47
+ prevent_curve_over_shooting: bool = False
48
+ """
49
+ Whether to prevent overshooting when draw curve line on linear sequence spots.
50
+ """
51
+
52
+ prevent_curve_over_shooting_threshold: ft.Number = 10.0
53
+ """
54
+ Threshold to prevent overshooting algorithm.
55
+ """
56
+
57
+ dash_pattern: Optional[list[int]] = None
58
+ """
59
+ Defines dash effect of the line. The value is a circular list of dash offsets
60
+ and lengths. For example, the list `[5, 10]` would result in dashes 5 pixels
61
+ long followed by blank spaces 10 pixels long. By default, a solid line is
62
+ drawn.
63
+ """
64
+
65
+ shadow: ft.BoxShadow = field(default_factory=lambda: ft.BoxShadow(color=ft.Colors.TRANSPARENT))
66
+ """
67
+ Shadow to drop by a chart line.
68
+
69
+ Value is of type [`BoxShadow`](https://flet.dev/docs/reference/types/boxshadow).
70
+ """
71
+
72
+ above_line_bgcolor: Optional[ft.ColorValue] = None
73
+ """
74
+ Fill the area above chart line with the specified
75
+ [color](https://flet.dev/docs/reference/colors).
76
+ """
77
+
78
+ above_line_gradient: Optional[ft.Gradient] = None
79
+ """
80
+ Fill the area above chart line with the specified gradient.
81
+ """
82
+
83
+ above_line_cutoff_y: Optional[ft.Number] = None
84
+ """
85
+ Cut off filled area above line chart at specific Y value.
86
+ """
87
+
88
+ above_line: Optional[ChartPointLine] = None
89
+ """
90
+ A vertical line drawn between a line point and the top edge of the chart.
91
+
92
+ Value is of type [`ChartPointLine`][(p).].
93
+ """
94
+
95
+ below_line_bgcolor: Optional[ft.ColorValue] = None
96
+ """
97
+ Fill the area below chart line with the specified
98
+ [color](https://flet.dev/docs/reference/colors).
99
+ """
100
+
101
+ below_line_gradient: Optional[ft.Gradient] = None
102
+ """
103
+ Fill the area below chart line with the specified gradient.
104
+ """
105
+
106
+ below_line_cutoff_y: Optional[ft.Number] = None
107
+ """
108
+ Cut off filled area below line chart at specific Y value.
109
+ """
110
+
111
+ below_line: Optional[ChartPointLine] = None
112
+ """
113
+ A vertical line drawn between a line point and the bottom edge of the chart.
114
+
115
+ Value is of type [`ChartPointLine`][(p).].
116
+ """
117
+
118
+ selected_below_line: Union[None, bool, ChartPointLine] = None
119
+ """
120
+ A vertical line drawn between selected line point and the bottom adge of the
121
+ chart. The value is either `True` - draw a line with default style, `False` - do
122
+ not draw a line under selected point, or an instance of
123
+ [`ChartPointLine`][(p).] class to
124
+ specify line style to draw.
125
+ """
126
+
127
+ point: Union[None, bool, ChartPointShape] = None
128
+ """
129
+ Defines the appearance and shape of a line point (dot).
130
+
131
+ Value is of type bool (`True` - draw a point with default style or `False` - do
132
+ not draw a line point) or of type [`ChartPointShape`][(p).].
133
+ """
134
+
135
+ selected_point: Union[None, bool, ChartPointShape] = None
136
+ """
137
+ Defines the appearance and shape of a selected line point.
138
+
139
+ Value is of type [`ChartPointShape`][(p).].
140
+ """
@@ -0,0 +1,85 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import Any, Optional, Union
3
+
4
+ import flet as ft
5
+
6
+ from .types import ChartDataPointTooltip, ChartPointLine, ChartPointShape
7
+
8
+ __all__ = ["LineChartDataPoint", "LineChartDataPointTooltip"]
9
+
10
+
11
+ @dataclass
12
+ class LineChartDataPointTooltip(ChartDataPointTooltip):
13
+ """Tooltip configuration for the [`LineChartDataPoint`][(p).]."""
14
+
15
+ text: Optional[str] = None
16
+ """
17
+ The text to display in the tooltip.
18
+
19
+ When `None`, defaults to [`LineChartDataPoint.y`][(p).].
20
+ """
21
+
22
+
23
+ @ft.control("LineChartDataPoint")
24
+ class LineChartDataPoint(ft.BaseControl):
25
+ """A [`LineChartData`][(p).] point."""
26
+
27
+ x: ft.Number
28
+ """
29
+ The position of a point on `X` axis.
30
+ """
31
+
32
+ y: ft.Number
33
+ """
34
+ The position of a point on `Y` axis.
35
+ """
36
+
37
+ selected: bool = False
38
+ """
39
+ Draw the point as selected when [`LineChart.interactive`][(p).]
40
+ is set to `False`.
41
+ """
42
+
43
+ point: Union[None, bool, ChartPointShape] = None
44
+ """
45
+ Defines the appearance and shape of a line point.
46
+
47
+ Value is of type [`ChartPointShape`][(p).].
48
+ """
49
+
50
+ selected_point: Union[None, bool, ChartPointShape] = None
51
+ """
52
+ Defines the appearance and shape of a selected line point.
53
+
54
+ Value is of type [`ChartPointShape`][(p).].
55
+ """
56
+
57
+ show_above_line: bool = True
58
+ """
59
+ Whether to display a line above data point.
60
+ """
61
+
62
+ show_below_line: bool = True
63
+ """
64
+ Whether to display a line below data point.
65
+ """
66
+
67
+ selected_below_line: Union[None, bool, ChartPointLine] = None
68
+ """
69
+ A vertical line drawn between selected line point and the bottom adge of the chart.
70
+
71
+ The value is either `True` - draw a line with default style, `False` - do not draw a
72
+ line under selected point, or an instance of [`ChartPointLine`][(p).] class to
73
+ specify line style to draw.
74
+ """
75
+
76
+ tooltip: LineChartDataPointTooltip = field(default_factory=lambda: LineChartDataPointTooltip())
77
+ """
78
+ Configuration of the tooltip for this data point.
79
+ """
80
+
81
+ show_tooltip: bool = True
82
+ """
83
+ Whether the [`tooltip`][..] should be shown when this data point is hovered over.
84
+ """
85
+
@@ -0,0 +1,64 @@
1
+ import io
2
+ import re
3
+ import xml.etree.ElementTree as ET
4
+ from dataclasses import field
5
+
6
+ import flet as ft
7
+
8
+ try:
9
+ from matplotlib.figure import Figure
10
+ except ImportError as e:
11
+ raise Exception(
12
+ 'Install "matplotlib" Python package to use MatplotlibChart control.'
13
+ ) from e
14
+
15
+ __all__ = ["MatplotlibChart"]
16
+
17
+
18
+ @ft.control(kw_only=True)
19
+ class MatplotlibChart(ft.Container):
20
+ """
21
+ Displays a [Matplotlib](https://matplotlib.org/) chart.
22
+
23
+ Warning:
24
+ This control requires the [`matplotlib`](https://matplotlib.org/) Python package to be installed.
25
+
26
+ See this [installation guide](index.md#installation) for more information.
27
+ """
28
+
29
+ figure: Figure = field(metadata={"skip": True})
30
+ """
31
+ Matplotlib figure to draw - an instance of
32
+ [`matplotlib.figure.Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure).
33
+ """
34
+
35
+ original_size: bool = False
36
+ """
37
+ Whether to display chart in original size.
38
+
39
+ Set to `False` to display a chart that fits configured bounds.
40
+ """
41
+
42
+ transparent: bool = False
43
+ """
44
+ Whether to remove the background from the chart.
45
+ """
46
+
47
+ def init(self):
48
+ self.alignment = ft.Alignment.center()
49
+ self.__img = ft.Image(fit=ft.BoxFit.FILL)
50
+ self.content = self.__img
51
+
52
+ def before_update(self):
53
+ super().before_update()
54
+ if self.figure is not None:
55
+ s = io.StringIO()
56
+ self.figure.savefig(s, format="svg", transparent=self.transparent)
57
+ svg = s.getvalue()
58
+
59
+ if not self.original_size:
60
+ root = ET.fromstring(svg)
61
+ w = float(re.findall(r"\d+", root.attrib["width"])[0])
62
+ h = float(re.findall(r"\d+", root.attrib["height"])[0])
63
+ self.__img.aspect_ratio = w / h
64
+ self.__img.src = svg
@@ -0,0 +1,89 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import Optional
3
+
4
+ import flet as ft
5
+
6
+ from .pie_chart_section import PieChartSection
7
+ from .types import ChartEventType
8
+
9
+ __all__ = ["PieChart", "PieChartEvent"]
10
+
11
+
12
+ @dataclass
13
+ class PieChartEvent(ft.Event[ft.EventControlType]):
14
+ type: ChartEventType
15
+ """
16
+ Type of the event.
17
+
18
+ Value is of type [`ChartEventType`][(p).].
19
+ """
20
+
21
+ section_index: Optional[int] = None
22
+ """
23
+ Section's index or `-1` if no section was hovered.
24
+ """
25
+
26
+ local_x: Optional[float] = None
27
+ """
28
+ X coordinate of the local position where the event occurred.
29
+ """
30
+
31
+ local_y: Optional[float] = None
32
+ """
33
+ Y coordinate of the local position where the event occurred.
34
+ """
35
+
36
+
37
+ @ft.control("PieChart")
38
+ class PieChart(ft.ConstrainedControl):
39
+ """
40
+ A pie chart control displaying multiple sections as slices of a circle.
41
+
42
+ ![Overview](assets/pie-chart/diagram.svg)
43
+ """
44
+
45
+ sections: list[PieChartSection] = field(default_factory=list)
46
+ """
47
+ A list of [`PieChartSection`][(p).]
48
+ controls drawn in a circle.
49
+ """
50
+
51
+ center_space_color: Optional[ft.ColorValue] = None
52
+ """
53
+ Free space [color](https://flet.dev/docs/reference/colors) in the middle of a chart.
54
+ """
55
+
56
+ center_space_radius: Optional[ft.Number] = None
57
+ """
58
+ Free space radius in the middle of a chart.
59
+ """
60
+
61
+ sections_space: Optional[ft.Number] = None
62
+ """
63
+ A gap between `sections`.
64
+ """
65
+
66
+ start_degree_offset: Optional[ft.Number] = None
67
+ """
68
+ By default, `sections` are drawn from zero degree (right side of the circle)
69
+ clockwise. You can change the starting point by setting `start_degree_offset`
70
+ (in degrees).
71
+ """
72
+
73
+ animation: ft.AnimationValue = field(
74
+ default_factory=lambda: ft.Animation(
75
+ duration=ft.Duration(milliseconds=150), curve=ft.AnimationCurve.LINEAR
76
+ )
77
+ )
78
+ """
79
+ Controls chart implicit animation.
80
+
81
+ Value is of type [`AnimationValue`](https://flet.dev/docs/reference/types/animationvalue).
82
+ """
83
+
84
+ on_event: ft.OptionalEventHandler[PieChartEvent["PieChart"]] = None
85
+ """
86
+ Fires when a chart section is hovered or clicked.
87
+
88
+ Event data is an instance [`PieChartEvent`][(p).].
89
+ """