Spaces:
Runtime error
Runtime error
eaglelandsonce
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -37,8 +37,8 @@ color_codes = {
|
|
37 |
# Add other types with their corresponding colors
|
38 |
}
|
39 |
|
40 |
-
#
|
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,29 +46,25 @@ def draw_grid(data, highlight=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 coords ==
|
57 |
-
|
58 |
-
|
59 |
else:
|
60 |
-
|
61 |
-
|
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():
|
74 |
st.title('Green Smart Village Application')
|
|
|
37 |
# Add other types with their corresponding colors
|
38 |
}
|
39 |
|
40 |
+
# Function to draw the grid with optional highlighting
|
41 |
+
def draw_grid(data, highlight_coords=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') # Default color is white if not specified
|
55 |
+
|
56 |
+
if highlight_coords and (coords[0], coords[1]) == tuple(highlight_coords):
|
57 |
+
highlighted_color = "#FFD700" # Gold for highlighting
|
58 |
+
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=highlighted_color, edgecolor='black', linewidth=2))
|
59 |
else:
|
60 |
+
ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
|
61 |
+
ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
|
|
|
|
|
|
|
|
|
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')
|