mesa
mesa copied to clipboard
SolaraViz: Improve Portrayal API
However, I'm wondering if we should consider improving this API in a follow-up. The current design feels a bit awkward:
- Simple cases require writing a function wrapper that always returns the same object
- The function --> class pattern isn't the most intuitive
Right now users must write:
def propertylayer_portrayal(layer):
return PropertyLayerStyle(colormap="viridis", colorbar=True)
Where the function wrapper adds no value when the style is uniform across all layers.
What if we allowed the visualization to accept either:
- A
PropertyLayerStyleinstance directly (for simple uniform styling) - A callable function (for conditional/per-layer styling)
Similar to how Python's sorted() accepts both key=str.lower and key=lambda x: complex_logic(x).
Originally posted by @EwoutH in https://github.com/projectmesa/mesa/pull/2912#discussion_r2589989850
@EwoutH Is this issue still open. I would like to work on this.
@EwoutH is this issue still open. I would like to work on this issue