From 9333da744ec2ee6f08cb22d36790669e7a602505 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Sun, 16 Oct 2022 17:23:08 -0700 Subject: [PATCH 01/12] Line chart initial commit --- sdk/python/flet/charts/line_chart.py | 67 ++++++++++++++++++++++++++++ sdk/python/flet/charts/types.py | 17 +++++++ 2 files changed, 84 insertions(+) create mode 100644 sdk/python/flet/charts/line_chart.py create mode 100644 sdk/python/flet/charts/types.py diff --git a/sdk/python/flet/charts/line_chart.py b/sdk/python/flet/charts/line_chart.py new file mode 100644 index 000000000..80574b0f7 --- /dev/null +++ b/sdk/python/flet/charts/line_chart.py @@ -0,0 +1,67 @@ +from typing import Any, List, Optional + +from beartype import beartype +from flet.animation import Curve +from flet.charts.types import GridLines + +from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.ref import Ref +from flet.types import PaddingValue + + +class LineChart(Control): + def __init__( + self, + ref: Optional[Ref] = None, + disabled: Optional[bool] = None, + visible: Optional[bool] = None, + data: Any = None, + # + # Specific + # + swap_animation_duration: Optional[int] = None, + swap_animation_curve: Optional[Curve] = None, + bgcolor: Optional[str] = None, + baseline_x: OptionalNumber = None, + min_x: OptionalNumber = None, + max_x: OptionalNumber = None, + baseline_y: OptionalNumber = None, + min_y: OptionalNumber = None, + max_y: OptionalNumber = None, + horizontal_lines: Optional[GridLines] = None, + vertical_lines: Optional[GridLines] = None, + ): + + Control.__init__( + self, + ref=ref, + disabled=disabled, + visible=visible, + data=data, + ) + + def _get_control_name(self): + return "linechart" + + def _get_children(self): + children = [] + if self.__title: + self.__title._set_attr_internal("n", "title") + children.append(self.__title) + if self.__content: + self.__content._set_attr_internal("n", "content") + children.append(self.__content) + for action in self.__actions: + action._set_attr_internal("n", "action") + children.append(action) + return children + + # open + @property + def open(self) -> Optional[bool]: + return self._get_attr("open", data_type="bool", def_value=False) + + @open.setter + @beartype + def open(self, value: Optional[bool]): + self._set_attr("open", value) diff --git a/sdk/python/flet/charts/types.py b/sdk/python/flet/charts/types.py new file mode 100644 index 000000000..8ebb6c35a --- /dev/null +++ b/sdk/python/flet/charts/types.py @@ -0,0 +1,17 @@ +import dataclasses +from dataclasses import field +from typing import List, Optional + +try: + from typing import Literal +except ImportError: + from typing_extensions import Literal + + +@dataclasses.dataclass +class GridLines: + show: bool = field(default=True) + interval: Optional[float] = field(default=None) + color: Optional[str] = field(default=None) + stroke_width: Optional[float] = field(default=None) + dash_pattern: Optional[List[int]] = field(default=None) From d35c3823e639366eb01d7d16eb0b24424b922882 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Mon, 17 Oct 2022 08:56:21 -0700 Subject: [PATCH 02/12] More chart classes --- .../flet/charts/{types.py => grid_lines.py} | 0 sdk/python/flet/charts/line_chart.py | 28 +++++++---- sdk/python/flet/charts/line_chart_axis.py | 43 +++++++++++++++++ .../flet/charts/line_chart_axis_label.py | 39 +++++++++++++++ sdk/python/flet/charts/line_chart_data.py | 48 +++++++++++++++++++ .../flet/charts/line_chart_data_point.py | 39 +++++++++++++++ 6 files changed, 187 insertions(+), 10 deletions(-) rename sdk/python/flet/charts/{types.py => grid_lines.py} (100%) create mode 100644 sdk/python/flet/charts/line_chart_axis.py create mode 100644 sdk/python/flet/charts/line_chart_axis_label.py create mode 100644 sdk/python/flet/charts/line_chart_data.py create mode 100644 sdk/python/flet/charts/line_chart_data_point.py diff --git a/sdk/python/flet/charts/types.py b/sdk/python/flet/charts/grid_lines.py similarity index 100% rename from sdk/python/flet/charts/types.py rename to sdk/python/flet/charts/grid_lines.py diff --git a/sdk/python/flet/charts/line_chart.py b/sdk/python/flet/charts/line_chart.py index 80574b0f7..25755006a 100644 --- a/sdk/python/flet/charts/line_chart.py +++ b/sdk/python/flet/charts/line_chart.py @@ -2,7 +2,10 @@ from beartype import beartype from flet.animation import Curve -from flet.charts.types import GridLines +from flet.border import Border +from flet.charts.line_chart_axis import LineChartAxis +from flet.charts.line_chart_data import LineChartData +from flet.charts.grid_lines import GridLines from flet.control import Control, MainAxisAlignment, OptionalNumber from flet.ref import Ref @@ -12,6 +15,7 @@ class LineChart(Control): def __init__( self, + data_series: Optional[List[LineChartData]] = None, ref: Optional[Ref] = None, disabled: Optional[bool] = None, visible: Optional[bool] = None, @@ -22,14 +26,19 @@ def __init__( swap_animation_duration: Optional[int] = None, swap_animation_curve: Optional[Curve] = None, bgcolor: Optional[str] = None, + border: Optional[Border] = None, + horizontal_grid_lines: Optional[GridLines] = None, + vertical_grid_lines: Optional[GridLines] = None, + left_axis: Optional[LineChartAxis] = None, + top_axis: Optional[LineChartAxis] = None, + right_axis: Optional[LineChartAxis] = None, + bottom_axis: Optional[LineChartAxis] = None, baseline_x: OptionalNumber = None, min_x: OptionalNumber = None, max_x: OptionalNumber = None, baseline_y: OptionalNumber = None, min_y: OptionalNumber = None, max_y: OptionalNumber = None, - horizontal_lines: Optional[GridLines] = None, - vertical_lines: Optional[GridLines] = None, ): Control.__init__( @@ -56,12 +65,11 @@ def _get_children(self): children.append(action) return children - # open + # data_series @property - def open(self) -> Optional[bool]: - return self._get_attr("open", data_type="bool", def_value=False) + def data_series(self): + return self.__data_series - @open.setter - @beartype - def open(self, value: Optional[bool]): - self._set_attr("open", value) + @data_series.setter + def data_series(self, value): + self.__data_series = value if value is not None else [] diff --git a/sdk/python/flet/charts/line_chart_axis.py b/sdk/python/flet/charts/line_chart_axis.py new file mode 100644 index 000000000..b70205985 --- /dev/null +++ b/sdk/python/flet/charts/line_chart_axis.py @@ -0,0 +1,43 @@ +from typing import Any, List, Optional + +from beartype import beartype +from flet.animation import Curve +from flet.charts.line_chart_axis_label import LineChartAxisLabel +from flet.charts.types import GridLines + +from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.ref import Ref +from flet.types import PaddingValue + + +class LineChartAxis(Control): + def __init__( + self, + ref: Optional[Ref] = None, + disabled: Optional[bool] = None, + visible: Optional[bool] = None, + data: Any = None, + # + # Specific + # + title: Optional[Control] = None, + show_labels: Optional[bool] = None, + labels: Optional[List[LineChartAxisLabel]] = None, + labels_interval: OptionalNumber = None, + reserved_size: OptionalNumber = None, + ): + + Control.__init__( + self, + ref=ref, + disabled=disabled, + visible=visible, + data=data, + ) + + def _get_control_name(self): + return "axis" + + def _get_children(self): + children = [] + return children diff --git a/sdk/python/flet/charts/line_chart_axis_label.py b/sdk/python/flet/charts/line_chart_axis_label.py new file mode 100644 index 000000000..743ab7fb9 --- /dev/null +++ b/sdk/python/flet/charts/line_chart_axis_label.py @@ -0,0 +1,39 @@ +from typing import Any, List, Optional + +from beartype import beartype +from flet.animation import Curve +from flet.charts.types import GridLines + +from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.ref import Ref +from flet.types import PaddingValue + + +class LineChartAxisLabel(Control): + def __init__( + self, + ref: Optional[Ref] = None, + disabled: Optional[bool] = None, + visible: Optional[bool] = None, + data: Any = None, + # + # Specific + # + value: OptionalNumber = None, + label: Optional[Control] = None, + ): + + Control.__init__( + self, + ref=ref, + disabled=disabled, + visible=visible, + data=data, + ) + + def _get_control_name(self): + return "l" + + def _get_children(self): + children = [] + return children diff --git a/sdk/python/flet/charts/line_chart_data.py b/sdk/python/flet/charts/line_chart_data.py new file mode 100644 index 000000000..7eaffb631 --- /dev/null +++ b/sdk/python/flet/charts/line_chart_data.py @@ -0,0 +1,48 @@ +from typing import Any, List, Optional + +from beartype import beartype +from flet.animation import Curve +from flet.charts.line_chart_data_point import LineChartDataPoint +from flet.charts.grid_lines import GridLines + +from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.ref import Ref +from flet.types import PaddingValue + + +class LineChartData(Control): + def __init__( + self, + data_points: Optional[List[LineChartDataPoint]] = None, + ref: Optional[Ref] = None, + disabled: Optional[bool] = None, + visible: Optional[bool] = None, + data: Any = None, + # + # Specific + # + curved: Optional[bool] = None, + color: Optional[bool] = None, + stroke_width: OptionalNumber = None, + stroke_cap_round: Optional[bool] = None, + above_line_color: Optional[str] = None, + below_line_color: Optional[str] = None, + show_markers: Optional[bool] = None, + # + # + ): + + Control.__init__( + self, + ref=ref, + disabled=disabled, + visible=visible, + data=data, + ) + + def _get_control_name(self): + return "data" + + def _get_children(self): + children = [] + return children diff --git a/sdk/python/flet/charts/line_chart_data_point.py b/sdk/python/flet/charts/line_chart_data_point.py new file mode 100644 index 000000000..a8808ce6b --- /dev/null +++ b/sdk/python/flet/charts/line_chart_data_point.py @@ -0,0 +1,39 @@ +from typing import Any, List, Optional + +from beartype import beartype +from flet.animation import Curve +from flet.charts.grid_lines import GridLines + +from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.ref import Ref +from flet.types import PaddingValue + + +class LineChartDataPoint(Control): + def __init__( + self, + x: OptionalNumber = None, + y: OptionalNumber = None, + ref: Optional[Ref] = None, + disabled: Optional[bool] = None, + visible: Optional[bool] = None, + data: Any = None, + # + # Specific + # + ): + + Control.__init__( + self, + ref=ref, + disabled=disabled, + visible=visible, + data=data, + ) + + def _get_control_name(self): + return "p" + + def _get_children(self): + children = [] + return children From e988ded3020ccd2c6e4f5727502ed6e73ce4366b Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Mon, 17 Oct 2022 21:44:25 -0700 Subject: [PATCH 03/12] LineChart Python model --- sdk/python/flet/charts/grid_lines.py | 5 - sdk/python/flet/charts/line_chart.py | 204 ++++++++++++++++-- sdk/python/flet/charts/line_chart_axis.py | 66 +++++- .../flet/charts/line_chart_axis_label.py | 33 ++- sdk/python/flet/charts/line_chart_data.py | 100 ++++++++- .../flet/charts/line_chart_data_point.py | 30 ++- 6 files changed, 396 insertions(+), 42 deletions(-) diff --git a/sdk/python/flet/charts/grid_lines.py b/sdk/python/flet/charts/grid_lines.py index 8ebb6c35a..b54f3ae4c 100644 --- a/sdk/python/flet/charts/grid_lines.py +++ b/sdk/python/flet/charts/grid_lines.py @@ -2,11 +2,6 @@ from dataclasses import field from typing import List, Optional -try: - from typing import Literal -except ImportError: - from typing_extensions import Literal - @dataclasses.dataclass class GridLines: diff --git a/sdk/python/flet/charts/line_chart.py b/sdk/python/flet/charts/line_chart.py index 25755006a..520d744cb 100644 --- a/sdk/python/flet/charts/line_chart.py +++ b/sdk/python/flet/charts/line_chart.py @@ -1,15 +1,14 @@ from typing import Any, List, Optional from beartype import beartype -from flet.animation import Curve from flet.border import Border from flet.charts.line_chart_axis import LineChartAxis from flet.charts.line_chart_data import LineChartData from flet.charts.grid_lines import GridLines -from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.control import Control, OptionalNumber from flet.ref import Ref -from flet.types import PaddingValue +from flet.types import AnimationValue class LineChart(Control): @@ -23,8 +22,7 @@ def __init__( # # Specific # - swap_animation_duration: Optional[int] = None, - swap_animation_curve: Optional[Curve] = None, + animate: AnimationValue = None, bgcolor: Optional[str] = None, border: Optional[Border] = None, horizontal_grid_lines: Optional[GridLines] = None, @@ -49,20 +47,48 @@ def __init__( data=data, ) + self.data_series = data_series + self.animate = animate + self.bgcolor = bgcolor + self.border = border + self.horizontal_grid_lines = horizontal_grid_lines + self.vertical_grid_lines = vertical_grid_lines + self.left_axis = left_axis + self.top_axis = top_axis + self.right_axis = right_axis + self.bottom_axis = bottom_axis + self.baseline_x = baseline_x + self.baseline_y = baseline_y + self.min_x = min_x + self.max_x = max_x + self.min_y = min_y + self.max_y = max_y + def _get_control_name(self): return "linechart" + def _before_build_command(self): + super()._before_build_command() + self._set_attr_json("horizontalGridLines", self.__horizontal_grid_lines) + self._set_attr_json("verticalGridLines", self.__vertical_grid_lines) + def _get_children(self): children = [] - if self.__title: - self.__title._set_attr_internal("n", "title") - children.append(self.__title) - if self.__content: - self.__content._set_attr_internal("n", "content") - children.append(self.__content) - for action in self.__actions: - action._set_attr_internal("n", "action") - children.append(action) + for ds in self.__data_series: + ds._set_attr_internal("n", "data") + children.append(ds) + if self.__left_axis: + self.__left_axis._set_attr_internal("n", "left_axis") + children.append(self.__left_axis) + if self.__top_axis: + self.__top_axis._set_attr_internal("n", "top_axis") + children.append(self.__top_axis) + if self.__right_axis: + self.__right_axis._set_attr_internal("n", "right_axis") + children.append(self.__right_axis) + if self.__bottom_axis: + self.__bottom_axis._set_attr_internal("n", "bottom_axis") + children.append(self.__bottom_axis) return children # data_series @@ -73,3 +99,153 @@ def data_series(self): @data_series.setter def data_series(self, value): self.__data_series = value if value is not None else [] + + # animate + @property + def animate(self) -> AnimationValue: + return self.__animate + + @animate.setter + @beartype + def animate(self, value: AnimationValue): + self.__animate = value + + # bgcolor + @property + def bgcolor(self) -> Optional[str]: + return self._get_attr("bgcolor") + + @bgcolor.setter + @beartype + def bgcolor(self, value: Optional[str]): + self._set_attr("bgcolor", value) + + # border + @property + def border(self) -> Optional[Border]: + return self.__border + + @border.setter + @beartype + def border(self, value: Optional[Border]): + self.__border = value + + # horizontal_grid_lines + @property + def horizontal_grid_lines(self) -> Optional[GridLines]: + return self.__horizontal_grid_lines + + @horizontal_grid_lines.setter + @beartype + def horizontal_grid_lines(self, value: Optional[GridLines]): + self.__horizontal_grid_lines = value + + # vertical_grid_lines + @property + def vertical_grid_lines(self) -> Optional[GridLines]: + return self.__vertical_grid_lines + + @vertical_grid_lines.setter + @beartype + def vertical_grid_lines(self, value: Optional[GridLines]): + self.__vertical_grid_lines = value + + # left_axis + @property + def left_axis(self) -> Optional[LineChartAxis]: + return self.__left_axis + + @left_axis.setter + @beartype + def left_axis(self, value: Optional[LineChartAxis]): + self.__left_axis = value + + # top_axis + @property + def top_axis(self) -> Optional[LineChartAxis]: + return self.__top_axis + + @top_axis.setter + @beartype + def top_axis(self, value: Optional[LineChartAxis]): + self.__top_axis = value + + # right_axis + @property + def right_axis(self) -> Optional[LineChartAxis]: + return self.__right_axis + + @right_axis.setter + @beartype + def right_axis(self, value: Optional[LineChartAxis]): + self.__right_axis = value + + # bottom_axis + @property + def bottom_axis(self) -> Optional[LineChartAxis]: + return self.__bottom_axis + + @bottom_axis.setter + @beartype + def bottom_axis(self, value: Optional[LineChartAxis]): + self.__bottom_axis = value + + # baseline_x + @property + def baseline_x(self) -> OptionalNumber: + return self._get_attr("baselinex", data_type="float", def_value=1.0) + + @baseline_x.setter + @beartype + def baseline_x(self, value: OptionalNumber): + self._set_attr("baselinex", value) + + # baseline_y + @property + def baseline_y(self) -> OptionalNumber: + return self._get_attr("baseliney", data_type="float", def_value=1.0) + + @baseline_y.setter + @beartype + def baseline_y(self, value: OptionalNumber): + self._set_attr("baseliney", value) + + # min_x + @property + def min_x(self) -> OptionalNumber: + return self._get_attr("minx", data_type="float", def_value=1.0) + + @min_x.setter + @beartype + def min_x(self, value: OptionalNumber): + self._set_attr("minx", value) + + # max_x + @property + def max_x(self) -> OptionalNumber: + return self._get_attr("maxx", data_type="float", def_value=1.0) + + @max_x.setter + @beartype + def max_x(self, value: OptionalNumber): + self._set_attr("maxx", value) + + # min_y + @property + def min_y(self) -> OptionalNumber: + return self._get_attr("miny", data_type="float", def_value=1.0) + + @min_y.setter + @beartype + def min_y(self, value: OptionalNumber): + self._set_attr("miny", value) + + # max_y + @property + def max_y(self) -> OptionalNumber: + return self._get_attr("maxy", data_type="float", def_value=1.0) + + @max_y.setter + @beartype + def max_y(self, value: OptionalNumber): + self._set_attr("maxy", value) diff --git a/sdk/python/flet/charts/line_chart_axis.py b/sdk/python/flet/charts/line_chart_axis.py index b70205985..06ca82165 100644 --- a/sdk/python/flet/charts/line_chart_axis.py +++ b/sdk/python/flet/charts/line_chart_axis.py @@ -1,13 +1,10 @@ from typing import Any, List, Optional from beartype import beartype -from flet.animation import Curve from flet.charts.line_chart_axis_label import LineChartAxisLabel -from flet.charts.types import GridLines -from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.control import Control, OptionalNumber from flet.ref import Ref -from flet.types import PaddingValue class LineChartAxis(Control): @@ -35,9 +32,70 @@ def __init__( data=data, ) + self.title = title + self.show_labels = show_labels + self.labels = labels + self.labels_interval = labels_interval + self.reserved_size = reserved_size + def _get_control_name(self): return "axis" def _get_children(self): children = [] + for label in self.__labels: + label._set_attr_internal("n", "label") + children.append(label) + if self.__title: + self.__title._set_attr_internal("n", "title") + children.append(self.__title) return children + + # title + @property + def title(self) -> Optional[Control]: + return self.__title + + @title.setter + @beartype + def title(self, value: Optional[Control]): + self.__title = value + + # show_labels + @property + def show_labels(self) -> Optional[bool]: + return self._get_attr("showLabels", data_type="bool", def_value=False) + + @show_labels.setter + @beartype + def show_labels(self, value: Optional[bool]): + self._set_attr("showLabels", value) + + # labels + @property + def labels(self): + return self.__labels + + @labels.setter + def labels(self, value): + self.__labels = value if value is not None else [] + + # labels_interval + @property + def labels_interval(self) -> OptionalNumber: + return self._get_attr("labelsInterval", data_type="float", def_value=1.0) + + @labels_interval.setter + @beartype + def labels_interval(self, value: OptionalNumber): + self._set_attr("labelsInterval", value) + + # reserved_size + @property + def reserved_size(self) -> OptionalNumber: + return self._get_attr("reservedSize", data_type="float", def_value=1.0) + + @reserved_size.setter + @beartype + def reserved_size(self, value: OptionalNumber): + self._set_attr("reservedSize", value) diff --git a/sdk/python/flet/charts/line_chart_axis_label.py b/sdk/python/flet/charts/line_chart_axis_label.py index 743ab7fb9..13b908085 100644 --- a/sdk/python/flet/charts/line_chart_axis_label.py +++ b/sdk/python/flet/charts/line_chart_axis_label.py @@ -1,12 +1,9 @@ -from typing import Any, List, Optional +from typing import Any, Optional from beartype import beartype -from flet.animation import Curve -from flet.charts.types import GridLines -from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.control import Control, OptionalNumber from flet.ref import Ref -from flet.types import PaddingValue class LineChartAxisLabel(Control): @@ -31,9 +28,35 @@ def __init__( data=data, ) + self.value = value + self.label = label + def _get_control_name(self): return "l" def _get_children(self): children = [] + if self.__label: + self.__label._set_attr_internal("n", "label") + children.append(self.__label) return children + + # value + @property + def value(self) -> OptionalNumber: + return self._get_attr("value", data_type="float", def_value=1.0) + + @value.setter + @beartype + def value(self, value: OptionalNumber): + self._set_attr("value", value) + + # label + @property + def label(self) -> Optional[Control]: + return self.__label + + @label.setter + @beartype + def label(self, value: Optional[Control]): + self.__label = value diff --git a/sdk/python/flet/charts/line_chart_data.py b/sdk/python/flet/charts/line_chart_data.py index 7eaffb631..3d9dbb4fe 100644 --- a/sdk/python/flet/charts/line_chart_data.py +++ b/sdk/python/flet/charts/line_chart_data.py @@ -1,13 +1,10 @@ from typing import Any, List, Optional from beartype import beartype -from flet.animation import Curve from flet.charts.line_chart_data_point import LineChartDataPoint -from flet.charts.grid_lines import GridLines -from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.control import Control, OptionalNumber from flet.ref import Ref -from flet.types import PaddingValue class LineChartData(Control): @@ -22,14 +19,12 @@ def __init__( # Specific # curved: Optional[bool] = None, - color: Optional[bool] = None, + color: Optional[str] = None, stroke_width: OptionalNumber = None, stroke_cap_round: Optional[bool] = None, above_line_color: Optional[str] = None, below_line_color: Optional[str] = None, show_markers: Optional[bool] = None, - # - # ): Control.__init__( @@ -40,9 +35,96 @@ def __init__( data=data, ) + self.data_points = data_points + self.curved = curved + self.color = color + self.stroke_width = stroke_width + self.stroke_cap_round = stroke_cap_round + self.show_markers = show_markers + self.above_line_color = above_line_color + self.below_line_color = below_line_color + def _get_control_name(self): return "data" def _get_children(self): - children = [] - return children + return self.__data_points + + # data_points + @property + def data_points(self): + return self.__data_points + + @data_points.setter + def data_points(self, value): + self.__data_points = value if value is not None else [] + + # stroke_width + @property + def stroke_width(self) -> OptionalNumber: + return self._get_attr("strokeWidth", data_type="float", def_value=1.0) + + @stroke_width.setter + @beartype + def stroke_width(self, value: OptionalNumber): + self._set_attr("strokeWidth", value) + + # curved + @property + def curved(self) -> Optional[bool]: + return self._get_attr("curved", data_type="bool", def_value=False) + + @curved.setter + @beartype + def curved(self, value: Optional[bool]): + self._set_attr("curved", value) + + # color + @property + def color(self) -> Optional[str]: + return self._get_attr("color") + + @color.setter + @beartype + def color(self, value: Optional[str]): + self._set_attr("color", value) + + # stroke_cap_round + @property + def stroke_cap_round(self) -> Optional[bool]: + return self._get_attr("strokeCapRound", data_type="bool", def_value=False) + + @stroke_cap_round.setter + @beartype + def stroke_cap_round(self, value: Optional[bool]): + self._set_attr("strokeCapRound", value) + + # show_markers + @property + def show_markers(self) -> Optional[bool]: + return self._get_attr("showMarkers", data_type="bool", def_value=False) + + @show_markers.setter + @beartype + def show_markers(self, value: Optional[bool]): + self._set_attr("showMarkers", value) + + # above_line_color + @property + def above_line_color(self) -> Optional[str]: + return self._get_attr("aboveLineColor") + + @above_line_color.setter + @beartype + def above_line_color(self, value: Optional[str]): + self._set_attr("aboveLineColor", value) + + # below_line_color + @property + def below_line_color(self) -> Optional[str]: + return self._get_attr("belowLineColor") + + @below_line_color.setter + @beartype + def below_line_color(self, value: Optional[str]): + self._set_attr("belowLineColor", value) diff --git a/sdk/python/flet/charts/line_chart_data_point.py b/sdk/python/flet/charts/line_chart_data_point.py index a8808ce6b..87dbe2092 100644 --- a/sdk/python/flet/charts/line_chart_data_point.py +++ b/sdk/python/flet/charts/line_chart_data_point.py @@ -1,12 +1,9 @@ -from typing import Any, List, Optional +from typing import Any, Optional from beartype import beartype -from flet.animation import Curve -from flet.charts.grid_lines import GridLines -from flet.control import Control, MainAxisAlignment, OptionalNumber +from flet.control import Control, OptionalNumber from flet.ref import Ref -from flet.types import PaddingValue class LineChartDataPoint(Control): @@ -31,9 +28,32 @@ def __init__( data=data, ) + self.x = x + self.y = y + def _get_control_name(self): return "p" def _get_children(self): children = [] return children + + # x + @property + def x(self) -> OptionalNumber: + return self._get_attr("x", data_type="float", def_value=1.0) + + @x.setter + @beartype + def x(self, value: OptionalNumber): + self._set_attr("x", value) + + # y + @property + def y(self) -> OptionalNumber: + return self._get_attr("y", data_type="float", def_value=1.0) + + @y.setter + @beartype + def y(self, value: OptionalNumber): + self._set_attr("y", value) From 6f1fcede2b551c3e18243b96f71f16b44774f264 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 19 Oct 2022 15:41:48 -0700 Subject: [PATCH 04/12] Use custom flutter_svg library --- client/pubspec.lock | 8 +++++--- package/pubspec.yaml | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/pubspec.lock b/client/pubspec.lock index d1c7bed50..1da57d55b 100644 --- a/client/pubspec.lock +++ b/client/pubspec.lock @@ -196,9 +196,11 @@ packages: flutter_svg: dependency: transitive description: - name: flutter_svg - url: "https://pub.dartlang.org" - source: hosted + path: "." + ref: image-transform-fix + resolved-ref: "1dd97b0b790ed04d8652e21652d9af6edd9f768f" + url: "https://github.com/flet-dev/flutter_svg.git" + source: git version: "1.1.5" flutter_test: dependency: "direct dev" diff --git a/package/pubspec.yaml b/package/pubspec.yaml index 7103c972b..d4daeb034 100644 --- a/package/pubspec.yaml +++ b/package/pubspec.yaml @@ -23,7 +23,10 @@ dependencies: markdown: ^6.0.1 file_picker: ^5.0.1 shared_preferences: ^2.0.15 - flutter_svg: ^1.1.5 + flutter_svg: + git: + url: https://github.com/flet-dev/flutter_svg.git + ref: image-transform-fix window_to_front: ^0.0.3 audioplayers: ^1.1.0 From c7c5559afd4ce5daa410a22726db25232e8ff708 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 19 Oct 2022 21:17:21 -0700 Subject: [PATCH 05/12] aspect_ratio added to all controls --- sdk/python/flet/animated_switcher.py | 2 ++ sdk/python/flet/card.py | 2 ++ sdk/python/flet/checkbox.py | 2 ++ sdk/python/flet/circle_avatar.py | 2 ++ sdk/python/flet/column.py | 2 ++ sdk/python/flet/constrained_control.py | 12 ++++++++++++ sdk/python/flet/container.py | 2 ++ sdk/python/flet/dropdown.py | 2 ++ sdk/python/flet/elevated_button.py | 2 ++ sdk/python/flet/floating_action_button.py | 2 ++ sdk/python/flet/form_field_control.py | 2 ++ sdk/python/flet/gesture_detector.py | 2 ++ sdk/python/flet/grid_view.py | 2 ++ sdk/python/flet/icon.py | 2 ++ sdk/python/flet/icon_button.py | 2 ++ sdk/python/flet/image.py | 2 ++ sdk/python/flet/list_tile.py | 2 ++ sdk/python/flet/list_view.py | 2 ++ sdk/python/flet/markdown.py | 2 ++ sdk/python/flet/navigation_rail.py | 2 ++ sdk/python/flet/outlined_button.py | 2 ++ sdk/python/flet/popup_menu_button.py | 2 ++ sdk/python/flet/progress_bar.py | 2 ++ sdk/python/flet/progress_ring.py | 2 ++ sdk/python/flet/radio.py | 2 ++ sdk/python/flet/row.py | 2 ++ sdk/python/flet/shader_mask.py | 2 ++ sdk/python/flet/slider.py | 2 ++ sdk/python/flet/stack.py | 2 ++ sdk/python/flet/switch.py | 2 ++ sdk/python/flet/tabs.py | 2 ++ sdk/python/flet/text.py | 2 ++ sdk/python/flet/text_button.py | 2 ++ sdk/python/flet/textfield.py | 2 ++ sdk/python/flet/window_drag_area.py | 2 ++ 35 files changed, 80 insertions(+) diff --git a/sdk/python/flet/animated_switcher.py b/sdk/python/flet/animated_switcher.py index f3ec138b4..f551fb5cf 100644 --- a/sdk/python/flet/animated_switcher.py +++ b/sdk/python/flet/animated_switcher.py @@ -25,6 +25,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -59,6 +60,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/card.py b/sdk/python/flet/card.py index dc1eb2ebc..401323b35 100644 --- a/sdk/python/flet/card.py +++ b/sdk/python/flet/card.py @@ -24,6 +24,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -55,6 +56,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/checkbox.py b/sdk/python/flet/checkbox.py index 4d48b9186..1fdf92b09 100644 --- a/sdk/python/flet/checkbox.py +++ b/sdk/python/flet/checkbox.py @@ -33,6 +33,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -72,6 +73,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/circle_avatar.py b/sdk/python/flet/circle_avatar.py index ddcc89665..5ae0c9e9f 100644 --- a/sdk/python/flet/circle_avatar.py +++ b/sdk/python/flet/circle_avatar.py @@ -24,6 +24,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -61,6 +62,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/column.py b/sdk/python/flet/column.py index e215dcee0..914fd0818 100644 --- a/sdk/python/flet/column.py +++ b/sdk/python/flet/column.py @@ -30,6 +30,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -66,6 +67,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/constrained_control.py b/sdk/python/flet/constrained_control.py index 78993cf01..3a0caf51e 100644 --- a/sdk/python/flet/constrained_control.py +++ b/sdk/python/flet/constrained_control.py @@ -29,6 +29,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -57,6 +58,7 @@ def __init__( self.scale = scale self.rotate = rotate self.offset = offset + self.aspect_ratio = aspect_ratio self.animate_opacity = animate_opacity self.animate_size = animate_size self.animate_position = animate_position @@ -169,6 +171,16 @@ def offset(self) -> OffsetValue: def offset(self, value: OffsetValue): self.__offset = value + # aspect_ratio + @property + def aspect_ratio(self) -> OptionalNumber: + return self._get_attr("aspectRatio") + + @aspect_ratio.setter + @beartype + def aspect_ratio(self, value: OptionalNumber): + self._set_attr("aspectRatio", value) + # animate_opacity @property def animate_opacity(self) -> AnimationValue: diff --git a/sdk/python/flet/container.py b/sdk/python/flet/container.py index 9c304e8e9..6f978cd48 100644 --- a/sdk/python/flet/container.py +++ b/sdk/python/flet/container.py @@ -55,6 +55,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -104,6 +105,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/dropdown.py b/sdk/python/flet/dropdown.py index 31f7a3a8a..4b91e022d 100644 --- a/sdk/python/flet/dropdown.py +++ b/sdk/python/flet/dropdown.py @@ -28,6 +28,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -94,6 +95,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/elevated_button.py b/sdk/python/flet/elevated_button.py index ba98f7ed3..ff0cdcaa9 100644 --- a/sdk/python/flet/elevated_button.py +++ b/sdk/python/flet/elevated_button.py @@ -25,6 +25,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -65,6 +66,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/floating_action_button.py b/sdk/python/flet/floating_action_button.py index baf0612dc..5a9a09fc3 100644 --- a/sdk/python/flet/floating_action_button.py +++ b/sdk/python/flet/floating_action_button.py @@ -24,6 +24,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -58,6 +59,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/form_field_control.py b/sdk/python/flet/form_field_control.py index 3ea6a750b..976d50dd9 100644 --- a/sdk/python/flet/form_field_control.py +++ b/sdk/python/flet/form_field_control.py @@ -31,6 +31,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -92,6 +93,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/gesture_detector.py b/sdk/python/flet/gesture_detector.py index ebe0b6a82..8f40b281c 100644 --- a/sdk/python/flet/gesture_detector.py +++ b/sdk/python/flet/gesture_detector.py @@ -67,6 +67,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -126,6 +127,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/grid_view.py b/sdk/python/flet/grid_view.py index 6e8664844..e23c302ca 100644 --- a/sdk/python/flet/grid_view.py +++ b/sdk/python/flet/grid_view.py @@ -30,6 +30,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -65,6 +66,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/icon.py b/sdk/python/flet/icon.py index 499123058..42607ba71 100644 --- a/sdk/python/flet/icon.py +++ b/sdk/python/flet/icon.py @@ -18,6 +18,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -44,6 +45,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/icon_button.py b/sdk/python/flet/icon_button.py index 3ad211d15..56ea769ad 100644 --- a/sdk/python/flet/icon_button.py +++ b/sdk/python/flet/icon_button.py @@ -25,6 +25,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -64,6 +65,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/image.py b/sdk/python/flet/image.py index 6119a71c2..147c91753 100644 --- a/sdk/python/flet/image.py +++ b/sdk/python/flet/image.py @@ -42,6 +42,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -80,6 +81,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/list_tile.py b/sdk/python/flet/list_tile.py index 9f3042e7d..3843a6199 100644 --- a/sdk/python/flet/list_tile.py +++ b/sdk/python/flet/list_tile.py @@ -29,6 +29,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -69,6 +70,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/list_view.py b/sdk/python/flet/list_view.py index f160a9c1f..ca98aad87 100644 --- a/sdk/python/flet/list_view.py +++ b/sdk/python/flet/list_view.py @@ -30,6 +30,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -65,6 +66,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/markdown.py b/sdk/python/flet/markdown.py index 8d1975f77..1ae08283f 100644 --- a/sdk/python/flet/markdown.py +++ b/sdk/python/flet/markdown.py @@ -33,6 +33,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -65,6 +66,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/navigation_rail.py b/sdk/python/flet/navigation_rail.py index 7c76c8cec..41d0cc251 100644 --- a/sdk/python/flet/navigation_rail.py +++ b/sdk/python/flet/navigation_rail.py @@ -151,6 +151,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -190,6 +191,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/outlined_button.py b/sdk/python/flet/outlined_button.py index e11e2cded..14ef7b22f 100644 --- a/sdk/python/flet/outlined_button.py +++ b/sdk/python/flet/outlined_button.py @@ -25,6 +25,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -62,6 +63,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/popup_menu_button.py b/sdk/python/flet/popup_menu_button.py index 1c24e88a0..e5d9831a9 100644 --- a/sdk/python/flet/popup_menu_button.py +++ b/sdk/python/flet/popup_menu_button.py @@ -103,6 +103,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -135,6 +136,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/progress_bar.py b/sdk/python/flet/progress_bar.py index 1530fe44a..f990f1124 100644 --- a/sdk/python/flet/progress_bar.py +++ b/sdk/python/flet/progress_bar.py @@ -23,6 +23,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -56,6 +57,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/progress_ring.py b/sdk/python/flet/progress_ring.py index 96c66d255..7420b565b 100644 --- a/sdk/python/flet/progress_ring.py +++ b/sdk/python/flet/progress_ring.py @@ -23,6 +23,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -56,6 +57,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/radio.py b/sdk/python/flet/radio.py index 9e318d363..3db7b6ad8 100644 --- a/sdk/python/flet/radio.py +++ b/sdk/python/flet/radio.py @@ -33,6 +33,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -69,6 +70,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/row.py b/sdk/python/flet/row.py index f34f9d432..76342c066 100644 --- a/sdk/python/flet/row.py +++ b/sdk/python/flet/row.py @@ -30,6 +30,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -66,6 +67,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/shader_mask.py b/sdk/python/flet/shader_mask.py index 8eb74512a..fce8a8e00 100644 --- a/sdk/python/flet/shader_mask.py +++ b/sdk/python/flet/shader_mask.py @@ -31,6 +31,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -63,6 +64,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/slider.py b/sdk/python/flet/slider.py index 1be046049..524372a33 100644 --- a/sdk/python/flet/slider.py +++ b/sdk/python/flet/slider.py @@ -23,6 +23,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -61,6 +62,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/stack.py b/sdk/python/flet/stack.py index a8150032b..3c6ff27a9 100644 --- a/sdk/python/flet/stack.py +++ b/sdk/python/flet/stack.py @@ -29,6 +29,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -58,6 +59,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/switch.py b/sdk/python/flet/switch.py index ad4330748..f11ee17e1 100644 --- a/sdk/python/flet/switch.py +++ b/sdk/python/flet/switch.py @@ -31,6 +31,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -67,6 +68,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/tabs.py b/sdk/python/flet/tabs.py index 9424f94a5..10c9148cc 100644 --- a/sdk/python/flet/tabs.py +++ b/sdk/python/flet/tabs.py @@ -91,6 +91,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -123,6 +124,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/text.py b/sdk/python/flet/text.py index 9274bca6b..e45a26abf 100644 --- a/sdk/python/flet/text.py +++ b/sdk/python/flet/text.py @@ -49,6 +49,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -92,6 +93,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/text_button.py b/sdk/python/flet/text_button.py index f9a96001c..969fac2e8 100644 --- a/sdk/python/flet/text_button.py +++ b/sdk/python/flet/text_button.py @@ -25,6 +25,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -62,6 +63,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/textfield.py b/sdk/python/flet/textfield.py index 9a95ca01e..d63a82475 100644 --- a/sdk/python/flet/textfield.py +++ b/sdk/python/flet/textfield.py @@ -50,6 +50,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -132,6 +133,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, diff --git a/sdk/python/flet/window_drag_area.py b/sdk/python/flet/window_drag_area.py index df30f4969..7ddc2c6f5 100644 --- a/sdk/python/flet/window_drag_area.py +++ b/sdk/python/flet/window_drag_area.py @@ -22,6 +22,7 @@ def __init__( rotate: RotateValue = None, scale: ScaleValue = None, offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, animate_opacity: AnimationValue = None, animate_size: AnimationValue = None, animate_position: AnimationValue = None, @@ -49,6 +50,7 @@ def __init__( rotate=rotate, scale=scale, offset=offset, + aspect_ratio=aspect_ratio, animate_opacity=animate_opacity, animate_size=animate_size, animate_position=animate_position, From f9a885c18cdad55f34730edea7d0181b259b70d0 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 19 Oct 2022 21:36:57 -0700 Subject: [PATCH 06/12] AspectRatio on Flutter side --- package/lib/src/controls/create_control.dart | 29 +++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/package/lib/src/controls/create_control.dart b/package/lib/src/controls/create_control.dart index 00bfe3320..70a46a9ce 100644 --- a/package/lib/src/controls/create_control.dart +++ b/package/lib/src/controls/create_control.dart @@ -326,15 +326,20 @@ Widget constrainedControl( return _expandable( _positionedControl( context, - _offsetControl( - context, - _scaledControl( + _aspectRatio( + _offsetControl( context, - _rotatedControl( + _scaledControl( context, - _sizedControl( - _tooltip(_opacity(context, widget, parent, control), - parent, control), + _rotatedControl( + context, + _sizedControl( + _tooltip( + _opacity(context, widget, parent, control), + parent, + control), + parent, + control), parent, control), parent, @@ -391,6 +396,16 @@ Widget _tooltip(Widget widget, Control? parent, Control control) { : widget; } +Widget _aspectRatio(Widget widget, Control? parent, Control control) { + var aspectRatio = control.attrDouble("aspectRatio"); + return aspectRatio != null + ? AspectRatio( + aspectRatio: aspectRatio, + child: widget, + ) + : widget; +} + Widget _rotatedControl( BuildContext context, Widget widget, Control? parent, Control control) { var rotationDetails = parseRotate(control, "rotate"); From d95c4c4f456691c477e766bfa60ed771fb9597a1 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 21 Oct 2022 11:50:59 -0700 Subject: [PATCH 07/12] Changed flutter_svg reference to flet-fixes branch --- package/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/pubspec.yaml b/package/pubspec.yaml index d4daeb034..65fdc83ee 100644 --- a/package/pubspec.yaml +++ b/package/pubspec.yaml @@ -26,7 +26,7 @@ dependencies: flutter_svg: git: url: https://github.com/flet-dev/flutter_svg.git - ref: image-transform-fix + ref: flet-fixes window_to_front: ^0.0.3 audioplayers: ^1.1.0 From b5b5d5c3cd40dc0c836695cc37ffb8aa346185e1 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 21 Oct 2022 13:39:40 -0700 Subject: [PATCH 08/12] MatplotlibChart control --- sdk/python/flet/charts/grid_lines.py | 12 - sdk/python/flet/charts/line_chart.py | 251 ------------------ sdk/python/flet/charts/line_chart_axis.py | 101 ------- .../flet/charts/line_chart_axis_label.py | 62 ----- sdk/python/flet/charts/line_chart_data.py | 130 --------- .../flet/charts/line_chart_data_point.py | 59 ---- sdk/python/flet/matplotlib_chart.py | 109 ++++++++ 7 files changed, 109 insertions(+), 615 deletions(-) delete mode 100644 sdk/python/flet/charts/grid_lines.py delete mode 100644 sdk/python/flet/charts/line_chart.py delete mode 100644 sdk/python/flet/charts/line_chart_axis.py delete mode 100644 sdk/python/flet/charts/line_chart_axis_label.py delete mode 100644 sdk/python/flet/charts/line_chart_data.py delete mode 100644 sdk/python/flet/charts/line_chart_data_point.py create mode 100644 sdk/python/flet/matplotlib_chart.py diff --git a/sdk/python/flet/charts/grid_lines.py b/sdk/python/flet/charts/grid_lines.py deleted file mode 100644 index b54f3ae4c..000000000 --- a/sdk/python/flet/charts/grid_lines.py +++ /dev/null @@ -1,12 +0,0 @@ -import dataclasses -from dataclasses import field -from typing import List, Optional - - -@dataclasses.dataclass -class GridLines: - show: bool = field(default=True) - interval: Optional[float] = field(default=None) - color: Optional[str] = field(default=None) - stroke_width: Optional[float] = field(default=None) - dash_pattern: Optional[List[int]] = field(default=None) diff --git a/sdk/python/flet/charts/line_chart.py b/sdk/python/flet/charts/line_chart.py deleted file mode 100644 index 520d744cb..000000000 --- a/sdk/python/flet/charts/line_chart.py +++ /dev/null @@ -1,251 +0,0 @@ -from typing import Any, List, Optional - -from beartype import beartype -from flet.border import Border -from flet.charts.line_chart_axis import LineChartAxis -from flet.charts.line_chart_data import LineChartData -from flet.charts.grid_lines import GridLines - -from flet.control import Control, OptionalNumber -from flet.ref import Ref -from flet.types import AnimationValue - - -class LineChart(Control): - def __init__( - self, - data_series: Optional[List[LineChartData]] = None, - ref: Optional[Ref] = None, - disabled: Optional[bool] = None, - visible: Optional[bool] = None, - data: Any = None, - # - # Specific - # - animate: AnimationValue = None, - bgcolor: Optional[str] = None, - border: Optional[Border] = None, - horizontal_grid_lines: Optional[GridLines] = None, - vertical_grid_lines: Optional[GridLines] = None, - left_axis: Optional[LineChartAxis] = None, - top_axis: Optional[LineChartAxis] = None, - right_axis: Optional[LineChartAxis] = None, - bottom_axis: Optional[LineChartAxis] = None, - baseline_x: OptionalNumber = None, - min_x: OptionalNumber = None, - max_x: OptionalNumber = None, - baseline_y: OptionalNumber = None, - min_y: OptionalNumber = None, - max_y: OptionalNumber = None, - ): - - Control.__init__( - self, - ref=ref, - disabled=disabled, - visible=visible, - data=data, - ) - - self.data_series = data_series - self.animate = animate - self.bgcolor = bgcolor - self.border = border - self.horizontal_grid_lines = horizontal_grid_lines - self.vertical_grid_lines = vertical_grid_lines - self.left_axis = left_axis - self.top_axis = top_axis - self.right_axis = right_axis - self.bottom_axis = bottom_axis - self.baseline_x = baseline_x - self.baseline_y = baseline_y - self.min_x = min_x - self.max_x = max_x - self.min_y = min_y - self.max_y = max_y - - def _get_control_name(self): - return "linechart" - - def _before_build_command(self): - super()._before_build_command() - self._set_attr_json("horizontalGridLines", self.__horizontal_grid_lines) - self._set_attr_json("verticalGridLines", self.__vertical_grid_lines) - - def _get_children(self): - children = [] - for ds in self.__data_series: - ds._set_attr_internal("n", "data") - children.append(ds) - if self.__left_axis: - self.__left_axis._set_attr_internal("n", "left_axis") - children.append(self.__left_axis) - if self.__top_axis: - self.__top_axis._set_attr_internal("n", "top_axis") - children.append(self.__top_axis) - if self.__right_axis: - self.__right_axis._set_attr_internal("n", "right_axis") - children.append(self.__right_axis) - if self.__bottom_axis: - self.__bottom_axis._set_attr_internal("n", "bottom_axis") - children.append(self.__bottom_axis) - return children - - # data_series - @property - def data_series(self): - return self.__data_series - - @data_series.setter - def data_series(self, value): - self.__data_series = value if value is not None else [] - - # animate - @property - def animate(self) -> AnimationValue: - return self.__animate - - @animate.setter - @beartype - def animate(self, value: AnimationValue): - self.__animate = value - - # bgcolor - @property - def bgcolor(self) -> Optional[str]: - return self._get_attr("bgcolor") - - @bgcolor.setter - @beartype - def bgcolor(self, value: Optional[str]): - self._set_attr("bgcolor", value) - - # border - @property - def border(self) -> Optional[Border]: - return self.__border - - @border.setter - @beartype - def border(self, value: Optional[Border]): - self.__border = value - - # horizontal_grid_lines - @property - def horizontal_grid_lines(self) -> Optional[GridLines]: - return self.__horizontal_grid_lines - - @horizontal_grid_lines.setter - @beartype - def horizontal_grid_lines(self, value: Optional[GridLines]): - self.__horizontal_grid_lines = value - - # vertical_grid_lines - @property - def vertical_grid_lines(self) -> Optional[GridLines]: - return self.__vertical_grid_lines - - @vertical_grid_lines.setter - @beartype - def vertical_grid_lines(self, value: Optional[GridLines]): - self.__vertical_grid_lines = value - - # left_axis - @property - def left_axis(self) -> Optional[LineChartAxis]: - return self.__left_axis - - @left_axis.setter - @beartype - def left_axis(self, value: Optional[LineChartAxis]): - self.__left_axis = value - - # top_axis - @property - def top_axis(self) -> Optional[LineChartAxis]: - return self.__top_axis - - @top_axis.setter - @beartype - def top_axis(self, value: Optional[LineChartAxis]): - self.__top_axis = value - - # right_axis - @property - def right_axis(self) -> Optional[LineChartAxis]: - return self.__right_axis - - @right_axis.setter - @beartype - def right_axis(self, value: Optional[LineChartAxis]): - self.__right_axis = value - - # bottom_axis - @property - def bottom_axis(self) -> Optional[LineChartAxis]: - return self.__bottom_axis - - @bottom_axis.setter - @beartype - def bottom_axis(self, value: Optional[LineChartAxis]): - self.__bottom_axis = value - - # baseline_x - @property - def baseline_x(self) -> OptionalNumber: - return self._get_attr("baselinex", data_type="float", def_value=1.0) - - @baseline_x.setter - @beartype - def baseline_x(self, value: OptionalNumber): - self._set_attr("baselinex", value) - - # baseline_y - @property - def baseline_y(self) -> OptionalNumber: - return self._get_attr("baseliney", data_type="float", def_value=1.0) - - @baseline_y.setter - @beartype - def baseline_y(self, value: OptionalNumber): - self._set_attr("baseliney", value) - - # min_x - @property - def min_x(self) -> OptionalNumber: - return self._get_attr("minx", data_type="float", def_value=1.0) - - @min_x.setter - @beartype - def min_x(self, value: OptionalNumber): - self._set_attr("minx", value) - - # max_x - @property - def max_x(self) -> OptionalNumber: - return self._get_attr("maxx", data_type="float", def_value=1.0) - - @max_x.setter - @beartype - def max_x(self, value: OptionalNumber): - self._set_attr("maxx", value) - - # min_y - @property - def min_y(self) -> OptionalNumber: - return self._get_attr("miny", data_type="float", def_value=1.0) - - @min_y.setter - @beartype - def min_y(self, value: OptionalNumber): - self._set_attr("miny", value) - - # max_y - @property - def max_y(self) -> OptionalNumber: - return self._get_attr("maxy", data_type="float", def_value=1.0) - - @max_y.setter - @beartype - def max_y(self, value: OptionalNumber): - self._set_attr("maxy", value) diff --git a/sdk/python/flet/charts/line_chart_axis.py b/sdk/python/flet/charts/line_chart_axis.py deleted file mode 100644 index 06ca82165..000000000 --- a/sdk/python/flet/charts/line_chart_axis.py +++ /dev/null @@ -1,101 +0,0 @@ -from typing import Any, List, Optional - -from beartype import beartype -from flet.charts.line_chart_axis_label import LineChartAxisLabel - -from flet.control import Control, OptionalNumber -from flet.ref import Ref - - -class LineChartAxis(Control): - def __init__( - self, - ref: Optional[Ref] = None, - disabled: Optional[bool] = None, - visible: Optional[bool] = None, - data: Any = None, - # - # Specific - # - title: Optional[Control] = None, - show_labels: Optional[bool] = None, - labels: Optional[List[LineChartAxisLabel]] = None, - labels_interval: OptionalNumber = None, - reserved_size: OptionalNumber = None, - ): - - Control.__init__( - self, - ref=ref, - disabled=disabled, - visible=visible, - data=data, - ) - - self.title = title - self.show_labels = show_labels - self.labels = labels - self.labels_interval = labels_interval - self.reserved_size = reserved_size - - def _get_control_name(self): - return "axis" - - def _get_children(self): - children = [] - for label in self.__labels: - label._set_attr_internal("n", "label") - children.append(label) - if self.__title: - self.__title._set_attr_internal("n", "title") - children.append(self.__title) - return children - - # title - @property - def title(self) -> Optional[Control]: - return self.__title - - @title.setter - @beartype - def title(self, value: Optional[Control]): - self.__title = value - - # show_labels - @property - def show_labels(self) -> Optional[bool]: - return self._get_attr("showLabels", data_type="bool", def_value=False) - - @show_labels.setter - @beartype - def show_labels(self, value: Optional[bool]): - self._set_attr("showLabels", value) - - # labels - @property - def labels(self): - return self.__labels - - @labels.setter - def labels(self, value): - self.__labels = value if value is not None else [] - - # labels_interval - @property - def labels_interval(self) -> OptionalNumber: - return self._get_attr("labelsInterval", data_type="float", def_value=1.0) - - @labels_interval.setter - @beartype - def labels_interval(self, value: OptionalNumber): - self._set_attr("labelsInterval", value) - - # reserved_size - @property - def reserved_size(self) -> OptionalNumber: - return self._get_attr("reservedSize", data_type="float", def_value=1.0) - - @reserved_size.setter - @beartype - def reserved_size(self, value: OptionalNumber): - self._set_attr("reservedSize", value) diff --git a/sdk/python/flet/charts/line_chart_axis_label.py b/sdk/python/flet/charts/line_chart_axis_label.py deleted file mode 100644 index 13b908085..000000000 --- a/sdk/python/flet/charts/line_chart_axis_label.py +++ /dev/null @@ -1,62 +0,0 @@ -from typing import Any, Optional - -from beartype import beartype - -from flet.control import Control, OptionalNumber -from flet.ref import Ref - - -class LineChartAxisLabel(Control): - def __init__( - self, - ref: Optional[Ref] = None, - disabled: Optional[bool] = None, - visible: Optional[bool] = None, - data: Any = None, - # - # Specific - # - value: OptionalNumber = None, - label: Optional[Control] = None, - ): - - Control.__init__( - self, - ref=ref, - disabled=disabled, - visible=visible, - data=data, - ) - - self.value = value - self.label = label - - def _get_control_name(self): - return "l" - - def _get_children(self): - children = [] - if self.__label: - self.__label._set_attr_internal("n", "label") - children.append(self.__label) - return children - - # value - @property - def value(self) -> OptionalNumber: - return self._get_attr("value", data_type="float", def_value=1.0) - - @value.setter - @beartype - def value(self, value: OptionalNumber): - self._set_attr("value", value) - - # label - @property - def label(self) -> Optional[Control]: - return self.__label - - @label.setter - @beartype - def label(self, value: Optional[Control]): - self.__label = value diff --git a/sdk/python/flet/charts/line_chart_data.py b/sdk/python/flet/charts/line_chart_data.py deleted file mode 100644 index 3d9dbb4fe..000000000 --- a/sdk/python/flet/charts/line_chart_data.py +++ /dev/null @@ -1,130 +0,0 @@ -from typing import Any, List, Optional - -from beartype import beartype -from flet.charts.line_chart_data_point import LineChartDataPoint - -from flet.control import Control, OptionalNumber -from flet.ref import Ref - - -class LineChartData(Control): - def __init__( - self, - data_points: Optional[List[LineChartDataPoint]] = None, - ref: Optional[Ref] = None, - disabled: Optional[bool] = None, - visible: Optional[bool] = None, - data: Any = None, - # - # Specific - # - curved: Optional[bool] = None, - color: Optional[str] = None, - stroke_width: OptionalNumber = None, - stroke_cap_round: Optional[bool] = None, - above_line_color: Optional[str] = None, - below_line_color: Optional[str] = None, - show_markers: Optional[bool] = None, - ): - - Control.__init__( - self, - ref=ref, - disabled=disabled, - visible=visible, - data=data, - ) - - self.data_points = data_points - self.curved = curved - self.color = color - self.stroke_width = stroke_width - self.stroke_cap_round = stroke_cap_round - self.show_markers = show_markers - self.above_line_color = above_line_color - self.below_line_color = below_line_color - - def _get_control_name(self): - return "data" - - def _get_children(self): - return self.__data_points - - # data_points - @property - def data_points(self): - return self.__data_points - - @data_points.setter - def data_points(self, value): - self.__data_points = value if value is not None else [] - - # stroke_width - @property - def stroke_width(self) -> OptionalNumber: - return self._get_attr("strokeWidth", data_type="float", def_value=1.0) - - @stroke_width.setter - @beartype - def stroke_width(self, value: OptionalNumber): - self._set_attr("strokeWidth", value) - - # curved - @property - def curved(self) -> Optional[bool]: - return self._get_attr("curved", data_type="bool", def_value=False) - - @curved.setter - @beartype - def curved(self, value: Optional[bool]): - self._set_attr("curved", value) - - # color - @property - def color(self) -> Optional[str]: - return self._get_attr("color") - - @color.setter - @beartype - def color(self, value: Optional[str]): - self._set_attr("color", value) - - # stroke_cap_round - @property - def stroke_cap_round(self) -> Optional[bool]: - return self._get_attr("strokeCapRound", data_type="bool", def_value=False) - - @stroke_cap_round.setter - @beartype - def stroke_cap_round(self, value: Optional[bool]): - self._set_attr("strokeCapRound", value) - - # show_markers - @property - def show_markers(self) -> Optional[bool]: - return self._get_attr("showMarkers", data_type="bool", def_value=False) - - @show_markers.setter - @beartype - def show_markers(self, value: Optional[bool]): - self._set_attr("showMarkers", value) - - # above_line_color - @property - def above_line_color(self) -> Optional[str]: - return self._get_attr("aboveLineColor") - - @above_line_color.setter - @beartype - def above_line_color(self, value: Optional[str]): - self._set_attr("aboveLineColor", value) - - # below_line_color - @property - def below_line_color(self) -> Optional[str]: - return self._get_attr("belowLineColor") - - @below_line_color.setter - @beartype - def below_line_color(self, value: Optional[str]): - self._set_attr("belowLineColor", value) diff --git a/sdk/python/flet/charts/line_chart_data_point.py b/sdk/python/flet/charts/line_chart_data_point.py deleted file mode 100644 index 87dbe2092..000000000 --- a/sdk/python/flet/charts/line_chart_data_point.py +++ /dev/null @@ -1,59 +0,0 @@ -from typing import Any, Optional - -from beartype import beartype - -from flet.control import Control, OptionalNumber -from flet.ref import Ref - - -class LineChartDataPoint(Control): - def __init__( - self, - x: OptionalNumber = None, - y: OptionalNumber = None, - ref: Optional[Ref] = None, - disabled: Optional[bool] = None, - visible: Optional[bool] = None, - data: Any = None, - # - # Specific - # - ): - - Control.__init__( - self, - ref=ref, - disabled=disabled, - visible=visible, - data=data, - ) - - self.x = x - self.y = y - - def _get_control_name(self): - return "p" - - def _get_children(self): - children = [] - return children - - # x - @property - def x(self) -> OptionalNumber: - return self._get_attr("x", data_type="float", def_value=1.0) - - @x.setter - @beartype - def x(self, value: OptionalNumber): - self._set_attr("x", value) - - # y - @property - def y(self) -> OptionalNumber: - return self._get_attr("y", data_type="float", def_value=1.0) - - @y.setter - @beartype - def y(self, value: OptionalNumber): - self._set_attr("y", value) diff --git a/sdk/python/flet/matplotlib_chart.py b/sdk/python/flet/matplotlib_chart.py new file mode 100644 index 000000000..f8b215da2 --- /dev/null +++ b/sdk/python/flet/matplotlib_chart.py @@ -0,0 +1,109 @@ +import io +import re +import xml.etree.ElementTree as ET +from typing import Any, Optional, Union + +from beartype import beartype + +from flet import alignment +from flet.container import Container +from flet.control import OptionalNumber +from flet.image import Image +from flet.ref import Ref +from flet.types import AnimationValue, OffsetValue, RotateValue, ScaleValue + +try: + from matplotlib.figure import Figure +except ImportError: + raise Exception( + 'Install "matplotlib" Python package to use MatplotlibChart control.' + ) + + +class MatplotlibChart(Container): + def __init__( + self, + figure: Optional[Figure] = None, + ref: Optional[Ref] = None, + expand: Union[None, bool, int] = None, + opacity: OptionalNumber = None, + rotate: RotateValue = None, + scale: ScaleValue = None, + offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, + animate_opacity: AnimationValue = None, + animate_size: AnimationValue = None, + animate_position: AnimationValue = None, + animate_rotation: AnimationValue = None, + animate_scale: AnimationValue = None, + animate_offset: AnimationValue = None, + on_animation_end=None, + tooltip: Optional[str] = None, + visible: Optional[bool] = None, + disabled: Optional[bool] = None, + data: Any = None, + ): + + Container.__init__( + self, + ref=ref, + expand=expand, + opacity=opacity, + rotate=rotate, + scale=scale, + offset=offset, + aspect_ratio=aspect_ratio, + animate_opacity=animate_opacity, + animate_size=animate_size, + animate_position=animate_position, + animate_rotation=animate_rotation, + animate_scale=animate_scale, + animate_offset=animate_offset, + on_animation_end=on_animation_end, + tooltip=tooltip, + visible=visible, + disabled=disabled, + data=data, + ) + + self.figure = figure + + def _is_isolated(self): + return True + + def _build(self): + self.alignment = alignment.center + self.__img = Image(fit="fill") + self.content = self.__img + + def _before_build_command(self): + super()._before_build_command() + if self.__figure is not None: + s = io.StringIO() + self.__figure.savefig(s, format="svg") + svg = s.getvalue() + + root = ET.fromstring(svg) + w = float(re.findall(r"\d+", root.attrib["width"])[0]) + h = float(re.findall(r"\d+", root.attrib["height"])[0]) + self.__img.aspect_ratio = w / h + self.__img.src = svg + + # figure + @property + def figure(self): + return self.__figure + + @figure.setter + def figure(self, value): + self.__figure = value + + # maintain_aspect_ratio + @property + def maintain_aspect_ratio(self) -> bool: + return self.__maintain_aspect_ratio + + @maintain_aspect_ratio.setter + @beartype + def maintain_aspect_ratio(self, value: bool): + self.__maintain_aspect_ratio = value From 4c7ed7891239c0e4045a01aeb92d795340482ee2 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 21 Oct 2022 13:59:33 -0700 Subject: [PATCH 09/12] Added MatplotlibChart.isolated --- sdk/python/flet/matplotlib_chart.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sdk/python/flet/matplotlib_chart.py b/sdk/python/flet/matplotlib_chart.py index f8b215da2..be09f2085 100644 --- a/sdk/python/flet/matplotlib_chart.py +++ b/sdk/python/flet/matplotlib_chart.py @@ -42,6 +42,10 @@ def __init__( visible: Optional[bool] = None, disabled: Optional[bool] = None, data: Any = None, + # + # Specific + # + isolated: bool = False, ): Container.__init__( @@ -67,9 +71,10 @@ def __init__( ) self.figure = figure + self.isolated = isolated def _is_isolated(self): - return True + return self.__isolated def _build(self): self.alignment = alignment.center @@ -89,6 +94,15 @@ def _before_build_command(self): self.__img.aspect_ratio = w / h self.__img.src = svg + # isolated + @property + def isolated(self): + return self.__isolated + + @isolated.setter + def isolated(self, value): + self.__isolated = value + # figure @property def figure(self): From da23cd61fea0189fb8c619de57cb8b0a1ffcad31 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 21 Oct 2022 21:23:32 -0700 Subject: [PATCH 10/12] Create plotly_chart.py --- sdk/python/flet/plotly_chart.py | 119 ++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 sdk/python/flet/plotly_chart.py diff --git a/sdk/python/flet/plotly_chart.py b/sdk/python/flet/plotly_chart.py new file mode 100644 index 000000000..041eaccef --- /dev/null +++ b/sdk/python/flet/plotly_chart.py @@ -0,0 +1,119 @@ +import io +import re +import xml.etree.ElementTree as ET +from typing import Any, Optional, Union + +from beartype import beartype + +from flet import alignment +from flet.container import Container +from flet.control import OptionalNumber +from flet.image import Image +from flet.ref import Ref +from flet.types import AnimationValue, OffsetValue, RotateValue, ScaleValue + +try: + from plotly.graph_objects import Figure +except ImportError: + raise Exception('Install "plotly" Python package to use PlotlyChart control.') + + +class PlotlyChart(Container): + def __init__( + self, + figure: Optional[Figure] = None, + ref: Optional[Ref] = None, + expand: Union[None, bool, int] = None, + opacity: OptionalNumber = None, + rotate: RotateValue = None, + scale: ScaleValue = None, + offset: OffsetValue = None, + aspect_ratio: OptionalNumber = None, + animate_opacity: AnimationValue = None, + animate_size: AnimationValue = None, + animate_position: AnimationValue = None, + animate_rotation: AnimationValue = None, + animate_scale: AnimationValue = None, + animate_offset: AnimationValue = None, + on_animation_end=None, + tooltip: Optional[str] = None, + visible: Optional[bool] = None, + disabled: Optional[bool] = None, + data: Any = None, + # + # Specific + # + isolated: bool = False, + ): + + Container.__init__( + self, + ref=ref, + expand=expand, + opacity=opacity, + rotate=rotate, + scale=scale, + offset=offset, + aspect_ratio=aspect_ratio, + animate_opacity=animate_opacity, + animate_size=animate_size, + animate_position=animate_position, + animate_rotation=animate_rotation, + animate_scale=animate_scale, + animate_offset=animate_offset, + on_animation_end=on_animation_end, + tooltip=tooltip, + visible=visible, + disabled=disabled, + data=data, + ) + + self.figure = figure + self.isolated = isolated + + def _is_isolated(self): + return self.__isolated + + def _build(self): + self.alignment = alignment.center + self.__img = Image(fit="fill") + self.content = self.__img + + def _before_build_command(self): + super()._before_build_command() + if self.__figure is not None: + svg = self.__figure.to_image(format="svg").decode("utf-8") + + root = ET.fromstring(svg) + w = float(re.findall(r"\d+", root.attrib["width"])[0]) + h = float(re.findall(r"\d+", root.attrib["height"])[0]) + self.__img.aspect_ratio = w / h + self.__img.src = svg + + # isolated + @property + def isolated(self): + return self.__isolated + + @isolated.setter + def isolated(self, value): + self.__isolated = value + + # figure + @property + def figure(self): + return self.__figure + + @figure.setter + def figure(self, value): + self.__figure = value + + # maintain_aspect_ratio + @property + def maintain_aspect_ratio(self) -> bool: + return self.__maintain_aspect_ratio + + @maintain_aspect_ratio.setter + @beartype + def maintain_aspect_ratio(self, value: bool): + self.__maintain_aspect_ratio = value From ff3da1e6203586fbedb2f2fc2c6de9759a6a1183 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 21 Oct 2022 21:36:18 -0700 Subject: [PATCH 11/12] Update pubspec.lock --- client/pubspec.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/pubspec.lock b/client/pubspec.lock index 1da57d55b..c1a54c621 100644 --- a/client/pubspec.lock +++ b/client/pubspec.lock @@ -197,8 +197,8 @@ packages: dependency: transitive description: path: "." - ref: image-transform-fix - resolved-ref: "1dd97b0b790ed04d8652e21652d9af6edd9f768f" + ref: flet-fixes + resolved-ref: "71166dc07d39b686f117319a04479d26e44c2a24" url: "https://github.com/flet-dev/flutter_svg.git" source: git version: "1.1.5" From 9e00d70b5151a1be76b273f08d906e7296fa367e Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Sat, 22 Oct 2022 13:09:13 -0700 Subject: [PATCH 12/12] original_size --- sdk/python/flet/matplotlib_chart.py | 20 ++++++++++++++++---- sdk/python/flet/plotly_chart.py | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/sdk/python/flet/matplotlib_chart.py b/sdk/python/flet/matplotlib_chart.py index be09f2085..a7b27a57c 100644 --- a/sdk/python/flet/matplotlib_chart.py +++ b/sdk/python/flet/matplotlib_chart.py @@ -46,6 +46,7 @@ def __init__( # Specific # isolated: bool = False, + original_size: bool = False, ): Container.__init__( @@ -72,6 +73,7 @@ def __init__( self.figure = figure self.isolated = isolated + self.original_size = original_size def _is_isolated(self): return self.__isolated @@ -88,12 +90,22 @@ def _before_build_command(self): self.__figure.savefig(s, format="svg") svg = s.getvalue() - root = ET.fromstring(svg) - w = float(re.findall(r"\d+", root.attrib["width"])[0]) - h = float(re.findall(r"\d+", root.attrib["height"])[0]) - self.__img.aspect_ratio = w / h + if not self.__original_size: + root = ET.fromstring(svg) + w = float(re.findall(r"\d+", root.attrib["width"])[0]) + h = float(re.findall(r"\d+", root.attrib["height"])[0]) + self.__img.aspect_ratio = w / h self.__img.src = svg + # original_size + @property + def original_size(self): + return self.__original_size + + @original_size.setter + def original_size(self, value): + self.__original_size = value + # isolated @property def isolated(self): diff --git a/sdk/python/flet/plotly_chart.py b/sdk/python/flet/plotly_chart.py index 041eaccef..db984b76d 100644 --- a/sdk/python/flet/plotly_chart.py +++ b/sdk/python/flet/plotly_chart.py @@ -44,6 +44,7 @@ def __init__( # Specific # isolated: bool = False, + original_size: bool = False, ): Container.__init__( @@ -70,6 +71,7 @@ def __init__( self.figure = figure self.isolated = isolated + self.original_size = original_size def _is_isolated(self): return self.__isolated @@ -84,12 +86,22 @@ def _before_build_command(self): if self.__figure is not None: svg = self.__figure.to_image(format="svg").decode("utf-8") - root = ET.fromstring(svg) - w = float(re.findall(r"\d+", root.attrib["width"])[0]) - h = float(re.findall(r"\d+", root.attrib["height"])[0]) - self.__img.aspect_ratio = w / h + if not self.__original_size: + root = ET.fromstring(svg) + w = float(re.findall(r"\d+", root.attrib["width"])[0]) + h = float(re.findall(r"\d+", root.attrib["height"])[0]) + self.__img.aspect_ratio = w / h self.__img.src = svg + # original_size + @property + def original_size(self): + return self.__original_size + + @original_size.setter + def original_size(self, value): + self.__original_size = value + # isolated @property def isolated(self):