
    [6gv                         d dl Zd dlmZmZmZmZmZ ddlm	Z	m
Z
 ddlmZmZmZmZ ddlmZ ddlmZ ej         G d d	e	ej                              ZdS )
    N)ListUnicodeDictobserveInteger   )
BaseFigureBasePlotlyType)BoxSelectorLassoSelectorInputDeviceStatePoints)custom_serializers)__frontend_version__c                   N    e Zd ZdZ ed                              d          Z ed                              d          Z ee                              d          Z	 ed                              d          Z
 ed                              d          Z ee                              d          Z  e            j        d'ddieZ  e            j        d'ddieZ  e            j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ  ed          j        d'ddieZ   ed          j        d'ddieZ! e"d	                              d          Z# e"d	                              d          Z$dZ%d
Z&	 d* fd	Z'd+dZ(d,dZ)d Z*d Z+	 d,dZ,d Z-d Z. e/d          d             Z0 e/d          d             Z1 e/d          d             Z2 e/d          d             Z3 e/d          d             Z4 e/d          d             Z5d  Z6d-d!Z7d" Z8d# Z9e:d$             Z;e;j<        d%             Z;e=d&             Z>e=d.d(            Z?e=d/d)            Z@ xZAS )0BaseFigureWidgetza
    Base class for FigureWidget. The FigureWidget class is code-generated as a
    subclass
    
FigureViewT)synczjupyterlab-plotlyFigureModelr   )
allow_noner   FNc                      t          t          |           j        d||||d| | j        rt                                           d| _        d| _        g | _        d| _        d| _	        d| _
        d S )N)datalayout_plotlyframesskip_invalidr   F )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_count)selfr   layoutr   r   kwargs	__class__s         P/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/plotly/basewidget.pyr   zBaseFigureWidget.__init__c   s     	/%%. 	
 %		
 	

 	
 	
 	
  	522444 %&!
 (-$
 (*$ $% 
 ',#     c                 ^    | j         dz   }|| _         d| _        |||d}|| _        d| _        dS )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_datalayout_edit_idsource_view_idN)r!   r"   _py2js_relayout)r'   layout_datar0   r/   msg_datas        r+   _send_relayout_msgz#BaseFigureWidget._send_relayout_msg   sP     2Q6$2!'+$
 ),,
 
  (#r,   c                     |                      |          }| j        dz   }|| _        d| _        | j        dz   }|| _        d| _        |||||d}|| _        d| _        dS )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_datarestyle_tracestrace_edit_idr/   r0   N)_normalize_trace_indexesr!   r"   r$   r%   _py2js_restyle)r'   r6   trace_indexesr0   r/   r8   restyle_msgs          r+   _send_restyle_msgz"BaseFigureWidget._send_restyle_msg   s    & 55mDD 2Q6$2!'+$014#0 &*#
 )+*,,
 
 *"r,   c                     | j         dz   }|| _         d| _        | j        dz   }|| _        d| _        |||d}|| _        d| _        dS )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_datar8   r/   N)r!   r"   r$   r%   _py2js_addTraces)r'   new_traces_datar/   r8   add_traces_msgs        r+   _send_addTraces_msgz$BaseFigureWidget._send_addTraces_msg   sm     2Q6$2!'+$014#0 &*#
 **,
 
 !/ $r,   c                 ,    ||d}|| _         d| _         dS )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_indsnew_trace_indsN)_py2js_moveTraces)r'   current_indsnew_indsmove_msgs       r+   _send_moveTraces_msgz%BaseFigureWidget._send_moveTraces_msg  s)     +7(SS "*!%r,   c                     |                      |          }| j        dz   }|| _        d| _        | j        dz   }|| _        d| _        ||||||d}|| _        d| _        dS )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_datar2   style_tracesr8   r/   r0   N)r9   r$   r%   r!   r"   _py2js_update)r'   r6   r.   r;   r0   r8   r/   
update_msgs           r+   _send_update_msgz!BaseFigureWidget._send_update_msg   s    , 55mDD 014#0 &*#2Q6$2!'+$
 '()*,,
 

 (!r,   c                     |                      |          }| j        dz   }|| _        d| _        | j        dz   }|| _        d| _        ||||||dd}|| _        d| _        dS )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)rM   r2   rN   animation_optsr8   r/   r0   )r9   r$   r%   r!   r"   _py2js_animate)r'   styles_datar.   r;   rS   r8   r/   animate_msgs           r+   _send_animate_msgz"BaseFigureWidget._send_animate_msgR  s    * 55mDD 014#0 &*#2Q6$2!'+$
 &(),*,"
 
 *"r,   c                     | j         dz   }|| _         d| _        | j        dz   }|| _        d| _        |||d}|| _        d| _        dS )z
        Send Plotly.deleteTraces message to the frontend

        Parameters
        ----------
        delete_inds : list[int]
            List of trace indexes of traces to delete
        r   T)delete_indsr/   r8   N)r$   r%   r!   r"   _py2js_deleteTraces)r'   rY   r8   r/   
delete_msgs        r+   _send_deleteTraces_msgz'BaseFigureWidget._send_deleteTraces_msg  sm     014#0 &*#2Q6$2!'+$
 ',*
 

 $. #'   r,   _js2py_traceDeltasc                 B   |d         }|s	d| _         dS |d         }|d         }|| j        k    r|D ]}|d         }d | j        D             }|                    |          }| j        |         }	t                              |	j        |          }
|                     |	j        |	j                  }|r||d}|| _	        d| _	        | 
                    |
|g           d| _        | j        s/| j        r( | j                                                     | j        (d| _         dS )	z@
        Process trace deltas message from the frontend
        newNtrace_deltasr8   uidc                     g | ]	}|j         
S r   )ra   ).0traces     r+   
<listcomp>z?BaseFigureWidget._handler_js2py_traceDeltas.<locals>.<listcomp>  s    ???Eei???r,   )remove_traceremove_propsF)r]   r$   r   indexr   _transform_data_prop_defaults_remove_overlapping_props_props_py2js_removeTraceProps _dispatch_trace_change_callbacksr%   r"   r#   pop)r'   changer3   r`   r8   delta	trace_uid
trace_uidstrace_index	uid_tracedelta_transformrg   remove_trace_props_msgs                r+   _handler_js2py_traceDeltasz+BaseFigureWidget._handler_js2py_traceDeltas  s    %= 	&*D#F/ 1 D444 & V V "%L	??TY???
(..y99 Ik2	 #3"B"B,e# #  $==$i&>   
   8(3(4. .* 4JD037D0 55o}UUUU +0D' / 92 96D04466888 2 9 #'r,   _js2py_layoutDeltac                 4   |d         }|s	d| _         dS |d         }|d         }|| j        k    rt                              | j        |          }|                     | j        | j                  }|rd|i}|| _        d| _        |D ]9}|d         }	| j        	                    |	          }
|
r|	| j        vr
i | j        |	<   :| 
                    |           d| _        | j        s/| j        r( | j                                                     | j        (d| _         dS )z@
        Process layout delta message from the frontend
        r_   Nlayout_deltar/   rg   r   F)ry   r!   r   ri   _layout_defaultsrk   _layout_py2js_removeLayoutPropsr(   _subplot_re_match!_dispatch_layout_change_callbacksr"   r%   r#   ro   )r'   rp   r3   r{   r/   rv   removed_propsremove_props_msgproppathpropmatchs              r+   _handler_js2py_layoutDeltaz+BaseFigureWidget._handler_js2py_layoutDelta  sn    %= 	&*D#F/!"23 T666 />>%| O !::d3 M
  5$2M#B 0@-04-
 , + +{55d;; +T44(*DK% 22?CCC ,1D( . 92 96D04466888 2 9 #'r,   _js2py_restylec                     |d         }|s	d| _         dS |d         }|d         }|d         }|                     |||           d| _         dS )zB
        Process Plotly.restyle message from the frontend
        r_   NrM   rN   r0   )r6   r;   r0   )r   plotly_restyle)r'   rp   r<   rM   rN   r0   s         r+   _handler_js2py_restylez'BaseFigureWidget._handler_js2py_restyle(  sy     Um 	"&DF .
">2$%56 	#&) 	 	
 	
 	
 #r,   _js2py_updatec                     |d         }|s	d| _         dS |d         }|d         }|d         }|d         }|                     ||||           d| _         dS )zA
        Process Plotly.update message from the frontend
        r_   NrM   rN   r2   r0   )r6   r.   r;   r0   )r   plotly_update)r'   rp   rP   styler;   r(   r0   s          r+   _handler_js2py_updatez&BaseFigureWidget._handler_js2py_updateD  s     E]
 	!%DF<(">2M*#$45 	 ')	 	 	
 	
 	
 "r,   _js2py_relayoutc                     |d         }|s	d| _         dS |d         }|d         }d|v r|                    d           |                     ||           d| _         dS )zC
        Process Plotly.relayout message from the frontend
        r_   Nr.   r0   lastInputTime)r.   r0   )r   ro   plotly_relayout)r'   rp   relayout_msgr.   r0   s        r+   _handler_js2py_relayoutz(BaseFigureWidget._handler_js2py_relayoutb  s     e} 	#'D F$_5%&67m++ o... 	=XXX#r,   _js2py_pointsCallbackc                 z    |d         }|s	d _         dS |d         }|                    dd          rP|d         }|d         }|d         }|dk    rt          di |}n'|dk    rt          di |}nt	          d	|z            d}|                    d
d          r|d
         }t          di |}	nd}	|d         }
 fdt          t           j                            D             }t          |
d         |
d         |
d         |
d                   D ]`\  }}}}||         }|d         
                    |           |d         
                    |           |d         
                    |           a|                                D ]\  }}t          di |} j        |         }|dk    r|                    ||	           ;|dk    r|                    ||	           X|dk    r|                    ||	           u|dk    r|                    ||           |dk    r|                    |           d _         dS )zC
        Process points callback message from the frontend
        r_   N
event_typeselectortypeselector_stateboxlassozUnsupported selector type: %sdevice_statepointsc           	      B    i | ]}|g g g j         |         j        |d S ))
point_indsxsys
trace_namert   )
_data_objsname)rc   	trace_indr'   s     r+   
<dictcomp>zBBaseFigureWidget._handler_js2py_pointsCallback.<locals>.<dictcomp>  sN     	
 	
 	
   "oi8=( 	
 	
 	
r,   r   r   point_indexesr;   r   plotly_clickplotly_hoverplotly_unhoverplotly_selectedplotly_deselectr   )r   getr   r   
ValueErrorr   rangelenr   zipappenditemsr   r   _dispatch_on_click_dispatch_on_hover_dispatch_on_unhover_dispatch_on_selection_dispatch_on_deselect)r'   rp   callback_datar   selector_dataselector_typer   r   device_state_datastatepoints_datatrace_pointsxy	point_indr   
trace_dicttrace_points_datar   rd   s   `                   r+   _handler_js2py_pointsCallbackz.BaseFigureWidget._handler_js2py_pointsCallback  s    u 	)-D&F #<0
 Z.. 	)*5M)&1M*+;<N%%&8888'))(::>:: !@=!PQQQH ^T22 	 -n =$99'899EEE $H-	
 	
 	
 	
 #3t#7#788	
 	
 	
 +.((	+
 +
 
	7 
	7&Aq)Y &i0Jt##A&&&t##A&&&|$++I6666 -9,>,>,@,@ 	4 	4(I(00/00FIi(E^++((7777~--((7777///**659999000,,VX>>>>000++F333%)"""r,   c                     t           )z/
        Customize html representation
        NotImplementedErrorr'   s    r+   _repr_html_zBaseFigureWidget._repr_html_  
     "!r,   c                     ddd| j         diS )zF
        Return mimebundle corresponding to default renderer.
        z(application/vnd.jupyter.widget-view+json   r   )version_majorversion_minormodel_id)	_model_id)r'   includeexcludevalidater)   s        r+   _repr_mimebundle_z"BaseFigureWidget._repr_mimebundle_  s&    
 7!"!" N9 9
 	
r,   c                     t           )zD
        Handle rich display of figures in ipython contexts
        r   r   s    r+   _ipython_display_z"BaseFigureWidget._ipython_display_  r   r,   c                 n    | j         s| j        r| j                            |           dS  |             dS )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_completed  sE     ' 	4+F 	(//33333BDDDDDr,   c                     | j         S N)r   r   s    r+   r   zBaseFigureWidget.frames  s    
 r,   c                 @    |rt                                            d S d S r   )r   r    )r'   
new_framess     r+   r   zBaseFigureWidget.frames  s,     	52244444	5 	5r,   c                  $    d} 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+   r    z&BaseFigureWidget._display_frames_error  s    D oor,   r   c                    g }t          | t                    rt          |t                    sJ |                                D ]\  }}t          |t                    st          j        |          rp|| v rk| |         }||fz   }t
                              |||          }|                    |           |s*|                     |           |	                    |           || v r4|dk    r.|                     |           |	                    ||fz              nt          | t                    rt          |t                    sJ t          |          D ]\  }	}|	t          |           k    r nk| |	         }|t          |t                    st          j        |          r7||	fz   }t
                              |||          }|                    |           |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
        ra   )
isinstancedictr   r	   _is_dict_listr   rk   extendro   r   list	enumerater   )

input_data
delta_data	prop_pathremovedp	delta_val	input_valrecur_prop_pathrecur_removedis
             r+   rk   z*BaseFigureWidget._remove_overlapping_props$  s   0  j$'' /	2j$///// * 0 0 2 2 5 59i.. 5*2J92U2U 5J$.qM	*3qd*:(8(R(R%y/) )  }555  ) <&NN1---#NN?;;;*__eNN1%%%NN9t#3444)50 
D)) 	2j$///// )* 5 5 2 29J''E&qM	)"9d33 *!/	:: * '01$&6O$4$N$N!9o% %M NN=111r,   c           
      b   i }t          | t                    rxt          |t                    s$t          d                    | |                    |                                D ]\  }}t          |t                    st          j        |          r^|| vrt          |t                    ri ng | |<   | |         }|                    t          	                    |||||fz                        || vst          j        | |         |          s|| |<   ||fz   }|||<   |rkt          |                                                               t          |                                                    D ]}	|                     |	           nt          | t                     rt          |t                     s$t          d                    | |                    t#          |          D ]\  }
}|
t%          |           k    r|                     d           | |
         }|_t          |t                    st          j        |          r6|                    t          	                    |||||
fz                        t          j        | |
         |          s|| |
<   ||||
fz   <   |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_datar   N)r   r   r   formatr   r	   r   updater   ri   r
   _vals_equalsetkeys
differencero   r   r   r   r   )r   r   r   r   r.   	from_propfrom_valr   relayout_path_propremove_propr   s              r+   ri   z BaseFigureWidget._transform_datas  s:   &  gt$$ X	G i..  BII '9 J     (1'8'8 E E#	8 h-- E1I(1S1S E !//3=h3M3M-URRSU	* !(	 2I!(((88%$*7*79,*F	 9      !//~7Q	*H8 8/ .6	*-:i\-I*<D&89  -#&w||~~#6#6#A#A	(())$ $ - -K KK,,,, && %	G i..  KRR '9 S      )33 G G8 G$$NN4(((#AJ	 (x.. )2<2J82T2T ) "(((88%$*7*71$*>	 9      *5gaj(KK G%-
>Fmqd&:;r,   )NNNFr   )NN)NNT)r   )Tr   )B__name__
__module____qualname____doc__r   tag
_view_name_view_moduler   _view_module_version_model_name_model_module_model_module_versionr   r   r}   r   _data_configr@   r:   r1   rO   rT   rZ   rG   r~   rm   r]   ry   r   r   r   r   r   r!   r$   _set_trace_uid_allow_disable_validationr   r4   r=   rC   rK   rQ   rW   r\   r   rx   r   r   r   r   r   r   r   r   r   propertyr   setterstaticmethodr    rk   ri   __classcell__)r*   s   @r+   r   r   
   s         &&***55J7.//333>>L"7#788<<$<GG'-((,,$,77KG/0044$4??M#G$899==4=HH ddffj99d9&899GDDFFJ77D7$677Eddffj99d9&899G 1ttt,,,0QQdQ>PQQ.TTT***.OODO<NOON/ddd+++/PPTP=OPPO-DDD)))-NN4N;MNNM.TTT***.OODO<NOON3$$$///3TTTASTT1---1RRtR?QRR8ttt4448     '    8ddd3337XXTXEWXX 3...2SSS@RSS2...2SSS@RSS.TTT***.OODO<NOON/ddd+++/PPTP=OPPO-DDD)))-NN4N;MNNM5DDD1115VV4VCUVV #71::>>t>44!'!**..d.33N %
 AF5 5 5 5 5 5r$ $ $ $@,# ,# ,# ,#\% % %B& & &, OS0" 0" 0" 0"d0# 0# 0#d( ( (F W!"">' >' #">'@ W!""=' =' #"='~ W# # #6 W_" " ": W$ $  $8 W$%%S* S* &%S*n" " "

 

 

 

" " "  *     X  ]5 5 ]5   \" L L L \L\ p p p \p p p p pr,   r   )
ipywidgetswidgets	traitletsr   r   r   r   r   basedatatypesr	   r
   	callbacksr   r   r   r   serializersr   versionr   register	DOMWidgetr   r   r,   r+   <module>r      s        ; ; ; ; ; ; ; ; ; ; ; ; ; ; 5 5 5 5 5 5 5 5 K K K K K K K K K K K K + + + + + + ) ) ) ) ) ) 	Y Y Y Y Yz7#4 Y Y Y Y Yr,   