@@ -48,20 +48,33 @@ def render_panel(
4848 text = f"{ dataset_id } / { time_label [0 :- 1 ]} "
4949 else :
5050 text = f"{ dataset_id } "
51- place_text = Typography (id = "text" , children = [text ], align = "center" )
52-
53- place_names = get_places (ctx , place_group )
54- select_places = Select (
55- id = "select_places" ,
56- label = "Places (points)" ,
57- value = "" ,
58- options = place_names ,
59- )
51+ place_text = Typography (id = "text" , children = [text ], align = "left" )
52+
53+ # Ideas
54+ # 1. Adding radio-button for two modes:
55+ # update mode - reactive to changes to dataset/places/time/variables
56+ # active mode -
57+
58+ # How should spectrum viewer behave?
59+ # It should be reactive to changes to dataset/places/times
60+ # How to freeze the current spectrum?
61+ # We add a button to add it permanently to the graph and then when a new point is
62+ # selected it becomes reactive again.
63+
64+ # Second mode - Just change for time but new line in graph for a new point
6065
61- button = Button (id = "button" , text = "Update" , style = {"maxWidth" : 100 })
66+ # First version: Reactive to time and place changes
67+ # Add button: Would add the spectrum view of current time and place to the graph
68+ # with legend place/time (static)
69+ # Delete button: Would delete the last one the spectrum views in the plot
70+ # Move the text align to left
71+
72+ # Make line chart and bar chart
73+
74+ add_button = Button (id = "add_button" , text = "Add" , style = {"maxWidth" : 100 })
6275
6376 controls = Box (
64- children = [select_places , button ],
77+ children = [add_button ],
6578 style = {
6679 "display" : "flex" ,
6780 "flexDirection" : "row" ,
@@ -182,20 +195,24 @@ def update_text(
182195@panel .callback (
183196 State ("@app" , "selectedDatasetId" ),
184197 Input ("@app" , "selectedTimeLabel" ),
198+ Input ("@app" , "selectedPlaceGeometry" ),
185199 State ("@app" , "selectedPlaceGroup" ),
186- State ( "select_places " , "value " ),
187- Input ("button " , "clicked " ),
200+ Input ( "add_button " , "clicked " ),
201+ Input ("plot " , "chart " ),
188202 Output ("plot" , "chart" ),
189203 Output ("error_message" , "children" ),
190204)
191205def update_plot (
192206 ctx : Context ,
193207 dataset_id : str | None = None ,
194208 time_label : str | None = None ,
209+ place_geo : dict [str , Any ] | None = None ,
195210 place_group : list [dict [str , Any ]] | None = None ,
196- place : list | None = None ,
197211 _clicked : bool | None = None ,
212+ chart = None ,
198213) -> tuple [alt .Chart | None , str ]:
214+ print ("clicked" , _clicked )
215+ print ("chart" , chart )
199216 dataset = get_dataset (ctx , dataset_id )
200217 has_point = any (
201218 feature .get ("geometry" , {}).get ("type" ) == "Point"
@@ -206,37 +223,39 @@ def update_plot(
206223 return None , "Missing dataset selection"
207224 elif not place_group or not has_point :
208225 return None , "Missing point selection"
209- elif not place :
210- return None , "Missing point selection from dropdown"
211-
212- place_group = gpd .GeoDataFrame (
213- [
214- {
215- "id" : feature ["id" ],
216- "name" : feature ["properties" ]["label" ],
217- "color" : feature ["properties" ]["color" ],
218- "x" : feature ["geometry" ]["coordinates" ][0 ],
219- "y" : feature ["geometry" ]["coordinates" ][1 ],
220- "geometry" : Point (
221- feature ["geometry" ]["coordinates" ][0 ],
222- feature ["geometry" ]["coordinates" ][1 ],
223- ),
224- }
225- for feature in place_group [0 ]["features" ]
226- if feature .get ("geometry" , {}).get ("type" ) == "Point"
227- ]
228- )
226+
227+ label = find_selected_point_label (place_group , place_geo )
228+
229+ if label is None :
230+ return None , "There is no label for the selected point"
231+
232+ if place_geo .get ("type" ) == "Point" :
233+ place_group = gpd .GeoDataFrame (
234+ [
235+ {
236+ "name" : label ,
237+ "x" : place_geo ["coordinates" ][0 ],
238+ "y" : place_geo ["coordinates" ][1 ],
239+ "geometry" : Point (
240+ place_geo ["coordinates" ][0 ],
241+ place_geo ["coordinates" ][1 ],
242+ ),
243+ }
244+ ]
245+ )
246+ else :
247+ return None , "Selected geometry must be a point"
229248
230249 place_group ["time" ] = pd .to_datetime (time_label ).tz_localize (None )
231- place = [place ]
232- source = get_spectra (dataset , place_group , place )
250+ places_select = [label ]
251+ source = get_spectra (dataset , place_group , places_select )
233252
234253 if source is None :
235254 return None , "No reflectances found in Variables"
236255
237256 chart = (
238257 alt .Chart (source )
239- .mark_line (point = True )
258+ .mark_bar (point = True )
240259 .encode (
241260 x = "wavelength:Q" ,
242261 y = "reflectance:Q" ,
@@ -249,36 +268,28 @@ def update_plot(
249268
250269
251270@panel .callback (
252- Input ("@app" , "selectedPlaceGroup " ),
253- Output ("select_places " , "options " ),
271+ Input ("@app" , "selectedPlaceGeometry " ),
272+ Output ("add_button " , "disabled " ),
254273)
255- def get_places (
256- ctx : Context ,
257- place_group : list [dict [str , Any ]],
258- ) -> list [str ]:
259-
260- if not place_group :
261- return []
262- else :
263- return [
264- feature ["properties" ]["label" ]
265- for feature in place_group [0 ]["features" ]
266- if feature .get ("geometry" , {}).get ("type" ) == "Point"
267- ]
268-
269-
270- @panel .callback (
271- State ("@app" , "themeMode" ),
272- Input ("@app" , "themeMode" ),
273- Output ("plot" , "theme" ),
274- )
275- def update_theme (
276- ctx : Context ,
277- theme_mode : str ,
278- _new_theme : bool | None = None ,
279- ) -> str :
280-
281- if theme_mode == "light" :
282- theme_mode = "default"
283-
284- return theme_mode
274+ def set_button_disablement (
275+ _ctx : Context ,
276+ place_geometry : str | None = None ,
277+ ) -> bool :
278+ print ("in set_button_disablement" , place_geometry )
279+ return not place_geometry
280+
281+
282+ def find_selected_point_label (features_data , target_point ):
283+ for feature_collection in features_data :
284+ for feature in feature_collection .get ("features" , []):
285+ geometry = feature .get ("geometry" , {})
286+ coordinates = geometry .get ("coordinates" , [])
287+ geo_type = geometry .get ("type" , "" )
288+
289+ if (
290+ coordinates == target_point ["coordinates" ]
291+ and geo_type == target_point ["type" ]
292+ ):
293+ return feature .get ("properties" , {}).get ("label" , None )
294+
295+ return None
0 commit comments