mesa icon indicating copy to clipboard operation
mesa copied to clipboard

SolaraViz: Improve Portrayal API

Open EwoutH opened this issue 3 weeks ago • 1 comments

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:

  1. A PropertyLayerStyle instance directly (for simple uniform styling)
  2. 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 avatar Dec 04 '25 19:12 EwoutH

@EwoutH Is this issue still open. I would like to work on this.

ShreyasN707 avatar Dec 07 '25 05:12 ShreyasN707

@EwoutH is this issue still open. I would like to work on this issue

codebyNJ avatar Dec 15 '25 17:12 codebyNJ