Skip to content

Commit ec00505

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 496dc79 commit ec00505

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

mesa/examples/basic/boltzmann_wealth_model/app.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import altair as alt
2-
31
from mesa.examples.basic.boltzmann_wealth_model.model import BoltzmannWealth
42
from mesa.mesa_logging import INFO, log_to_stderr
53
from mesa.visualization import (
@@ -67,4 +65,4 @@ def agent_portrayal(agent):
6765
model_params=model_params,
6866
name="Boltzmann Wealth Model",
6967
)
70-
page # noqa
68+
page # noqa

mesa/visualization/backends/altair_backend.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ def collect_agent_data(
201201

202202
return final_data
203203

204-
205-
206204
def draw_agents(
207205
self, arguments, chart_width: int = 450, chart_height: int = 350, **kwargs
208206
):
@@ -219,7 +217,8 @@ def draw_agents(
219217
"size": arguments["size"][i],
220218
"shape": arguments["shape"][i],
221219
"opacity": arguments["opacity"][i],
222-
"strokeWidth": arguments["strokeWidth"][i] / 10, # Scale for continuous domain
220+
"strokeWidth": arguments["strokeWidth"][i]
221+
/ 10, # Scale for continuous domain
223222
"original_color": arguments["color"][i],
224223
}
225224
# Add tooltip data if available
@@ -230,7 +229,11 @@ def draw_agents(
230229
# Determine fill and stroke colors
231230
if arguments["filled"][i]:
232231
record["viz_fill_color"] = arguments["color"][i]
233-
record["viz_stroke_color"] = arguments["stroke"][i] if isinstance(arguments["stroke"][i], str) else None
232+
record["viz_stroke_color"] = (
233+
arguments["stroke"][i]
234+
if isinstance(arguments["stroke"][i], str)
235+
else None
236+
)
234237
else:
235238
record["viz_fill_color"] = None
236239
record["viz_stroke_color"] = arguments["color"][i]
@@ -240,19 +243,18 @@ def draw_agents(
240243
df = pd.DataFrame(records)
241244

242245
# Ensure all columns that should be numeric are, handling potential Nones
243-
numeric_cols = ['x', 'y', 'size', 'opacity', 'strokeWidth', 'original_color']
246+
numeric_cols = ["x", "y", "size", "opacity", "strokeWidth", "original_color"]
244247
for col in numeric_cols:
245248
if col in df.columns:
246-
df[col] = pd.to_numeric(df[col], errors='coerce')
247-
249+
df[col] = pd.to_numeric(df[col], errors="coerce")
248250

249251
# Get tooltip keys from the first valid record
250252
tooltip_list = ["x", "y"]
251253
# This is the corrected line:
252254
if any(t is not None for t in arguments["tooltip"]):
253-
first_valid_tooltip = next((t for t in arguments["tooltip"] if t), None)
254-
if first_valid_tooltip:
255-
tooltip_list.extend(first_valid_tooltip.keys())
255+
first_valid_tooltip = next((t for t in arguments["tooltip"] if t), None)
256+
if first_valid_tooltip:
257+
tooltip_list.extend(first_valid_tooltip.keys())
256258

257259
# Extract additional parameters from kwargs
258260
title = kwargs.pop("title", "")
@@ -316,10 +318,16 @@ def draw_agents(
316318
),
317319
title="Shape",
318320
),
319-
opacity=alt.Opacity("opacity:Q", title="Opacity", scale=alt.Scale(domain=[0, 1], range=[0, 1])),
321+
opacity=alt.Opacity(
322+
"opacity:Q",
323+
title="Opacity",
324+
scale=alt.Scale(domain=[0, 1], range=[0, 1]),
325+
),
320326
fill=fill_encoding,
321327
stroke=alt.Stroke("viz_stroke_color:N", scale=None),
322-
strokeWidth=alt.StrokeWidth("strokeWidth:Q", scale=alt.Scale(domain=[0, 1])),
328+
strokeWidth=alt.StrokeWidth(
329+
"strokeWidth:Q", scale=alt.Scale(domain=[0, 1])
330+
),
323331
tooltip=tooltip_list,
324332
)
325333
.properties(title=title, width=chart_width, height=chart_height)
@@ -431,4 +439,4 @@ def draw_propertylayer(
431439
main_charts.append(current_chart)
432440

433441
base = alt.layer(*main_charts).resolve_scale(color="independent")
434-
return base
442+
return base

mesa/visualization/components/portrayal_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ def __post_init__(self):
118118
if self.color is not None and self.colormap is not None:
119119
raise ValueError("Specify either 'color' or 'colormap', not both.")
120120
if self.color is None and self.colormap is None:
121-
raise ValueError("Specify one of 'color' or 'colormap'")
121+
raise ValueError("Specify one of 'color' or 'colormap'")

0 commit comments

Comments
 (0)