eaglelandsonce commited on
Commit
654556e
·
verified ·
1 Parent(s): 2fe29e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import json
3
  import matplotlib.pyplot as plt
@@ -41,14 +42,9 @@ def draw_grid(data, highlight_coords=None):
41
  fig, ax = plt.subplots(figsize=(12, 12))
42
  nrows, ncols = data['size']['rows'], data['size']['columns']
43
  ax.set_xlim(0, ncols)
44
- ax.set_ylim(0, nrows) # Keep the original limits
45
  ax.set_xticks(range(ncols+1))
46
  ax.set_yticks(range(nrows+1))
47
-
48
- # Relabel y-axis with reversed order
49
- y_labels = list(range(nrows, -1, -1)) # Generates labels from nrows to 0
50
- ax.set_yticklabels(y_labels)
51
-
52
  ax.grid(True)
53
 
54
  for building in data['buildings']:
@@ -57,19 +53,29 @@ def draw_grid(data, highlight_coords=None):
57
  size = building['size']
58
  color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
59
 
60
- # Plotting logic remains unchanged
61
- ax.add_patch(plt.Rectangle((coords[1], coords[0]), size, size, color=color, edgecolor='black', linewidth=1))
62
- ax.text(coords[1]+0.5*size, coords[0]+0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
- # No change in drawing roads, assuming your original logic fits here
65
-
66
  ax.set_xlabel('Columns')
67
  ax.set_ylabel('Rows')
68
  ax.set_title('Village Layout with Color Coding')
69
  return fig
70
 
71
-
72
-
73
  # Main Streamlit app function
74
  def main():
75
  st.title('Green Smart Village Application')
@@ -108,4 +114,4 @@ def main():
108
  st.write("HIN number details will be displayed here...") # Placeholder for actual HIN number check
109
 
110
  if __name__ == "__main__":
111
- main()
 
1
+ User
2
  import streamlit as st
3
  import json
4
  import matplotlib.pyplot as plt
 
42
  fig, ax = plt.subplots(figsize=(12, 12))
43
  nrows, ncols = data['size']['rows'], data['size']['columns']
44
  ax.set_xlim(0, ncols)
45
+ ax.set_ylim(0, nrows)
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']:
 
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
+ # Drawing roads
64
+ for road in data.get('roads', []): # Ensures compatibility if 'roads' key is missing
65
+ start, end = road['start'], road['end']
66
+ road_color = road.get('color', '#696969') # Dark gray as default road color
67
+ if start[0] == end[0]: # Vertical road
68
+ for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
69
+ ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road_color))
70
+ else: # Horizontal road
71
+ for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
72
+ ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road_color))
73
 
 
 
74
  ax.set_xlabel('Columns')
75
  ax.set_ylabel('Rows')
76
  ax.set_title('Village Layout with Color Coding')
77
  return fig
78
 
 
 
79
  # Main Streamlit app function
80
  def main():
81
  st.title('Green Smart Village Application')
 
114
  st.write("HIN number details will be displayed here...") # Placeholder for actual HIN number check
115
 
116
  if __name__ == "__main__":
117
+ main()