@@ -201,8 +201,6 @@ def collect_agent_data(
201
201
202
202
return final_data
203
203
204
-
205
-
206
204
def draw_agents (
207
205
self , arguments , chart_width : int = 450 , chart_height : int = 350 , ** kwargs
208
206
):
@@ -219,7 +217,8 @@ def draw_agents(
219
217
"size" : arguments ["size" ][i ],
220
218
"shape" : arguments ["shape" ][i ],
221
219
"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
223
222
"original_color" : arguments ["color" ][i ],
224
223
}
225
224
# Add tooltip data if available
@@ -230,7 +229,11 @@ def draw_agents(
230
229
# Determine fill and stroke colors
231
230
if arguments ["filled" ][i ]:
232
231
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
+ )
234
237
else :
235
238
record ["viz_fill_color" ] = None
236
239
record ["viz_stroke_color" ] = arguments ["color" ][i ]
@@ -240,19 +243,18 @@ def draw_agents(
240
243
df = pd .DataFrame (records )
241
244
242
245
# 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" ]
244
247
for col in numeric_cols :
245
248
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" )
248
250
249
251
# Get tooltip keys from the first valid record
250
252
tooltip_list = ["x" , "y" ]
251
253
# This is the corrected line:
252
254
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 ())
256
258
257
259
# Extract additional parameters from kwargs
258
260
title = kwargs .pop ("title" , "" )
@@ -316,10 +318,16 @@ def draw_agents(
316
318
),
317
319
title = "Shape" ,
318
320
),
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
+ ),
320
326
fill = fill_encoding ,
321
327
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
+ ),
323
331
tooltip = tooltip_list ,
324
332
)
325
333
.properties (title = title , width = chart_width , height = chart_height )
@@ -431,4 +439,4 @@ def draw_propertylayer(
431
439
main_charts .append (current_chart )
432
440
433
441
base = alt .layer (* main_charts ).resolve_scale (color = "independent" )
434
- return base
442
+ return base
0 commit comments