Skip to content

Commit 0ac3e27

Browse files
v1: MatplotlibChart interactive with toolbar (#19)
* MPL v2 draft * Added toml for tests * Cursors, rubberband support * MPL.on_message event * Toolbar add, no Download yet * Right-click handle, download, keyboard draft * Some cleanup, animation and event samples * Get rid of OptionalEventHandler * Update method name and toolbar icons Renamed 'init' to 'build' in MatplotlibChart for clarity. Changed pan and zoom toolbar icons in tests to use OPEN_WITH and SEARCH for better representation. * Expose MatplotlibChart event classes in __init__ Added MatplotlibChartMessageEvent and MatplotlibChartToolbarButtonsUpdateEvent to the public API in __init__.py. Also replaced async canvas capture methods with their synchronous counterparts in MatplotlibChart for image handling. * Refactor MatplotlibChart and update test formatting Refactored src/flet_charts/matplotlib_chart.py for improved readability, async focus handling, and event argument types. Updated test files to use consistent formatting, removed unused imports, and replaced deprecated FilePicker API usage. Enhanced code clarity and maintainability across chart and test modules. * Add MatplotlibChartWithToolbar and update test Introduces MatplotlibChartWithToolbar for integrated chart and toolbar controls. Updates __init__.py to export the new class, refactors tests/mpl_v2_basic.py to use MatplotlibChartWithToolbar, and adds debug output and minor improvements to MatplotlibChart. * Refactor chart components and update tests Added 'isolated=True' to chart controls for better encapsulation. Replaced print statements with logger.debug for improved logging. Refactored test files to use MatplotlibChartWithToolbar, simplifying toolbar and event handling logic, and added a new 3D chart test. * Set matplotlib backend in library, remove from tests Moved the matplotlib backend configuration to the main library file (matplotlib_chart.py) and removed redundant backend setting from all test files. This centralizes backend setup and simplifies test scripts. * Set figure size and remove expand in 3D plot test Specifies the figure size in the 3D plot test and removes the 'expand=True' argument from MatplotlibChartWithToolbar for consistency and improved layout control. * Inline FilePicker instance in download method Refactored the download method to instantiate FilePicker inline instead of assigning it to a variable, simplifying the code.
1 parent 6902aeb commit 0ac3e27

File tree

10 files changed

+745
-33
lines changed

10 files changed

+745
-33
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = [{ name = "Flet contributors", email = "[email protected]" }]
77
license = "Apache-2.0"
88
requires-python = ">=3.10"
99
dependencies = [
10-
"flet >=0.70.0.dev0",
10+
"flet",
1111
]
1212

1313
[project.urls]

src/flet_charts/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
LineChartDataPoint,
2020
LineChartDataPointTooltip,
2121
)
22-
from flet_charts.matplotlib_chart import MatplotlibChart
22+
from flet_charts.matplotlib_chart import (
23+
MatplotlibChart,
24+
MatplotlibChartMessageEvent,
25+
MatplotlibChartToolbarButtonsUpdateEvent,
26+
)
27+
from flet_charts.matplotlib_chart_with_toolbar import MatplotlibChartWithToolbar
2328
from flet_charts.pie_chart import PieChart, PieChartEvent
2429
from flet_charts.pie_chart_section import PieChartSection
2530
from flet_charts.plotly_chart import PlotlyChart
@@ -78,4 +83,7 @@
7883
"ScatterChartSpot",
7984
"ScatterChartSpotTooltip",
8085
"ScatterChartTooltip",
86+
"MatplotlibChartMessageEvent",
87+
"MatplotlibChartToolbarButtonsUpdateEvent",
88+
"MatplotlibChartWithToolbar",
8189
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from matplotlib import _api
2+
from matplotlib.backends import backend_webagg_core
3+
4+
5+
class FigureCanvasFletAgg(backend_webagg_core.FigureCanvasWebAggCore):
6+
manager_class = _api.classproperty(lambda cls: FigureManagerFletAgg)
7+
supports_blit = False
8+
9+
10+
class FigureManagerFletAgg(backend_webagg_core.FigureManagerWebAgg):
11+
_toolbar2_class = backend_webagg_core.NavigationToolbar2WebAgg
12+
13+
14+
FigureCanvas = FigureCanvasFletAgg
15+
FigureManager = FigureManagerFletAgg
16+
interactive = True

0 commit comments

Comments
 (0)