Spaces:
Sleeping
Sleeping
Birgir
commited on
Commit
·
01cb819
1
Parent(s):
302cd89
added muvable circles and stops
Browse files- app/app.py +34 -2
app/app.py
CHANGED
@@ -121,6 +121,7 @@ with ui.layout_columns(col_widths=[8, 4]):
|
|
121 |
def incomeScore():
|
122 |
score = scores()
|
123 |
return f"{round(float(score["income_score"]), 2)}"
|
|
|
124 |
@render.plot(alt="A chart of income distribution.")
|
125 |
def income_plot():
|
126 |
print("Generating income distribution bar chart")
|
@@ -264,7 +265,7 @@ def _():
|
|
264 |
for layer in map.widget.layers:
|
265 |
if layer.name == "stops" or layer.name == "radius":
|
266 |
map.widget.remove_layer(layer)
|
267 |
-
|
268 |
for stop, color in stops:
|
269 |
if type(color) == list:
|
270 |
smallerRad = 0
|
@@ -273,6 +274,8 @@ def _():
|
|
273 |
circle.location = stop
|
274 |
circle.radius = rad - smallerRad
|
275 |
circle.color = c
|
|
|
|
|
276 |
circles.append(circle)
|
277 |
smallerRad =+ 50
|
278 |
else:
|
@@ -281,7 +284,11 @@ def _():
|
|
281 |
circle.radius = rad
|
282 |
circle.color = color
|
283 |
circle.fill_color = color
|
|
|
|
|
284 |
circles.append(circle)
|
|
|
|
|
285 |
|
286 |
icon = AwesomeIcon(name="bus", marker_color="black", icon_color="white")
|
287 |
icon1 = DivIcon(html = '<div style="border-radius:50%;background-color: black; width: 10px; height: 10px;"></div>')
|
@@ -290,9 +297,13 @@ def _():
|
|
290 |
icon=icon,
|
291 |
icon_anchor=(10,10),
|
292 |
icon_size=(0,0),
|
293 |
-
draggable=
|
|
|
294 |
marker.on_click(functools.partial(create_marker_callback, id=stop))
|
|
|
|
|
295 |
markers.append(marker)
|
|
|
296 |
|
297 |
layerGroup = LayerGroup(layers=markers, name="stops")
|
298 |
layerGroup2 = LayerGroup(layers=circles, name="radius")
|
@@ -312,6 +323,27 @@ def create_marker_callback(id, **kwargs):
|
|
312 |
map.widget.center = kwargs["coordinates"]
|
313 |
stop.set(id)
|
314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
@reactive.effect
|
316 |
def centerMap():
|
317 |
mapCenter = input.reset()
|
|
|
121 |
def incomeScore():
|
122 |
score = scores()
|
123 |
return f"{round(float(score["income_score"]), 2)}"
|
124 |
+
|
125 |
@render.plot(alt="A chart of income distribution.")
|
126 |
def income_plot():
|
127 |
print("Generating income distribution bar chart")
|
|
|
265 |
for layer in map.widget.layers:
|
266 |
if layer.name == "stops" or layer.name == "radius":
|
267 |
map.widget.remove_layer(layer)
|
268 |
+
i = 0
|
269 |
for stop, color in stops:
|
270 |
if type(color) == list:
|
271 |
smallerRad = 0
|
|
|
274 |
circle.location = stop
|
275 |
circle.radius = rad - smallerRad
|
276 |
circle.color = c
|
277 |
+
circle.fill_opacity = 0.1
|
278 |
+
circle.name = i
|
279 |
circles.append(circle)
|
280 |
smallerRad =+ 50
|
281 |
else:
|
|
|
284 |
circle.radius = rad
|
285 |
circle.color = color
|
286 |
circle.fill_color = color
|
287 |
+
circle.fill_opacity = 0.1
|
288 |
+
circle.name = str(i)
|
289 |
circles.append(circle)
|
290 |
+
|
291 |
+
|
292 |
|
293 |
icon = AwesomeIcon(name="bus", marker_color="black", icon_color="white")
|
294 |
icon1 = DivIcon(html = '<div style="border-radius:50%;background-color: black; width: 10px; height: 10px;"></div>')
|
|
|
297 |
icon=icon,
|
298 |
icon_anchor=(10,10),
|
299 |
icon_size=(0,0),
|
300 |
+
draggable=True)
|
301 |
+
marker.name = str(i)
|
302 |
marker.on_click(functools.partial(create_marker_callback, id=stop))
|
303 |
+
marker.on_move(functools.partial(reset_marker, index=i))
|
304 |
+
|
305 |
markers.append(marker)
|
306 |
+
i += 1
|
307 |
|
308 |
layerGroup = LayerGroup(layers=markers, name="stops")
|
309 |
layerGroup2 = LayerGroup(layers=circles, name="radius")
|
|
|
323 |
map.widget.center = kwargs["coordinates"]
|
324 |
stop.set(id)
|
325 |
|
326 |
+
def reset_marker(index, **kwargs):
|
327 |
+
cord = kwargs["location"]
|
328 |
+
x = cord[0]
|
329 |
+
y = cord[1]
|
330 |
+
for layer in map.widget.layers:
|
331 |
+
if layer.name == "radius": # Check for the correct LayerGroup
|
332 |
+
for circle in layer.layers:
|
333 |
+
if circle.name == str(index): # Match the Circle by name
|
334 |
+
circle.location = [x, y] # Update the Circle's location
|
335 |
+
stop.set((x,y))
|
336 |
+
|
337 |
+
|
338 |
+
|
339 |
+
new_core = initBackend.get_station_score(
|
340 |
+
(y, x),
|
341 |
+
radius=input.rad(),
|
342 |
+
w_density=input.w_density(),
|
343 |
+
w_income=input.w_income(),
|
344 |
+
w_age=input.w_age()
|
345 |
+
)
|
346 |
+
|
347 |
@reactive.effect
|
348 |
def centerMap():
|
349 |
mapCenter = input.reset()
|