@@ -1744,6 +1744,10 @@ def marker_values_for_cutoff(
17441744
17451745
17461746def _create_plotly_curve_binary (rtichoke_curve_list : dict [str , Any ]) -> go .Figure :
1747+ initial_cutoff = (
1748+ rtichoke_curve_list ["cutoffs" ][0 ] if rtichoke_curve_list ["cutoffs" ] else None
1749+ )
1750+
17471751 non_interactive_curve = [
17481752 go .Scatter (
17491753 x = rtichoke_curve_list ["performance_data_ready_for_curve" ]
@@ -1773,11 +1777,53 @@ def _create_plotly_curve_binary(rtichoke_curve_list: dict[str, Any]) -> go.Figur
17731777 for group in rtichoke_curve_list ["reference_group_keys" ]
17741778 ]
17751779
1780+ def xy_at_cutoff (group , c ):
1781+ row = (
1782+ rtichoke_curve_list ["performance_data_ready_for_curve" ]
1783+ .filter (
1784+ (pl .col ("reference_group" ) == group )
1785+ & (pl .col ("chosen_cutoff" ) == c )
1786+ & pl .col ("x" ).is_not_null ()
1787+ & pl .col ("y" ).is_not_null ()
1788+ )
1789+ .select (["x" , "y" , "text" ])
1790+ .limit (1 )
1791+ )
1792+ if row .height == 0 :
1793+ return None , None , None
1794+ r = row .row (0 )
1795+ return r [0 ], r [1 ], r [2 ]
1796+
1797+ def marker_values_for_cutoff (
1798+ cutoff : float ,
1799+ ) -> tuple [list [list ], list [list ], list [list ]]:
1800+ marker_values = [
1801+ xy_at_cutoff (group , cutoff )
1802+ for group in rtichoke_curve_list ["reference_group_keys" ]
1803+ ]
1804+
1805+ xs = [[x ] if x is not None else [] for x , _ , _ in marker_values ]
1806+ ys = [[y ] if y is not None else [] for _ , y , _ in marker_values ]
1807+ texts = [[text ] if text is not None else [] for _ , _ , text in marker_values ]
1808+
1809+ return xs , ys , texts
1810+
1811+ initial_xs , initial_ys , initial_texts = (
1812+ marker_values_for_cutoff (initial_cutoff )
1813+ if initial_cutoff is not None
1814+ else (
1815+ [[] for _ in rtichoke_curve_list ["reference_group_keys" ]],
1816+ [[] for _ in rtichoke_curve_list ["reference_group_keys" ]],
1817+ [[] for _ in rtichoke_curve_list ["reference_group_keys" ]],
1818+ )
1819+ )
1820+
17761821 initial_interactive_markers = [
17771822 go .Scatter (
1778- x = [],
1779- y = [],
1780- text = [],
1823+ x = initial_xs [idx ],
1824+ y = initial_ys [idx ],
1825+ text = initial_texts [idx ],
1826+ hovertext = initial_texts [idx ],
17811827 mode = "markers" ,
17821828 marker = {
17831829 "size" : 12 ,
@@ -1798,7 +1844,7 @@ def _create_plotly_curve_binary(rtichoke_curve_list: dict[str, Any]) -> go.Figur
17981844 showlegend = False ,
17991845 hoverinfo = "text" ,
18001846 )
1801- for group in rtichoke_curve_list ["reference_group_keys" ]
1847+ for idx , group in enumerate ( rtichoke_curve_list ["reference_group_keys" ])
18021848 ]
18031849
18041850 reference_traces = [
@@ -1838,47 +1884,24 @@ def _create_plotly_curve_binary(rtichoke_curve_list: dict[str, Any]) -> go.Figur
18381884 )
18391885 )
18401886
1841- def xy_at_cutoff (group , c ):
1842- row = (
1843- rtichoke_curve_list ["performance_data_ready_for_curve" ]
1844- .filter (
1845- (pl .col ("reference_group" ) == group )
1846- & (pl .col ("chosen_cutoff" ) == c )
1847- & pl .col ("x" ).is_not_null ()
1848- & pl .col ("y" ).is_not_null ()
1849- )
1850- .select (["x" , "y" , "text" ])
1851- .limit (1 )
1887+ steps = []
1888+ for cutoff in rtichoke_curve_list ["cutoffs" ]:
1889+ xs , ys , texts = marker_values_for_cutoff (cutoff )
1890+ steps .append (
1891+ {
1892+ "method" : "restyle" ,
1893+ "args" : [
1894+ {
1895+ "x" : xs ,
1896+ "y" : ys ,
1897+ "text" : texts ,
1898+ "hovertext" : texts ,
1899+ },
1900+ dyn_idx ,
1901+ ],
1902+ "label" : f"{ cutoff :g} " ,
1903+ }
18521904 )
1853- if row .height == 0 :
1854- return None , None , None
1855- r = row .row (0 )
1856- return r [0 ], r [1 ], r [2 ]
1857-
1858- steps = [
1859- {
1860- "method" : "restyle" ,
1861- "args" : [
1862- {
1863- "x" : [
1864- [xy_at_cutoff (group , cutoff )[0 ]]
1865- if xy_at_cutoff (group , cutoff )[0 ] is not None
1866- else []
1867- for group in rtichoke_curve_list ["reference_group_keys" ]
1868- ],
1869- "y" : [
1870- [xy_at_cutoff (group , cutoff )[1 ]]
1871- if xy_at_cutoff (group , cutoff )[1 ] is not None
1872- else []
1873- for group in rtichoke_curve_list ["reference_group_keys" ]
1874- ],
1875- },
1876- dyn_idx ,
1877- ],
1878- "label" : f"{ cutoff :g} " ,
1879- }
1880- for cutoff in rtichoke_curve_list ["cutoffs" ]
1881- ]
18821905
18831906 slider_dict = _create_slider_dict (
18841907 rtichoke_curve_list ["animation_slider_prefix" ], steps
0 commit comments