Skip to content

Commit

Permalink
fixed tooltip type detection and syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico committed Mar 15, 2024
1 parent af4c3c5 commit 3b705f9
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions mesa/experimental/components/altair.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import contextlib
import datetime
from typing import Optional

import solara
Expand Down Expand Up @@ -35,39 +34,19 @@ def portray(g):
all_agent_data.append(agent_data)
return all_agent_data

def detect_type(key):
key_type = type(all_agent_data[0][key])
tooltip_type = ""
if key_type == int:
tooltip_type = "quantitative"
elif key_type == datetime.datetime:
tooltip_type = "temporal"
else:
tooltip_type = "nominal"
# TODO: check if the string can be considered
# as a date time object and, if so,
# change tooltip_type to "temporal"

return tooltip_type

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

tooltip_types = {}
for key in all_agent_data[0].keys():
if key not in invalid_tooltips:
tooltip_types[key] = detect_type(key)

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=tooltip_types[key])
for key in all_agent_data[0].keys()
if key not in invalid_tooltips
],
alt.Tooltip(key, type=alt.utils.infer_vegalite_type([all_agent_data[0][key]]))
for key in all_agent_data[0] if key not in invalid_tooltips
]
}
has_color = "color" in all_agent_data[0]
if has_color:
Expand Down

0 comments on commit 3b705f9

Please sign in to comment.