maidr 0.22.1__py3-none-any.whl → 0.23.0__py3-none-any.whl

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/__init__.py CHANGED
@@ -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
maidr/core/maidr.py CHANGED
@@ -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:
maidr/patch/barplot.py CHANGED
@@ -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
 
maidr/util/environment.py CHANGED
@@ -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
@@ -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
- maidr/__init__.py,sha256=ABDD1_FOfLPWDA5gMifMwKyoWCkWv9pistkI4dAedOw,357
1
+ maidr/__init__.py,sha256=Ljve4SYKQEgmUc2B-UKQtoN9Z376J0sElayLOlEgHuY,357
2
2
  maidr/api.py,sha256=GNyYSF8jEOsqCY4ZWLw3hh6RmRDewkWh6DJbzWfEwOA,1721
3
3
  maidr/core/__init__.py,sha256=WgxLpSEYMc4k3OyEOf1shOxfEq0ASzppEIZYmE91ThQ,25
4
4
  maidr/core/context_manager.py,sha256=6cT7ZGOApSpC-SLD2XZWWU_H08i-nfv-JUlzXOtvWYw,3374
@@ -7,21 +7,21 @@ maidr/core/enum/library.py,sha256=e8ujT_L-McJWfoVJd1ty9K_2bwITnf1j0GPLsnAcHes,10
7
7
  maidr/core/enum/maidr_key.py,sha256=WLLn2kSkUp4KzhMIiV6U6H5JCYuS1QjbXmR5EiyGy2E,759
8
8
  maidr/core/enum/plot_type.py,sha256=pyfyIwlq3taqe2Z1sVUSbMsTp5QTvYBlZXsMMMclEVM,293
9
9
  maidr/core/figure_manager.py,sha256=e6nI5pGqH0NM3yzt2jeiae4lrBlIOhkDN92GZJ3MNmk,3988
10
- maidr/core/maidr.py,sha256=eQHe4UGBu0l5C8Jdd9UGVt0qdrU37niwVgV-2n2_p6g,12575
10
+ maidr/core/maidr.py,sha256=w27bsjX42uGZofaCDtMlZGNPYVMvg0mKU7r0xQFDeTY,12560
11
11
  maidr/core/plot/__init__.py,sha256=xDIpRGM-4DfaSSL3nKcXrjdMecCHJ6en4K4nA_fPefQ,83
12
- maidr/core/plot/barplot.py,sha256=a5dOAaWqfbllLBN4U8JjPWSbONGqM8QUTTmUSccMd6U,1981
12
+ maidr/core/plot/barplot.py,sha256=1HfoqyDGKIXkYQnCHN83Ye_faKpNQ3R4wjlbjD5jUyk,2092
13
13
  maidr/core/plot/boxplot.py,sha256=WuHrUy6CFZRBfVDjl9MU262mfLFR6DWF_2h4zN3wcMI,5881
14
14
  maidr/core/plot/grouped_barplot.py,sha256=6D7KT1pjf7XP4XRERmRHYpXY83VikyGcGp-37qQZPEU,2101
15
15
  maidr/core/plot/heatmap.py,sha256=yMS-31tS2GW4peds9LtZesMxmmTV_YfqYO5M_t5KasQ,2521
16
16
  maidr/core/plot/histogram.py,sha256=QV5W-6ZJQQcZsrM91JJBX-ONktJzH7yg_et5_bBPfQQ,1525
17
17
  maidr/core/plot/lineplot.py,sha256=NEsnreoJ2Qe7fcY7iPHbrJ7UgL1DnGyMmL_4fNcMaQI,3309
18
- maidr/core/plot/maidr_plot.py,sha256=D-LVQEZEVR6JNcv9FrnYYVIKniSWJjvD8UczbgTeGhE,2974
18
+ maidr/core/plot/maidr_plot.py,sha256=B6hjsu-jSWlevEqJawgwjMOJr51nBBNh7yqJdSTkNhw,3681
19
19
  maidr/core/plot/maidr_plot_factory.py,sha256=QGcHK_oquY_M2_KJVEtc5-rBAD-gm7KI1kSD7cduHzg,1691
20
20
  maidr/core/plot/scatterplot.py,sha256=o0i0uS-wXK9ZrENxneoHbh3-u-2goRONp19Yu9QLsaY,1257
21
21
  maidr/exception/__init__.py,sha256=PzaXoYBhyZxMDcJkuxJugDx7jZeseI0El6LpxIwXyG4,46
22
22
  maidr/exception/extraction_error.py,sha256=rd37Oxa9gn2OWFWt9AOH5fv0hNd3sAWGvpDMFBuJY2I,607
23
23
  maidr/patch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
- maidr/patch/barplot.py,sha256=iCoYaqlHou6_rSnbjfZwpRU8ENnYcfQ9JCdUxhrSgCA,2416
24
+ maidr/patch/barplot.py,sha256=nxgBWBMUyf3eAW56CN5EKYYy3vsTgEPRlcvNYS3-WiU,2479
25
25
  maidr/patch/boxplot.py,sha256=Mcz94pSf7PT3SyRsI8TDrIKVdEmiiUQouXvd05mtnfw,2846
26
26
  maidr/patch/clear.py,sha256=2Sc4CIt5jRGkew3TxFsBZm-uowC9yDSxtraEcXZjmGw,396
27
27
  maidr/patch/common.py,sha256=bRe4jruUvCIwp1t1E8Q3OuQ0eEyHgpMjXVpsPBZj4C8,843
@@ -31,13 +31,13 @@ maidr/patch/histogram.py,sha256=tnyKkTMuzDXdyQBywhpHZgH3i2mXzOCSyfUSRM0tfUg,1315
31
31
  maidr/patch/lineplot.py,sha256=_EyqOp8BcO-kGq9sn8PyNQ8-Bz0FsnHAufXRkTGQzBw,1025
32
32
  maidr/patch/scatterplot.py,sha256=kln6zZwjVsdQzICalo-RnBOJrx1BnIB2xYUwItHvSNY,525
33
33
  maidr/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
- maidr/util/environment.py,sha256=pa6NOoZLQQDmQvWitSTtB9nI2A7xETHLeJRNqWHybik,4220
34
+ maidr/util/environment.py,sha256=NJzbcFUCIk7OF29eIae8jyHax9p8fQgFLmxM6Af0fUY,4465
35
35
  maidr/util/mixin/__init__.py,sha256=aGJZNhtWh77yIVPc7ipIZm1OajigjMtCWYKPuDWTC-c,217
36
- maidr/util/mixin/extractor_mixin.py,sha256=AjpgCo_dgASdTwFumfgDOoVCVioxDDoqFWphaBj5gz4,4764
36
+ maidr/util/mixin/extractor_mixin.py,sha256=oHtwpmS5kARvaLrSO3DKTPQxyFUw9nOcKN7rzTj1q4g,5192
37
37
  maidr/util/mixin/merger_mixin.py,sha256=V0qLw_6DUB7X6CQ3BCMpsCQX_ZuwAhoSTm_E4xAJFKM,712
38
38
  maidr/widget/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
39
  maidr/widget/shiny.py,sha256=wrrw2KAIpE_A6CNQGBtNHauR1DjenA_n47qlFXX9_rk,745
40
- maidr-0.22.1.dist-info/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
41
- maidr-0.22.1.dist-info/METADATA,sha256=joyaX_YNioraA-OG3yiArVGVlsnsePZgZav0nYrLtbM,2688
42
- maidr-0.22.1.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
43
- maidr-0.22.1.dist-info/RECORD,,
40
+ maidr-0.23.0.dist-info/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
41
+ maidr-0.23.0.dist-info/METADATA,sha256=wpNic98dvQs53YS3btM7WPNvNEXgnwYEnYcljNTNvN4,2688
42
+ maidr-0.23.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
43
+ maidr-0.23.0.dist-info/RECORD,,
File without changes