maidr 1.7.3__py3-none-any.whl → 1.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
maidr/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.7.3"
1
+ __version__ = "1.8.0"
2
2
 
3
3
  from .api import close, render, save_html, show, stacked
4
4
  from .core import Maidr
maidr/api.py CHANGED
@@ -11,7 +11,44 @@ from maidr.core.enum import PlotType
11
11
  from maidr.core.figure_manager import FigureManager
12
12
 
13
13
 
14
- def render(plot: Any) -> Tag:
14
+ def _get_plot_or_current(plot: Any | None) -> Any:
15
+ """
16
+ Get the plot object or current matplotlib figure if plot is None.
17
+
18
+ Parameters
19
+ ----------
20
+ plot : Any or None
21
+ The plot object. If None, returns the current matplotlib figure.
22
+
23
+ Returns
24
+ -------
25
+ Any
26
+ The plot object or current matplotlib figure.
27
+ """
28
+ if plot is None:
29
+ # Lazy import matplotlib.pyplot when needed
30
+ import matplotlib.pyplot as plt
31
+
32
+ return plt.gcf()
33
+ return plot
34
+
35
+
36
+ def render(plot: Any | None = None) -> Tag:
37
+ """
38
+ Render a MAIDR plot to HTML.
39
+
40
+ Parameters
41
+ ----------
42
+ plot : Any or None, optional
43
+ The plot object to render. If None, uses the current matplotlib figure.
44
+
45
+ Returns
46
+ -------
47
+ htmltools.Tag
48
+ The rendered HTML representation of the plot.
49
+ """
50
+ plot = _get_plot_or_current(plot)
51
+
15
52
  ax = FigureManager.get_axes(plot)
16
53
  if isinstance(ax, list):
17
54
  for axes in ax:
@@ -23,10 +60,29 @@ def render(plot: Any) -> Tag:
23
60
 
24
61
 
25
62
  def show(
26
- plot: Any,
63
+ plot: Any | None = None,
27
64
  renderer: Literal["auto", "ipython", "browser"] = "auto",
28
65
  clear_fig: bool = True,
29
66
  ) -> object:
67
+ """
68
+ Display a MAIDR plot.
69
+
70
+ Parameters
71
+ ----------
72
+ plot : Any or None, optional
73
+ The plot object to display. If None, uses the current matplotlib figure.
74
+ renderer : {"auto", "ipython", "browser"}, default "auto"
75
+ The renderer to use for display.
76
+ clear_fig : bool, default True
77
+ Whether to clear the figure after displaying.
78
+
79
+ Returns
80
+ -------
81
+ object
82
+ The display result.
83
+ """
84
+ plot = _get_plot_or_current(plot)
85
+
30
86
  ax = FigureManager.get_axes(plot)
31
87
  if isinstance(ax, list):
32
88
  for axes in ax:
@@ -38,8 +94,33 @@ def show(
38
94
 
39
95
 
40
96
  def save_html(
41
- plot: Any, file: str, *, lib_dir: str | None = "lib", include_version: bool = True
97
+ plot: Any | None = None,
98
+ *,
99
+ file: str,
100
+ lib_dir: str | None = "lib",
101
+ include_version: bool = True
42
102
  ) -> str:
103
+ """
104
+ Save a MAIDR plot as HTML file.
105
+
106
+ Parameters
107
+ ----------
108
+ plot : Any or None, optional
109
+ The plot object to save. If None, uses the current matplotlib figure.
110
+ file : str
111
+ The file path where to save the HTML.
112
+ lib_dir : str or None, default "lib"
113
+ Directory name for libraries.
114
+ include_version : bool, default True
115
+ Whether to include version information.
116
+
117
+ Returns
118
+ -------
119
+ str
120
+ The path to the saved HTML file.
121
+ """
122
+ plot = _get_plot_or_current(plot)
123
+
43
124
  ax = FigureManager.get_axes(plot)
44
125
  htmls = []
45
126
  if isinstance(ax, list):
@@ -59,6 +140,16 @@ def stacked(plot: Axes | BarContainer) -> Maidr:
59
140
  return FigureManager.create_maidr(ax, PlotType.STACKED)
60
141
 
61
142
 
62
- def close(plot: Any) -> None:
143
+ def close(plot: Any | None = None) -> None:
144
+ """
145
+ Close a MAIDR plot and clean up resources.
146
+
147
+ Parameters
148
+ ----------
149
+ plot : Any or None, optional
150
+ The plot object to close. If None, uses the current matplotlib figure.
151
+ """
152
+ plot = _get_plot_or_current(plot)
153
+
63
154
  ax = FigureManager.get_axes(plot)
64
155
  FigureManager.destroy(ax.get_figure())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maidr
3
- Version: 1.7.3
3
+ Version: 1.8.0
4
4
  Summary: Multimodal Access and Interactive Data Representations
5
5
  Project-URL: Homepage, https://xability.github.io/py-maidr
6
6
  Project-URL: Repository, https://github.com/xability/py-maidr
@@ -1,5 +1,5 @@
1
- maidr/__init__.py,sha256=yWh6GLg3euB1LRZdmADmvGibtFcvZtr48m0w2uFEykU,415
2
- maidr/api.py,sha256=gRNLXqUWpFGdD-I7Nu6J0_LeEni9KRAr0TBHwHaDAsc,1928
1
+ maidr/__init__.py,sha256=WHwg8BcJQIcf4dsUFOdKS_frxDfuHewDEGnBBg9j3WE,415
2
+ maidr/api.py,sha256=od539V0CKcs15FEXQo0hX_hK_A0U3noHE54obdHcTqY,4138
3
3
  maidr/core/__init__.py,sha256=WgxLpSEYMc4k3OyEOf1shOxfEq0ASzppEIZYmE91ThQ,25
4
4
  maidr/core/context_manager.py,sha256=6cT7ZGOApSpC-SLD2XZWWU_H08i-nfv-JUlzXOtvWYw,3374
5
5
  maidr/core/figure_manager.py,sha256=t-lhe4jj2gsF5-8VUBUZOPlDutKjm_AZ8xXWJU2pFRc,5555
@@ -52,7 +52,7 @@ maidr/util/mixin/extractor_mixin.py,sha256=j2Rv2vh_gqqcxLV1ka3xsPaPAfWsX94CtKIW2
52
52
  maidr/util/mixin/merger_mixin.py,sha256=V0qLw_6DUB7X6CQ3BCMpsCQX_ZuwAhoSTm_E4xAJFKM,712
53
53
  maidr/widget/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
54
  maidr/widget/shiny.py,sha256=wrrw2KAIpE_A6CNQGBtNHauR1DjenA_n47qlFXX9_rk,745
55
- maidr-1.7.3.dist-info/METADATA,sha256=uOTyppfpjH4RVQSO0x9S4owUWLM9X2Ta9-sCjr3xQD0,3154
56
- maidr-1.7.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
57
- maidr-1.7.3.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
58
- maidr-1.7.3.dist-info/RECORD,,
55
+ maidr-1.8.0.dist-info/METADATA,sha256=JSCtmOqsD8Mka8aDihHcqHs4wJ9Yc4eBYV3by-pQSl0,3154
56
+ maidr-1.8.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
57
+ maidr-1.8.0.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
58
+ maidr-1.8.0.dist-info/RECORD,,
File without changes