mesa / mesa/mesa

SolaraViz: Improve Portrayal API

Open
#2,923 4 comments 0 reactions 0 assignees View on GitHub
enhancement visualisation
Dominant language
Python
Stars
3.9k
Forks
1.3k
Avg merge
2d 12h
Merged PRs (30d)
20

Description

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:
```python
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_

Contributor guide

Open the contributing guide

Research direction

The issue names no files or tests; start by reviewing the portrayal API discussion in PR #2912 and locating the current SolaraViz portrayal entry point. Done means uniform styling can use a PropertyLayerStyle instance directly while conditional styling continues to support a callable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.