flet-charts 0.2.0.dev35__py3-none-any.whl → 0.70.0.dev6551__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 (46) hide show
  1. flet_charts/__init__.py +59 -17
  2. flet_charts/bar_chart.py +87 -30
  3. flet_charts/bar_chart_group.py +1 -2
  4. flet_charts/bar_chart_rod.py +36 -5
  5. flet_charts/candlestick_chart.py +269 -0
  6. flet_charts/candlestick_chart_spot.py +98 -0
  7. flet_charts/chart_axis.py +29 -9
  8. flet_charts/line_chart.py +76 -14
  9. flet_charts/line_chart_data.py +30 -5
  10. flet_charts/line_chart_data_point.py +33 -4
  11. flet_charts/matplotlib_backends/backend_flet_agg.py +16 -0
  12. flet_charts/matplotlib_chart.py +396 -36
  13. flet_charts/matplotlib_chart_with_toolbar.py +125 -0
  14. flet_charts/pie_chart.py +3 -6
  15. flet_charts/pie_chart_section.py +25 -18
  16. flet_charts/plotly_chart.py +17 -6
  17. flet_charts/radar_chart.py +214 -0
  18. flet_charts/radar_data_set.py +66 -0
  19. flet_charts/scatter_chart.py +75 -29
  20. flet_charts/scatter_chart_spot.py +44 -6
  21. flet_charts/types.py +159 -16
  22. flet_charts-0.70.0.dev6551.dist-info/METADATA +67 -0
  23. flet_charts-0.70.0.dev6551.dist-info/RECORD +47 -0
  24. flutter/flet_charts/CHANGELOG.md +1 -1
  25. flutter/flet_charts/LICENSE +1 -1
  26. flutter/flet_charts/analysis_options.yaml +1 -1
  27. flutter/flet_charts/lib/src/bar_chart.dart +2 -0
  28. flutter/flet_charts/lib/src/candlestick_chart.dart +129 -0
  29. flutter/flet_charts/lib/src/extension.dart +6 -0
  30. flutter/flet_charts/lib/src/radar_chart.dart +104 -0
  31. flutter/flet_charts/lib/src/scatter_chart.dart +22 -21
  32. flutter/flet_charts/lib/src/utils/bar_chart.dart +137 -73
  33. flutter/flet_charts/lib/src/utils/candlestick_chart.dart +118 -0
  34. flutter/flet_charts/lib/src/utils/charts.dart +12 -0
  35. flutter/flet_charts/lib/src/utils/line_chart.dart +15 -3
  36. flutter/flet_charts/lib/src/utils/pie_chart.dart +1 -0
  37. flutter/flet_charts/lib/src/utils/radar_chart.dart +90 -0
  38. flutter/flet_charts/lib/src/utils/scatter_chart.dart +22 -21
  39. flutter/flet_charts/pubspec.lock +85 -71
  40. flutter/flet_charts/pubspec.yaml +10 -9
  41. flet_charts-0.2.0.dev35.dist-info/METADATA +0 -69
  42. flet_charts-0.2.0.dev35.dist-info/RECORD +0 -38
  43. flutter/flet_charts/README.md +0 -3
  44. {flet_charts-0.2.0.dev35.dist-info → flet_charts-0.70.0.dev6551.dist-info}/WHEEL +0 -0
  45. {flet_charts-0.2.0.dev35.dist-info → flet_charts-0.70.0.dev6551.dist-info}/licenses/LICENSE +0 -0
  46. {flet_charts-0.2.0.dev35.dist-info → flet_charts-0.70.0.dev6551.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,98 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import Optional, Union
3
+
4
+ import flet as ft
5
+ from flet_charts.types import ChartDataPointTooltip
6
+
7
+ __all__ = ["CandlestickChartSpot", "CandlestickChartSpotTooltip"]
8
+
9
+
10
+ @dataclass
11
+ class CandlestickChartSpotTooltip(ChartDataPointTooltip):
12
+ """Tooltip configuration for the [`CandlestickChartSpot`][(p).]."""
13
+
14
+ bottom_margin: ft.Number = 8
15
+ """
16
+ Space between the tooltip bubble and the candlestick.
17
+ """
18
+
19
+ def copy(
20
+ self,
21
+ *,
22
+ text: Optional[str] = None,
23
+ text_style: Optional[ft.TextStyle] = None,
24
+ text_align: Optional[ft.TextAlign] = None,
25
+ text_spans: Optional[list[ft.TextSpan]] = None,
26
+ rtl: Optional[bool] = None,
27
+ bottom_margin: Optional[ft.Number] = None,
28
+ ) -> "CandlestickChartSpotTooltip":
29
+ """
30
+ Returns a copy of this object with the specified properties overridden.
31
+ """
32
+ return CandlestickChartSpotTooltip(
33
+ text=text if text is not None else self.text,
34
+ text_style=text_style if text_style is not None else self.text_style,
35
+ text_align=text_align if text_align is not None else self.text_align,
36
+ text_spans=text_spans.copy()
37
+ if text_spans is not None
38
+ else (self.text_spans.copy() if self.text_spans is not None else None),
39
+ rtl=rtl if rtl is not None else self.rtl,
40
+ bottom_margin=bottom_margin
41
+ if bottom_margin is not None
42
+ else self.bottom_margin,
43
+ )
44
+
45
+
46
+ @ft.control("CandlestickChartSpot")
47
+ class CandlestickChartSpot(ft.BaseControl):
48
+ """Represents a candlestick rendered on a [`CandlestickChart`][(p).]."""
49
+
50
+ x: ft.Number
51
+ """
52
+ The position of the candlestick on the X axis.
53
+ """
54
+
55
+ open: ft.Number
56
+ """
57
+ The open value of the candlestick.
58
+ """
59
+
60
+ high: ft.Number
61
+ """
62
+ The high value of the candlestick.
63
+ """
64
+
65
+ low: ft.Number
66
+ """
67
+ The low value of the candlestick.
68
+ """
69
+
70
+ close: ft.Number
71
+ """
72
+ The close value of the candlestick.
73
+ """
74
+
75
+ selected: bool = False
76
+ """
77
+ Whether to treat this candlestick as selected.
78
+ """
79
+
80
+ tooltip: Union[CandlestickChartSpotTooltip, str] = field(
81
+ default_factory=lambda: CandlestickChartSpotTooltip()
82
+ )
83
+ """
84
+ Tooltip configuration for this candlestick.
85
+ """
86
+
87
+ show_tooltip: bool = True
88
+ """
89
+ Whether the tooltip should be shown when this candlestick is highlighted.
90
+ """
91
+
92
+ def before_update(self):
93
+ super().before_update()
94
+ self._internals["tooltip"] = (
95
+ CandlestickChartSpotTooltip(text=self.tooltip)
96
+ if isinstance(self.tooltip, str)
97
+ else self.tooltip
98
+ )
flet_charts/chart_axis.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from dataclasses import field
2
- from typing import Optional, Union
2
+ from typing import Optional
3
3
 
4
4
  import flet as ft
5
5
 
@@ -17,11 +17,9 @@ class ChartAxisLabel(ft.BaseControl):
17
17
  A value to draw label for.
18
18
  """
19
19
 
20
- label: Optional[Union[ft.Control, str]] = None
20
+ label: Optional[ft.StrOrControl] = None
21
21
  """
22
- The label to display for the specified `value`.
23
-
24
- Can be a string or a `Control`.
22
+ The label to display for the specified [`value`][(c).].
25
23
  """
26
24
 
27
25
 
@@ -38,12 +36,12 @@ class ChartAxis(ft.BaseControl):
38
36
 
39
37
  title_size: ft.Number = 16
40
38
  """
41
- Width or height of title area.
39
+ The size of title area.
42
40
  """
43
41
 
44
42
  show_labels: bool = True
45
43
  """
46
- Whether to display the `labels` along the axis.
44
+ Whether to display the [`labels`][(c).] along the axis.
47
45
  If `labels` is empty then automatic labels are displayed.
48
46
  """
49
47
 
@@ -55,10 +53,32 @@ class ChartAxis(ft.BaseControl):
55
53
 
56
54
  label_spacing: Optional[ft.Number] = None
57
55
  """
58
- The interval between automatic labels.
56
+ The spacing/interval between labels.
57
+
58
+ If a value is not set, a suitable value
59
+ will be automatically calculated and used.
59
60
  """
60
61
 
61
62
  label_size: ft.Number = 22
62
63
  """
63
- Width or height of labels area.
64
+ The maximum space for each label in [`labels`][(c).].
65
+
66
+ Each label will stretch to fit this space.
67
+ """
68
+
69
+ show_min: bool = True
70
+ """
71
+ Whether to display a label for the minimum value
72
+ independent of the sampling interval.
64
73
  """
74
+
75
+ show_max: bool = True
76
+ """
77
+ Whether to display a label for the maximum value
78
+ independent of the sampling interval.
79
+ """
80
+
81
+ def before_update(self):
82
+ super().before_update()
83
+ if self.label_spacing == 0:
84
+ raise ValueError("label_spacing cannot be 0")
flet_charts/line_chart.py CHANGED
@@ -2,10 +2,9 @@ from dataclasses import dataclass, field
2
2
  from typing import Any, Optional
3
3
 
4
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
5
+ from flet_charts.chart_axis import ChartAxis
6
+ from flet_charts.line_chart_data import LineChartData
7
+ from flet_charts.types import ChartEventType, ChartGridLines, HorizontalAlignment
9
8
 
10
9
  __all__ = [
11
10
  "LineChart",
@@ -27,6 +26,20 @@ class LineChartEventSpot:
27
26
  The line's point index or `-1` if no point was hovered.
28
27
  """
29
28
 
29
+ def copy(
30
+ self,
31
+ *,
32
+ bar_index: Optional[int] = None,
33
+ spot_index: Optional[int] = None,
34
+ ) -> "LineChartEventSpot":
35
+ """
36
+ Returns a copy of this object with the specified properties overridden.
37
+ """
38
+ return LineChartEventSpot(
39
+ bar_index=bar_index if bar_index is not None else self.bar_index,
40
+ spot_index=spot_index if spot_index is not None else self.spot_index,
41
+ )
42
+
30
43
 
31
44
  @dataclass
32
45
  class LineChartEvent(ft.Event["LineChart"]):
@@ -72,7 +85,7 @@ class LineChartTooltip:
72
85
  Restricts the tooltip's width.
73
86
  """
74
87
 
75
- rotate_angle: ft.Number = 0.0
88
+ rotation: ft.Number = 0.0
76
89
  """
77
90
  The tooltip's rotation angle in degrees.
78
91
  """
@@ -84,7 +97,7 @@ class LineChartTooltip:
84
97
 
85
98
  border_side: ft.BorderSide = field(default_factory=lambda: ft.BorderSide.none())
86
99
  """
87
- The tooltip's border side.
100
+ Defines the borders of this tooltip.
88
101
  """
89
102
 
90
103
  fit_inside_horizontally: bool = False
@@ -102,13 +115,58 @@ class LineChartTooltip:
102
115
  Whether to force the tooltip container to top of the line.
103
116
  """
104
117
 
118
+ horizontal_alignment: HorizontalAlignment = HorizontalAlignment.CENTER
119
+ """
120
+ The horizontal alignment of this tooltip.
121
+ """
122
+
123
+ def copy(
124
+ self,
125
+ *,
126
+ bgcolor: Optional[ft.ColorValue] = None,
127
+ border_radius: Optional[ft.BorderRadiusValue] = None,
128
+ margin: Optional[ft.Number] = None,
129
+ padding: Optional[ft.PaddingValue] = None,
130
+ max_width: Optional[ft.Number] = None,
131
+ rotation: Optional[ft.Number] = None,
132
+ horizontal_offset: Optional[ft.Number] = None,
133
+ border_side: Optional[ft.BorderSide] = None,
134
+ fit_inside_horizontally: Optional[bool] = None,
135
+ fit_inside_vertically: Optional[bool] = None,
136
+ show_on_top_of_chart_box_area: Optional[bool] = None,
137
+ ) -> "LineChartTooltip":
138
+ """
139
+ Returns a copy of this object with the specified properties overridden.
140
+ """
141
+ return LineChartTooltip(
142
+ bgcolor=bgcolor if bgcolor is not None else self.bgcolor,
143
+ border_radius=border_radius
144
+ if border_radius is not None
145
+ else self.border_radius,
146
+ margin=margin if margin is not None else self.margin,
147
+ padding=padding if padding is not None else self.padding,
148
+ max_width=max_width if max_width is not None else self.max_width,
149
+ rotation=rotation if rotation is not None else self.rotation,
150
+ horizontal_offset=horizontal_offset
151
+ if horizontal_offset is not None
152
+ else self.horizontal_offset,
153
+ border_side=border_side if border_side is not None else self.border_side,
154
+ fit_inside_horizontally=fit_inside_horizontally
155
+ if fit_inside_horizontally is not None
156
+ else self.fit_inside_horizontally,
157
+ fit_inside_vertically=fit_inside_vertically
158
+ if fit_inside_vertically is not None
159
+ else self.fit_inside_vertically,
160
+ show_on_top_of_chart_box_area=show_on_top_of_chart_box_area
161
+ if show_on_top_of_chart_box_area is not None
162
+ else self.show_on_top_of_chart_box_area,
163
+ )
164
+
105
165
 
106
166
  @ft.control("LineChart")
107
- class LineChart(ft.ConstrainedControl):
167
+ class LineChart(ft.LayoutControl):
108
168
  """
109
169
  Draws a line chart.
110
-
111
- ![Overview](assets/line-chart/diagram.svg)
112
170
  """
113
171
 
114
172
  data_series: list[LineChartData] = field(default_factory=list)
@@ -165,22 +223,22 @@ class LineChart(ft.ConstrainedControl):
165
223
  Controls drawing of chart's vertical lines.
166
224
  """
167
225
 
168
- left_axis: ChartAxis = field(default_factory=lambda: ChartAxis(label_size=44))
226
+ left_axis: Optional[ChartAxis] = None
169
227
  """
170
228
  Defines the appearance of the left axis, its title and labels.
171
229
  """
172
230
 
173
- top_axis: ChartAxis = field(default_factory=lambda: ChartAxis(label_size=30))
231
+ top_axis: Optional[ChartAxis] = None
174
232
  """
175
233
  Defines the appearance of the top axis, its title and labels.
176
234
  """
177
235
 
178
- right_axis: ChartAxis = field(default_factory=lambda: ChartAxis(label_size=44))
236
+ right_axis: Optional[ChartAxis] = None
179
237
  """
180
238
  Defines the appearance of the right axis, its title and labels.
181
239
  """
182
240
 
183
- bottom_axis: ChartAxis = field(default_factory=lambda: ChartAxis(label_size=30))
241
+ bottom_axis: Optional[ChartAxis] = None
184
242
  """
185
243
  Defines the appearance of the bottom axis, its title and labels.
186
244
  """
@@ -215,9 +273,13 @@ class LineChart(ft.ConstrainedControl):
215
273
  Defines the maximum displayed value for Y axis.
216
274
  """
217
275
 
218
- tooltip: LineChartTooltip = field(default_factory=lambda: LineChartTooltip())
276
+ tooltip: Optional[LineChartTooltip] = field(
277
+ default_factory=lambda: LineChartTooltip()
278
+ )
219
279
  """
220
280
  The tooltip configuration for this chart.
281
+
282
+ If set to `None`, no tooltips will be shown throughout this chart.
221
283
  """
222
284
 
223
285
  on_event: Optional[ft.EventHandler[LineChartEvent]] = None
@@ -2,9 +2,8 @@ from dataclasses import field
2
2
  from typing import Optional, Union
3
3
 
4
4
  import flet as ft
5
-
6
- from .line_chart_data_point import LineChartDataPoint
7
- from .types import ChartPointLine, ChartPointShape
5
+ from flet_charts.line_chart_data_point import LineChartDataPoint
6
+ from flet_charts.types import ChartPointLine, ChartPointShape
8
7
 
9
8
  __all__ = ["LineChartData"]
10
9
 
@@ -19,7 +18,7 @@ class LineChartData(ft.BaseControl):
19
18
 
20
19
  curved: bool = False
21
20
  """
22
- Set to `True` to draw chart line as a curve.
21
+ Whether to draw this chart line as a curve.
23
22
  """
24
23
 
25
24
  color: ft.ColorValue = ft.Colors.CYAN
@@ -49,7 +48,7 @@ class LineChartData(ft.BaseControl):
49
48
 
50
49
  prevent_curve_over_shooting_threshold: ft.Number = 10.0
51
50
  """
52
- Threshold to prevent overshooting algorithm.
51
+ Threshold for [`prevent_curve_over_shooting`][(c).] algorithm.
53
52
  """
54
53
 
55
54
  dash_pattern: Optional[list[int]] = None
@@ -128,3 +127,29 @@ class LineChartData(ft.BaseControl):
128
127
  """
129
128
  Defines the appearance and shape of a selected line point.
130
129
  """
130
+
131
+ curve_smoothness: ft.Number = 0.35
132
+ """
133
+ Defines the smoothness of a curve line,
134
+ when [`curved`][(c).] is set to `True`.
135
+ """
136
+
137
+ rounded_stroke_join: bool = False
138
+ """
139
+ Whether to draw rounded line joins.
140
+ """
141
+
142
+ step_direction: Optional[ft.Number] = None
143
+ """
144
+ Determines the direction of each step.
145
+
146
+ If not `None`, this chart will be drawn as a
147
+ [Step Line Chart](https://docs.anychart.com/Basic_Charts/Step_Line_Chart).
148
+
149
+ Below are some typical values:
150
+
151
+ - `0.0`: Go to the next spot directly, with the current point's y value.
152
+ - `0.5`: Go to the half with the current spot y, and with the next spot y
153
+ for the rest.
154
+ - `1.0`: Go to the next spot y and direct line to the next spot.
155
+ """
@@ -2,8 +2,7 @@ from dataclasses import dataclass, field
2
2
  from typing import Optional, Union
3
3
 
4
4
  import flet as ft
5
-
6
- from .types import ChartDataPointTooltip, ChartPointLine, ChartPointShape
5
+ from flet_charts.types import ChartDataPointTooltip, ChartPointLine, ChartPointShape
7
6
 
8
7
  __all__ = ["LineChartDataPoint", "LineChartDataPointTooltip"]
9
8
 
@@ -19,6 +18,28 @@ class LineChartDataPointTooltip(ChartDataPointTooltip):
19
18
  When `None`, defaults to [`LineChartDataPoint.y`][(p).].
20
19
  """
21
20
 
21
+ def copy(
22
+ self,
23
+ *,
24
+ text: Optional[str] = None,
25
+ text_style: Optional[ft.TextStyle] = None,
26
+ text_align: Optional[ft.TextAlign] = None,
27
+ text_spans: Optional[list[ft.TextSpan]] = None,
28
+ rtl: Optional[bool] = None,
29
+ ) -> "LineChartDataPointTooltip":
30
+ """
31
+ Returns a copy of this object with the specified properties overridden.
32
+ """
33
+ return LineChartDataPointTooltip(
34
+ text=text if text is not None else self.text,
35
+ text_style=text_style if text_style is not None else self.text_style,
36
+ text_align=text_align if text_align is not None else self.text_align,
37
+ text_spans=text_spans.copy()
38
+ if text_spans is not None
39
+ else (self.text_spans.copy() if self.text_spans is not None else None),
40
+ rtl=rtl if rtl is not None else self.rtl,
41
+ )
42
+
22
43
 
23
44
  @ft.control("LineChartDataPoint")
24
45
  class LineChartDataPoint(ft.BaseControl):
@@ -69,7 +90,7 @@ class LineChartDataPoint(ft.BaseControl):
69
90
  specify line style to draw.
70
91
  """
71
92
 
72
- tooltip: LineChartDataPointTooltip = field(
93
+ tooltip: Union[LineChartDataPointTooltip, str] = field(
73
94
  default_factory=lambda: LineChartDataPointTooltip()
74
95
  )
75
96
  """
@@ -78,5 +99,13 @@ class LineChartDataPoint(ft.BaseControl):
78
99
 
79
100
  show_tooltip: bool = True
80
101
  """
81
- Whether the [`tooltip`][..] should be shown when this data point is hovered over.
102
+ Whether the [`tooltip`][(c).] should be shown when this data point is hovered over.
82
103
  """
104
+
105
+ def before_update(self):
106
+ super().before_update()
107
+ self._internals["tooltip"] = (
108
+ LineChartDataPointTooltip(text=self.tooltip)
109
+ if isinstance(self.tooltip, str)
110
+ else self.tooltip
111
+ )
@@ -0,0 +1,16 @@
1
+ from matplotlib import _api
2
+ from matplotlib.backends import backend_webagg_core
3
+
4
+
5
+ class FigureCanvasFletAgg(backend_webagg_core.FigureCanvasWebAggCore):
6
+ manager_class = _api.classproperty(lambda cls: FigureManagerFletAgg)
7
+ supports_blit = False
8
+
9
+
10
+ class FigureManagerFletAgg(backend_webagg_core.FigureManagerWebAgg):
11
+ _toolbar2_class = backend_webagg_core.NavigationToolbar2WebAgg
12
+
13
+
14
+ FigureCanvas = FigureCanvasFletAgg
15
+ FigureManager = FigureManagerFletAgg
16
+ interactive = True