Feature: Portrayal components for agents and property layers #2661
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses issue #2436 and is based on discussions from PR #2640 and #2642. It introduces three new features into Mesa:
AgentPortrayalStyle
,PropertyLayerStyle
, andPropertyLayerPortrayal
. The goal is to initiate an API redesign for separating agent, grid, and property layer drawing, as discussed in #2642.Implementation
As described, this PR introduces three new dataclasses in Mesa. Let's explore them:
AgentPortrayalStyle
:This class validates parameters for agent portrayal in its
__post_init__
method and uses the__iter__
dunder method to convert the class into a dictionary.Usage:
PropertyLayerStyle
:This class also validates parameters in its
__post_init__
method. For instance, a property layer can take either a color or a colormap:This class serves as the basis for the next class
PropertyLayerPortrayal
that is explained below.PropertyLayerPortrayal
:Manages property layer styles and introduces a new way to define property layer portrayal for multiple layers. Defines a dictionary named layers:
add_layer
method is used to add portrayal for different layers.Usage:
Additional Notes:
Some changes are made in
mpl_space_drawing.py
according to the current features.