maidr 0.16.0__py3-none-any.whl → 0.17.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__ = "0.16.0"
1
+ __version__ = "0.17.0"
2
2
 
3
3
  from .api import close, render, save_html, set_engine, show, stacked
4
4
  from .core import Maidr
maidr/api.py CHANGED
@@ -20,16 +20,31 @@ def render(plot: Any) -> Tag:
20
20
 
21
21
  def show(plot: Any, renderer: Literal["auto", "ipython", "browser"] = "auto") -> object:
22
22
  ax = FigureManager.get_axes(plot)
23
- maidr = FigureManager.get_maidr(ax.get_figure())
24
- return maidr.show(renderer)
23
+ htmls = []
24
+ if type(ax) is list:
25
+ for axes in ax:
26
+ maidr = FigureManager.get_maidr(axes.get_figure())
27
+ htmls.append(maidr.render())
28
+ return htmls[-1].show(renderer)
29
+ else:
30
+ maidr = FigureManager.get_maidr(ax.get_figure())
31
+ return maidr.show(renderer)
25
32
 
26
33
 
27
34
  def save_html(
28
35
  plot: Any, file: str, *, lib_dir: str | None = "lib", include_version: bool = True
29
36
  ) -> str:
30
37
  ax = FigureManager.get_axes(plot)
31
- maidr = FigureManager.get_maidr(ax.get_figure())
32
- return maidr.save_html(file, lib_dir=lib_dir, include_version=include_version)
38
+ htmls = []
39
+ if type(ax) is list:
40
+ for axes in ax:
41
+ maidr = FigureManager.get_maidr(axes.get_figure())
42
+ htmls.append(maidr.render())
43
+ htmls[-1].save_html(file, libdir=lib_dir, include_version=include_version)
44
+ return htmls[-1]
45
+ else:
46
+ maidr = FigureManager.get_maidr(ax.get_figure())
47
+ return maidr.save_html(file, lib_dir=lib_dir, include_version=include_version)
33
48
 
34
49
 
35
50
  def stacked(plot: Axes | BarContainer) -> Maidr:
maidr/core/maidr.py CHANGED
@@ -139,7 +139,7 @@ class Maidr:
139
139
 
140
140
  def _flatten_maidr(self) -> dict | list[dict]:
141
141
  """Return a single plot schema or a list of schemas from the Maidr instance."""
142
- if self.plot_type == PlotType.LINE:
142
+ if self.plot_type in (PlotType.LINE, PlotType.DODGED, PlotType.STACKED):
143
143
  self._plots = [self._plots[0]]
144
144
  maidr = [plot.schema for plot in self._plots]
145
145
 
@@ -149,8 +149,13 @@ class Maidr:
149
149
  plot[MaidrKey.SELECTOR] = plot[MaidrKey.SELECTOR].replace(
150
150
  "maidr='true'", f"maidr='{self.selector_id}'"
151
151
  )
152
-
153
- return maidr if len(maidr) != 1 else maidr[0]
152
+ engine = Environment.get_engine()
153
+ if engine == "js":
154
+ return maidr if len(maidr) != 1 else maidr[0]
155
+ return {
156
+ "id": Maidr._unique_id(),
157
+ "subplots": [[{"id": Maidr._unique_id(), "layers": maidr}]],
158
+ }
154
159
 
155
160
  def _get_svg(self) -> HTML:
156
161
  """Extract the chart SVG from ``matplotlib.figure.Figure``."""
@@ -200,6 +205,7 @@ class Maidr:
200
205
 
201
206
  engine = Environment.get_engine()
202
207
 
208
+ # MAIDR_TS_CDN_URL = "http://localhost:8080/maidr.js" # DEMO URL
203
209
  MAIDR_TS_CDN_URL = "https://cdn.jsdelivr.net/npm/maidr-ts/dist/maidr.js"
204
210
 
205
211
  maidr_js_script = f"""
@@ -38,10 +38,10 @@ class BarPlot(MaidrPlot, ContainerExtractorMixin, LevelExtractorMixin, DictMerge
38
38
  levels = self.extract_level(self.ax)
39
39
  if engine == "ts":
40
40
  formatted_data = []
41
- combined_data = (
42
- zip(levels, data) if plot[0].orientation == "vertical" else zip(levels, data) # type: ignore
41
+ combined_data = list(
42
+ zip(levels, data) if plot[0].orientation == "vertical" else zip(data, levels) # type: ignore
43
43
  )
44
- if len(data) == len(plot): # type: ignore
44
+ if combined_data: # type: ignore
45
45
  for x, y in combined_data: # type: ignore
46
46
  formatted_data.append({"x": x, "y": y})
47
47
  return formatted_data
@@ -96,7 +96,7 @@ class MultiLinePlot(MaidrPlot, LineExtractorMixin):
96
96
  }
97
97
  for x, y in line.get_xydata() # type: ignore
98
98
  ]
99
-
100
- all_line_data.append(line_data)
99
+ if len(line_data) > 0:
100
+ all_line_data.append(line_data)
101
101
 
102
102
  return all_line_data if all_line_data else None
maidr/patch/barplot.py CHANGED
@@ -52,16 +52,18 @@ def bar(
52
52
  bottom = kwargs.get("bottom")
53
53
  if bottom is not None:
54
54
  plot_type = PlotType.STACKED
55
- elif args:
56
- x = args[0]
57
- is_numeric = False
58
- if isinstance(x, np.ndarray) and np.issubdtype(x.dtype, np.number):
59
- is_numeric = True
60
- elif isinstance(x, (list, tuple)) and x and isinstance(x[0], Number):
61
- is_numeric = True
62
- if is_numeric:
63
- plot_type = PlotType.DODGED
55
+ else:
56
+ if len(args) >= 3:
57
+ real_width = args[2]
58
+ else:
59
+ real_width = kwargs.get("width", 0.8)
60
+
61
+ align = kwargs.get("align", "center")
64
62
 
63
+ if (isinstance(real_width, (int, float)) and float(real_width) < 0.8) or (
64
+ align == "edge"
65
+ ):
66
+ plot_type = PlotType.DODGED
65
67
  return common(plot_type, wrapped, instance, args, kwargs)
66
68
 
67
69
 
@@ -45,9 +45,36 @@ class LevelExtractorMixin:
45
45
 
46
46
  level = None
47
47
  if MaidrKey.X == key:
48
- level = [label.get_text() for label in ax.get_xticklabels()]
48
+ ticks = ax.get_xticks()
49
+ labels = [label.get_text() for label in ax.get_xticklabels()]
50
+
51
+ if hasattr(ax, "dataLim") and ax.dataLim.width != 0:
52
+ # Use the actual data limits rather than padded view limits
53
+ data_x_min, data_x_max = ax.dataLim.x0, ax.dataLim.x0 + ax.dataLim.width
54
+ # Filter tick labels to only those within the actual data range
55
+ valid_indices = [
56
+ i for i, pos in enumerate(ticks) if data_x_min <= pos <= data_x_max
57
+ ]
58
+ labels = [labels[i] for i in valid_indices if i < len(labels)]
59
+
60
+ level = labels
49
61
  elif MaidrKey.Y == key:
50
- level = [label.get_text() for label in ax.get_yticklabels()]
62
+ ticks = ax.get_yticks()
63
+ labels = [label.get_text() for label in ax.get_yticklabels()]
64
+
65
+ if hasattr(ax, "dataLim") and ax.dataLim.height != 0:
66
+ # Use the actual data limits rather than padded view limits
67
+ data_y_min, data_y_max = (
68
+ ax.dataLim.y0,
69
+ ax.dataLim.y0 + ax.dataLim.height,
70
+ )
71
+ # Filter tick labels to only those within the actual data range
72
+ valid_indices = [
73
+ i for i, pos in enumerate(ticks) if data_y_min <= pos <= data_y_max
74
+ ]
75
+ labels = [labels[i] for i in valid_indices if i < len(labels)]
76
+
77
+ level = labels
51
78
  elif MaidrKey.FILL == key:
52
79
  level = [container.get_label() for container in ax.containers]
53
80
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: maidr
3
- Version: 0.16.0
3
+ Version: 0.17.0
4
4
  Summary: Multimodal Access and Interactive Data Representations
5
5
  License: GPL-3.0-or-later
6
6
  Keywords: accessibility,visualization,sonification,braille,tactile,multimodal,data representation,blind,low vision,visual impairments
@@ -1,5 +1,5 @@
1
- maidr/__init__.py,sha256=c9XIJcwH7iiFKgL4lkZi08iLSDirzPxVAx3Uz1I9ATs,369
2
- maidr/api.py,sha256=u2WOQ8RWmXpzseEgbZJCB7FFZs7cEy-ya-Q18tGAYB4,1350
1
+ maidr/__init__.py,sha256=AYJCYrGlBnEnS5wvW5Et0HzM56fv4fB3HCdfFK66fto,369
2
+ maidr/api.py,sha256=iVPdD8D2cRmfGuTWNuElBSbrGH4akxPXYEyf_e-MWHg,1870
3
3
  maidr/core/__init__.py,sha256=WgxLpSEYMc4k3OyEOf1shOxfEq0ASzppEIZYmE91ThQ,25
4
4
  maidr/core/context_manager.py,sha256=HSzD4wpiALdI4Vm0QTdWqi1MWR5Uqy8BX_lOlCM3JYY,3463
5
5
  maidr/core/enum/__init__.py,sha256=9ee78L0dlxEx4ulUGVlD-J23UcUZmrGu0rXms54up3c,93
@@ -7,21 +7,21 @@ maidr/core/enum/library.py,sha256=e8ujT_L-McJWfoVJd1ty9K_2bwITnf1j0GPLsnAcHes,10
7
7
  maidr/core/enum/maidr_key.py,sha256=LNtt74d2gurefDNPD3SLLsTxKqO9qTyo3PBAUAyofnc,736
8
8
  maidr/core/enum/plot_type.py,sha256=pyfyIwlq3taqe2Z1sVUSbMsTp5QTvYBlZXsMMMclEVM,293
9
9
  maidr/core/figure_manager.py,sha256=rd8XEwqNmfKu1I9zGD1p9g3wVlkMYNCrdLLCg4IzlfQ,3934
10
- maidr/core/maidr.py,sha256=G7ACqroX80F9z4-tJj6-YFcjvv9--A-qrmH1Syp4jgQ,11717
10
+ maidr/core/maidr.py,sha256=aw9JZHGS090guSF1l67xr_BU1quHojHSQz2Yn2-wD8s,12038
11
11
  maidr/core/plot/__init__.py,sha256=xDIpRGM-4DfaSSL3nKcXrjdMecCHJ6en4K4nA_fPefQ,83
12
- maidr/core/plot/barplot.py,sha256=DGiMbakzER-Czpzekw-yBHXZuzWpBg7ODtJPQ8voI04,2605
12
+ maidr/core/plot/barplot.py,sha256=b7r0cz3yMZzWwiTJVUy1yWBXhv_oN9rwEb6hfKVg3Zs,2600
13
13
  maidr/core/plot/boxplot.py,sha256=roADG8xJYRQlZPYbfGBQSQRw8974lhVnngGKEKXJttk,6090
14
14
  maidr/core/plot/grouped_barplot.py,sha256=tAiOWwtfsWDwyGdUuCdQ6-f8UQxnsDDwpN30Skk8p-U,2071
15
15
  maidr/core/plot/heatmap.py,sha256=_Hn_wXsu-BQBYs4YO440-WRhmXAJ1WeBndBGVEUAP5M,2447
16
16
  maidr/core/plot/histogram.py,sha256=QV5W-6ZJQQcZsrM91JJBX-ONktJzH7yg_et5_bBPfQQ,1525
17
- maidr/core/plot/lineplot.py,sha256=5FKgT4s6l9Y7Lb7ELJ4SqMo0ItqimEhbKMgoVG_Rmu8,3242
17
+ maidr/core/plot/lineplot.py,sha256=OQQtJb7lmO-lZTQfhqMV4sfztyuEicZfe95y9nIhfTo,3280
18
18
  maidr/core/plot/maidr_plot.py,sha256=_9Ugn3cUwi-URxeTRbDAKDZwASrB65p9TKOXhFX1zbU,3176
19
19
  maidr/core/plot/maidr_plot_factory.py,sha256=QGcHK_oquY_M2_KJVEtc5-rBAD-gm7KI1kSD7cduHzg,1691
20
20
  maidr/core/plot/scatterplot.py,sha256=sQhT80w0Sp9AsUAZi4v6lfWsHJAvuFcer2aAE2NpAYE,1240
21
21
  maidr/exception/__init__.py,sha256=PzaXoYBhyZxMDcJkuxJugDx7jZeseI0El6LpxIwXyG4,46
22
22
  maidr/exception/extraction_error.py,sha256=rd37Oxa9gn2OWFWt9AOH5fv0hNd3sAWGvpDMFBuJY2I,607
23
23
  maidr/patch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
- maidr/patch/barplot.py,sha256=X2vsC_OMGk5ubMc29YZ1il5D5loYtJ5scjCy5gk098g,2412
24
+ maidr/patch/barplot.py,sha256=iCoYaqlHou6_rSnbjfZwpRU8ENnYcfQ9JCdUxhrSgCA,2416
25
25
  maidr/patch/boxplot.py,sha256=Mcz94pSf7PT3SyRsI8TDrIKVdEmiiUQouXvd05mtnfw,2846
26
26
  maidr/patch/clear.py,sha256=2Sc4CIt5jRGkew3TxFsBZm-uowC9yDSxtraEcXZjmGw,396
27
27
  maidr/patch/common.py,sha256=bRe4jruUvCIwp1t1E8Q3OuQ0eEyHgpMjXVpsPBZj4C8,843
@@ -33,11 +33,11 @@ maidr/patch/scatterplot.py,sha256=JZJXy3vWbJgzZh2zysNrqSA7MRcfSCms6lr_MY5CMD0,52
33
33
  maidr/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  maidr/util/environment.py,sha256=xtfibTH4RXW2GC7R_9OQo119BTe5M3bx0u13eFZaiZs,4554
35
35
  maidr/util/mixin/__init__.py,sha256=aGJZNhtWh77yIVPc7ipIZm1OajigjMtCWYKPuDWTC-c,217
36
- maidr/util/mixin/extractor_mixin.py,sha256=lOVDaNsHnOS2aYxiGXAigGjt8WXzcer9MocaipcOh60,3511
36
+ maidr/util/mixin/extractor_mixin.py,sha256=AjpgCo_dgASdTwFumfgDOoVCVioxDDoqFWphaBj5gz4,4764
37
37
  maidr/util/mixin/merger_mixin.py,sha256=V0qLw_6DUB7X6CQ3BCMpsCQX_ZuwAhoSTm_E4xAJFKM,712
38
38
  maidr/widget/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
39
  maidr/widget/shiny.py,sha256=wrrw2KAIpE_A6CNQGBtNHauR1DjenA_n47qlFXX9_rk,745
40
- maidr-0.16.0.dist-info/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
41
- maidr-0.16.0.dist-info/METADATA,sha256=i1WmNwRomAMP244eEJoCaTUyuGhaWQWsm96MKL5K0RY,2688
42
- maidr-0.16.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
43
- maidr-0.16.0.dist-info/RECORD,,
40
+ maidr-0.17.0.dist-info/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
41
+ maidr-0.17.0.dist-info/METADATA,sha256=xXcEWUWeA_lR30cXjAiCPyuNgO-e3-7mfwG2ggy5Su4,2688
42
+ maidr-0.17.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
43
+ maidr-0.17.0.dist-info/RECORD,,
File without changes