*L isddlmZddlZddlmZmZmZmZddlm Z ddl m Z m Z ddl mZmZmZmZddlmZddlZGd d e ej*Zy) )deepcopyN)ListDictobserveInteger) display_jupyter_version_warnings) BaseFigureBasePlotlyType) BoxSelector LassoSelectorInputDeviceStatePoints)custom_serializersceZdZdZej ejdz dz Ze jd&ddie Z e jd&ddie Ze jd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie Ze djd&ddie ZedjdZ edjdZ!dZ"d Z# d)fd Z$d Z%d*d Z&d+d Z'dZ(dZ) d+dZ*dZ+dZ,e-ddZ.e-ddZ/e-ddZ0e-ddZ1e-ddZ2e-ddZ3dZ4d,d Z5d!Z6d"Z7e8d#Z9e9jtd$Z9e;d%ZxZ?S)/BaseFigureWidgetza Base class for FigureWidget. The FigureWidget class is code-generated as a subclass package_datazwidgetbundle.jssyncT) allow_noner)rFc Ftt| d||||d||jrtj d|_d|_g|_d|_d|_ d|_ t|jj|_t|j|_y)N)data layout_plotlyframes skip_invalidrF)superr__init__ _frame_objs_display_frames_error_last_layout_edit_id_layout_edit_in_process_waiting_edit_callbacks_last_trace_edit_id_trace_edit_in_process _view_countr _layout_obj_props_widget_layout_data _widget_data)selfrlayoutrrkwargs __class__s W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/plotly/basewidget.pyrzBaseFigureWidget.__init__Zs .  %         2 2 4%&! (-$ (*$$% ',# 't'7'7'>'>?$TZZ0c|SNr)r+argsr-s r/showzBaseFigureWidget.shows r0cf|jdz}||_d|_|||d}||_d|_y)a Send Plotly.relayout message to the frontend Parameters ---------- layout_data : dict Plotly.relayout layout data source_view_id : str UID of view that triggered this relayout operation (e.g. By the user clicking 'zoom' in the toolbar). None if the operation was not triggered by a frontend view r T) relayout_datalayout_edit_idsource_view_idN)r r!_py2js_relayout)r+ layout_datar8r7msg_datas r/_send_relayout_msgz#BaseFigureWidget._send_relayout_msgsH22Q6$2!'+$ ),,  (#r0c|j|}|jdz}||_d|_|jdz}||_d|_|||||d}||_d|_y)a Send Plotly.restyle message to the frontend Parameters ---------- restyle_data : dict Plotly.restyle restyle data trace_indexes : list[int] List of trace indexes that the restyle operation applies to source_view_id : str UID of view that triggered this restyle operation (e.g. By the user clicking the legend to hide a trace). None if the operation was not triggered by a frontend view r T) restyle_datarestyle_traces trace_edit_idr7r8N)_normalize_trace_indexesr r!r#r$_py2js_restyle)r+r> trace_indexesr8r7r@ restyle_msgs r/_send_restyle_msgz"BaseFigureWidget._send_restyle_msgs&55mD 22Q6$2!'+$0014 #0 &*# )+*,,  *"r0c|jdz}||_d|_|jdz}||_d|_|||d}||_d|_y)z Send Plotly.addTraces message to the frontend Parameters ---------- new_traces_data : list[dict] List of trace data for new traces as accepted by Plotly.addTraces r T) trace_datar@r7N)r r!r#r$_py2js_addTraces)r+new_traces_datar7r@add_traces_msgs r/_send_addTraces_msgz$BaseFigureWidget._send_addTraces_msgsh22Q6$2!'+$0014 #0 &*# **, !/ $r0c*||d}||_d|_y)z Send Plotly.moveTraces message to the frontend Parameters ---------- current_inds : list[int] List of current trace indexes new_inds : list[int] List of new trace indexes )current_trace_indsnew_trace_indsN)_py2js_moveTraces)r+ current_indsnew_indsmove_msgs r/_send_moveTraces_msgz%BaseFigureWidget._send_moveTraces_msg s +7(S"*!%r0c|j|}|jdz}||_d|_|jdz}||_d|_||||||d}||_d|_y)a' Send Plotly.update message to the frontend Parameters ---------- restyle_data : dict Plotly.update restyle data relayout_data : dict Plotly.update relayout data trace_indexes : list[int] List of trace indexes that the update operation applies to source_view_id : str UID of view that triggered this update operation (e.g. By the user clicking a button). None if the operation was not triggered by a frontend view r T) style_datar: style_tracesr@r7r8N)rAr#r$r r! _py2js_update)r+r>r6rCr8r@r7 update_msgs r/_send_update_msgz!BaseFigureWidget._send_update_msgs,55mD 0014 #0 &*#22Q6$2!'+$ '()*,,  (!r0c|j|}|jdz}||_d|_|jdz}||_d|_||||||dd}||_d|_y)a Send Plotly.update message to the frontend Note: there is no source_view_id parameter because animations triggered by the fontend are not currently supported Parameters ---------- styles_data : list[dict] Plotly.animate styles data relayout_data : dict Plotly.animate relayout data trace_indexes : list[int] List of trace indexes that the animate operation applies to r TN)rUr:rVanimation_optsr@r7r8)rAr#r$r r!_py2js_animate)r+ styles_datar6rCr[r@r7 animate_msgs r/_send_animate_msgz"BaseFigureWidget._send_animate_msgPs*55mD 0014 #0 &*#22Q6$2!'+$ &(),*," *"r0c|jdz}||_d|_|jdz}||_d|_|||d}||_d|_y)z Send Plotly.deleteTraces message to the frontend Parameters ---------- delete_inds : list[int] List of trace indexes of traces to delete r T) delete_indsr7r@N)r#r$r r!_py2js_deleteTraces)r+rar@r7 delete_msgs r/_send_deleteTraces_msgz'BaseFigureWidget._send_deleteTraces_msgsh0014 #0 &*#22Q6$2!'+$ ',* $. #' r0_js2py_traceDeltasc~|d}|sd|_y|d}|d}||jk(r|D]}|d}|jDcgc]}|j}}|j |} |j| } t j | j|} |j| j| j} | r| | d} | |_ d|_ |j| | gd|_ |js8|jr,|jj|jr,d|_ycc}w)z@ Process trace deltas message from the frontend newN trace_deltasr@uid) remove_trace remove_propsF)rer#rriindexr_transform_data_prop_defaults_remove_overlapping_propsr'_py2js_removeTraceProps _dispatch_trace_change_callbacksr$r!r"pop)r+changer;rhr@delta trace_uidtrace trace_uids trace_index uid_tracedelta_transformrkremove_trace_props_msgs r/_handler_js2py_traceDeltasz+BaseFigureWidget._handler_js2py_traceDeltass^%=&*D # /  1 D44 4% V!%L 59YY?Eeii? ?(..y9  IIk2 #3"B"B,,e# $==$$i&>&>   (3(4.*4JD037D055o }U; V@+0D '//226D00446822#'I@sD:_js2py_layoutDeltac^|d}|sd|_y|d}|d}||jk(rtj|j|}|j |j |j}|rd|i}||_d|_|D]C}|d} |jj| } | s&| |jvs5i|j| <E|j|d|_ |js8|jr,|jj|jr,d|_y)z@ Process layout delta message from the frontend rgN layout_deltar7rkrF)r}r rrm_layout_defaultsror(_py2js_removeLayoutPropsr,_subplot_re_match!_dispatch_layout_change_callbacksr!r$r"rr) r+rsr;rr7rz removed_propsremove_props_msgproppathpropmatchs r/_handler_js2py_layoutDeltaz+BaseFigureWidget._handler_js2py_layoutDeltasB%=&*D # / !"23 T66 6.>>%%|O!::##T%:%:M $2M#B 0@-04- , +{ 55d;T4(*DKK%  +  2 2? C,1D (..226D00446822#'r0_js2py_restylecv|d}|sd|_y|d}|d}|d}|j|||d|_y)zB Process Plotly.restyle message from the frontend rgNrUrVr8)r>rCr8)rplotly_restyle)r+rsrDrUrVr8s r/_handler_js2py_restylez'BaseFigureWidget._handler_js2py_restyle#sbUm "&D   . ">2 $%56 #&)  #r0 _js2py_updatec|d}|sd|_y|d}|d}|d}|d}|j||||d|_y)zA Process Plotly.update message from the frontend rgNrUrVr:r8)r>r6rCr8)r plotly_update)r+rsrXstylerCr,r8s r/_handler_js2py_updatez&BaseFigureWidget._handler_js2py_update?soE] !%D  <(">2 M*#$45  ')  "r0_js2py_relayoutc|d}|sd|_y|d}|d}d|vr|jd|j||d|_y)zC Process Plotly.relayout message from the frontend rgNr6r8 lastInputTime)r6r8)rrrplotly_relayout)r+rs relayout_msgr6r8s r/_handler_js2py_relayoutz(BaseFigureWidget._handler_js2py_relayout]see} #'D $_5 %&67 m +   o . =X#r0_js2py_pointsCallbackc |d}|sd|_y|d}|jddr?|d}|d}|d}|dk(r tdi|}n!|dk(r tdi|}nt d |zd}|jd dr|d }t di|} nd} |d } t t|jD cic]"} | ggg|j| j| d $} } t| d | d| d| dD]H\} }}} | | }|d j| |dj||dj|J| jD]\} }tdi|}|j| }|dk(r|j|| 8|dk(r|j!|| P|dk(r|j#|| h|dk(r|j%|||dk(s|j'|d|_ycc} w)zC Process points callback message from the frontend rgN event_typeselectortypeselector_stateboxlassozUnsupported selector type: %s device_statepoints) point_indsxsys trace_namerxrr point_indexesrCr plotly_click plotly_hoverplotly_unhoverplotly_selectedplotly_deselectr)rgetr r ValueErrorrrangelen _data_objsnamezipappenditemsrr_dispatch_on_click_dispatch_on_hover_dispatch_on_unhover_dispatch_on_selection_dispatch_on_deselect)r+rs callback_datar selector_data selector_typerrdevice_state_datastate points_data trace_ind trace_pointsxy point_ind trace_dicttrace_points_datarrvs r/_handler_js2py_pointsCallbackz.BaseFigureWidget._handler_js2py_pointsCallbackzstu )-D & #<0    Z .)*5M)&1M*+;: !@=!PQQH   ^T 2 -n = $9'89EE$H- #3t#78    "ooi8==(     +.      (  ( + 7 &Aq)Y &i0J t  # #A & t  # #A & | $ + +I 6 7-9,>,>,@ 4 (I(0/0FIIi(E^+((7~-((7//**65900,,VX>00++F3 4&*"O  s2'G1ct)z/ Customize html representation NotImplementedErrorr+s r/ _repr_html_zBaseFigureWidget._repr_html_ "!r0c tt|jj|_t|j |_ddd|jdiS)zF Return mimebundle corresponding to default renderer. z(application/vnd.jupyter.widget-view+jsonr) version_major version_minormodel_id)rrr&r'r(r)r* _model_id)r+includeexcludevalidater-s r/_repr_mimebundle_z"BaseFigureWidget._repr_mimebundle_sU )* 't'7'7'>'>?$TZZ0 6!"!" NN9  r0ct)zD Handle rich display of figures in ipython contexts rrs r/_ipython_display_z"BaseFigureWidget._ipython_display_rr0cz|js |jr|jj|y|y)a Register a function to be called after all pending trace and layout edit operations have completed If there are no pending edit operations then function is called immediately Parameters ---------- fn : callable Function of zero arguments to be called when all pending edit operations have completed N)r!r$r"r)r+fns r/on_edits_completedz#BaseFigureWidget.on_edits_completeds.  ' '4+F+F  ( ( / / 3 Dr0c|jSr2)rrs r/rzBaseFigureWidget.framess r0c2|rtjyyr2)rr)r+ new_framess r/rzBaseFigureWidget.framess   2 2 4 r0cd}t|)z Display an informative error when user attempts to set frames on a FigureWidget Raises ------ ValueError always z Frames are not supported by the plotly.graph_objs.FigureWidget class. Note: Frames are supported by the plotly.graph_objs.Figure class)r)msgs r/rz&BaseFigureWidget._display_frames_errorsDor0rc,g}t|trt|tsJ|jD]\}}t|tstj|r^||vs0||}||fz}t j |||}|j||rf|j||j|||vs|dk7s|j||j||fz|St|trt|tsJt|D]q\} }| t|k\r|S|| }|t|tstj|sD|| fz}t j |||}|j|s|S)a Remove properties in input_data that are also in delta_data, and do so recursively. Exception: Never remove 'uid' from input_data, this property is used to align traces Parameters ---------- input_data : dict|list delta_data : dict|list Returns ------- list[tuple[str|int]] List of removed property path tuples ri) isinstancedictrr _is_dict_listrroextendrrrlist enumerater) input_data delta_data prop_pathremovedp delta_val input_valrecur_prop_path recur_removedis r/roz*BaseFigureWidget._remove_overlapping_props%s0 j$ 'j$/ // * 0 0 2 5 9i.*2J2J92UJ$.qM *3qd*:(8(R(R%y/)  }5 )&NN1-#NN?;*_eNN1%NN9t#34) 5Z+ D )j$/ // )* 5 2 9J' 'qM )"9d3!// :'01$&6O$4$N$N!9o%MNN=1! 2$r0c i}t|tr=t|tstdj|||j D]\}}t|tst j |rM||vrt|tring||<||}|jtj|||||fzx||vstj|||r|||<||fz}|||<|rUt|jjt|jD]} |j| |St|t rt|t stdj||t#|D]\} }| t%|k\r|j'd|| }|Rt|tst j |r-|jtj||||| fz~tj|| |r||| <|||| fz<|S)aB Transform to_data into from_data and return relayout-style description of the transformation Parameters ---------- to_data : dict|list from_data : dict|list Returns ------- dict relayout-style description of the transformation z,Mismatched data types: {to_dict} {from_data})to_dict from_data) should_remove relayout_pathz5Mismatched data types: to_data: {to_data} {from_data})to_datarN)rrrformatrr rupdaterrmr _vals_equalsetkeys differencerrrrrr) rrrrr6 from_propfrom_valrrelayout_path_prop remove_proprs r/rmz BaseFigureWidget._transform_datasss&  gt $i. BII '9J(1'8 E# 8h-1I1I(1S /3=h3MRSU *!( 2I!(((88%$*7*79,*F 9!/~7Q7Q *H8.6 *-:i\-I* 9*55gaj(K%- >F mqd&:;/ G2r0)NNNFr2)NN)NNT)r)Tr)@__name__ __module__ __qualname____doc__pathlibPath__file__parent_esmrtagrr(rr*_configrHrBr9rWr\rbrOrrprer}rrrrrr r#_set_trace_uid_allow_disable_validationrr4r<rErKrSrYr_rdrr|rrrrrrrrrpropertyrsetter staticmethodrrorm __classcell__)r.s@r/rr s  7<< ! ( (> 94>+=>Ldfjj9d9&89G1tt,00QdQ>PQ.TT*..ODO>t>4!!*..d.3N % AF91v $@,#\%B&,OS0"d0#d(F !"<'#<'| !"<'#<'| ##6 _"": $ $8 $%R*&R*l"  &"*   ]]55  "KKZiir0r)copyrr traitletsrrrrplotly.io._renderersr basedatatypesr r callbacksr r rr serializersr anywidget AnyWidgetrrr0r/rs922A5KK+Qz9#6#6Qr0