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,89 @@
1
+ from dataclasses import field
2
+ from typing import Optional
3
+
4
+ import flet as ft
5
+
6
+ __all__ = ["PieChartSection"]
7
+
8
+
9
+ @ft.control("PieChartSection")
10
+ class PieChartSection(ft.BaseControl):
11
+ """
12
+ Configures a [PieChart][(p).] section.
13
+
14
+ Raises:
15
+ AssertionError: If [`title_position`][(c).] or
16
+ [`badge_position`][(c).] is not between `0.0` and `1.0` inclusive.
17
+ """
18
+
19
+ value: ft.Number
20
+ """
21
+ Determines how much the section should occupy. This depends on sum of all sections,
22
+ each section should occupy (`value` / sum of all values) * `360` degrees.
23
+ """
24
+
25
+ radius: Optional[ft.Number] = None
26
+ """
27
+ External radius of the section.
28
+ """
29
+
30
+ color: Optional[ft.ColorValue] = None
31
+ """
32
+ Background [color](https://flet.dev/docs/reference/colors) of the section.
33
+ """
34
+
35
+ border_side: ft.BorderSide = field(default_factory=lambda: ft.BorderSide.none())
36
+ """
37
+ The border around section shape.
38
+
39
+ Value is of type [`BorderSide`](https://flet.dev/docs/reference/types/borderside).
40
+ """
41
+
42
+ title: Optional[str] = None
43
+ """
44
+ A title drawn at the center of the section.
45
+ """
46
+
47
+ title_style: Optional[ft.TextStyle] = None
48
+ """
49
+ The style to draw `title` with.
50
+
51
+ The value is an instance of [`TextStyle`](https://flet.dev/docs/reference/types/textstyle)
52
+ class.
53
+ """
54
+
55
+ title_position: Optional[ft.Number] = None
56
+ """
57
+ The position/offset of the title relative to the section's center.
58
+
59
+ By default the title is drawn in the middle of the section.
60
+
61
+ Note:
62
+ Must be between `0.0` (near the center)
63
+ and `1.0`(near the outside of the chart) inclusive.
64
+ """
65
+
66
+ badge: Optional[ft.Control] = None
67
+ """
68
+ An optional `Control` drawn in the middle of a section.
69
+ """
70
+
71
+ badge_position: Optional[ft.Number] = None
72
+ """
73
+ The position/offset of the badge relative to the section's center.
74
+
75
+ By default the badge is drawn in the middle of the section.
76
+
77
+ Note:
78
+ Must be between `0.0` (near the center)
79
+ and `1.0`(near the outside of the chart) inclusive.
80
+ """
81
+
82
+ def before_update(self):
83
+ super().before_update()
84
+ assert self.title_position is None or (0.0 <= self.title_position <= 1.0), (
85
+ f"title_position ({self.title_position}) must be between 0.0 and 1.0 inclusive"
86
+ )
87
+ assert self.badge_position is None or (0.0 <= self.badge_position <= 1.0), (
88
+ f"badge_position ({self.badge_position}) must be between 0.0 and 1.0 inclusive"
89
+ )
@@ -0,0 +1,56 @@
1
+ import re
2
+ import xml.etree.ElementTree as ET
3
+ from dataclasses import field
4
+
5
+ import flet as ft
6
+
7
+ try:
8
+ from plotly.graph_objects import Figure
9
+ except ImportError as e:
10
+ raise Exception(
11
+ 'Install "plotly" Python package to use PlotlyChart control.'
12
+ ) from e
13
+
14
+ __all__ = ["PlotlyChart"]
15
+
16
+
17
+ @ft.control(kw_only=True)
18
+ class PlotlyChart(ft.Container):
19
+ """
20
+ Displays a [Plotly](https://plotly.com/python/) chart.
21
+
22
+ Warning:
23
+ This control requires the [`plotly`](https://plotly.com/python/) Python package to be installed.
24
+
25
+ See this [installation guide](index.md#installation) for more information.
26
+ """
27
+
28
+ figure: Figure = field(metadata={"skip": True})
29
+ """
30
+ Plotly figure to draw -
31
+ an instance of [`plotly.graph_objects.Figure`](https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html).
32
+ """
33
+
34
+ original_size: bool = False
35
+ """
36
+ Whether to display this chart in original size.
37
+
38
+ Set to `False` for it to fit it's configured bounds.
39
+ """
40
+
41
+ def init(self):
42
+ self.alignment = ft.Alignment.center()
43
+ self.__img = ft.Image(fit=ft.BoxFit.FILL)
44
+ self.content = self.__img
45
+
46
+ def before_update(self):
47
+ super().before_update()
48
+ if self.figure is not None:
49
+ svg = self.figure.to_image(format="svg").decode("utf-8")
50
+
51
+ if not self.original_size:
52
+ root = ET.fromstring(svg)
53
+ w = float(re.findall(r"\d+", root.attrib["width"])[0])
54
+ h = float(re.findall(r"\d+", root.attrib["height"])[0])
55
+ self.__img.aspect_ratio = w / h
56
+ self.__img.src = svg
@@ -0,0 +1,218 @@
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 .scatter_chart_spot import ScatterChartSpot
8
+ from .types import ChartEventType, ChartGridLines, ChartHorizontalAlignment
9
+
10
+ __all__ = ["ScatterChart", "ScatterChartEvent", "ScatterChartTooltip"]
11
+
12
+
13
+ @dataclass
14
+ class ScatterChartTooltip:
15
+ """Configuration of the tooltip for [`ScatterChart`][(p).]s."""
16
+
17
+ bgcolor: ft.ColorValue = "#FF607D8B"
18
+ """
19
+ The tooltip's background [color](https://flet.dev/docs/reference/colors).
20
+ """
21
+
22
+ border_radius: Optional[ft.BorderRadiusValue] = None
23
+ """
24
+ The tooltip's border radius.
25
+ """
26
+
27
+ padding: Optional[ft.PaddingValue] = None
28
+ """
29
+ Applies a padding for showing contents inside the tooltip.
30
+ """
31
+
32
+ max_width: Optional[ft.Number] = None
33
+ """
34
+ Restricts the tooltip's width.
35
+ """
36
+
37
+ rotate_angle: Optional[ft.Number] = None
38
+ """
39
+ The tooltip's rotation angle in degrees.
40
+ """
41
+
42
+ horizontal_offset: Optional[ft.Number] = None
43
+ """
44
+ Applies horizontal offset for showing tooltip.
45
+ """
46
+
47
+ horizontal_alignment: Optional[ChartHorizontalAlignment] = None
48
+ """
49
+ The tooltip's horizontal alignment.
50
+ """
51
+
52
+ border_side: Optional[ft.BorderSide] = None
53
+ """
54
+ The tooltip's border side.
55
+ """
56
+
57
+ fit_inside_horizontally: Optional[bool] = None
58
+ """
59
+ Forces the tooltip to shift horizontally inside the chart, if overflow happens.
60
+ """
61
+
62
+ fit_inside_vertically: Optional[bool] = None
63
+ """
64
+ Forces the tooltip to shift vertically inside the chart, if overflow happens.
65
+ """
66
+
67
+
68
+ @dataclass
69
+ class ScatterChartEvent(ft.Event[ft.EventControlType]):
70
+ type: ChartEventType
71
+ """
72
+ Type of the event (e.g. tapDown, panUpdate)
73
+ """
74
+
75
+ spot_index: Optional[int] = None
76
+ """
77
+ Index of the touched spot, if any
78
+ """
79
+
80
+
81
+ @ft.control("ScatterChart")
82
+ class ScatterChart(ft.ConstrainedControl):
83
+ """
84
+ A scatter chart control.
85
+
86
+ ScatterChart draws some points in a square space,
87
+ points are defined by [`ScatterChartSpot`][(p).]s.
88
+ """
89
+
90
+ spots: list[ScatterChartSpot] = field(default_factory=list)
91
+ """
92
+ List of [`ScatterChartSpot`][(p).]s to show on the chart.
93
+ """
94
+
95
+ animation: ft.AnimationValue = field(
96
+ default_factory=lambda: ft.Animation(
97
+ duration=ft.Duration(milliseconds=150), curve=ft.AnimationCurve.LINEAR
98
+ )
99
+ )
100
+ """
101
+ Controls chart implicit animation.
102
+
103
+ Value is of [`AnimationValue`](https://flet.dev/docs/reference/types/animationvalue)
104
+ type.
105
+ """
106
+
107
+ interactive: bool = True
108
+ """
109
+ Enables automatic tooltips when hovering chart bars.
110
+ """
111
+
112
+ handle_built_in_touches: bool = True
113
+ """
114
+ Whether to show a tooltip popup on top of the spots if a touch occurs.
115
+ """
116
+
117
+ long_press_duration: Optional[ft.DurationValue] = None
118
+ """
119
+ The duration of a long press on the chart.
120
+ """
121
+
122
+ bgcolor: Optional[ft.ColorValue] = None
123
+ """
124
+ The chart's background color.
125
+ """
126
+
127
+ border: Optional[ft.Border] = None
128
+ """
129
+ The border around the chart.
130
+ """
131
+
132
+ horizontal_grid_lines: Optional[ChartGridLines] = None
133
+ """
134
+ Controls drawing of chart's horizontal lines.
135
+
136
+ Value is of type [`ChartGridLines`][(p).].
137
+ """
138
+
139
+ vertical_grid_lines: Optional[ChartGridLines] = None
140
+ """
141
+ Controls drawing of chart's vertical lines.
142
+
143
+ Value is of type [`ChartGridLines`][(p).].
144
+ """
145
+
146
+ left_axis: ChartAxis = field(default_factory=lambda: ChartAxis())
147
+ """
148
+ Configures the appearance of the left axis, its title and labels.
149
+
150
+ Value is of type [`ChartAxis`][(p).].
151
+ """
152
+
153
+ top_axis: ChartAxis = field(default_factory=lambda: ChartAxis())
154
+ """
155
+ Configures the appearance of the top axis, its title and labels.
156
+
157
+ Value is of type [`ChartAxis`][(p).].
158
+ """
159
+
160
+ right_axis: ChartAxis = field(default_factory=lambda: ChartAxis())
161
+ """
162
+ Configures the appearance of the right axis, its title and labels.
163
+
164
+ Value is of type [`ChartAxis`][(p).].
165
+ """
166
+
167
+ bottom_axis: ChartAxis = field(default_factory=lambda: ChartAxis())
168
+ """
169
+ Configures the appearance of the bottom axis, its title and labels.
170
+
171
+ Value is of type [`ChartAxis`][(p).].
172
+ """
173
+
174
+ baseline_x: Optional[ft.Number] = None
175
+ """
176
+ The baseline value for X axis.
177
+ """
178
+
179
+ min_x: Optional[ft.Number] = None
180
+ """
181
+ The minimum displayed value for X axis.
182
+ """
183
+
184
+ max_x: Optional[ft.Number] = None
185
+ """
186
+ The maximum displayed value for X axis.
187
+ """
188
+
189
+ baseline_y: Optional[ft.Number] = None
190
+ """
191
+ Baseline value for Y axis.
192
+ """
193
+
194
+ min_y: Optional[ft.Number] = None
195
+ """
196
+ The minimum displayed value for Y axis.
197
+ """
198
+
199
+ max_y: Optional[ft.Number] = None
200
+ """
201
+ The maximum displayed value for Y axis.
202
+ """
203
+
204
+ tooltip: Optional[ScatterChartTooltip] = None
205
+ """
206
+ The tooltip configuration for the chart.
207
+ """
208
+
209
+ on_event: ft.OptionalEventHandler[ScatterChartEvent["ScatterChart"]] = None
210
+ """
211
+ Fires when an event occurs on the chart.
212
+
213
+ Event handler receives an instance of [`ScatterChartEvent`][(p).].
214
+ """
215
+
216
+ def __post_init__(self, ref: Optional[ft.Ref[Any]]):
217
+ super().__post_init__(ref)
218
+ self._internals["skip_properties"] = ["tooltip"]
@@ -0,0 +1,102 @@
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, ChartPointShape
7
+
8
+ __all__ = ["ScatterChartSpot", "ScatterChartSpotTooltip"]
9
+
10
+
11
+ @dataclass
12
+ class ScatterChartSpotTooltip(ChartDataPointTooltip):
13
+ """
14
+ Tooltip configuration for the [`ScatterChartSpot`][(p).].
15
+ """
16
+
17
+ text: Optional[str] = None
18
+ """
19
+ The text to display in the tooltip.
20
+
21
+ When `None`, defaults to [`ScatterChartSpot.y`][(p).].
22
+ """
23
+
24
+
25
+ @ft.control("ScatterChartSpot")
26
+ class ScatterChartSpot(ft.BaseControl):
27
+ """A spot on a scatter chart."""
28
+
29
+ x: Optional[ft.Number] = None
30
+ """
31
+ The position of a spot on `X` axis.
32
+ """
33
+
34
+ y: Optional[ft.Number] = None
35
+ """
36
+ The position of a spot on `Y` axis.
37
+ """
38
+
39
+ visible: bool = True
40
+ """
41
+ Determines wether to show or hide the spot.
42
+ """
43
+
44
+ radius: Optional[ft.Number] = None
45
+ """
46
+ Radius of a spot.
47
+ """
48
+
49
+ color: Optional[ft.ColorValue] = None
50
+ """
51
+ Color of a spot.
52
+ """
53
+
54
+ render_priority: ft.Number = 0
55
+ """
56
+ Sort by this to manage overlap.
57
+ """
58
+
59
+ x_error: Optional[Any] = None
60
+ """
61
+ Determines the error range of the data point using
62
+ (FlErrorRange)[https://github.com/imaNNeo/fl_chart/blob/main/repo_files/documentations/base_chart.md#flerrorrange]
63
+ (which ontains lowerBy and upperValue) for the `X` axis.
64
+ """
65
+
66
+ y_error: Optional[Any] = None
67
+ """
68
+ Determines the error range of the data point using
69
+ (FlErrorRange)[https://github.com/imaNNeo/fl_chart/blob/main/repo_files/documentations/base_chart.md#flerrorrange]
70
+ (which ontains lowerBy and upperValue) for the `Y` axis.
71
+ """
72
+
73
+ selected: bool = False
74
+ """
75
+ TBD
76
+ """
77
+
78
+ tooltip: ScatterChartSpotTooltip = field(default_factory=lambda: ScatterChartSpotTooltip())
79
+ """
80
+ Tooltip configuration for this spot.
81
+ """
82
+
83
+ show_tooltip: bool = True
84
+ """
85
+ Wether to show the tooltip.
86
+ """
87
+
88
+ label_text: Optional[str] = None
89
+ """
90
+ TBD
91
+ """
92
+
93
+ label_style: Optional[ft.TextStyle] = None
94
+ """
95
+ TBD
96
+ """
97
+
98
+ point: Union[None, bool, ChartPointShape] = None
99
+ """
100
+ TBD
101
+ """
102
+