diff --git a/sdk/python/examples/controls/charts/bar_chart/__init__.py b/sdk/python/examples/controls/charts/bar_chart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/examples/controls/charts/bar_chart/example_1.py b/sdk/python/examples/controls/charts/bar_chart/example_1.py index 98029dc971..fb1c91fd98 100644 --- a/sdk/python/examples/controls/charts/bar_chart/example_1.py +++ b/sdk/python/examples/controls/charts/bar_chart/example_1.py @@ -93,4 +93,5 @@ def main(page: ft.Page): ) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/bar_chart/example_2.py b/sdk/python/examples/controls/charts/bar_chart/example_2.py index 6acdc099b8..56f275005f 100644 --- a/sdk/python/examples/controls/charts/bar_chart/example_2.py +++ b/sdk/python/examples/controls/charts/bar_chart/example_2.py @@ -70,4 +70,5 @@ def on_chart_event(e: fch.BarChartEvent): ) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/candlestick_chart/__init__.py b/sdk/python/examples/controls/charts/candlestick_chart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/examples/controls/charts/candlestick_chart/example_1.py b/sdk/python/examples/controls/charts/candlestick_chart/example_1.py index 4cfb62c259..21e631dd81 100644 --- a/sdk/python/examples/controls/charts/candlestick_chart/example_1.py +++ b/sdk/python/examples/controls/charts/candlestick_chart/example_1.py @@ -124,4 +124,5 @@ def handle_event(e: fch.CandlestickChartEvent): ) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/line_chart/__init__.py b/sdk/python/examples/controls/charts/line_chart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/examples/controls/charts/line_chart/example_1.py b/sdk/python/examples/controls/charts/line_chart/example_1.py index 50b0f6f4b6..9a4734c203 100644 --- a/sdk/python/examples/controls/charts/line_chart/example_1.py +++ b/sdk/python/examples/controls/charts/line_chart/example_1.py @@ -203,4 +203,5 @@ def toggle_data(e: ft.Event[ft.IconButton]): page.add(ft.IconButton(ft.Icons.REFRESH, on_click=toggle_data), chart) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/line_chart/example_2.py b/sdk/python/examples/controls/charts/line_chart/example_2.py index be384be542..e541023cc2 100644 --- a/sdk/python/examples/controls/charts/line_chart/example_2.py +++ b/sdk/python/examples/controls/charts/line_chart/example_2.py @@ -136,4 +136,5 @@ def toggle_data(e: ft.Event[ft.ElevatedButton]): page.add(ft.Button("avg", on_click=toggle_data), chart) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/matplotlib_chart/__init__.py b/sdk/python/examples/controls/charts/matplotlib_chart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/examples/controls/charts/matplotlib_chart/animate.py b/sdk/python/examples/controls/charts/matplotlib_chart/animate.py index d2073574e1..87cdebeb8d 100644 --- a/sdk/python/examples/controls/charts/matplotlib_chart/animate.py +++ b/sdk/python/examples/controls/charts/matplotlib_chart/animate.py @@ -53,4 +53,5 @@ def update_lines(num, walks, lines): page.add(flet_charts.MatplotlibChartWithToolbar(figure=fig, expand=True)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/matplotlib_chart/bar_chart.py b/sdk/python/examples/controls/charts/matplotlib_chart/bar_chart.py index a96589826f..b0fb23e225 100644 --- a/sdk/python/examples/controls/charts/matplotlib_chart/bar_chart.py +++ b/sdk/python/examples/controls/charts/matplotlib_chart/bar_chart.py @@ -21,4 +21,5 @@ def main(page: ft.Page): page.add(fch.MatplotlibChart(figure=fig, expand=True)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/matplotlib_chart/handle_events.py b/sdk/python/examples/controls/charts/matplotlib_chart/handle_events.py index ea3de39d14..6a71831065 100644 --- a/sdk/python/examples/controls/charts/matplotlib_chart/handle_events.py +++ b/sdk/python/examples/controls/charts/matplotlib_chart/handle_events.py @@ -100,4 +100,5 @@ def update(self): page.add(flet_charts.MatplotlibChartWithToolbar(figure=fig, expand=True)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/matplotlib_chart/3d.py b/sdk/python/examples/controls/charts/matplotlib_chart/three_d.py similarity index 95% rename from sdk/python/examples/controls/charts/matplotlib_chart/3d.py rename to sdk/python/examples/controls/charts/matplotlib_chart/three_d.py index 3ec3eb65c4..214318b08f 100644 --- a/sdk/python/examples/controls/charts/matplotlib_chart/3d.py +++ b/sdk/python/examples/controls/charts/matplotlib_chart/three_d.py @@ -33,4 +33,5 @@ def main(page: ft.Page): page.add(flet_charts.MatplotlibChartWithToolbar(figure=fig)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/matplotlib_chart/toolbar.py b/sdk/python/examples/controls/charts/matplotlib_chart/toolbar.py index 43da77460f..d58c1ead61 100644 --- a/sdk/python/examples/controls/charts/matplotlib_chart/toolbar.py +++ b/sdk/python/examples/controls/charts/matplotlib_chart/toolbar.py @@ -33,4 +33,5 @@ def main(page: ft.Page): page.add(fch.MatplotlibChartWithToolbar(figure=fig, expand=True)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/pie_chart/__init__.py b/sdk/python/examples/controls/charts/pie_chart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/examples/controls/charts/pie_chart/example_1.py b/sdk/python/examples/controls/charts/pie_chart/example_1.py index b8acd8931a..8f84c472b0 100644 --- a/sdk/python/examples/controls/charts/pie_chart/example_1.py +++ b/sdk/python/examples/controls/charts/pie_chart/example_1.py @@ -50,4 +50,5 @@ def on_chart_event(e: fch.PieChartEvent): page.add(chart) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/pie_chart/example_2.py b/sdk/python/examples/controls/charts/pie_chart/example_2.py index 1e48927ca7..97701fb3ac 100644 --- a/sdk/python/examples/controls/charts/pie_chart/example_2.py +++ b/sdk/python/examples/controls/charts/pie_chart/example_2.py @@ -65,4 +65,5 @@ def on_chart_event(e: fch.PieChartEvent): page.add(chart) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/pie_chart/example_3.py b/sdk/python/examples/controls/charts/pie_chart/example_3.py index 9c725da6d5..38d649e74a 100644 --- a/sdk/python/examples/controls/charts/pie_chart/example_3.py +++ b/sdk/python/examples/controls/charts/pie_chart/example_3.py @@ -87,4 +87,5 @@ def on_chart_event(e: fch.PieChartEvent): page.add(chart) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/plotly_chart/__init__.py b/sdk/python/examples/controls/charts/plotly_chart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/examples/controls/charts/plotly_chart/example_1.py b/sdk/python/examples/controls/charts/plotly_chart/example_1.py index 78ad629ab6..1ac3d9ad1e 100644 --- a/sdk/python/examples/controls/charts/plotly_chart/example_1.py +++ b/sdk/python/examples/controls/charts/plotly_chart/example_1.py @@ -11,4 +11,5 @@ def main(page: ft.Page): page.add(fch.PlotlyChart(figure=fig, expand=True)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/plotly_chart/example_2.py b/sdk/python/examples/controls/charts/plotly_chart/example_2.py index b6e6c98816..0060b1b67b 100644 --- a/sdk/python/examples/controls/charts/plotly_chart/example_2.py +++ b/sdk/python/examples/controls/charts/plotly_chart/example_2.py @@ -19,4 +19,5 @@ def main(page: ft.Page): page.add(fch.PlotlyChart(figure=fig, expand=True)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/plotly_chart/example_3.py b/sdk/python/examples/controls/charts/plotly_chart/example_3.py index c7f6bc8838..436bf87f24 100644 --- a/sdk/python/examples/controls/charts/plotly_chart/example_3.py +++ b/sdk/python/examples/controls/charts/plotly_chart/example_3.py @@ -13,4 +13,5 @@ def main(page: ft.Page): page.add(fch.PlotlyChart(figure=fig, expand=True)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/plotly_chart/example_4.py b/sdk/python/examples/controls/charts/plotly_chart/example_4.py index c121a10370..9fdf998721 100644 --- a/sdk/python/examples/controls/charts/plotly_chart/example_4.py +++ b/sdk/python/examples/controls/charts/plotly_chart/example_4.py @@ -55,4 +55,5 @@ def main(page: ft.Page): page.add(fch.PlotlyChart(figure=fig, expand=True)) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/examples/controls/charts/radar_chart/__init__.py b/sdk/python/examples/controls/charts/radar_chart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/examples/controls/charts/radar_chart/example_1.py b/sdk/python/examples/controls/charts/radar_chart/example_1.py index bbd137dea4..454c15b844 100644 --- a/sdk/python/examples/controls/charts/radar_chart/example_1.py +++ b/sdk/python/examples/controls/charts/radar_chart/example_1.py @@ -5,7 +5,7 @@ def main(page: ft.Page): page.title = "Radar chart" page.padding = 20 - page.vertical_alignment = page.horizontal_alignment = "center" + # page.vertical_alignment = page.horizontal_alignment = "center" page.theme_mode = ft.ThemeMode.LIGHT categories = ["macOS", "Linux", "Windows"] diff --git a/sdk/python/examples/controls/charts/scatter_chart/__init__.py b/sdk/python/examples/controls/charts/scatter_chart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/examples/controls/charts/scatter_chart/example_1.py b/sdk/python/examples/controls/charts/scatter_chart/example_1.py index 175af4319f..e3ed0c76cc 100644 --- a/sdk/python/examples/controls/charts/scatter_chart/example_1.py +++ b/sdk/python/examples/controls/charts/scatter_chart/example_1.py @@ -157,4 +157,5 @@ def handle_event(e: fch.ScatterChartEvent): ) -ft.run(main) +if __name__ == "__main__": + ft.run(main) diff --git a/sdk/python/packages/flet-charts/integration_tests/conftest.py b/sdk/python/packages/flet-charts/integration_tests/conftest.py new file mode 100644 index 0000000000..608d26608b --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/conftest.py @@ -0,0 +1,32 @@ +from pathlib import Path + +import pytest_asyncio + +import flet.testing as ftt + + +def create_flet_app(request): + params = getattr(request, "param", {}) + return ftt.FletTestApp( + flutter_app_dir=(Path(__file__).parent / "../../../../../client").resolve(), + test_path=request.fspath, + flet_app_main=params.get("flet_app_main"), + skip_pump_and_settle=params.get("skip_pump_and_settle", False), + assets_dir=Path(__file__).resolve().parent / "assets", + ) + + +@pytest_asyncio.fixture(scope="module") +async def flet_app(request): + flet_app = create_flet_app(request) + await flet_app.start() + yield flet_app + await flet_app.teardown() + + +@pytest_asyncio.fixture(scope="function") +async def flet_app_function(request): + flet_app = create_flet_app(request) + await flet_app.start() + yield flet_app + await flet_app.teardown() diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/example_1.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/example_1.png new file mode 100644 index 0000000000..d8edda72f3 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/example_1.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/example_2.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/example_2.png new file mode 100644 index 0000000000..59984cabf1 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/example_2.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/image_for_docs.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/image_for_docs.png new file mode 100644 index 0000000000..896bf4e802 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/bar_chart/image_for_docs.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/candlestick_chart/example_1.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/candlestick_chart/example_1.png new file mode 100644 index 0000000000..31bd5be78a Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/candlestick_chart/example_1.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/candlestick_chart/image_for_docs.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/candlestick_chart/image_for_docs.png new file mode 100644 index 0000000000..ebe189336c Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/candlestick_chart/image_for_docs.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/example_1.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/example_1.png new file mode 100644 index 0000000000..0d50433bee Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/example_1.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/example_2.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/example_2.png new file mode 100644 index 0000000000..35f2c91b14 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/example_2.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/image_for_docs.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/image_for_docs.png new file mode 100644 index 0000000000..b5d03d566c Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/line_chart/image_for_docs.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/bar_chart.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/bar_chart.png new file mode 100644 index 0000000000..7f3250b9d8 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/bar_chart.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/handle_events.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/handle_events.png new file mode 100644 index 0000000000..ebaffcbe88 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/handle_events.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/three_d.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/three_d.png new file mode 100644 index 0000000000..c3fd1f8d4f Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/three_d.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/toolbar.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/toolbar.png new file mode 100644 index 0000000000..63f0388b82 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/matplotlib_chart/toolbar.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_1.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_1.png new file mode 100644 index 0000000000..30716c1f34 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_1.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_2.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_2.png new file mode 100644 index 0000000000..6abdb67a5d Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_2.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_3.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_3.png new file mode 100644 index 0000000000..e9ef47d553 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/pie_chart/example_3.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/radar_chart/example_1.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/radar_chart/example_1.png new file mode 100644 index 0000000000..afd0d9b91f Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/radar_chart/example_1.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/radar_chart/image_for_docs.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/radar_chart/image_for_docs.png new file mode 100644 index 0000000000..e978295f44 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/radar_chart/image_for_docs.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/scatter_chart/example_1.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/scatter_chart/example_1.png new file mode 100644 index 0000000000..75b1d61347 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/scatter_chart/example_1.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/scatter_chart/image_for_docs.png b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/scatter_chart/image_for_docs.png new file mode 100644 index 0000000000..2284808ac1 Binary files /dev/null and b/sdk/python/packages/flet-charts/integration_tests/examples/golden/macos/scatter_chart/image_for_docs.png differ diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/test_bar_chart.py b/sdk/python/packages/flet-charts/integration_tests/examples/test_bar_chart.py new file mode 100644 index 0000000000..cd11c982d4 --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/examples/test_bar_chart.py @@ -0,0 +1,71 @@ +import pytest + +import flet as ft +import flet_charts as fch +import flet.testing as ftt +from examples.controls.charts.bar_chart import example_1, example_2 + + +@pytest.mark.asyncio(loop_scope="function") +async def test_image_for_docs(flet_app_function: ftt.FletTestApp, request): + flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT + await flet_app_function.assert_control_screenshot( + request.node.name, + fch.BarChart( + border=ft.Border.all(1, ft.Colors.GREY_400), + groups=[ + fch.BarChartGroup( + x=0, + rods=[ + fch.BarChartRod( + from_y=0, + to_y=40, + color=ft.Colors.BLUE_GREY_200, + ), + ], + ), + fch.BarChartGroup( + x=1, + rods=[ + fch.BarChartRod( + from_y=0, + to_y=60, + color=ft.Colors.BLUE_GREY_600, + ), + ], + ), + ], + ), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_1.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_1(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_1", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_2.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_2(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_2", + await flet_app_function.page.take_screenshot(), + ) diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/test_candlestick_chart.py b/sdk/python/packages/flet-charts/integration_tests/examples/test_candlestick_chart.py new file mode 100644 index 0000000000..7a795fdd4b --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/examples/test_candlestick_chart.py @@ -0,0 +1,53 @@ +import pytest + +import flet as ft +import flet_charts as fch +import flet.testing as ftt +from examples.controls.charts.candlestick_chart import example_1 + + +@pytest.mark.asyncio(loop_scope="function") +async def test_image_for_docs(flet_app_function: ftt.FletTestApp, request): + flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT + await flet_app_function.assert_control_screenshot( + request.node.name, + fch.CandlestickChart( + min_x=-1, + max_x=2, + min_y=20, + max_y=30, + bgcolor=ft.Colors.AMBER_200, + spots=[ + fch.CandlestickChartSpot( + x=0, + open=22.6, + high=28.3, + low=21.4, + close=24.1, + ), + fch.CandlestickChartSpot( + x=1, + open=25.4, + high=27.6, + low=22.3, + close=23.9, + ), + ], + ), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_1.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_1(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_1", + await flet_app_function.page.take_screenshot(), + ) diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/test_line_chart.py b/sdk/python/packages/flet-charts/integration_tests/examples/test_line_chart.py new file mode 100644 index 0000000000..eff2f18774 --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/examples/test_line_chart.py @@ -0,0 +1,72 @@ +import pytest + +import flet as ft +import flet_charts as fch +import flet.testing as ftt +from examples.controls.charts.line_chart import example_1, example_2 + + +@pytest.mark.asyncio(loop_scope="function") +async def test_image_for_docs(flet_app_function: ftt.FletTestApp, request): + flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT + await flet_app_function.assert_control_screenshot( + request.node.name, + fch.LineChart( + data_series=[ + fch.LineChartData( + color=ft.Colors.BLUE_GREY_500, + curved=True, + points=[ + fch.LineChartDataPoint(1, 0.5), + fch.LineChartDataPoint(2, 1.5), + fch.LineChartDataPoint(3, 1), + ], + ), + fch.LineChartData( + color=ft.Colors.AMBER_400, + curved=True, + points=[ + fch.LineChartDataPoint(1, 2), + fch.LineChartDataPoint(2, 0.5), + fch.LineChartDataPoint(3, 1.5), + ], + ), + ], + min_y=0, + max_y=3, + min_x=0, + max_x=5, + ), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_1.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_1(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_1", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_2.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_2(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_2", + await flet_app_function.page.take_screenshot(), + ) diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/test_matplotlib_chart.py b/sdk/python/packages/flet-charts/integration_tests/examples/test_matplotlib_chart.py new file mode 100644 index 0000000000..51deb31124 --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/examples/test_matplotlib_chart.py @@ -0,0 +1,72 @@ +import pytest + +import flet as ft +import flet_charts as fch +import flet.testing as ftt +from examples.controls.charts.matplotlib_chart import ( + bar_chart, + handle_events, + toolbar, + three_d, +) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": bar_chart.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_bar_chart(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "bar_chart", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": handle_events.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_handle_events(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "handle_events", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": toolbar.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_toolbar(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "toolbar", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": three_d.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_three_d(flet_app_function: ftt.FletTestApp): + flet_app_function.assert_screenshot( + "three_d", + await flet_app_function.take_page_controls_screenshot(), + ) diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/test_pie_chart.py b/sdk/python/packages/flet-charts/integration_tests/examples/test_pie_chart.py new file mode 100644 index 0000000000..9bccf04151 --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/examples/test_pie_chart.py @@ -0,0 +1,54 @@ +import pytest + +import flet as ft +import flet_charts as fch +import flet.testing as ftt +from examples.controls.charts.pie_chart import example_1, example_2, example_3 + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_1.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_1(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_1", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_2.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_2(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_2", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_3.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_3(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_3", + await flet_app_function.page.take_screenshot(), + ) diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/test_plotly_chart.py b/sdk/python/packages/flet-charts/integration_tests/examples/test_plotly_chart.py new file mode 100644 index 0000000000..a753fc1517 --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/examples/test_plotly_chart.py @@ -0,0 +1,79 @@ +import pytest + +import flet as ft +import flet_charts as fch +import flet.testing as ftt +from examples.controls.charts.plotly_chart import ( + example_1, + example_2, + example_3, + example_4, +) + + +@pytest.mark.skip(reason="poltly control temporarily out of service") +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_1.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_1(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_1", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.skip(reason="poltly control temporarily out of service") +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_2.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_2(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_2", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.skip(reason="poltly control temporarily out of service") +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_3.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_3(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_3", + await flet_app_function.page.take_screenshot(), + ) + + +@pytest.mark.skip(reason="poltly control temporarily out of service") +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_4.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_4(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_4", + await flet_app_function.page.take_screenshot(), + ) diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/test_radar_chart.py b/sdk/python/packages/flet-charts/integration_tests/examples/test_radar_chart.py new file mode 100644 index 0000000000..75979fbdd5 --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/examples/test_radar_chart.py @@ -0,0 +1,62 @@ +import pytest + +import flet as ft +import flet_charts as fch +import flet.testing as ftt +from examples.controls.charts.radar_chart import example_1 + + +@pytest.mark.asyncio(loop_scope="function") +async def test_image_for_docs(flet_app_function: ftt.FletTestApp, request): + flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT + flet_app_function.page.padding = 20 + flet_app_function.page.update() + await flet_app_function.assert_control_screenshot( + request.node.name, + fch.RadarChart( + # expand=True, + titles=[ + fch.RadarChartTitle(text="winter", position_percentage_offset=0.1), + fch.RadarChartTitle(text="spring", position_percentage_offset=0.1), + fch.RadarChartTitle(text="summer", position_percentage_offset=0.1), + fch.RadarChartTitle(text="autumn", position_percentage_offset=0.1), + ], + radar_shape=fch.RadarShape.CIRCLE, + data_sets=[ + fch.RadarDataSet( + fill_color=ft.Colors.with_opacity(0.2, ft.Colors.BLUE_GREY_700), + entries=[ + fch.RadarDataSetEntry(130), + fch.RadarDataSetEntry(95), + fch.RadarDataSetEntry(190), + fch.RadarDataSetEntry(60), + ], + ), + fch.RadarDataSet( + fill_color=ft.Colors.with_opacity(0.2, ft.Colors.CYAN_400), + entries=[ + fch.RadarDataSetEntry(90), + fch.RadarDataSetEntry(45), + fch.RadarDataSetEntry(265), + fch.RadarDataSetEntry(150), + ], + ), + ], + ), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_1.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_1(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_1", + await flet_app_function.page.take_screenshot(), + ) diff --git a/sdk/python/packages/flet-charts/integration_tests/examples/test_scatter_chart.py b/sdk/python/packages/flet-charts/integration_tests/examples/test_scatter_chart.py new file mode 100644 index 0000000000..1266c89239 --- /dev/null +++ b/sdk/python/packages/flet-charts/integration_tests/examples/test_scatter_chart.py @@ -0,0 +1,68 @@ +import pytest + + +import flet as ft +import flet_charts as fch +import flet.testing as ftt +from examples.controls.charts.scatter_chart import example_1 + + +@pytest.mark.asyncio(loop_scope="function") +async def test_image_for_docs(flet_app_function: ftt.FletTestApp, request): + flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT + chart_spots = [ + fch.ScatterChartSpot( + x=i * 2, + y=i * 3, + ) + for i in range(10) + ] + chart_spots += [ + fch.ScatterChartSpot( + x=i, + y=i, + ) + for i in range(10) + ] + + chart_spots += [ + fch.ScatterChartSpot( + x=i + 2, + y=i + 10, + ) + for i in range(10) + ] + + await flet_app_function.assert_control_screenshot( + request.node.name, + fch.ScatterChart( + # expand=True, + aspect_ratio=1.0, + # min_x=0.0, + # max_x=50.0, + # min_y=0.0, + # max_y=50.0, + # left_axis=fch.ChartAxis(show_labels=False), + # right_axis=fch.ChartAxis(show_labels=False), + # top_axis=fch.ChartAxis(show_labels=False), + # bottom_axis=fch.ChartAxis(show_labels=False), + # show_tooltips_for_selected_spots_only=False, + spots=chart_spots, + ), + ) + + +@pytest.mark.parametrize( + "flet_app_function", + [{"flet_app_main": example_1.main}], + indirect=True, +) +@pytest.mark.asyncio(loop_scope="function") +async def test_example_1(flet_app_function: ftt.FletTestApp): + flet_app_function.page.enable_screenshots = True + flet_app_function.page.update() + await flet_app_function.tester.pump_and_settle() + flet_app_function.assert_screenshot( + "example_1", + await flet_app_function.page.take_screenshot(), + ) diff --git a/sdk/python/packages/flet-charts/src/flet_charts/bar_chart.py b/sdk/python/packages/flet-charts/src/flet_charts/bar_chart.py index e51fd4e2c8..f054fca49a 100644 --- a/sdk/python/packages/flet-charts/src/flet_charts/bar_chart.py +++ b/sdk/python/packages/flet-charts/src/flet_charts/bar_chart.py @@ -115,27 +115,35 @@ def copy( """ return BarChartTooltip( bgcolor=bgcolor if bgcolor is not None else self.bgcolor, - border_radius=border_radius - if border_radius is not None - else self.border_radius, + border_radius=( + border_radius if border_radius is not None else self.border_radius + ), margin=margin if margin is not None else self.margin, padding=padding if padding is not None else self.padding, max_width=max_width if max_width is not None else self.max_width, rotation=rotation if rotation is not None else self.rotation, - horizontal_offset=horizontal_offset - if horizontal_offset is not None - else self.horizontal_offset, + horizontal_offset=( + horizontal_offset + if horizontal_offset is not None + else self.horizontal_offset + ), border_side=border_side if border_side is not None else self.border_side, - fit_inside_horizontally=fit_inside_horizontally - if fit_inside_horizontally is not None - else self.fit_inside_horizontally, - fit_inside_vertically=fit_inside_vertically - if fit_inside_vertically is not None - else self.fit_inside_vertically, + fit_inside_horizontally=( + fit_inside_horizontally + if fit_inside_horizontally is not None + else self.fit_inside_horizontally + ), + fit_inside_vertically=( + fit_inside_vertically + if fit_inside_vertically is not None + else self.fit_inside_vertically + ), direction=direction if direction is not None else self.direction, - horizontal_alignment=horizontal_alignment - if horizontal_alignment is not None - else self.horizontal_alignment, + horizontal_alignment=( + horizontal_alignment + if horizontal_alignment is not None + else self.horizontal_alignment + ), ) @@ -166,6 +174,26 @@ class BarChartEvent(ft.Event["BarChart"]): class BarChart(ft.LayoutControl): """ Draws a bar chart. + + ```python + fch.BarChart( + border=ft.Border.all(1, ft.Colors.GREY_400), + groups=[ + fch.BarChartGroup( + x=0, + rods=[ + fch.BarChartRod( + from_y=0, + to_y=40, + color=ft.Colors.BLUE_GREY_200, + ), + ], + ), + ... + ], + ) + ``` + """ groups: list[BarChartGroup] = field(default_factory=list) diff --git a/sdk/python/packages/flet-charts/src/flet_charts/candlestick_chart.py b/sdk/python/packages/flet-charts/src/flet_charts/candlestick_chart.py index 7062d5e624..98e33b8861 100644 --- a/sdk/python/packages/flet-charts/src/flet_charts/candlestick_chart.py +++ b/sdk/python/packages/flet-charts/src/flet_charts/candlestick_chart.py @@ -96,28 +96,38 @@ def copy( """ return CandlestickChartTooltip( bgcolor=bgcolor if bgcolor is not None else self.bgcolor, - border_radius=border_radius - if border_radius is not None - else self.border_radius, + border_radius=( + border_radius if border_radius is not None else self.border_radius + ), padding=padding if padding is not None else self.padding, max_width=max_width if max_width is not None else self.max_width, rotation=rotation if rotation is not None else self.rotation, - horizontal_offset=horizontal_offset - if horizontal_offset is not None - else self.horizontal_offset, - horizontal_alignment=horizontal_alignment - if horizontal_alignment is not None - else self.horizontal_alignment, + horizontal_offset=( + horizontal_offset + if horizontal_offset is not None + else self.horizontal_offset + ), + horizontal_alignment=( + horizontal_alignment + if horizontal_alignment is not None + else self.horizontal_alignment + ), border_side=border_side if border_side is not None else self.border_side, - fit_inside_horizontally=fit_inside_horizontally - if fit_inside_horizontally is not None - else self.fit_inside_horizontally, - fit_inside_vertically=fit_inside_vertically - if fit_inside_vertically is not None - else self.fit_inside_vertically, - show_on_top_of_chart_box_area=show_on_top_of_chart_box_area - if show_on_top_of_chart_box_area is not None - else self.show_on_top_of_chart_box_area, + fit_inside_horizontally=( + fit_inside_horizontally + if fit_inside_horizontally is not None + else self.fit_inside_horizontally + ), + fit_inside_vertically=( + fit_inside_vertically + if fit_inside_vertically is not None + else self.fit_inside_vertically + ), + show_on_top_of_chart_box_area=( + show_on_top_of_chart_box_area + if show_on_top_of_chart_box_area is not None + else self.show_on_top_of_chart_box_area + ), ) @@ -140,6 +150,27 @@ class CandlestickChartEvent(ft.Event["CandlestickChart"]): class CandlestickChart(ft.LayoutControl): """ Draws a candlestick chart representing OHLC values. + + ```python + fch.CandlestickChart( + min_x=-1, + max_x=2, + min_y=20, + max_y=30, + bgcolor=ft.Colors.AMBER_200, + spots=[ + fch.CandlestickChartSpot( + x=0, + open=22.6, + high=28.3, + low=21.4, + close=24.1, + ), + ... + ], + ) + ``` + """ spots: list[CandlestickChartSpot] = field(default_factory=list) diff --git a/sdk/python/packages/flet-charts/src/flet_charts/line_chart.py b/sdk/python/packages/flet-charts/src/flet_charts/line_chart.py index 8543dd44e3..8018ab1e7e 100644 --- a/sdk/python/packages/flet-charts/src/flet_charts/line_chart.py +++ b/sdk/python/packages/flet-charts/src/flet_charts/line_chart.py @@ -140,26 +140,34 @@ def copy( """ return LineChartTooltip( bgcolor=bgcolor if bgcolor is not None else self.bgcolor, - border_radius=border_radius - if border_radius is not None - else self.border_radius, + border_radius=( + border_radius if border_radius is not None else self.border_radius + ), margin=margin if margin is not None else self.margin, padding=padding if padding is not None else self.padding, max_width=max_width if max_width is not None else self.max_width, rotation=rotation if rotation is not None else self.rotation, - horizontal_offset=horizontal_offset - if horizontal_offset is not None - else self.horizontal_offset, + horizontal_offset=( + horizontal_offset + if horizontal_offset is not None + else self.horizontal_offset + ), border_side=border_side if border_side is not None else self.border_side, - fit_inside_horizontally=fit_inside_horizontally - if fit_inside_horizontally is not None - else self.fit_inside_horizontally, - fit_inside_vertically=fit_inside_vertically - if fit_inside_vertically is not None - else self.fit_inside_vertically, - show_on_top_of_chart_box_area=show_on_top_of_chart_box_area - if show_on_top_of_chart_box_area is not None - else self.show_on_top_of_chart_box_area, + fit_inside_horizontally=( + fit_inside_horizontally + if fit_inside_horizontally is not None + else self.fit_inside_horizontally + ), + fit_inside_vertically=( + fit_inside_vertically + if fit_inside_vertically is not None + else self.fit_inside_vertically + ), + show_on_top_of_chart_box_area=( + show_on_top_of_chart_box_area + if show_on_top_of_chart_box_area is not None + else self.show_on_top_of_chart_box_area + ), ) @@ -167,6 +175,28 @@ def copy( class LineChart(ft.LayoutControl): """ Draws a line chart. + + ```python + fch.LineChart( + data_series=[ + fch.LineChartData( + color=ft.Colors.BLUE_GREY_500, + curved=True, + points=[ + fch.LineChartDataPoint(1, 0.5), + fch.LineChartDataPoint(2, 1.5), + fch.LineChartDataPoint(3, 1), + ], + ), + ... + ], + min_y=0, + max_y=3, + min_x=0, + max_x=5, + ) + ``` + """ data_series: list[LineChartData] = field(default_factory=list) diff --git a/sdk/python/packages/flet-charts/src/flet_charts/radar_chart.py b/sdk/python/packages/flet-charts/src/flet_charts/radar_chart.py index 423d2197d1..efe68b94df 100644 --- a/sdk/python/packages/flet-charts/src/flet_charts/radar_chart.py +++ b/sdk/python/packages/flet-charts/src/flet_charts/radar_chart.py @@ -86,6 +86,27 @@ class RadarChartEvent(ft.Event["RadarChart"]): class RadarChart(ft.LayoutControl): """ A radar chart made of multiple datasets. + + ```python + fch.RadarChart( + titles=[ + fch.RadarChartTitle(text="winter"), + ... + ], + radar_shape=fch.RadarShape.CIRCLE, + data_sets=[ + fch.RadarDataSet( + fill_color=ft.Colors.with_opacity(0.2, ft.Colors.BLUE_GREY_700), + entries=[ + fch.RadarDataSetEntry(130), + ... + ], + ), + ... + ], + ) + ``` + """ data_sets: list[RadarDataSet] = field(default_factory=list) diff --git a/sdk/python/packages/flet-charts/src/flet_charts/scatter_chart.py b/sdk/python/packages/flet-charts/src/flet_charts/scatter_chart.py index 01c24c89e8..767368420c 100644 --- a/sdk/python/packages/flet-charts/src/flet_charts/scatter_chart.py +++ b/sdk/python/packages/flet-charts/src/flet_charts/scatter_chart.py @@ -84,25 +84,33 @@ def copy( """ return ScatterChartTooltip( bgcolor=bgcolor if bgcolor is not None else self.bgcolor, - border_radius=border_radius - if border_radius is not None - else self.border_radius, + border_radius=( + border_radius if border_radius is not None else self.border_radius + ), padding=padding if padding is not None else self.padding, max_width=max_width if max_width is not None else self.max_width, rotation=rotation if rotation is not None else self.rotation, - horizontal_offset=horizontal_offset - if horizontal_offset is not None - else self.horizontal_offset, - horizontal_alignment=horizontal_alignment - if horizontal_alignment is not None - else self.horizontal_alignment, + horizontal_offset=( + horizontal_offset + if horizontal_offset is not None + else self.horizontal_offset + ), + horizontal_alignment=( + horizontal_alignment + if horizontal_alignment is not None + else self.horizontal_alignment + ), border_side=border_side if border_side is not None else self.border_side, - fit_inside_horizontally=fit_inside_horizontally - if fit_inside_horizontally is not None - else self.fit_inside_horizontally, - fit_inside_vertically=fit_inside_vertically - if fit_inside_vertically is not None - else self.fit_inside_vertically, + fit_inside_horizontally=( + fit_inside_horizontally + if fit_inside_horizontally is not None + else self.fit_inside_horizontally + ), + fit_inside_vertically=( + fit_inside_vertically + if fit_inside_vertically is not None + else self.fit_inside_vertically + ), ) @@ -126,6 +134,19 @@ class ScatterChart(ft.LayoutControl): ScatterChart draws some points in a square space, points are defined by [`ScatterChartSpot`][(p).]s. + + ```python + + fch.ScatterChart( + aspect_ratio=1.0, + spots=[fch.ScatterChartSpot( + x=random.uniform(4, 50), + y=random.uniform(4, 50), + ) + for _ in range(30)] + ) + ``` + """ spots: list[ScatterChartSpot] = field(default_factory=list) diff --git a/sdk/python/packages/flet/docs/charts/bar_chart.md b/sdk/python/packages/flet/docs/charts/bar_chart.md index ebc71360cd..015d390ec1 100644 --- a/sdk/python/packages/flet/docs/charts/bar_chart.md +++ b/sdk/python/packages/flet/docs/charts/bar_chart.md @@ -1,11 +1,11 @@ --- class_name: flet_charts.bar_chart.BarChart examples: ../../examples/controls/charts/bar_chart -example_images: ../examples/controls/charts/bar_chart/media +example_images: ../test-images-charts/examples/golden/macos/bar_chart diagram: assets/bar-chart-diagram.svg --- -{{ class_summary(class_name, image_url=diagram, image_width="100%") }} +{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic bar chart", image_width="80%") }} ## Examples @@ -23,6 +23,6 @@ diagram: assets/bar-chart-diagram.svg --8<-- "{{ examples }}/example_2.py" ``` -{{ image(example_images + "/example_2.gif", width="80%") }} +{{ image(example_images + "/example_2.png", width="80%") }} {{ class_members(class_name) }} diff --git a/sdk/python/packages/flet/docs/charts/candlestick_chart.md b/sdk/python/packages/flet/docs/charts/candlestick_chart.md index 0e0d7c3587..1784c561f2 100644 --- a/sdk/python/packages/flet/docs/charts/candlestick_chart.md +++ b/sdk/python/packages/flet/docs/charts/candlestick_chart.md @@ -1,10 +1,10 @@ --- class_name: flet_charts.candlestick_chart.CandlestickChart examples: ../../examples/controls/charts/candlestick_chart -example_images: ../examples/controls/charts/candlestick_chart/media +example_images: ../test-images-charts/examples/golden/macos/candlestick_chart --- -{{ class_summary(class_name) }} +{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic candlestick chart", image_width="80%") }} ## Examples diff --git a/sdk/python/packages/flet/docs/charts/line_chart.md b/sdk/python/packages/flet/docs/charts/line_chart.md index 639813ff0e..f8bfbd0205 100644 --- a/sdk/python/packages/flet/docs/charts/line_chart.md +++ b/sdk/python/packages/flet/docs/charts/line_chart.md @@ -1,11 +1,11 @@ --- class_name: flet_charts.line_chart.LineChart examples: ../../examples/controls/charts/line_chart -example_images: ../examples/controls/charts/line_chart/media +example_images: ../test-images-charts/examples/golden/macos/line_chart diagram: assets/line-chart-diagram.svg --- -{{ class_summary(class_name, image_url=diagram, image_width="100%") }} +{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic line chart", image_width="80%") }} ## Examples @@ -15,7 +15,7 @@ diagram: assets/line-chart-diagram.svg --8<-- "{{ examples }}/example_1.py" ``` -{{ image(example_images + "/example_1.gif", width="80%") }} +{{ image(example_images + "/example_1.png", width="80%") }} ### Example 2 @@ -23,6 +23,6 @@ diagram: assets/line-chart-diagram.svg --8<-- "{{ examples }}/example_2.py" ``` -{{ image(example_images + "/example_2.gif", width="80%") }} +{{ image(example_images + "/example_2.png", width="80%") }} {{ class_members(class_name) }} diff --git a/sdk/python/packages/flet/docs/charts/matplotlib_chart.md b/sdk/python/packages/flet/docs/charts/matplotlib_chart.md index f5e10f150c..9bf195d231 100644 --- a/sdk/python/packages/flet/docs/charts/matplotlib_chart.md +++ b/sdk/python/packages/flet/docs/charts/matplotlib_chart.md @@ -1,7 +1,8 @@ --- class_name: flet_charts.matplotlib_chart.MatplotlibChart examples: ../../examples/controls/charts/matplotlib_chart -example_images: ../examples/controls/charts/matplotlib_chart/media +example_images: ../test-images-charts/examples/golden/macos/matplotlib_chart +example_media: ../examples/controls/charts/matplotlib_chart/media --- {{ class_summary(class_name, image_url=example_images + "/toolbar.png", image_width="80%") }} @@ -31,10 +32,10 @@ Based on an official [Matplotlib example](https://matplotlib.org/stable/gallery/ ### 3D chart ```python ---8<-- "{{ examples }}/3d.py" +--8<-- "{{ examples }}/three_d.py" ``` -{{ image(example_images + "/3d.png", width="80%") }} +{{ image(example_images + "/three_d.png", width="80%") }} ### Handle events @@ -50,6 +51,6 @@ Based on an official [Matplotlib example](https://matplotlib.org/stable/gallery/ --8<-- "{{ examples }}/animate.py" ``` -{{ image(example_images + "/animate.png", width="80%") }} +{{ image(example_media + "/animate.png", width="80%") }} {{ class_members(class_name) }} diff --git a/sdk/python/packages/flet/docs/charts/pie_chart.md b/sdk/python/packages/flet/docs/charts/pie_chart.md index 2f05455289..d0976a1356 100644 --- a/sdk/python/packages/flet/docs/charts/pie_chart.md +++ b/sdk/python/packages/flet/docs/charts/pie_chart.md @@ -1,7 +1,7 @@ --- class_name: flet_charts.pie_chart.PieChart examples: ../../examples/controls/charts/pie_chart -example_images: ../examples/controls/charts/pie_chart/media +example_images: ../test-images-charts/examples/golden/macos/pie_chart diagram: assets/pie-chart-diagram.svg --- @@ -15,7 +15,7 @@ diagram: assets/pie-chart-diagram.svg --8<-- "{{ examples }}/example_1.py" ``` -{{ image(example_images + "/example_1.gif", width="80%") }} +{{ image(example_images + "/example_1.png", width="80%") }} ### Example 2 @@ -23,7 +23,7 @@ diagram: assets/pie-chart-diagram.svg --8<-- "{{ examples }}/example_2.py" ``` -{{ image(example_images + "/example_2.gif", width="80%") }} +{{ image(example_images + "/example_2.png", width="80%") }} ### Example 3 @@ -31,6 +31,6 @@ diagram: assets/pie-chart-diagram.svg --8<-- "{{ examples }}/example_3.py" ``` -{{ image(example_images + "/example_3.gif", width="80%") }} +{{ image(example_images + "/example_3.png", width="80%") }} {{ class_members(class_name) }} diff --git a/sdk/python/packages/flet/docs/charts/radar_chart.md b/sdk/python/packages/flet/docs/charts/radar_chart.md index 359da53a87..04c50c3d90 100644 --- a/sdk/python/packages/flet/docs/charts/radar_chart.md +++ b/sdk/python/packages/flet/docs/charts/radar_chart.md @@ -1,10 +1,10 @@ --- class_name: flet_charts.radar_chart.RadarChart examples: ../../examples/controls/charts/radar_chart -example_images: ../examples/controls/charts/radar_chart/media +example_images: ../test-images-charts/examples/golden/macos/radar_chart --- -{{ class_summary(class_name) }} +{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic radar chart", image_width="100%") }} ## Examples diff --git a/sdk/python/packages/flet/docs/charts/scatter_chart.md b/sdk/python/packages/flet/docs/charts/scatter_chart.md index c9d9dac678..4f29b1a9dd 100644 --- a/sdk/python/packages/flet/docs/charts/scatter_chart.md +++ b/sdk/python/packages/flet/docs/charts/scatter_chart.md @@ -1,10 +1,10 @@ --- class_name: flet_charts.scatter_chart.ScatterChart examples: ../../examples/controls/charts/scatter_chart -example_images: ../examples/controls/charts/scatter_chart/media +example_images: ../test-images-charts/examples/golden/macos/scatter_chart --- -{{ class_summary(class_name) }} +{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic scatter chart", image_width="80%") }} ## Examples diff --git a/sdk/python/packages/flet/mkdocs.yml b/sdk/python/packages/flet/mkdocs.yml index ef883d38fc..334f5783ab 100644 --- a/sdk/python/packages/flet/mkdocs.yml +++ b/sdk/python/packages/flet/mkdocs.yml @@ -163,6 +163,9 @@ plugins: - source_dir: integration_tests target_url_path: test-images include_exts: [".png", ".gif", ".svg"] + - source_dir: ../flet-charts/integration_tests + target_url_path: test-images-charts + include_exts: [".png", ".gif", ".svg"] # Markdown Extensions markdown_extensions: