Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -38,7 +38,7 @@ color_codes = {
|
|
38 |
}
|
39 |
|
40 |
# Function to draw the grid with optional highlighting
|
41 |
-
def draw_grid(data,
|
42 |
fig, ax = plt.subplots(figsize=(12, 12))
|
43 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
44 |
ax.set_xlim(0, ncols)
|
@@ -46,25 +46,40 @@ def draw_grid(data, highlight_coords=None):
|
|
46 |
ax.set_xticks(range(ncols+1))
|
47 |
ax.set_yticks(range(nrows+1))
|
48 |
ax.grid(True)
|
49 |
-
|
50 |
for building in data['buildings']:
|
51 |
coords = building['coords']
|
52 |
b_type = building['type']
|
53 |
size = building['size']
|
54 |
-
color = color_codes.get(b_type, '#FFFFFF') #
|
55 |
-
|
56 |
-
if
|
57 |
-
|
58 |
-
|
59 |
else:
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
ax.set_xlabel('Columns')
|
64 |
ax.set_ylabel('Rows')
|
65 |
ax.set_title('Village Layout with Color Coding')
|
66 |
return fig
|
67 |
|
|
|
68 |
# Main Streamlit app function
|
69 |
def main():
|
70 |
st.title('Green Smart Village Application')
|
|
|
38 |
}
|
39 |
|
40 |
# Function to draw the grid with optional highlighting
|
41 |
+
def draw_grid(data, highlight=None):
|
42 |
fig, ax = plt.subplots(figsize=(12, 12))
|
43 |
nrows, ncols = data['size']['rows'], data['size']['columns']
|
44 |
ax.set_xlim(0, ncols)
|
|
|
46 |
ax.set_xticks(range(ncols+1))
|
47 |
ax.set_yticks(range(nrows+1))
|
48 |
ax.grid(True)
|
49 |
+
|
50 |
for building in data['buildings']:
|
51 |
coords = building['coords']
|
52 |
b_type = building['type']
|
53 |
size = building['size']
|
54 |
+
color = color_codes.get(b_type, '#FFFFFF') # Use default color if type is not found
|
55 |
+
# Highlight the selected building
|
56 |
+
if coords == highlight:
|
57 |
+
edgecolor = 'red' # Highlight color
|
58 |
+
linewidth = 3 # Make the border thicker for the selected building
|
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 |
+
# Draw roads
|
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():
|
85 |
st.title('Green Smart Village Application')
|