@@ -90,12 +90,17 @@ def render_panel(
9090
9191 note = Typography (
9292 id = "note" ,
93- children = ["NOTE: You can only add a maximum of 10 spectrum plots at a time" ],
93+ children = [
94+ "NOTE: Only add a maximum of 10 spectrum plots at a time as older "
95+ "ones are removed. When switching from 'Add' to 'Update' mode, "
96+ "the existing bar plots will be cleared if any."
97+ ],
9498 )
9599
96100 return Box (
97101 children = [
98- "Choose an exploration mode and create/select points to view the Spectrum data." ,
102+ "Choose an exploration mode and select points to visualize their spectral "
103+ "reflectance across available wavelengths in this highly dynamic Spectrum View." ,
99104 note ,
100105 control_bar ,
101106 error_message ,
@@ -221,16 +226,16 @@ def update_plot(
221226 )
222227
223228 if dataset is None :
224- return None , "Missing dataset selection" , spectrum_list , previous_mode
229+ return None , "Missing dataset selection" , spectrum_list , exploration_radio_group
225230 elif not place_group or not has_point :
226- return None , "Missing point selection" , spectrum_list , previous_mode
231+ return None , "Missing point selection" , spectrum_list , exploration_radio_group
227232
228233 label = find_selected_point_label (place_group , place_geo )
229234
230235 if label is None :
231236 return (
232237 None ,
233- "There is no label for the selected point" ,
238+ "There is no label for the selected point or no point is selected " ,
234239 spectrum_list ,
235240 previous_mode ,
236241 )
@@ -259,7 +264,7 @@ def update_plot(
259264 if new_spectrum_data is None or new_spectrum_data .empty :
260265 return None , "No reflectances found in Variables" , spectrum_list , previous_mode
261266
262- new_spectrum_data ["legend " ] = new_spectrum_data ["places" ] + ": " + time_label
267+ new_spectrum_data ["Legend " ] = new_spectrum_data ["places" ] + ": " + time_label
263268
264269 existing_data = extract_data_from_chart (current_chart )
265270
@@ -288,36 +293,36 @@ def update_plot(
288293
289294 # Vega Altair doesn’t support xOffset with x:Q, so we manually shift each bar
290295 # slightly
291- unique_groups = sorted (updated_data ["legend " ].unique ())
296+ unique_groups = sorted (updated_data ["Legend " ].unique ())
292297 n_groups = len (unique_groups )
293298 group_offset_map = {
294299 group : i - (n_groups - 1 ) / 2 for i , group in enumerate (unique_groups )
295300 }
296301
297302 bar_spacing = 3
298303 updated_data ["x_offset" ] = updated_data .apply (
299- lambda row : row ["wavelength" ] + group_offset_map [row ["legend " ]] * bar_spacing ,
304+ lambda row : row ["wavelength" ] + group_offset_map [row ["Legend " ]] * bar_spacing ,
300305 axis = 1 ,
301306 )
302307
303308 new_chart = create_chart_from_data (updated_data )
304- previous_mode = exploration_radio_group
305- return new_chart , "" , spectrum_list , previous_mode
309+ return new_chart , "" , spectrum_list , exploration_radio_group
306310
307311
308312def find_selected_point_label (
309313 features_data : list [dict [str , Any ]], target_point : dict [str , Any ]
310314) -> str | None :
315+ if target_point is None :
316+ return None
311317 for feature_collection in features_data :
312318 for feature in feature_collection .get ("features" , []):
313319 geometry = feature .get ("geometry" , {})
314320 coordinates = geometry .get ("coordinates" , [])
315321 geo_type = geometry .get ("type" , "" )
316322
317- if (
318- coordinates == target_point ["coordinates" ]
319- and geo_type == target_point ["type" ]
320- ):
323+ if coordinates == target_point .get (
324+ "coordinates" , []
325+ ) and geo_type == target_point .get ("type" , "" ):
321326 return feature .get ("properties" , {}).get ("label" , None )
322327
323328 return None
@@ -346,7 +351,7 @@ def create_chart_from_data(data: pd.DataFrame) -> alt.Chart:
346351 x = "wavelength:N" ,
347352 y = "reflectance:Q" ,
348353 xOffset = "places:N" ,
349- color = "legend :N" ,
354+ color = "Legend :N" ,
350355 tooltip = ["places" , "variable" , "wavelength" , "reflectance" ],
351356 )
352357 .properties (width = "container" , height = "container" )
@@ -358,8 +363,8 @@ def create_chart_from_data(data: pd.DataFrame) -> alt.Chart:
358363 .encode (
359364 x = alt .X ("x_offset:Q" , title = "Wavelength" ),
360365 y = alt .Y ("reflectance:Q" , title = "Reflectance" ),
361- xOffset = "legend :N" ,
362- color = "legend :N" ,
366+ xOffset = "Legend :N" ,
367+ color = "Legend :N" ,
363368 tooltip = ["places" , "variable" , "wavelength" , "reflectance" ],
364369 )
365370 ).properties (width = "container" , height = "container" )
0 commit comments