maidr 0.12.3__tar.gz → 0.14.0__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.12.3 → maidr-0.14.0}/PKG-INFO +1 -1
  2. {maidr-0.12.3 → maidr-0.14.0}/maidr/__init__.py +2 -2
  3. {maidr-0.12.3 → maidr-0.14.0}/maidr/api.py +6 -1
  4. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/maidr.py +35 -11
  5. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/barplot.py +23 -6
  6. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/lineplot.py +4 -0
  7. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/maidr_plot.py +5 -0
  8. {maidr-0.12.3 → maidr-0.14.0}/maidr/util/environment.py +13 -0
  9. {maidr-0.12.3 → maidr-0.14.0}/pyproject.toml +1 -1
  10. {maidr-0.12.3 → maidr-0.14.0}/LICENSE +0 -0
  11. {maidr-0.12.3 → maidr-0.14.0}/README.md +0 -0
  12. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/__init__.py +0 -0
  13. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/context_manager.py +0 -0
  14. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/enum/__init__.py +0 -0
  15. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/enum/library.py +0 -0
  16. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/enum/maidr_key.py +0 -0
  17. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/enum/plot_type.py +0 -0
  18. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/figure_manager.py +0 -0
  19. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/__init__.py +0 -0
  20. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/boxplot.py +0 -0
  21. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/grouped_barplot.py +0 -0
  22. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/heatmap.py +0 -0
  23. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/histogram.py +0 -0
  24. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/maidr_plot_factory.py +0 -0
  25. {maidr-0.12.3 → maidr-0.14.0}/maidr/core/plot/scatterplot.py +0 -0
  26. {maidr-0.12.3 → maidr-0.14.0}/maidr/exception/__init__.py +0 -0
  27. {maidr-0.12.3 → maidr-0.14.0}/maidr/exception/extraction_error.py +0 -0
  28. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/__init__.py +0 -0
  29. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/barplot.py +0 -0
  30. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/boxplot.py +0 -0
  31. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/clear.py +0 -0
  32. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/common.py +0 -0
  33. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/heatmap.py +0 -0
  34. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/highlight.py +0 -0
  35. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/histogram.py +0 -0
  36. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/lineplot.py +0 -0
  37. {maidr-0.12.3 → maidr-0.14.0}/maidr/patch/scatterplot.py +0 -0
  38. {maidr-0.12.3 → maidr-0.14.0}/maidr/util/__init__.py +0 -0
  39. {maidr-0.12.3 → maidr-0.14.0}/maidr/util/mixin/__init__.py +0 -0
  40. {maidr-0.12.3 → maidr-0.14.0}/maidr/util/mixin/extractor_mixin.py +0 -0
  41. {maidr-0.12.3 → maidr-0.14.0}/maidr/util/mixin/merger_mixin.py +0 -0
  42. {maidr-0.12.3 → maidr-0.14.0}/maidr/widget/__init__.py +0 -0
  43. {maidr-0.12.3 → maidr-0.14.0}/maidr/widget/shiny.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: maidr
3
- Version: 0.12.3
3
+ Version: 0.14.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,6 @@
1
- __version__ = "0.12.3"
1
+ __version__ = "0.14.0"
2
2
 
3
+ from .api import close, render, save_html, set_engine, show, stacked
3
4
  from .core import Maidr
4
5
  from .core.enum import PlotType
5
6
  from .patch import (
@@ -12,7 +13,6 @@ from .patch import (
12
13
  lineplot,
13
14
  scatterplot,
14
15
  )
15
- from .api import close, render, save_html, show, stacked
16
16
 
17
17
  __all__ = [
18
18
  "close",
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Literal, Any
3
+ from typing import Any, Literal
4
4
 
5
5
  from htmltools import Tag
6
6
  from matplotlib.axes import Axes
@@ -9,6 +9,7 @@ from matplotlib.container import BarContainer
9
9
  from maidr.core import Maidr
10
10
  from maidr.core.enum import PlotType
11
11
  from maidr.core.figure_manager import FigureManager
12
+ from maidr.util.environment import Environment
12
13
 
13
14
 
14
15
  def render(plot: Any) -> Tag:
@@ -39,3 +40,7 @@ def stacked(plot: Axes | BarContainer) -> Maidr:
39
40
  def close(plot: Any) -> None:
40
41
  ax = FigureManager.get_axes(plot)
41
42
  FigureManager.destroy(ax.get_figure())
43
+
44
+
45
+ def set_engine(engine: Literal["js", "ts"] = "js"):
46
+ Environment._set_engine(engine=engine)
@@ -44,6 +44,7 @@ class Maidr:
44
44
  self._fig = fig
45
45
  self._plots = []
46
46
  self.maidr_id = None
47
+ self.selector_id = Maidr._unique_id()
47
48
 
48
49
  @property
49
50
  def fig(self) -> Figure:
@@ -78,7 +79,10 @@ class Maidr:
78
79
  html = self._create_html_doc()
79
80
  return html.save_html(file, libdir=lib_dir, include_version=include_version)
80
81
 
81
- def show(self, renderer: Literal["auto", "ipython", "browser"] = "auto") -> object:
82
+ def show(
83
+ self,
84
+ renderer: Literal["auto", "ipython", "browser"] = "auto",
85
+ ) -> object:
82
86
  """
83
87
  Preview the HTML content using the specified renderer.
84
88
 
@@ -122,7 +126,7 @@ class Maidr:
122
126
  maidr = f"\nlet maidr = {json.dumps(self._flatten_maidr(), indent=2)}\n"
123
127
 
124
128
  # In SVG we will replace maidr=id with the unique id.
125
- svg = svg.replace('maidr="true"', f'maidr="{self.maidr_id}"')
129
+ svg = svg.replace('maidr="true"', f'maidr="{self.selector_id}"')
126
130
 
127
131
  # Inject plot's svg and MAIDR structure into html tag.
128
132
  return Maidr._inject_plot(svg, maidr, self.maidr_id)
@@ -139,7 +143,7 @@ class Maidr:
139
143
  for plot in maidr:
140
144
  if MaidrKey.SELECTOR in plot:
141
145
  plot[MaidrKey.SELECTOR] = plot[MaidrKey.SELECTOR].replace(
142
- "maidr='true'", f"maidr='{self.maidr_id}'"
146
+ "maidr='true'", f"maidr='{self.selector_id}'"
143
147
  )
144
148
 
145
149
  return maidr if len(maidr) != 1 else maidr[0]
@@ -190,13 +194,11 @@ class Maidr:
190
194
  def _inject_plot(plot: HTML, maidr: str, maidr_id) -> Tag:
191
195
  """Embed the plot and associated MAIDR scripts into the HTML structure."""
192
196
 
193
- script_check = f"""
194
- function initializeMaidr(maidrId) {{
195
- if (window.init) {{
196
- window.init(maidrId);
197
- }}
198
- }}
197
+ engine = Environment.get_engine()
198
+
199
+ MAIDR_TS_CDN_URL = "https://cdn.jsdelivr.net/npm/maidr-ts/dist/maidr.js"
199
200
 
201
+ maidr_js_script = f"""
200
202
  if (!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/maidr/dist/maidr.min.js"]')) {{
201
203
  var script = document.createElement('script');
202
204
  script.type = 'text/javascript';
@@ -210,12 +212,31 @@ class Maidr:
210
212
  }}
211
213
  """
212
214
 
215
+ maidr_ts_script = f"""
216
+ if (!document.querySelector('script[src="{MAIDR_TS_CDN_URL}"]'))
217
+ {{
218
+ var script = document.createElement('script');
219
+ script.type = 'module';
220
+ script.src = '{MAIDR_TS_CDN_URL}';
221
+ script.addEventListener('load', function() {{
222
+ window.main();
223
+ }});
224
+ document.head.appendChild(script);
225
+ }} else {{
226
+ document.addEventListener('DOMContentLoaded', function (e) {{
227
+ window.main();
228
+ }});
229
+ }}
230
+ """
231
+
232
+ script = maidr_js_script if engine == "js" else maidr_ts_script
233
+
213
234
  base_html = tags.div(
214
235
  tags.link(
215
236
  rel="stylesheet",
216
237
  href="https://cdn.jsdelivr.net/npm/maidr/dist/maidr_style.min.css",
217
238
  ),
218
- tags.script(script_check, type="text/javascript"),
239
+ tags.script(script, type="text/javascript"),
219
240
  tags.div(plot),
220
241
  )
221
242
 
@@ -223,7 +244,10 @@ class Maidr:
223
244
 
224
245
  # Render the plot inside an iframe if in a Jupyter notebook, Google Colab
225
246
  # or VSCode notebook. No need for iframe if this is a Quarto document.
226
- if Environment.is_notebook() and not is_quarto:
247
+ # For TypeScript we will use iframe by default for now
248
+ if (Environment.is_notebook() and not is_quarto) or (
249
+ engine == "ts" and Environment.is_notebook()
250
+ ):
227
251
  unique_id = "iframe_" + Maidr._unique_id()
228
252
 
229
253
  def generate_iframe_script(unique_id: str) -> str:
@@ -6,6 +6,7 @@ from matplotlib.container import BarContainer
6
6
  from maidr.core.enum import MaidrKey, PlotType
7
7
  from maidr.core.plot import MaidrPlot
8
8
  from maidr.exception import ExtractionError
9
+ from maidr.util.environment import Environment
9
10
  from maidr.util.mixin import (
10
11
  ContainerExtractorMixin,
11
12
  DictMergerMixin,
@@ -18,18 +19,34 @@ class BarPlot(MaidrPlot, ContainerExtractorMixin, LevelExtractorMixin, DictMerge
18
19
  super().__init__(ax, PlotType.BAR)
19
20
 
20
21
  def _extract_axes_data(self) -> dict:
22
+ engine = Environment.get_engine()
23
+
21
24
  base_schema = super()._extract_axes_data()
22
- bar_ax_schema = {
23
- MaidrKey.X: {
24
- MaidrKey.LEVEL: self.extract_level(self.ax),
25
- },
26
- }
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
+ }
27
32
  return self.merge_dict(base_schema, bar_ax_schema)
28
33
 
29
34
  def _extract_plot_data(self) -> list:
35
+ engine = Environment.get_engine()
30
36
  plot = self.extract_container(self.ax, BarContainer, include_all=True)
31
37
  data = self._extract_bar_container_data(plot)
32
-
38
+ levels = self.extract_level(self.ax)
39
+ if engine == "ts":
40
+ formatted_data = []
41
+ combined_data = (
42
+ zip(levels, data) if plot[0].orientation == "vertical" else zip(levels, data) # type: ignore
43
+ )
44
+ if len(data) == len(plot): # 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)
33
50
  if data is None:
34
51
  raise ExtractionError(self.type, plot)
35
52
 
@@ -6,6 +6,7 @@ from matplotlib.lines import Line2D
6
6
  from maidr.core.enum import MaidrKey, PlotType
7
7
  from maidr.core.plot import MaidrPlot
8
8
  from maidr.exception import ExtractionError
9
+ from maidr.util.environment import Environment
9
10
  from maidr.util.mixin import LineExtractorMixin
10
11
 
11
12
 
@@ -19,6 +20,9 @@ class LinePlot(MaidrPlot, LineExtractorMixin):
19
20
  def _extract_plot_data(self) -> list[dict]:
20
21
  plot = self.extract_line(self.ax)
21
22
  data = self._extract_line_data(plot)
23
+ engine = Environment.get_engine()
24
+ if engine == "ts":
25
+ data = [data]
22
26
 
23
27
  if data is None:
24
28
  raise ExtractionError(self.type, plot)
@@ -1,9 +1,11 @@
1
1
  from __future__ import annotations
2
+
2
3
  from abc import ABC, abstractmethod
3
4
 
4
5
  from matplotlib.axes import Axes
5
6
 
6
7
  from maidr.core.enum import MaidrKey, PlotType
8
+ from maidr.util.environment import Environment
7
9
 
8
10
 
9
11
  class MaidrPlot(ABC):
@@ -65,6 +67,9 @@ class MaidrPlot(ABC):
65
67
 
66
68
  def _extract_axes_data(self) -> dict:
67
69
  """Extract the plot's axes data"""
70
+ engine = Environment.get_engine()
71
+ if engine == "ts":
72
+ return {MaidrKey.X: self.ax.get_xlabel(), MaidrKey.Y: self.ax.get_ylabel()}
68
73
  return {
69
74
  MaidrKey.X: {
70
75
  MaidrKey.LABEL: self.ax.get_xlabel(),
@@ -1,8 +1,21 @@
1
1
  import json
2
2
  import os
3
+ from typing import Literal
3
4
 
4
5
 
5
6
  class Environment:
7
+ _engine = "js"
8
+
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
+
6
19
  @staticmethod
7
20
  def is_interactive_shell() -> bool:
8
21
  """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.12.3"
7
+ version = "0.14.0"
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