maidr 0.22.0__py3-none-any.whl → 0.22.2__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,6 +1,6 @@
1
- __version__ = "0.22.0"
1
+ __version__ = "0.22.2"
2
2
 
3
- from .api import close, render, save_html, set_engine, show, stacked
3
+ from .api import close, render, save_html, show, stacked
4
4
  from .core import Maidr
5
5
  from .core.enum import PlotType
6
6
  from .patch import (
maidr/api.py CHANGED
@@ -53,7 +53,3 @@ def stacked(plot: Axes | BarContainer) -> Maidr:
53
53
  def close(plot: Any) -> None:
54
54
  ax = FigureManager.get_axes(plot)
55
55
  FigureManager.destroy(ax.get_figure())
56
-
57
-
58
- def set_engine(engine: Literal["js", "ts"] = "js"):
59
- Environment._set_engine(engine=engine)
maidr/core/maidr.py CHANGED
@@ -11,7 +11,6 @@ from typing import Any, Literal
11
11
  from htmltools import HTML, HTMLDocument, Tag, tags
12
12
  from lxml import etree
13
13
  from matplotlib.figure import Figure
14
- from matplotlib.patches import Rectangle
15
14
 
16
15
  from maidr.core.context_manager import HighlightContextManager
17
16
  from maidr.core.enum.maidr_key import MaidrKey
@@ -142,19 +141,6 @@ class Maidr:
142
141
 
143
142
  def _flatten_maidr(self) -> dict | list[dict]:
144
143
  """Return a single plot schema or a list of schemas from the Maidr instance."""
145
- # To support legacy JS Engine we will just return the format in this way
146
- # but soon enough this should be deprecated and when we will completely
147
- # transition to TypeScript :)
148
- engine = Environment.get_engine()
149
- if engine == "js":
150
- if self.plot_type in (PlotType.LINE, PlotType.DODGED, PlotType.STACKED):
151
- self._plots = [self._plots[0]]
152
- maidr = [plot.schema for plot in self._plots]
153
-
154
- return maidr if len(maidr) != 1 else maidr[0]
155
-
156
- # Now let's start building the maidr object for the newer TypeScript engine
157
-
158
144
  if self.plot_type in (PlotType.DODGED, PlotType.STACKED):
159
145
  self._plots = [self._plots[0]]
160
146
 
@@ -251,27 +237,10 @@ class Maidr:
251
237
  @staticmethod
252
238
  def _inject_plot(plot: HTML, maidr: str, maidr_id) -> Tag:
253
239
  """Embed the plot and associated MAIDR scripts into the HTML structure."""
254
-
255
- engine = Environment.get_engine()
256
-
257
240
  # MAIDR_TS_CDN_URL = "http://localhost:8080/maidr.js" # DEMO URL
258
241
  MAIDR_TS_CDN_URL = "https://cdn.jsdelivr.net/npm/maidr-ts/dist/maidr.js"
259
242
 
260
- maidr_js_script = f"""
261
- if (!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/maidr/dist/maidr.min.js"]')) {{
262
- var script = document.createElement('script');
263
- script.type = 'text/javascript';
264
- script.src = 'https://cdn.jsdelivr.net/npm/maidr/dist/maidr.min.js';
265
- script.addEventListener('load', function() {{
266
- window.init("{maidr_id}");
267
- }});
268
- document.head.appendChild(script);
269
- }} else {{
270
- window.init("{maidr_id}");
271
- }}
272
- """
273
-
274
- maidr_ts_script = f"""
243
+ script = f"""
275
244
  if (!document.querySelector('script[src="{MAIDR_TS_CDN_URL}"]'))
276
245
  {{
277
246
  var script = document.createElement('script');
@@ -288,8 +257,6 @@ class Maidr:
288
257
  }}
289
258
  """
290
259
 
291
- script = maidr_js_script if engine == "js" else maidr_ts_script
292
-
293
260
  base_html = tags.div(
294
261
  tags.link(
295
262
  rel="stylesheet",
@@ -299,14 +266,12 @@ class Maidr:
299
266
  tags.div(plot),
300
267
  )
301
268
 
302
- is_quarto = os.getenv("IS_QUARTO") == "True"
269
+ # is_quarto = os.getenv("IS_QUARTO") == "True"
303
270
 
304
271
  # Render the plot inside an iframe if in a Jupyter notebook, Google Colab
305
272
  # or VSCode notebook. No need for iframe if this is a Quarto document.
306
273
  # For TypeScript we will use iframe by default for now
307
- if (Environment.is_notebook() and not is_quarto) or (
308
- engine == "ts" and Environment.is_notebook()
309
- ):
274
+ if Environment.is_notebook() or Environment.is_shiny():
310
275
  unique_id = "iframe_" + Maidr._unique_id()
311
276
 
312
277
  def generate_iframe_script(unique_id: str) -> str:
@@ -3,10 +3,9 @@ from __future__ import annotations
3
3
  from matplotlib.axes import Axes
4
4
  from matplotlib.container import BarContainer
5
5
 
6
- from maidr.core.enum import MaidrKey, PlotType
6
+ from maidr.core.enum import PlotType
7
7
  from maidr.core.plot import MaidrPlot
8
8
  from maidr.exception import ExtractionError
9
- from maidr.util.environment import Environment
10
9
  from maidr.util.mixin import (
11
10
  ContainerExtractorMixin,
12
11
  DictMergerMixin,
@@ -18,35 +17,20 @@ class BarPlot(MaidrPlot, ContainerExtractorMixin, LevelExtractorMixin, DictMerge
18
17
  def __init__(self, ax: Axes) -> None:
19
18
  super().__init__(ax, PlotType.BAR)
20
19
 
21
- def _extract_axes_data(self) -> dict:
22
- engine = Environment.get_engine()
23
-
24
- base_schema = super()._extract_axes_data()
25
- bar_ax_schema = {}
26
- if engine == "js":
27
- bar_ax_schema = {
28
- MaidrKey.X: {
29
- MaidrKey.LEVEL: self.extract_level(self.ax),
30
- },
31
- }
32
- return self.merge_dict(base_schema, bar_ax_schema)
33
-
34
20
  def _extract_plot_data(self) -> list:
35
- engine = Environment.get_engine()
36
21
  plot = self.extract_container(self.ax, BarContainer, include_all=True)
37
22
  data = self._extract_bar_container_data(plot)
38
23
  levels = self.extract_level(self.ax)
39
- if engine == "ts":
40
- formatted_data = []
41
- combined_data = list(
42
- zip(levels, data) if plot[0].orientation == "vertical" else zip(data, levels) # type: ignore
43
- )
44
- if combined_data: # type: ignore
45
- for x, y in combined_data: # type: ignore
46
- formatted_data.append({"x": x, "y": y})
47
- return formatted_data
48
- if len(formatted_data) == 0:
49
- raise ExtractionError(self.type, plot)
24
+ formatted_data = []
25
+ combined_data = list(
26
+ zip(levels, data) if plot[0].orientation == "vertical" else zip(data, levels) # type: ignore
27
+ )
28
+ if combined_data: # type: ignore
29
+ for x, y in combined_data: # type: ignore
30
+ formatted_data.append({"x": x, "y": y})
31
+ return formatted_data
32
+ if len(formatted_data) == 0:
33
+ raise ExtractionError(self.type, plot)
50
34
  if data is None:
51
35
  raise ExtractionError(self.type, plot)
52
36
 
@@ -7,7 +7,6 @@ from maidr.core.enum.maidr_key import MaidrKey
7
7
  from maidr.core.enum.plot_type import PlotType
8
8
  from maidr.core.plot.maidr_plot import MaidrPlot
9
9
  from maidr.exception.extraction_error import ExtractionError
10
- from maidr.util.environment import Environment
11
10
  from maidr.util.mixin.extractor_mixin import LineExtractorMixin
12
11
 
13
12
 
@@ -43,20 +42,11 @@ class MultiLinePlot(MaidrPlot, LineExtractorMixin):
43
42
  super().__init__(ax, PlotType.LINE)
44
43
 
45
44
  def _get_selector(self) -> Union[str, List[str]]:
46
- if Environment.get_engine() == "js":
47
- return "g[maidr='true'] > path"
48
45
  return ["g[maidr='true'] > path"]
49
46
 
50
47
  def _extract_plot_data(self) -> list[dict]:
51
48
  plot = self.extract_lines(self.ax)
52
49
  data = self._extract_line_data(plot)
53
- engine = Environment.get_engine()
54
- if engine == "js":
55
- if len(data) > 1:
56
- raise Exception(
57
- "MultiLine Plot not supported in JS. Use TypeScript Engine for this plot!"
58
- )
59
- data = data[0]
60
50
 
61
51
  if data is None:
62
52
  raise ExtractionError(self.type, plot)
@@ -94,11 +84,15 @@ class MultiLinePlot(MaidrPlot, LineExtractorMixin):
94
84
  self._elements.append(line)
95
85
 
96
86
  # Extract data from this line
87
+
88
+ label: str = line.get_label() # type: ignore
97
89
  line_data = [
98
90
  {
99
91
  MaidrKey.X: float(x),
100
92
  MaidrKey.Y: float(y),
101
- MaidrKey.FILL: line.get_label(),
93
+ # Replace labels starting with '_child' with an empty string to exclude
94
+ # internal or non-relevant labels from being used as identifiers.
95
+ MaidrKey.FILL: (label if not label.startswith("_child") else ""),
102
96
  }
103
97
  for x, y in line.get_xydata() # type: ignore
104
98
  ]
@@ -5,7 +5,6 @@ from abc import ABC, abstractmethod
5
5
  from matplotlib.axes import Axes
6
6
 
7
7
  from maidr.core.enum import MaidrKey, PlotType
8
- from maidr.util.environment import Environment
9
8
 
10
9
 
11
10
  class MaidrPlot(ABC):
@@ -26,7 +25,8 @@ class MaidrPlot(ABC):
26
25
  type : PlotType
27
26
  The specific type of the plot.
28
27
  _schema : dict
29
- A dictionary containing structured data about the plot, including type, title, axes labels, and data.
28
+ A dictionary containing structured data about the plot, including type, title,
29
+ axes labels, and data.
30
30
 
31
31
  Methods
32
32
  -------
@@ -70,17 +70,7 @@ class MaidrPlot(ABC):
70
70
 
71
71
  def _extract_axes_data(self) -> dict:
72
72
  """Extract the plot's axes data"""
73
- engine = Environment.get_engine()
74
- if engine == "ts":
75
- return {MaidrKey.X: self.ax.get_xlabel(), MaidrKey.Y: self.ax.get_ylabel()}
76
- return {
77
- MaidrKey.X: {
78
- MaidrKey.LABEL: self.ax.get_xlabel(),
79
- },
80
- MaidrKey.Y: {
81
- MaidrKey.LABEL: self.ax.get_ylabel(),
82
- },
83
- }
73
+ return {MaidrKey.X: self.ax.get_xlabel(), MaidrKey.Y: self.ax.get_ylabel()}
84
74
 
85
75
  @abstractmethod
86
76
  def _extract_plot_data(self) -> list | dict:
@@ -7,7 +7,6 @@ from matplotlib.collections import PathCollection
7
7
  from maidr.core.enum import MaidrKey, PlotType
8
8
  from maidr.core.plot import MaidrPlot
9
9
  from maidr.exception import ExtractionError
10
- from maidr.util.environment import Environment
11
10
  from maidr.util.mixin import CollectionExtractorMixin
12
11
 
13
12
 
@@ -16,8 +15,6 @@ class ScatterPlot(MaidrPlot, CollectionExtractorMixin):
16
15
  super().__init__(ax, PlotType.SCATTER)
17
16
 
18
17
  def _get_selector(self) -> str | list[str]:
19
- if Environment.get_engine() == "js":
20
- return "g[maidr='true'] > use"
21
18
  return ["g[maidr='true'] > g > use"]
22
19
 
23
20
  def _extract_plot_data(self) -> list[dict]:
maidr/patch/barplot.py CHANGED
@@ -64,6 +64,9 @@ def bar(
64
64
  align == "edge"
65
65
  ):
66
66
  plot_type = PlotType.DODGED
67
+ if "dodge" in kwargs:
68
+ plot_type = PlotType.DODGED
69
+
67
70
  return common(plot_type, wrapped, instance, args, kwargs)
68
71
 
69
72
 
maidr/util/environment.py CHANGED
@@ -1,21 +1,10 @@
1
1
  import json
2
2
  import os
3
- from typing import Literal
4
3
 
5
4
 
6
5
  class Environment:
7
6
  _engine = "ts"
8
7
 
9
- @classmethod
10
- def _set_engine(cls, engine: Literal["js", "ts"]) -> None:
11
- """Set the engine to use for the MAIDR instance."""
12
- cls._engine = engine
13
-
14
- @classmethod
15
- def get_engine(cls) -> str:
16
- """Get the engine to use for the MAIDR instance."""
17
- return cls._engine
18
-
19
8
  @staticmethod
20
9
  def is_interactive_shell() -> bool:
21
10
  """Return True if the environment is an interactive shell."""
@@ -42,6 +31,16 @@ class Environment:
42
31
  except ImportError:
43
32
  return False
44
33
 
34
+ @staticmethod
35
+ def is_shiny() -> bool:
36
+ """Return True if the environment is a Shiny app."""
37
+ try:
38
+ import shiny
39
+
40
+ return shiny.__name__ == "shiny"
41
+ except ImportError:
42
+ return False
43
+
45
44
  @staticmethod
46
45
  def is_vscode_notebook() -> bool:
47
46
  """Return True if the environment is a VSCode notebook."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: maidr
3
- Version: 0.22.0
3
+ Version: 0.22.2
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=2VBiSAduUh4hV98_OTtLEKhjtiMBHaxFnsoQzpCEkVU,369
2
- maidr/api.py,sha256=nor5zAtz82RX2zTmfRGRIEz269mqEPGawZ9GMijbcfs,1818
1
+ maidr/__init__.py,sha256=rqvpwh77dvV86dbscY3OPvc7wX6V9xQbgjk-zwRTriI,357
2
+ maidr/api.py,sha256=GNyYSF8jEOsqCY4ZWLw3hh6RmRDewkWh6DJbzWfEwOA,1721
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/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=WLLn2kSkUp4KzhMIiV6U6H5JCYuS1QjbXmR5EiyGy2E,759
8
8
  maidr/core/enum/plot_type.py,sha256=pyfyIwlq3taqe2Z1sVUSbMsTp5QTvYBlZXsMMMclEVM,293
9
9
  maidr/core/figure_manager.py,sha256=e6nI5pGqH0NM3yzt2jeiae4lrBlIOhkDN92GZJ3MNmk,3988
10
- maidr/core/maidr.py,sha256=VYiHLGTH1tR1Ua6BC2nPMxK_FqqVr_oyndOX88s5XVc,14011
10
+ maidr/core/maidr.py,sha256=w27bsjX42uGZofaCDtMlZGNPYVMvg0mKU7r0xQFDeTY,12560
11
11
  maidr/core/plot/__init__.py,sha256=xDIpRGM-4DfaSSL3nKcXrjdMecCHJ6en4K4nA_fPefQ,83
12
- maidr/core/plot/barplot.py,sha256=0w-HAGi4wqB9c8qaMIv-KcjFHs99m74Tcn3fD7m1DxA,2555
12
+ maidr/core/plot/barplot.py,sha256=a5dOAaWqfbllLBN4U8JjPWSbONGqM8QUTTmUSccMd6U,1981
13
13
  maidr/core/plot/boxplot.py,sha256=WuHrUy6CFZRBfVDjl9MU262mfLFR6DWF_2h4zN3wcMI,5881
14
14
  maidr/core/plot/grouped_barplot.py,sha256=6D7KT1pjf7XP4XRERmRHYpXY83VikyGcGp-37qQZPEU,2101
15
15
  maidr/core/plot/heatmap.py,sha256=yMS-31tS2GW4peds9LtZesMxmmTV_YfqYO5M_t5KasQ,2521
16
16
  maidr/core/plot/histogram.py,sha256=QV5W-6ZJQQcZsrM91JJBX-ONktJzH7yg_et5_bBPfQQ,1525
17
- maidr/core/plot/lineplot.py,sha256=kPLX0MBmz_Q1FKTMkoELaMSVWPWcDtxp-_VRDmGb4Pg,3447
18
- maidr/core/plot/maidr_plot.py,sha256=k1-MifHMwDjD-TNQn5DIJ-ShtUiQgjxo7NjMIxGaW9Q,3303
17
+ maidr/core/plot/lineplot.py,sha256=NEsnreoJ2Qe7fcY7iPHbrJ7UgL1DnGyMmL_4fNcMaQI,3309
18
+ maidr/core/plot/maidr_plot.py,sha256=D-LVQEZEVR6JNcv9FrnYYVIKniSWJjvD8UczbgTeGhE,2974
19
19
  maidr/core/plot/maidr_plot_factory.py,sha256=QGcHK_oquY_M2_KJVEtc5-rBAD-gm7KI1kSD7cduHzg,1691
20
- maidr/core/plot/scatterplot.py,sha256=TNnd1dGCiE-qxQI30oHstF0jju50_uR08CDr-Ep4ahU,1392
20
+ maidr/core/plot/scatterplot.py,sha256=o0i0uS-wXK9ZrENxneoHbh3-u-2goRONp19Yu9QLsaY,1257
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=iCoYaqlHou6_rSnbjfZwpRU8ENnYcfQ9JCdUxhrSgCA,2416
24
+ maidr/patch/barplot.py,sha256=nxgBWBMUyf3eAW56CN5EKYYy3vsTgEPRlcvNYS3-WiU,2479
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
@@ -31,13 +31,13 @@ maidr/patch/histogram.py,sha256=tnyKkTMuzDXdyQBywhpHZgH3i2mXzOCSyfUSRM0tfUg,1315
31
31
  maidr/patch/lineplot.py,sha256=_EyqOp8BcO-kGq9sn8PyNQ8-Bz0FsnHAufXRkTGQzBw,1025
32
32
  maidr/patch/scatterplot.py,sha256=kln6zZwjVsdQzICalo-RnBOJrx1BnIB2xYUwItHvSNY,525
33
33
  maidr/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
- maidr/util/environment.py,sha256=VSDzKybCiRmUiP_SpBswVh0g78kl0FE2LhXIB8kXh_s,4554
34
+ maidr/util/environment.py,sha256=NJzbcFUCIk7OF29eIae8jyHax9p8fQgFLmxM6Af0fUY,4465
35
35
  maidr/util/mixin/__init__.py,sha256=aGJZNhtWh77yIVPc7ipIZm1OajigjMtCWYKPuDWTC-c,217
36
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.22.0.dist-info/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
41
- maidr-0.22.0.dist-info/METADATA,sha256=9gGDataWifBMLjLjpKqeQd2j1K-YRIKKU4UZOTQMvrY,2688
42
- maidr-0.22.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
43
- maidr-0.22.0.dist-info/RECORD,,
40
+ maidr-0.22.2.dist-info/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
41
+ maidr-0.22.2.dist-info/METADATA,sha256=0icmzAmbYyHT8FgQOVqcv6E_7dSN0M-_egxRyrLUpQI,2688
42
+ maidr-0.22.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
43
+ maidr-0.22.2.dist-info/RECORD,,
File without changes