Skip to content

Commit 6196a82

Browse files
committed
Revert "feat: support multilayer plot using maidr-ts"
This reverts commit a697c73.
1 parent a697c73 commit 6196a82

File tree

6 files changed

+18
-124
lines changed

6 files changed

+18
-124
lines changed

example/multilayer/example_mpl_multilayer.py

-57
This file was deleted.

maidr/api.py

+4-19
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,16 @@ def render(plot: Any) -> Tag:
2020

2121
def show(plot: Any, renderer: Literal["auto", "ipython", "browser"] = "auto") -> object:
2222
ax = FigureManager.get_axes(plot)
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-
htmls[-1].show(renderer)
29-
else:
30-
maidr = FigureManager.get_maidr(ax.get_figure())
31-
return maidr.show(renderer)
23+
maidr = FigureManager.get_maidr(ax.get_figure())
24+
return maidr.show(renderer)
3225

3326

3427
def save_html(
3528
plot: Any, file: str, *, lib_dir: str | None = "lib", include_version: bool = True
3629
) -> str:
3730
ax = FigureManager.get_axes(plot)
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)
31+
maidr = FigureManager.get_maidr(ax.get_figure())
32+
return maidr.save_html(file, lib_dir=lib_dir, include_version=include_version)
4833

4934

5035
def stacked(plot: Axes | BarContainer) -> Maidr:

maidr/core/maidr.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _create_html_doc(self) -> HTMLDocument:
139139

140140
def _flatten_maidr(self) -> dict | list[dict]:
141141
"""Return a single plot schema or a list of schemas from the Maidr instance."""
142-
if self.plot_type == PlotType.LINE or self.plot_type == PlotType.DODGED:
142+
if self.plot_type == PlotType.LINE:
143143
self._plots = [self._plots[0]]
144144
maidr = [plot.schema for plot in self._plots]
145145

@@ -150,11 +150,7 @@ def _flatten_maidr(self) -> dict | list[dict]:
150150
"maidr='true'", f"maidr='{self.selector_id}'"
151151
)
152152

153-
# return maidr if len(maidr) != 1 else maidr[0]
154-
return {
155-
"id": Maidr._unique_id(),
156-
"panels": [[{"id": Maidr._unique_id(), "layers": maidr}]],
157-
}
153+
return maidr if len(maidr) != 1 else maidr[0]
158154

159155
def _get_svg(self) -> HTML:
160156
"""Extract the chart SVG from ``matplotlib.figure.Figure``."""
@@ -204,7 +200,6 @@ def _inject_plot(plot: HTML, maidr: str, maidr_id) -> Tag:
204200

205201
engine = Environment.get_engine()
206202

207-
# MAIDR_TS_CDN_URL = "http://localhost:8000/maidr.js" # DEMO URL
208203
MAIDR_TS_CDN_URL = "https://cdn.jsdelivr.net/npm/maidr-ts/dist/maidr.js"
209204

210205
maidr_js_script = f"""

maidr/core/plot/barplot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _extract_plot_data(self) -> list:
4141
combined_data = (
4242
zip(levels, data) if plot[0].orientation == "vertical" else zip(levels, data) # type: ignore
4343
)
44-
if combined_data: # type: ignore
44+
if len(data) == len(plot): # type: ignore
4545
for x, y in combined_data: # type: ignore
4646
formatted_data.append({"x": x, "y": y})
4747
return formatted_data

maidr/patch/barplot.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,16 @@ def bar(
5252
bottom = kwargs.get("bottom")
5353
if bottom is not None:
5454
plot_type = PlotType.STACKED
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")
62-
63-
if (isinstance(real_width, (int, float)) and float(real_width) < 0.8) or (
64-
align == "edge"
65-
):
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:
6663
plot_type = PlotType.DODGED
64+
6765
return common(plot_type, wrapped, instance, args, kwargs)
6866

6967

maidr/util/mixin/extractor_mixin.py

+2-29
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,9 @@ def extract_level(ax: Axes, key: MaidrKey = MaidrKey.X) -> list[str] | None:
4545

4646
level = None
4747
if MaidrKey.X == key:
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
48+
level = [label.get_text() for label in ax.get_xticklabels()]
6149
elif MaidrKey.Y == key:
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
50+
level = [label.get_text() for label in ax.get_yticklabels()]
7851
elif MaidrKey.FILL == key:
7952
level = [container.get_label() for container in ax.containers]
8053

0 commit comments

Comments
 (0)