55from rich .text import Text
66from textual import on , work
77from textual .app import ComposeResult
8- from textual .containers import Container
8+ from textual .containers import Container , Horizontal
99from textual .widgets import (
10+ Button ,
1011 Collapsible ,
1112 Digits ,
1213 Footer ,
@@ -71,6 +72,10 @@ def compose(self) -> ComposeResult:
7172
7273 with Collapsible (title = "Cumulative Profit" , id = "dsh-cp-collap" , collapsed = True ):
7374 with Container (id = "dsh-chart-container" ):
75+ with Horizontal (id = "dsh-chart-header" ):
76+ yield Button (
77+ "Refresh" , id = "dash-refresh-chart-button" , variant = "success"
78+ )
7479 yield SelectionList (id = "dsh-chart-bot-list" , classes = "bg-static-default" )
7580 yield PlotextPlot (id = "dash-cumprof-profit" , classes = "bg-static-default collap-update" )
7681
@@ -125,8 +130,7 @@ async def update_per_five_sec(self):
125130
126131 dsh_cp_collap = self .query_one ("#dsh-cp-collap" )
127132 if dsh_cp_collap .collapsed is False :
128- selected_bots = self .query_one ("#dsh-chart-bot-list" ).selected
129- self .update_cumulative_profit_plot (bot_list = selected_bots )
133+ self .update_cumulative_profit_plot ()
130134
131135 def _render_open_trade_data (self , data , trading_mode = "spot" ):
132136 row_data = []
@@ -426,10 +430,12 @@ def update_dashboard_all_trade_summary(self):
426430 ats = self .query_one ("#dash-all-trade-summary" )
427431 ats .loading = False
428432
429- @work (group = "dash_chart_worker" , exclusive = True , thread = True )
433+ @work (group = "dash_chart_worker" , exclusive = False , thread = True )
430434 def update_cumulative_profit_plot (self , bot_list = None ):
431435 client_dfs = self .app .client_dfs
432436
437+ bot_list = self .query_one ("#dsh-chart-bot-list" ).selected
438+
433439 all_cum_data = pd .DataFrame ()
434440 if "all_closed" in client_dfs :
435441 if bot_list is None or not bot_list :
@@ -446,6 +452,7 @@ def update_cumulative_profit_plot(self, bot_list=None):
446452 chart_container = self .query_one ("#dash-cumprof-profit" )
447453 cplt = chart_container .plt
448454 cplt .clear_data ()
455+ cplt .clf ()
449456
450457 dfmt = "Y-m-d"
451458 cplt .date_form (dfmt )
@@ -466,6 +473,8 @@ def update_cumulative_profit_plot(self, bot_list=None):
466473 )
467474 cplt .ylabel ("Profit" )
468475
476+ self .app .call_from_thread (chart_container .refresh )
477+
469478 worker = get_current_worker ()
470479 if not worker .is_cancelled :
471480 self .app .call_from_thread (chart_container .set_loading , False )
@@ -474,9 +483,11 @@ def update_cumulative_profit_plot(self, bot_list=None):
474483 def update_cum_plot_from_list (self ) -> None :
475484 chart_container = self .query_one ("#dash-cumprof-profit" )
476485 chart_container .loading = True
486+ self .update_cumulative_profit_plot ()
477487
478- selected_bots = self .query_one ("#dsh-chart-bot-list" ).selected
479- self .update_cumulative_profit_plot (bot_list = selected_bots )
488+ @on (Button .Pressed , "#dash-refresh-chart-button" )
489+ def refresh_dash_chart_button_pressed (self ) -> None :
490+ self .update_cum_plot_from_list ()
480491
481492 @on (Collapsible .Toggled )
482493 def toggle_collapsible (self , event : Collapsible .Toggled ) -> None :
0 commit comments