Skip to content

Commit

Permalink
Add tooltip option to Altair chart (#2082)
Browse files Browse the repository at this point in the history
* add: tooltip option to altair.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixed tooltip type detection and syntax

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* tooltip semplification

---------

Co-authored-by: Federico <federico.serratorevr@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 15, 2024
1 parent de24299 commit 1634b8f
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit 1634b8f

Please sign in to comment.