maidr 0.22.1__tar.gz → 0.23.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.22.1 → maidr-0.23.0}/PKG-INFO +1 -1
  2. {maidr-0.22.1 → maidr-0.23.0}/maidr/__init__.py +1 -1
  3. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/maidr.py +1 -2
  4. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/barplot.py +2 -0
  5. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/maidr_plot.py +22 -1
  6. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/barplot.py +3 -0
  7. {maidr-0.22.1 → maidr-0.23.0}/maidr/util/environment.py +10 -0
  8. {maidr-0.22.1 → maidr-0.23.0}/maidr/util/mixin/extractor_mixin.py +12 -0
  9. {maidr-0.22.1 → maidr-0.23.0}/pyproject.toml +1 -1
  10. {maidr-0.22.1 → maidr-0.23.0}/LICENSE +0 -0
  11. {maidr-0.22.1 → maidr-0.23.0}/README.md +0 -0
  12. {maidr-0.22.1 → maidr-0.23.0}/maidr/api.py +0 -0
  13. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/__init__.py +0 -0
  14. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/context_manager.py +0 -0
  15. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/enum/__init__.py +0 -0
  16. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/enum/library.py +0 -0
  17. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/enum/maidr_key.py +0 -0
  18. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/enum/plot_type.py +0 -0
  19. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/figure_manager.py +0 -0
  20. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/__init__.py +0 -0
  21. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/boxplot.py +0 -0
  22. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/grouped_barplot.py +0 -0
  23. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/heatmap.py +0 -0
  24. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/histogram.py +0 -0
  25. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/lineplot.py +0 -0
  26. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/maidr_plot_factory.py +0 -0
  27. {maidr-0.22.1 → maidr-0.23.0}/maidr/core/plot/scatterplot.py +0 -0
  28. {maidr-0.22.1 → maidr-0.23.0}/maidr/exception/__init__.py +0 -0
  29. {maidr-0.22.1 → maidr-0.23.0}/maidr/exception/extraction_error.py +0 -0
  30. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/__init__.py +0 -0
  31. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/boxplot.py +0 -0
  32. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/clear.py +0 -0
  33. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/common.py +0 -0
  34. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/heatmap.py +0 -0
  35. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/highlight.py +0 -0
  36. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/histogram.py +0 -0
  37. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/lineplot.py +0 -0
  38. {maidr-0.22.1 → maidr-0.23.0}/maidr/patch/scatterplot.py +0 -0
  39. {maidr-0.22.1 → maidr-0.23.0}/maidr/util/__init__.py +0 -0
  40. {maidr-0.22.1 → maidr-0.23.0}/maidr/util/mixin/__init__.py +0 -0
  41. {maidr-0.22.1 → maidr-0.23.0}/maidr/util/mixin/merger_mixin.py +0 -0
  42. {maidr-0.22.1 → maidr-0.23.0}/maidr/widget/__init__.py +0 -0
  43. {maidr-0.22.1 → maidr-0.23.0}/maidr/widget/shiny.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: maidr
3
- Version: 0.22.1
3
+ Version: 0.23.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.22.1"
1
+ __version__ = "0.23.0"
2
2
 
3
3
  from .api import close, render, save_html, show, stacked
4
4
  from .core import Maidr
@@ -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
@@ -272,7 +271,7 @@ class Maidr:
272
271
  # Render the plot inside an iframe if in a Jupyter notebook, Google Colab
273
272
  # or VSCode notebook. No need for iframe if this is a Quarto document.
274
273
  # For TypeScript we will use iframe by default for now
275
- if Environment.is_notebook():
274
+ if Environment.is_notebook() or Environment.is_shiny():
276
275
  unique_id = "iframe_" + Maidr._unique_id()
277
276
 
278
277
  def generate_iframe_script(unique_id: str) -> str:
@@ -48,6 +48,8 @@ class BarPlot(MaidrPlot, ContainerExtractorMixin, LevelExtractorMixin, DictMerge
48
48
  # Flatten all the `list[BarContainer]` to `list[Patch]`.
49
49
  plot = [patch for container in plot for patch in container.patches]
50
50
  level = self.extract_level(self.ax)
51
+ if len(level) == 0: # type: ignore
52
+ level = ["" for _ in range(len(plot))] # type: ignore
51
53
 
52
54
  if len(plot) != len(level):
53
55
  return None
@@ -68,9 +68,30 @@ class MaidrPlot(ABC):
68
68
  """Return the CSS selector for highlighting elements."""
69
69
  return "g[maidr='true'] > path"
70
70
 
71
+ def extract_shared_xlabel(self, ax, y_threshold=0.2):
72
+ # First, try to get an xlabel from any shared axes.
73
+ siblings = ax.get_shared_x_axes().get_siblings(ax)
74
+ for shared_ax in siblings:
75
+ xlabel = shared_ax.get_xlabel()
76
+ if xlabel: # if non-empty
77
+ return xlabel
78
+
79
+ for text in ax.figure.texts:
80
+ if text.get_position()[1] < y_threshold:
81
+ label = text.get_text().strip()
82
+ if label:
83
+ return label
84
+
85
+ return ""
86
+
71
87
  def _extract_axes_data(self) -> dict:
72
88
  """Extract the plot's axes data"""
73
- return {MaidrKey.X: self.ax.get_xlabel(), MaidrKey.Y: self.ax.get_ylabel()}
89
+ x_labels = self.ax.get_xlabel()
90
+ if not x_labels:
91
+ x_labels = self.extract_shared_xlabel(self.ax)
92
+ if not x_labels:
93
+ x_labels = "X"
94
+ return {MaidrKey.X: x_labels, MaidrKey.Y: self.ax.get_ylabel()}
74
95
 
75
96
  @abstractmethod
76
97
  def _extract_plot_data(self) -> list | dict:
@@ -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
 
@@ -31,6 +31,16 @@ class Environment:
31
31
  except ImportError:
32
32
  return False
33
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
+
34
44
  @staticmethod
35
45
  def is_vscode_notebook() -> bool:
36
46
  """Return True if the environment is a VSCode notebook."""
@@ -78,8 +78,20 @@ class LevelExtractorMixin:
78
78
  elif MaidrKey.FILL == key:
79
79
  level = [container.get_label() for container in ax.containers]
80
80
 
81
+ if len(level) == 0: # type: ignore
82
+ level = LevelExtractorMixin.extract_shared_xtick_labels(ax)
83
+
81
84
  return level
82
85
 
86
+ @staticmethod
87
+ def extract_shared_xtick_labels(ax):
88
+ siblings = ax.get_shared_x_axes().get_siblings(ax)
89
+ for shared_ax in siblings:
90
+ labels = [label.get_text() for label in shared_ax.get_xticklabels()]
91
+ if any(labels):
92
+ return labels
93
+ return []
94
+
83
95
 
84
96
  class LineExtractorMixin:
85
97
  @staticmethod
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "maidr"
7
- version = "0.22.1"
7
+ version = "0.23.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