Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,7 @@ color_codes = {
|
|
37 |
# Add other types with their corresponding colors
|
38 |
}
|
39 |
|
40 |
-
#
|
41 |
def draw_grid(data, highlight=None):
|
42 |
fig, ax = plt.subplots(figsize=(12, 12))
|
43 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
@@ -51,34 +51,23 @@ def draw_grid(data, highlight=None):
|
|
51 |
coords = building['coords']
|
52 |
b_type = building['type']
|
53 |
size = building['size']
|
54 |
-
color = color_codes.get(b_type, '#FFFFFF')
|
55 |
# Highlight the selected building
|
56 |
if coords == highlight:
|
57 |
-
edgecolor = 'red'
|
58 |
-
linewidth = 3
|
59 |
else:
|
60 |
edgecolor = 'black'
|
61 |
linewidth = 1
|
62 |
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor=edgecolor, linewidth=linewidth))
|
63 |
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
|
64 |
-
|
65 |
-
#
|
66 |
-
for road in data.get('roads', []):
|
67 |
-
start, end = road['start'], road['end']
|
68 |
-
road_color = road.get('color', '#000000') # Default road color is black
|
69 |
-
# Determine if the road is vertical or horizontal and draw it
|
70 |
-
if start[0] == end[0]: # Vertical road
|
71 |
-
for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
|
72 |
-
ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road_color))
|
73 |
-
else: # Horizontal road
|
74 |
-
for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
|
75 |
-
ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road_color))
|
76 |
|
77 |
ax.set_xlabel('Columns')
|
78 |
ax.set_ylabel('Rows')
|
79 |
ax.set_title('Village Layout with Color Coding')
|
80 |
return fig
|
81 |
-
|
82 |
|
83 |
# Main Streamlit app function
|
84 |
def main():
|
|
|
37 |
# Add other types with their corresponding colors
|
38 |
}
|
39 |
|
40 |
+
# Modified draw_grid function with highlighting based on coordinates
|
41 |
def draw_grid(data, highlight=None):
|
42 |
fig, ax = plt.subplots(figsize=(12, 12))
|
43 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
|
|
51 |
coords = building['coords']
|
52 |
b_type = building['type']
|
53 |
size = building['size']
|
54 |
+
color = color_codes.get(b_type, '#FFFFFF')
|
55 |
# Highlight the selected building
|
56 |
if coords == highlight:
|
57 |
+
edgecolor = 'red'
|
58 |
+
linewidth = 3
|
59 |
else:
|
60 |
edgecolor = 'black'
|
61 |
linewidth = 1
|
62 |
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor=edgecolor, linewidth=linewidth))
|
63 |
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
|
64 |
+
|
65 |
+
# Add the roads drawing logic here, if applicable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
ax.set_xlabel('Columns')
|
68 |
ax.set_ylabel('Rows')
|
69 |
ax.set_title('Village Layout with Color Coding')
|
70 |
return fig
|
|
|
71 |
|
72 |
# Main Streamlit app function
|
73 |
def main():
|