Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tooltip option to Altair chart #2082

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mesa/experimental/components/altair.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def SpaceAltair(model, agent_portrayal, dependencies: Optional[list[any]] = None
def _draw_grid(space, agent_portrayal):
def portray(g):
all_agent_data = []
for content, (x, y) in space.coord_iter():
for content, (x, y) in g.coord_iter():
if not content:
continue
if not hasattr(content, "__iter__"):
Expand All @@ -35,11 +35,18 @@ def portray(g):
return all_agent_data

all_agent_data = portray(space)
invalid_tooltips = ["color", "size", "x", "y"]

encoding_dict = {
# no x-axis label
"x": alt.X("x", axis=None, type="ordinal"),
# no y-axis label
"y": alt.Y("y", axis=None, type="ordinal"),
"tooltip": [
alt.Tooltip(key, type=alt.utils.infer_vegalite_type([value]))
for key, value in all_agent_data[0].items()
if key not in invalid_tooltips
],
}
has_color = "color" in all_agent_data[0]
if has_color:
Expand Down