maidr 0.22.0__tar.gz → 0.22.1__tar.gz

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.
Files changed (43) hide show
  1. {maidr-0.22.0 → maidr-0.22.1}/PKG-INFO +1 -1
  2. {maidr-0.22.0 → maidr-0.22.1}/maidr/__init__.py +2 -2
  3. {maidr-0.22.0 → maidr-0.22.1}/maidr/api.py +0 -4
  4. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/maidr.py +3 -37
  5. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/barplot.py +11 -27
  6. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/lineplot.py +5 -11
  7. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/maidr_plot.py +3 -13
  8. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/scatterplot.py +0 -3
  9. {maidr-0.22.0 → maidr-0.22.1}/maidr/util/environment.py +0 -11
  10. {maidr-0.22.0 → maidr-0.22.1}/pyproject.toml +1 -1
  11. {maidr-0.22.0 → maidr-0.22.1}/LICENSE +0 -0
  12. {maidr-0.22.0 → maidr-0.22.1}/README.md +0 -0
  13. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/__init__.py +0 -0
  14. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/context_manager.py +0 -0
  15. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/enum/__init__.py +0 -0
  16. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/enum/library.py +0 -0
  17. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/enum/maidr_key.py +0 -0
  18. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/enum/plot_type.py +0 -0
  19. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/figure_manager.py +0 -0
  20. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/__init__.py +0 -0
  21. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/boxplot.py +0 -0
  22. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/grouped_barplot.py +0 -0
  23. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/heatmap.py +0 -0
  24. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/histogram.py +0 -0
  25. {maidr-0.22.0 → maidr-0.22.1}/maidr/core/plot/maidr_plot_factory.py +0 -0
  26. {maidr-0.22.0 → maidr-0.22.1}/maidr/exception/__init__.py +0 -0
  27. {maidr-0.22.0 → maidr-0.22.1}/maidr/exception/extraction_error.py +0 -0
  28. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/__init__.py +0 -0
  29. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/barplot.py +0 -0
  30. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/boxplot.py +0 -0
  31. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/clear.py +0 -0
  32. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/common.py +0 -0
  33. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/heatmap.py +0 -0
  34. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/highlight.py +0 -0
  35. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/histogram.py +0 -0
  36. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/lineplot.py +0 -0
  37. {maidr-0.22.0 → maidr-0.22.1}/maidr/patch/scatterplot.py +0 -0
  38. {maidr-0.22.0 → maidr-0.22.1}/maidr/util/__init__.py +0 -0
  39. {maidr-0.22.0 → maidr-0.22.1}/maidr/util/mixin/__init__.py +0 -0
  40. {maidr-0.22.0 → maidr-0.22.1}/maidr/util/mixin/extractor_mixin.py +0 -0
  41. {maidr-0.22.0 → maidr-0.22.1}/maidr/util/mixin/merger_mixin.py +0 -0
  42. {maidr-0.22.0 → maidr-0.22.1}/maidr/widget/__init__.py +0 -0
  43. {maidr-0.22.0 → maidr-0.22.1}/maidr/widget/shiny.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: maidr
3
- Version: 0.22.0
3
+ Version: 0.22.1
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,6 +1,6 @@
1
- __version__ = "0.22.0"
1
+ __version__ = "0.22.1"
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 (
@@ -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)
@@ -142,19 +142,6 @@ class Maidr:
142
142
 
143
143
  def _flatten_maidr(self) -> dict | list[dict]:
144
144
  """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
145
  if self.plot_type in (PlotType.DODGED, PlotType.STACKED):
159
146
  self._plots = [self._plots[0]]
160
147
 
@@ -251,27 +238,10 @@ class Maidr:
251
238
  @staticmethod
252
239
  def _inject_plot(plot: HTML, maidr: str, maidr_id) -> Tag:
253
240
  """Embed the plot and associated MAIDR scripts into the HTML structure."""
254
-
255
- engine = Environment.get_engine()
256
-
257
241
  # MAIDR_TS_CDN_URL = "http://localhost:8080/maidr.js" # DEMO URL
258
242
  MAIDR_TS_CDN_URL = "https://cdn.jsdelivr.net/npm/maidr-ts/dist/maidr.js"
259
243
 
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"""
244
+ script = f"""
275
245
  if (!document.querySelector('script[src="{MAIDR_TS_CDN_URL}"]'))
276
246
  {{
277
247
  var script = document.createElement('script');
@@ -288,8 +258,6 @@ class Maidr:
288
258
  }}
289
259
  """
290
260
 
291
- script = maidr_js_script if engine == "js" else maidr_ts_script
292
-
293
261
  base_html = tags.div(
294
262
  tags.link(
295
263
  rel="stylesheet",
@@ -299,14 +267,12 @@ class Maidr:
299
267
  tags.div(plot),
300
268
  )
301
269
 
302
- is_quarto = os.getenv("IS_QUARTO") == "True"
270
+ # is_quarto = os.getenv("IS_QUARTO") == "True"
303
271
 
304
272
  # Render the plot inside an iframe if in a Jupyter notebook, Google Colab
305
273
  # or VSCode notebook. No need for iframe if this is a Quarto document.
306
274
  # 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
- ):
275
+ if Environment.is_notebook():
310
276
  unique_id = "iframe_" + Maidr._unique_id()
311
277
 
312
278
  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]:
@@ -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."""
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "maidr"
7
- version = "0.22.0"
7
+ version = "0.22.1"
8
8
  description = "Multimodal Access and Interactive Data Representations"
9
9
  authors = [
10
10
  "JooYoung Seo <jseo1005@illinois.edu>",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes