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

Implemented post_process in Altair based components #2641

Merged
merged 10 commits into from
Jan 31, 2025
11 changes: 8 additions & 3 deletions mesa/visualization/components/altair_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def make_altair_space(

Args:
agent_portrayal: Function to portray agents.
propertylayer_portrayal: not yet implemented
propertylayer_portrayal: A user specified callable that will be called with the Chart instance from Altair. Allows for fine tuning plots (e.g., control ticks)
post_process :not yet implemented
space_drawing_kwargs : not yet implemented

Expand All @@ -46,13 +46,15 @@ def agent_portrayal(a):
return {"id": a.unique_id}

def MakeSpaceAltair(model):
return SpaceAltair(model, agent_portrayal)
return SpaceAltair(model, agent_portrayal, post_process=post_process)

return MakeSpaceAltair


@solara.component
def SpaceAltair(model, agent_portrayal, dependencies: list[any] | None = None):
def SpaceAltair(
model, agent_portrayal, dependencies: list[any] | None = None, post_process=None
):
"""Create an Altair-based space visualization component.

Returns:
Expand All @@ -65,6 +67,9 @@ def SpaceAltair(model, agent_portrayal, dependencies: list[any] | None = None):
space = model.space

chart = _draw_grid(space, agent_portrayal)
# Apply post-processing if provided
if post_process is not None:
chart = post_process(chart)
solara.FigureAltair(chart)


Expand Down
Loading