Skip to content

Commit bbf7c9f

Browse files
committed
feat: support highlight in line, bar and histogram plots using maidr ts
1 parent 9e57a7c commit bbf7c9f

File tree

10 files changed

+104
-25
lines changed

10 files changed

+104
-25
lines changed

Diff for: example/bar/example_bar_plot.ipynb

+30-7
Large diffs are not rendered by default.

Diff for: example/bar/matplotlib/example_mpl_bar_plot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import maidr
55

66
# To use maidr's typescript build set the following command to use maidr ts
7-
# maidr.set_engine("ts")
7+
maidr.set_engine("ts")
88

99
# Load dataset
1010
tips = sns.load_dataset("tips")

Diff for: example/bar/seaborn/example_sns_bar_plot.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import maidr
55

6+
maidr.set_engine("ts")
7+
68
# Load the penguins dataset
79
penguins = sns.load_dataset("penguins")
810

Diff for: example/histogram/example_histogram_plot.ipynb

+27-5
Large diffs are not rendered by default.

Diff for: example/line/example_line_plot.ipynb

+27-5
Large diffs are not rendered by default.

Diff for: example/line/matplotlib/example_mpl_line.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import maidr
55

6-
# maidr.set_engine("ts")
6+
maidr.set_engine("ts")
77

88
# Load the flights dataset from seaborn
99
flights = sns.load_dataset("flights")

Diff for: example/line/seaborn/example_sns_line.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import maidr
55

6+
maidr.set_engine("ts")
7+
68
# Load the 'tips' dataset from seaborn
79
tips = sns.load_dataset("tips")
810

Diff for: maidr/core/enum/maidr_key.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class MaidrKey(str, Enum):
55
# Maidr info keys.
66
ID = "id"
77
ORIENTATION = "orientation"
8-
SELECTOR = "selector"
8+
SELECTOR = "selectors"
99
TYPE = "type"
1010

1111
# Plot data keys.

Diff for: maidr/core/maidr.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,18 @@ def _flatten_maidr(self) -> dict | list[dict]:
160160

161161
for plot in self._plots:
162162
schema = plot.schema
163+
163164
if MaidrKey.SELECTOR in schema:
164-
schema[MaidrKey.SELECTOR] = schema[MaidrKey.SELECTOR].replace(
165-
"maidr='true'", f"maidr='{self.selector_id}'"
166-
)
165+
if isinstance(schema[MaidrKey.SELECTOR], str):
166+
schema[MaidrKey.SELECTOR] = schema[MaidrKey.SELECTOR].replace(
167+
"maidr='true'", f"maidr='{self.selector_id}'"
168+
)
169+
if isinstance(schema[MaidrKey.SELECTOR], list):
170+
for i in range(len(schema[MaidrKey.SELECTOR])):
171+
schema[MaidrKey.SELECTOR][i] = schema[MaidrKey.SELECTOR][
172+
i
173+
].replace("maidr='true'", f"maidr='{self.selector_id}'")
174+
167175
plot_schemas.append(
168176
{
169177
"schema": schema,

Diff for: maidr/core/plot/lineplot.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class MultiLinePlot(MaidrPlot, LineExtractorMixin):
4242
def __init__(self, ax: Axes, **kwargs):
4343
super().__init__(ax, PlotType.LINE)
4444

45-
def _get_selector(self) -> str:
46-
return "g[maidr='true'] > path"
45+
def _get_selector(self) -> list[str]:
46+
return ["g[maidr='true'] > path"]
4747

4848
def _extract_plot_data(self) -> list[dict]:
4949
plot = self.extract_lines(self.ax)

0 commit comments

Comments
 (0)