|
1 | 1 | import contextlib
|
2 | 2 | from typing import Optional
|
3 | 3 |
|
4 |
| -import pandas as pd |
5 | 4 | import solara
|
6 | 5 |
|
7 | 6 | with contextlib.suppress(ImportError):
|
@@ -36,25 +35,24 @@ def portray(g):
|
36 | 35 | return all_agent_data
|
37 | 36 |
|
38 | 37 | all_agent_data = portray(space)
|
39 |
| - df = pd.DataFrame(all_agent_data) |
| 38 | + encoding_dict = { |
| 39 | + # no x-axis label |
| 40 | + "x": alt.X("x", axis=None, type="ordinal"), |
| 41 | + # no y-axis label |
| 42 | + "y": alt.Y("y", axis=None, type="ordinal"), |
| 43 | + } |
| 44 | + has_color = "color" in all_agent_data[0] |
| 45 | + if has_color: |
| 46 | + encoding_dict["color"] = alt.Color("color", type="nominal") |
| 47 | + has_size = "size" in all_agent_data[0] |
| 48 | + if has_size: |
| 49 | + encoding_dict["size"] = alt.Size("size", type="quantitative") |
| 50 | + |
40 | 51 | chart = (
|
41 |
| - alt.Chart(df) |
| 52 | + alt.Chart(alt.Data(values=all_agent_data), encoding=alt.Encoding(**encoding_dict)) |
42 | 53 | .mark_point(filled=True)
|
43 |
| - .encode( |
44 |
| - # no x-axis label |
45 |
| - x=alt.X("x", axis=None), |
46 |
| - # no y-axis label |
47 |
| - y=alt.Y("y", axis=None), |
48 |
| - ) |
| 54 | + .properties(width=space.width * 15, height=space.height * 15) |
49 | 55 | # .configure_view(strokeOpacity=0) # hide grid/chart lines
|
50 | 56 | )
|
51 | 57 |
|
52 |
| - has_color = hasattr(all_agent_data[0], "color") |
53 |
| - if has_color: |
54 |
| - chart = chart.encode(color=alt.Color("color")) |
55 |
| - |
56 |
| - has_size = hasattr(all_agent_data[0], "size") |
57 |
| - if has_size: |
58 |
| - chart = chart.encode(size=alt.Size("size")) |
59 |
| - |
60 | 58 | return chart
|
0 commit comments