1+ """Altair-based renderer for Mesa spaces. 
2+ 
3+ This module provides an Altair-based renderer for visualizing Mesa model spaces, 
4+ agents, and property layers with interactive charting capabilities. 
5+ """ 
6+ 
17import  warnings 
28from  collections .abc  import  Callable 
39from  dataclasses  import  fields 
@@ -201,8 +207,6 @@ def collect_agent_data(
201207
202208        return  final_data 
203209
204- 
205- 
206210    def  draw_agents (
207211        self , arguments , chart_width : int  =  450 , chart_height : int  =  350 , ** kwargs 
208212    ):
@@ -219,7 +223,8 @@ def draw_agents(
219223                "size" : arguments ["size" ][i ],
220224                "shape" : arguments ["shape" ][i ],
221225                "opacity" : arguments ["opacity" ][i ],
222-                 "strokeWidth" : arguments ["strokeWidth" ][i ] /  10 , # Scale for continuous domain 
226+                 "strokeWidth" : arguments ["strokeWidth" ][i ]
227+                 /  10 ,  # Scale for continuous domain 
223228                "original_color" : arguments ["color" ][i ],
224229            }
225230            # Add tooltip data if available 
@@ -230,7 +235,11 @@ def draw_agents(
230235            # Determine fill and stroke colors 
231236            if  arguments ["filled" ][i ]:
232237                record ["viz_fill_color" ] =  arguments ["color" ][i ]
233-                 record ["viz_stroke_color" ] =  arguments ["stroke" ][i ] if  isinstance (arguments ["stroke" ][i ], str ) else  None 
238+                 record ["viz_stroke_color" ] =  (
239+                     arguments ["stroke" ][i ]
240+                     if  isinstance (arguments ["stroke" ][i ], str )
241+                     else  None 
242+                 )
234243            else :
235244                record ["viz_fill_color" ] =  None 
236245                record ["viz_stroke_color" ] =  arguments ["color" ][i ]
@@ -240,19 +249,18 @@ def draw_agents(
240249        df  =  pd .DataFrame (records )
241250
242251        # Ensure all columns that should be numeric are, handling potential Nones 
243-         numeric_cols  =  ['x' ,  'y' ,  ' size' ,  ' opacity' ,  ' strokeWidth' ,  ' original_color' 
252+         numeric_cols  =  ["x" ,  "y" ,  " size" ,  " opacity" ,  " strokeWidth" ,  " original_color" 
244253        for  col  in  numeric_cols :
245254            if  col  in  df .columns :
246-                 df [col ] =  pd .to_numeric (df [col ], errors = 'coerce' )
247- 
255+                 df [col ] =  pd .to_numeric (df [col ], errors = "coerce" )
248256
249257        # Get tooltip keys from the first valid record 
250258        tooltip_list  =  ["x" , "y" ]
251259        # This is the corrected line: 
252260        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 ())
261+             first_valid_tooltip  =  next ((t  for  t  in  arguments ["tooltip" ] if  t ), None )
262+             if  first_valid_tooltip :
263+                 tooltip_list .extend (first_valid_tooltip .keys ())
256264
257265        # Extract additional parameters from kwargs 
258266        title  =  kwargs .pop ("title" , "" )
@@ -316,10 +324,16 @@ def draw_agents(
316324                    ),
317325                    title = "Shape" ,
318326                ),
319-                 opacity = alt .Opacity ("opacity:Q" , title = "Opacity" , scale = alt .Scale (domain = [0 , 1 ], range = [0 , 1 ])),
327+                 opacity = alt .Opacity (
328+                     "opacity:Q" ,
329+                     title = "Opacity" ,
330+                     scale = alt .Scale (domain = [0 , 1 ], range = [0 , 1 ]),
331+                 ),
320332                fill = fill_encoding ,
321333                stroke = alt .Stroke ("viz_stroke_color:N" , scale = None ),
322-                 strokeWidth = alt .StrokeWidth ("strokeWidth:Q" , scale = alt .Scale (domain = [0 , 1 ])),
334+                 strokeWidth = alt .StrokeWidth (
335+                     "strokeWidth:Q" , scale = alt .Scale (domain = [0 , 1 ])
336+                 ),
323337                tooltip = tooltip_list ,
324338            )
325339            .properties (title = title , width = chart_width , height = chart_height )
@@ -431,4 +445,4 @@ def draw_propertylayer(
431445                main_charts .append (current_chart )
432446
433447        base  =  alt .layer (* main_charts ).resolve_scale (color = "independent" )
434-         return  base 
448+         return  base 
0 commit comments