@@ -653,40 +653,49 @@ def load_file(self):
653653 logger .warning ("No data found. Please upload a file first." )
654654 ui .notify ("No data found. Please upload a file first." , type = "warning" )
655655
656- async def async_run_mapper (self ):
656+ def notification_running_start (self , message ):
657657 notification = ui .notification (timeout = None , type = "ongoing" )
658- notification .message = "Running Mapper..."
658+ notification .message = message
659659 notification .spinner = True
660+ return notification
661+
662+ def notification_running_stop (self , notification , message , type = None ):
663+ if type is not None :
664+ notification .type = type
665+ notification .message = message
666+ notification .timeout = 5.0
667+ notification .spinner = False
668+
669+ async def async_run_mapper (self ):
670+ notification = self .notification_running_start ("Running Mapper..." )
660671 df_X = self .storage .get ("df" , pd .DataFrame ())
661672 if df_X is None or df_X .empty :
662- logger .warning ("No data found. Please upload a file first." )
663- ui .notify ("No data found. Please upload a file first." , type = "warning" )
664- notification .message = "No data found. Please upload a file first."
665- notification .spinner = False
666- notification .dismiss ()
673+ logger .warning ("No data found. Please load data first." )
674+ self .notification_running_stop (
675+ notification ,
676+ "Running Mapper failed: No data found, please load data first." ,
677+ type = "warning" ,
678+ )
667679 return
668680 mapper_config = self .get_mapper_config ()
669681 result = await run .cpu_bound (run_mapper , df_X , ** asdict (mapper_config ))
670682 if result is None :
671- notification . message = "Something went wrong."
672- notification . spinner = False
673- notification . dismiss ( )
683+ self . notification_running_stop (
684+ notification , "Running Mapper failed." , type = "error"
685+ )
674686 return
675687 mapper_graph , df_y = result
676688 if mapper_graph is not None :
677689 self .storage ["mapper_graph" ] = mapper_graph
678690 if df_y is not None :
679691 self .storage ["df_y" ] = df_y
680- notification .message = "Running Mapper Completed!"
681- notification .spinner = False
682- notification .dismiss ()
683-
692+ self .notification_running_stop (
693+ notification , "Running Mapper completed." , type = "positive"
694+ )
684695 await self .async_draw_mapper ()
685696
686697 async def async_draw_mapper (self ):
687- notification = ui .notification (timeout = None , type = "ongoing" )
688- notification .message = "Drawing Mapper..."
689- notification .spinner = True
698+ notification = self .notification_running_start ("Drawing Mapper..." )
690699
691700 mapper_config = self .get_mapper_config ()
692701
@@ -697,13 +706,11 @@ async def async_draw_mapper(self):
697706
698707 if df_X .empty or mapper_graph is None :
699708 logger .warning ("No data or Mapper graph found. Please run Mapper first." )
700- ui .notify (
701- "No data or Mapper graph found. Please run Mapper first." ,
709+ self .notification_running_stop (
710+ notification = notification ,
711+ message = "Drawing Mapper failed: no data or graph found." ,
702712 type = "warning" ,
703713 )
704- notification .message = "No data or Mapper graph found."
705- notification .spinner = False
706- notification .dismiss ()
707714 return
708715
709716 mapper_fig = await run .cpu_bound (
@@ -714,17 +721,21 @@ async def async_draw_mapper(self):
714721 mapper_graph ,
715722 ** asdict (mapper_config ),
716723 )
724+ if mapper_fig is None :
725+ self .notification_running_stop (
726+ notification , "Drawing Mapper failed." , type = "error"
727+ )
728+ return
717729
718730 logger .info ("Displaying Mapper plot." )
719731 if self .draw_area is not None :
720732 self .draw_area .clear ()
721733 self .plot_container .clear ()
722734 with self .plot_container :
723735 self .draw_area = ui .plotly (mapper_fig ).classes ("w-full h-full" )
724-
725- notification .message = "Drawing Mapper Completed!"
726- notification .spinner = False
727- notification .dismiss ()
736+ self .notification_running_stop (
737+ notification , "Drawing Mapper completed" , type = "positive"
738+ )
728739
729740
730741def startup ():
0 commit comments