Description
I have taken a closer look at the solara matplotlib visualization support in MESA and tried to refactor it a bit because of various redundancies. However, I ran into a few issues. Basically, how the data is gathered before plotting is dependent on the type of space that is to be visualized. For example, there is no relevant position data when visualizing networks. Offsets to x and y are added for grids. Moreover, for discrete spaces, we have multiple implementations of both old-style and new-style (e.g., HexSingleGrid, HexMultiGrid, HexGrid). I believe it is quite easy to abstract away whether you are plotting an old-style or a new-style space. They mainly differ with respect to how you get the agents to plot and their (x, y) coordinates, which is easily wrapped into custom generators (these generators are probably also useful for the altair side of things, so I'll probably add a components.util module).
In an attempt to make sense of this all, I have come to the following breakdown:
OrthogonalGrid = SingleGrid | MultiGrid | OrthogonalMooreGrid | OrthogonalVonNeumannGrid
HexGrid = HexSingleGrid | HexMultiGrid | HexGrid
ContinousSpace
Network = NetworkGrid | mesa.experimental.grid_space.Network
VoronoiGrid
draw_orthogonal_grid(space: OrthogonalGrid, agent_portrayal: Callable, propertylayer_portrayal: Callable)
...
draw_hex_grid(space: HexGrid, agent_portrayal: Callable, propertylayer_portrayal: Callable):
...
draw_network(space: Network, agent_portrayal: Callable, propertylayer_portrayal: Callable):
...
draw_continuous_space(space: ContinousSpace, agent_portrayal: Callable):
...
draw_voroinoi_grid(space: VoronoiGrid, agent_portrayal: Callable, propertylayer_portrayal: Callable):
...
I have several questions:
- Does the breakdown into types of spaces make sense?
- Did I miss anything?
- Property layers are currently implemented in
DiscreteSpace
for new-style spaces. So they are available in all new style spaces, includingNetwork
andVoronoiGrid
. Should property grids be moved fromDiscreteSpace
toGrid
? This would mimic old-style spaces. I also question whether property layers are presently meaningful for networks or Voronoi meshes. (I want to focus the conversation on improving the current visualization code, so please don't bring up ideas on how to expand property layers to also work in e.g., VoronoiGrid or continuous spaces).
If this brake down makes sense, I'll reorganize the code accordingly and start writing some tests for it.