maidr 0.12.3__tar.gz → 0.13.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.
- {maidr-0.12.3 → maidr-0.13.0}/PKG-INFO +1 -1
- {maidr-0.12.3 → maidr-0.13.0}/maidr/__init__.py +2 -2
- {maidr-0.12.3 → maidr-0.13.0}/maidr/api.py +6 -1
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/maidr.py +32 -9
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/barplot.py +23 -6
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/maidr_plot.py +5 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/util/environment.py +13 -0
- {maidr-0.12.3 → maidr-0.13.0}/pyproject.toml +1 -1
- {maidr-0.12.3 → maidr-0.13.0}/LICENSE +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/README.md +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/__init__.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/context_manager.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/enum/__init__.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/enum/library.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/enum/maidr_key.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/enum/plot_type.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/figure_manager.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/__init__.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/boxplot.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/grouped_barplot.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/heatmap.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/histogram.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/lineplot.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/maidr_plot_factory.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/core/plot/scatterplot.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/exception/__init__.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/exception/extraction_error.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/__init__.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/barplot.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/boxplot.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/clear.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/common.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/heatmap.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/highlight.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/histogram.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/lineplot.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/patch/scatterplot.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/util/__init__.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/util/mixin/__init__.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/util/mixin/extractor_mixin.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/util/mixin/merger_mixin.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/widget/__init__.py +0 -0
- {maidr-0.12.3 → maidr-0.13.0}/maidr/widget/shiny.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: maidr
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.13.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.
|
|
1
|
+
__version__ = "0.13.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
|
|
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)
|
|
@@ -78,7 +78,10 @@ class Maidr:
|
|
|
78
78
|
html = self._create_html_doc()
|
|
79
79
|
return html.save_html(file, libdir=lib_dir, include_version=include_version)
|
|
80
80
|
|
|
81
|
-
def show(
|
|
81
|
+
def show(
|
|
82
|
+
self,
|
|
83
|
+
renderer: Literal["auto", "ipython", "browser"] = "auto",
|
|
84
|
+
) -> object:
|
|
82
85
|
"""
|
|
83
86
|
Preview the HTML content using the specified renderer.
|
|
84
87
|
|
|
@@ -190,13 +193,11 @@ class Maidr:
|
|
|
190
193
|
def _inject_plot(plot: HTML, maidr: str, maidr_id) -> Tag:
|
|
191
194
|
"""Embed the plot and associated MAIDR scripts into the HTML structure."""
|
|
192
195
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
window.init(maidrId);
|
|
197
|
-
}}
|
|
198
|
-
}}
|
|
196
|
+
engine = Environment.get_engine()
|
|
197
|
+
|
|
198
|
+
MAIDR_TS_CDN_URL = "https://cdn.jsdelivr.net/npm/maidr-ts/dist/maidr.js"
|
|
199
199
|
|
|
200
|
+
maidr_js_script = f"""
|
|
200
201
|
if (!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/maidr/dist/maidr.min.js"]')) {{
|
|
201
202
|
var script = document.createElement('script');
|
|
202
203
|
script.type = 'text/javascript';
|
|
@@ -210,12 +211,31 @@ class Maidr:
|
|
|
210
211
|
}}
|
|
211
212
|
"""
|
|
212
213
|
|
|
214
|
+
maidr_ts_script = f"""
|
|
215
|
+
if (!document.querySelector('script[src="{MAIDR_TS_CDN_URL}"]'))
|
|
216
|
+
{{
|
|
217
|
+
var script = document.createElement('script');
|
|
218
|
+
script.type = 'module';
|
|
219
|
+
script.src = '{MAIDR_TS_CDN_URL}';
|
|
220
|
+
script.addEventListener('load', function() {{
|
|
221
|
+
window.main();
|
|
222
|
+
}});
|
|
223
|
+
document.head.appendChild(script);
|
|
224
|
+
}} else {{
|
|
225
|
+
document.addEventListener('DOMContentLoaded', function (e) {{
|
|
226
|
+
window.main();
|
|
227
|
+
}});
|
|
228
|
+
}}
|
|
229
|
+
"""
|
|
230
|
+
|
|
231
|
+
script = maidr_js_script if engine == "js" else maidr_ts_script
|
|
232
|
+
|
|
213
233
|
base_html = tags.div(
|
|
214
234
|
tags.link(
|
|
215
235
|
rel="stylesheet",
|
|
216
236
|
href="https://cdn.jsdelivr.net/npm/maidr/dist/maidr_style.min.css",
|
|
217
237
|
),
|
|
218
|
-
tags.script(
|
|
238
|
+
tags.script(script, type="text/javascript"),
|
|
219
239
|
tags.div(plot),
|
|
220
240
|
)
|
|
221
241
|
|
|
@@ -223,7 +243,10 @@ class Maidr:
|
|
|
223
243
|
|
|
224
244
|
# Render the plot inside an iframe if in a Jupyter notebook, Google Colab
|
|
225
245
|
# or VSCode notebook. No need for iframe if this is a Quarto document.
|
|
226
|
-
|
|
246
|
+
# For TypeScript we will use iframe by default for now
|
|
247
|
+
if (Environment.is_notebook() and not is_quarto) or (
|
|
248
|
+
engine == "ts" and Environment.is_notebook()
|
|
249
|
+
):
|
|
227
250
|
unique_id = "iframe_" + Maidr._unique_id()
|
|
228
251
|
|
|
229
252
|
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
|
-
|
|
24
|
-
|
|
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
|
|
|
@@ -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."""
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|