maidr 0.16.1__tar.gz → 0.17.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.16.1 → maidr-0.17.0}/PKG-INFO +1 -1
  2. {maidr-0.16.1 → maidr-0.17.0}/maidr/__init__.py +1 -1
  3. {maidr-0.16.1 → maidr-0.17.0}/maidr/api.py +19 -4
  4. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/maidr.py +9 -3
  5. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/barplot.py +3 -3
  6. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/barplot.py +11 -9
  7. {maidr-0.16.1 → maidr-0.17.0}/maidr/util/mixin/extractor_mixin.py +29 -2
  8. {maidr-0.16.1 → maidr-0.17.0}/pyproject.toml +1 -1
  9. {maidr-0.16.1 → maidr-0.17.0}/LICENSE +0 -0
  10. {maidr-0.16.1 → maidr-0.17.0}/README.md +0 -0
  11. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/__init__.py +0 -0
  12. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/context_manager.py +0 -0
  13. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/enum/__init__.py +0 -0
  14. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/enum/library.py +0 -0
  15. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/enum/maidr_key.py +0 -0
  16. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/enum/plot_type.py +0 -0
  17. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/figure_manager.py +0 -0
  18. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/__init__.py +0 -0
  19. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/boxplot.py +0 -0
  20. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/grouped_barplot.py +0 -0
  21. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/heatmap.py +0 -0
  22. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/histogram.py +0 -0
  23. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/lineplot.py +0 -0
  24. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/maidr_plot.py +0 -0
  25. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/maidr_plot_factory.py +0 -0
  26. {maidr-0.16.1 → maidr-0.17.0}/maidr/core/plot/scatterplot.py +0 -0
  27. {maidr-0.16.1 → maidr-0.17.0}/maidr/exception/__init__.py +0 -0
  28. {maidr-0.16.1 → maidr-0.17.0}/maidr/exception/extraction_error.py +0 -0
  29. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/__init__.py +0 -0
  30. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/boxplot.py +0 -0
  31. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/clear.py +0 -0
  32. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/common.py +0 -0
  33. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/heatmap.py +0 -0
  34. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/highlight.py +0 -0
  35. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/histogram.py +0 -0
  36. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/lineplot.py +0 -0
  37. {maidr-0.16.1 → maidr-0.17.0}/maidr/patch/scatterplot.py +0 -0
  38. {maidr-0.16.1 → maidr-0.17.0}/maidr/util/__init__.py +0 -0
  39. {maidr-0.16.1 → maidr-0.17.0}/maidr/util/environment.py +0 -0
  40. {maidr-0.16.1 → maidr-0.17.0}/maidr/util/mixin/__init__.py +0 -0
  41. {maidr-0.16.1 → maidr-0.17.0}/maidr/util/mixin/merger_mixin.py +0 -0
  42. {maidr-0.16.1 → maidr-0.17.0}/maidr/widget/__init__.py +0 -0
  43. {maidr-0.16.1 → maidr-0.17.0}/maidr/widget/shiny.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: maidr
3
- Version: 0.16.1
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,4 +1,4 @@
1
- __version__ = "0.16.1"
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
@@ -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:
@@ -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
@@ -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
 
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "maidr"
7
- version = "0.16.1"
7
+ version = "0.17.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