
    bZh                         d dl mZ d dlZd dlmZmZmZmZ d dl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Z G d	 d
eej*                        Zy)    )deepcopyN)ListDictobserveInteger) display_jupyter_version_warnings   )
BaseFigureBasePlotlyType)BoxSelectorLassoSelectorInputDeviceStatePoints)custom_serializersc                       e Zd ZdZ ej
                  e      j                  dz  dz  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      j                  d      Z  ed      j                  d      Z!dZ"d	Z#	 d) fd
	Z$d Z%d*dZ&d+dZ'd Z(d Z)	 d+dZ*d Z+d Z, e-d      d        Z. e-d      d        Z/ e-d      d        Z0 e-d      d        Z1 e-d      d        Z2 e-d      d        Z3d Z4d,d Z5d! Z6d" Z7e8d#        Z9e9jt                  d$        Z9e;d%        Z<e;d-d'       Z=e;d.d(       Z> xZ?S )/BaseFigureWidgetza
    Base class for FigureWidget. The FigureWidget class is code-generated as a
    subclass
    package_datazwidgetbundle.jssyncT)
allow_noner   )r   Fc                 F   t        t        | 
  d||||d| | j                  rt        j	                          d| _        d| _        g | _        d| _        d| _	        d| _
        t        | j                  j                        | _        t        | j                        | _        y )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_countr   _layout_obj_props_widget_layout_data_widget_data)selfr   layoutr   r   kwargs	__class__s         `/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/plotly/basewidget.pyr   zBaseFigureWidget.__init__Z   s     	. 	
 %		

 	
 224 %&!
 (-$
 (*$ $% 
 ',#  't'7'7'>'>?$TZZ0    c                     | S Nr   )r+   argsr-   s      r/   showzBaseFigureWidget.show   s    r0   c                 f    | j                   dz   }|| _         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_datalayout_edit_idsource_view_idN)r    r!   _py2js_relayout)r+   layout_datar8   r7   msg_datas        r/   _send_relayout_msgz#BaseFigureWidget._send_relayout_msg   sH     22Q6$2!'+$
 ),,
  (#r0   c                     | j                  |      }| j                  dz   }|| _        d| _        | j                  dz   }|| _        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_datarestyle_tracestrace_edit_idr7   r8   N)_normalize_trace_indexesr    r!   r#   r$   _py2js_restyle)r+   r>   trace_indexesr8   r7   r@   restyle_msgs          r/   _send_restyle_msgz"BaseFigureWidget._send_restyle_msg   s    & 55mD 22Q6$2!'+$0014#0 &*#
 )+*,,
 *"r0   c                     | j                   dz   }|| _         d| _        | j                  dz   }|| _        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@   r7   N)r    r!   r#   r$   _py2js_addTraces)r+   new_traces_datar7   r@   add_traces_msgs        r/   _send_addTraces_msgz$BaseFigureWidget._send_addTraces_msg   sh     22Q6$2!'+$0014#0 &*#
 **,
 !/ $r0   c                 *    ||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_indsnew_trace_indsN)_py2js_moveTraces)r+   current_indsnew_indsmove_msgs       r/   _send_moveTraces_msgz%BaseFigureWidget._send_moveTraces_msg
  s      +7(S "*!%r0   c                     | j                  |      }| j                  dz   }|| _        d| _        | j                  dz   }|| _        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@   r7   r8   N)rA   r#   r$   r    r!   _py2js_update)r+   r>   r6   rC   r8   r@   r7   
update_msgs           r/   _send_update_msgz!BaseFigureWidget._send_update_msg  s    , 55mD 0014#0 &*#22Q6$2!'+$
 '()*,,

 (!r0   c                     | j                  |      }| j                  dz   }|| _        d| _        | j                  dz   }|| _        d| _        ||||||dd}|| _        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)rU   r:   rV   animation_optsr@   r7   r8   )rA   r#   r$   r    r!   _py2js_animate)r+   styles_datar6   rC   r[   r@   r7   animate_msgs           r/   _send_animate_msgz"BaseFigureWidget._send_animate_msgQ  s    * 55mD 0014#0 &*#22Q6$2!'+$
 &(),*,"
 *"r0   c                     | j                   dz   }|| _         d| _        | j                  dz   }|| _        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_indsr7   r@   N)r#   r$   r    r!   _py2js_deleteTraces)r+   ra   r@   r7   
delete_msgs        r/   _send_deleteTraces_msgz'BaseFigureWidget._send_deleteTraces_msg  sh     0014#0 &*#22Q6$2!'+$
 ',*

 $. #' r0   _js2py_traceDeltasc                 ~   |d   }|sd| _         y|d   }|d   }|| j                  k(  r|D ]  }|d   }| j                  D cg c]  }|j                   }}|j	                  |      }	| j                  |	   }
t
        j                  |
j                  |      }| j                  |
j                  |
j                        }|r|	|d}|| _
        d| _
        | j                  ||	g        d| _        | j                  s8| j                  r, | j                  j                                 | j                  r,d| _         yc c}w )z@
        Process trace deltas message from the frontend
        newNtrace_deltasr@   uid)remove_traceremove_propsF)re   r#   r   ri   indexr   _transform_data_prop_defaults_remove_overlapping_propsr'   _py2js_removeTraceProps _dispatch_trace_change_callbacksr$   r!   r"   pop)r+   changer;   rh   r@   delta	trace_uidtrace
trace_uidstrace_index	uid_tracedelta_transformrk   remove_trace_props_msgs                 r/   _handler_js2py_traceDeltasz+BaseFigureWidget._handler_js2py_traceDeltas  sb    %=&*D#/ 1 D444 & V "%L	59YY?Eeii?
?(..y9 IIk2	 #3"B"B,,e#  $==$$i&>&> 
  (3(4.* 4JD037D0 55o}U=VB +0D' //226D004468 22 #'I @s   D:_js2py_layoutDeltac                 ^   |d   }|sd| _         y|d   }|d   }|| j                  k(  rt        j                  | j                  |      }| j                  | j                  | j                        }|rd|i}|| _        d| _        |D ]C  }|d   }	| j                  j                  |	      }
|
s&|	| j                  vs5i | j                  |	<   E | j                  |       d| _        | j                  s8| j                  r, | j                  j                                 | j                  r,d| _         y)z@
        Process layout delta message from the frontend
        rg   Nlayout_deltar7   rk   r   F)r}   r    r   rm   _layout_defaultsro   r(   _py2js_removeLayoutPropsr,   _subplot_re_match!_dispatch_layout_change_callbacksr!   r$   r"   rr   )r+   rs   r;   r   r7   rz   removed_propsremove_props_msgproppathpropmatchs              r/   _handler_js2py_layoutDeltaz+BaseFigureWidget._handler_js2py_layoutDelta  sD    %=&*D#/!"23 T666 />>%%|O !::##T%:%:M
 $2M#B 0@-04-
 , +{55d;T4(*DKK%+ 22?C ,1D( ..226D004468 22 #'r0   _js2py_restylec                 v    |d   }|sd| _         y|d   }|d   }|d   }| j                  |||       d| _         y)zB
        Process Plotly.restyle message from the frontend
        rg   NrU   rV   r8   )r>   rC   r8   )r   plotly_restyle)r+   rs   rD   rU   rV   r8   s         r/   _handler_js2py_restylez'BaseFigureWidget._handler_js2py_restyle'  sb     Um"&D .
">2$%56 	#&) 	 	
 #r0   _js2py_updatec                     |d   }|sd| _         y|d   }|d   }|d   }|d   }| j                  ||||       d| _         y)zA
        Process Plotly.update message from the frontend
        rg   NrU   rV   r:   r8   )r>   r6   rC   r8   )r   plotly_update)r+   rs   rX   stylerC   r,   r8   s          r/   _handler_js2py_updatez&BaseFigureWidget._handler_js2py_updateC  so     E]
!%D<(">2M*#$45 	 ')	 	 	
 "r0   _js2py_relayoutc                     |d   }|sd| _         y|d   }|d   }d|v r|j                  d       | j                  ||       d| _         y)zC
        Process Plotly.relayout message from the frontend
        rg   Nr6   r8   lastInputTime)r6   r8   )r   rr   plotly_relayout)r+   rs   relayout_msgr6   r8   s        r/   _handler_js2py_relayoutz(BaseFigureWidget._handler_js2py_relayouta  se     e}#'D $_5%&67m+ o. 	=X#r0   _js2py_pointsCallbackc           
         |d   }|sd| _         y|d   }|j                  dd      r?|d   }|d   }|d   }|dk(  rt        di |}n!|dk(  rt        di |}nt	        d	|z        d}|j                  d
d      r|d
   }t        di |}	nd}	|d   }
t        t        | j                              D ci c]"  }|g g g | j                  |   j                  |d$ }}t        |
d   |
d   |
d   |
d         D ]H  \  }}}}||   }|d   j                  |       |d   j                  |       |d   j                  |       J |j                         D ]  \  }}t        di |}| j                  |   }|dk(  r|j                  ||	       8|dk(  r|j!                  ||	       P|dk(  r|j#                  ||	       h|dk(  r|j%                  ||       |dk(  s|j'                  |        d| _         yc c}w )zC
        Process points callback message from the frontend
        rg   N
event_typeselectortypeselector_stateboxlassozUnsupported selector type: %sdevice_statepoints)
point_indsxsys
trace_namerx   r   r   point_indexesrC   r   plotly_clickplotly_hoverplotly_unhoverplotly_selectedplotly_deselectr   )r   getr   r   
ValueErrorr   rangelen
_data_objsnamezipappenditemsr   r   _dispatch_on_click_dispatch_on_hover_dispatch_on_unhover_dispatch_on_selection_dispatch_on_deselect)r+   rs   callback_datar   selector_dataselector_typer   r   device_state_datastatepoints_data	trace_indtrace_pointsxy	point_ind
trace_dicttrace_points_datar   rv   s                       r/   _handler_js2py_pointsCallbackz.BaseFigureWidget._handler_js2py_pointsCallback~  st    u)-D& #<0
 Z.)*5M)&1M*+;<N%&88')(:>: !@=!PQQH ^T2 -n =$9'89EE $H- #3t#78	
   "ooi8==( 	
 	
 +.((	+
 
	7&Aq)Y &i0Jt##A&t##A&|$++I6
	7 -9,>,>,@ 	4(I(0/0FIIi(E^+((7~-((7//**65900,,VX>00++F3	4 &*"Q	
s   2'G1c                     t         )z/
        Customize html representation
        NotImplementedErrorr+   s    r/   _repr_html_zBaseFigureWidget._repr_html_  
     "!r0   c                     t                t        | j                  j                        | _        t        | j
                        | _        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)r   r   r&   r'   r(   r)   r*   	_model_id)r+   includeexcludevalidater-   s        r/   _repr_mimebundle_z"BaseFigureWidget._repr_mimebundle_  sU     	)*
 't'7'7'>'>?$TZZ06!"!" NN9
 	
r0   c                     t         )zD
        Handle rich display of figures in ipython contexts
        r   r   s    r/   _ipython_display_z"BaseFigureWidget._ipython_display_  r   r0   c                 z    | j                   s| j                  r| j                  j                  |       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_completed  s.     ''4+F+F((//3Dr0   c                     | j                   S r2   )r   r   s    r/   r   zBaseFigureWidget.frames  s    
 r0   c                 2    |rt         j                          y y r2   )r   r   )r+   
new_framess     r/   r   zBaseFigureWidget.frames  s    224 r0   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 or0   r   c                 ,   g }t        | t              rt        |t              sJ |j                         D ]  \  }}t        |t              st        j                  |      r^|| v s0| |   }||fz   }t
        j                  |||      }|j                  |       |rf| j                  |       |j                  |       || v s|dk7  s| j                  |       |j                  ||fz           |S t        | t              rt        |t              sJ t        |      D ]q  \  }	}|	t        |       k\  r |S | |	   }|t        |t              st        j                  |      sD||	fz   }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   )
isinstancedictr   r
   _is_dict_listr   ro   extendrr   r   list	enumerater   )

input_data
delta_data	prop_pathremovedp	delta_val	input_valrecur_prop_pathrecur_removedis
             r/   ro   z*BaseFigureWidget._remove_overlapping_props*  s   0  j$'j$// * 0 0 2 59i.*2J2J92UJ$.qM	*3qd*:(8(R(R%y/)  }5  )&NN1-#NN?;*_eNN1%NN9t#34)5\ - 
D)j$// )* 5 29J'"  'qM	)"9d3!//	: '01$&6O$4$N$N!9o%M NN=1#2& r0   c           
         i }t        | t              r=t        |t              st        dj                  | |            |j	                         D ]  \  }}t        |t              st        j                  |      rM|| vrt        |t              ri ng | |<   | |   }|j                  t        j                  |||||fz                x|| vst        j                  | |   |      r|| |<   ||fz   }|||<    |rUt        | j                               j                  t        |j                                     D ]  }	| j                  |	        |S t        | t               rt        |t               st        dj                  | |            t#        |      D ]  \  }
}|
t%        |       k\  r| j'                  d       | |
   }|Rt        |t              st        j                  |      r-|j                  t        j                  |||||
fz                ~t        j                  | |
   |      r|| |
<   ||||
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   rm   r   _vals_equalsetkeys
differencerr   r   r   r   r   )r   r   r   r   r6   	from_propfrom_valr   relayout_path_propremove_propr   s              r/   rm   z BaseFigureWidget._transform_datay  s   &  gt$ i. BII '9 J   (1'8 E#	8 h-1I1I(1S !/3=h3MRSU	* !(	 2I!(((88%$*7*79,*F	 9  !/~7Q7Q	*H8 .6	*-:i\-I*<D&899E> #&w||~#6#A#A	()$ -K KK,-\ O & i. KRR '9 S    )3 G8 G$NN4(#AJ	 (x.*2J2J82T "(((88%$*7*71$*>	 9  *55gaj(K%-
>Fmqd&:;3G6 r0   )NNNFr2   )NN)NNT)r   )Tr   )@__name__
__module____qualname____doc__pathlibPath__file__parent_esmr   tagr   r(   r   r*   _configrH   rB   r9   rW   r\   rb   rO   r   rp   re   r}   r   r   r   r   r   r    r#   _set_trace_uid_allow_disable_validationr   r4   r<   rE   rK   rS   rY   r_   rd   r   r|   r   r   r   r   r   r   r   r   r   propertyr   setterstaticmethodr   ro   rm   __classcell__)r.   s   @r/   r   r      s   
 7<<!((>9<MMD  TVZZ@T@-?@N46::>4>+=>Ldfjj9d9&89G 1tt,00QdQ>PQ.TT*..ODO<NON/dd+//PTP=OPO-DD)--N4N;MNM.TT*..ODO<NON3$$/33TTAST1-11RtR?QR8tt488   '  8dd377XTXEWX 3.22SS@RS2.22SS@RS.TT*..ODO<NON/dd+//PTP=OPO-DD)--N4N;MNM5DD155V4VCUV #1:>>t>4!!*..d.3N %
 AF:1x
$@,#\%B&, OS0"d0#d(F !">' #>'@ !"=' #='~ # #6 _" ": $  $8 $%S* &S*n"
&"*     ]]5 5  " L L\ p pr0   r   )copyr   r  	traitletsr   r   r   r   plotly.io._renderersr   basedatatypesr
   r   	callbacksr   r   r   r   serializersr   	anywidget	AnyWidgetr   r   r0   r/   <module>r     s9      2 2 A 5 K K + ^z9#6#6 ^r0   