Skip to content

Commit

Permalink
Merge pull request #13 from EwoutH/patch-4
Browse files Browse the repository at this point in the history
Update get_agent_data_from_coord_iter to allow no agents on the grid
  • Loading branch information
Corvince authored Dec 14, 2023
2 parents cf0ae4e + 585d1f6 commit 4a102a9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/mesa_interactive/components/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import solara


def get_agent_data_from_coord_iter(data):
for agent, (x, y) in data:
if agent:
agent_data = json.loads(
json.dumps(agent.__dict__, skipkeys=True, default=str)
)
agent_data["x"] = x
agent_data["y"] = y
agent_data.pop("model", None)
agent_data.pop("pos", None)
yield agent_data

def get_agent_data_from_coord_iter(agents_per_coordinate):
for agents, (x, y) in agents_per_coordinate:
if agents: # Checking if the list is non-empty
for agent in agents:
agent_data = json.loads(
json.dumps(agent.__dict__, skipkeys=True, default=str)
)
agent_data["x"] = x
agent_data["y"] = y
agent_data.pop("model", None)
agent_data.pop("pos", None)
yield agent_data

def create_grid(
color: str | None = None,
Expand Down

0 comments on commit 4a102a9

Please sign in to comment.