
    gv                         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y)
    N)ListUnicodeDictobserveInteger   )
BaseFigureBasePlotlyType)BoxSelectorLassoSelectorInputDeviceStatePoints)custom_serializers)__frontend_version__c                       e Zd ZdZ ed      j                  d      Z ed      j                  d      Z ee      j                  d      Z	 ed      j                  d      Z
 ed      j                  d      Z ee      j                  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	      j                  d      Z# e"d	      j                  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;jx                  d$        Z;e=d%        Z>e=d-d'       Z?e=d.d(       Z@ xZAS )/BaseFigureWidgetza
    Base class for FigureWidget. The FigureWidget class is code-generated as a
    subclass
    
FigureViewT)synczjupyterlab-plotlyFigureModelr   )
allow_noner   Fc                     t        t        | 
  d||||d| | j                  rt        j	                          d| _        d| _        g | _        d| _        d| _	        d| _
        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_count)selfr   layoutr   r   kwargs	__class__s         N/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/plotly/basewidget.pyr   zBaseFigureWidget.__init__c   s     	. 	
 %		

 	
 224 %&!
 (-$
 (*$ $% 
 ',#     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_datar0   r/   msg_datas        r+   _send_relayout_msgz#BaseFigureWidget._send_relayout_msg   sH     22Q6$2!'+$
 ),,
  (#r,   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_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 22Q6$2!'+$0014#0 &*#
 )+*,,
 *"r,   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_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   sh     22Q6$2!'+$0014#0 &*#
 **,
 !/ $r,   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 "*!%r,   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_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 0014#0 &*#22Q6$2!'+$
 '()*,,

 (!r,   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)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 0014#0 &*#22Q6$2!'+$
 &(),*,"
 *"r,   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_indsr/   r8   N)r$   r%   r!   r"   _py2js_deleteTraces)r'   rY   r8   r/   
delete_msgs        r+   _send_deleteTraces_msgz'BaseFigureWidget._send_deleteTraces_msg  sh     0014#0 &*#22Q6$2!'+$
 ',*

 $. #' r,   _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_deltasr8   uid)remove_traceremove_propsF)r]   r$   r   ra   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
trace_uidstrace_index	uid_tracedelta_transformrc   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
        r_   Nlayout_deltar/   rc   r   F)rv   r!   r   re   _layout_defaultsrg   _layout_py2js_removeLayoutPropsr(   _subplot_re_match!_dispatch_layout_change_callbacksr"   r%   r#   rk   )r'   rl   r3   rx   r/   rs   removed_propsremove_props_msgproppathpropmatchs              r+   _handler_js2py_layoutDeltaz+BaseFigureWidget._handler_js2py_layoutDelta  sB    %=&*D#/!"23 T666 />>%%|O !::d33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 #'r,   _js2py_restylec                 v    |d   }|sd| _         y|d   }|d   }|d   }| j                  |||       d| _         y)zB
        Process Plotly.restyle message from the frontend
        r_   NrM   rN   r0   )r6   r;   r0   )r   plotly_restyle)r'   rl   r<   rM   rN   r0   s         r+   _handler_js2py_restylez'BaseFigureWidget._handler_js2py_restyle(  sb     Um"&D .
">2$%56 	#&) 	 	
 #r,   _js2py_updatec                     |d   }|sd| _         y|d   }|d   }|d   }|d   }| j                  ||||       d| _         y)zA
        Process Plotly.update message from the frontend
        r_   NrM   rN   r2   r0   )r6   r.   r;   r0   )r   plotly_update)r'   rl   rP   styler;   r(   r0   s          r+   _handler_js2py_updatez&BaseFigureWidget._handler_js2py_updateD  so     E]
!%D<(">2M*#$45 	 ')	 	 	
 "r,   _js2py_relayoutc                     |d   }|sd| _         y|d   }|d   }d|v r|j                  d       | j                  ||       d| _         y)zC
        Process Plotly.relayout message from the frontend
        r_   Nr.   r0   lastInputTime)r.   r0   )r   rk   plotly_relayout)r'   rl   relayout_msgr.   r0   s        r+   _handler_js2py_relayoutz(BaseFigureWidget._handler_js2py_relayoutb  se     e}#'D $_5%&67m+ o. 	=X#r,   _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
        r_   N
event_typeselectortypeselector_stateboxlassozUnsupported selector type: %sdevice_statepoints)
point_indsxsys
trace_namerq   r   r   point_indexesr;   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'   rl   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   ro   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_  
     "!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!"!" NN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                 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Dr,   c                     | j                   S N)r   r   s    r+   r   zBaseFigureWidget.frames  s    
 r,   c                 2    |rt         j                          y y r   )r   r    )r'   
new_framess     r+   r   zBaseFigureWidget.frames  s    224 r,   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r,   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
        ra   )
isinstancedictr   r	   _is_dict_listr   rg   extendrk   r   list	enumerater   )

input_data
delta_data	prop_pathremovedp	delta_val	input_valrecur_prop_pathrecur_removedis
             r+   rg   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& r,   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   re   r
   _vals_equalsetkeys
differencerk   r   r   r   r   )r   r   r   r   r.   	from_propfrom_valr   relayout_path_propremove_propr   s              r+   re   z BaseFigureWidget._transform_datas  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 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   rz   r   _data_configr@   r:   r1   rO   rT   rZ   rG   r{   ri   r]   rv   r   r   r   r   r   r!   r$   _set_trace_uid_allow_disable_validationr   r4   r=   rC   rK   rQ   rW   r\   r   ru   r   r   r   r   r   r   r   r   r   propertyr   setterstaticmethodr    rg   re   __classcell__)r*   s   @r+   r   r   
   s}    &***5J./333>L"#78<<$<G-(,,$,7K/044$4?M#$89==4=H dfjj9d9&89GDFJJ7D7$67E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5r$@,#\%B&, OS0"d0#d(F !">' #>'@ !"=' #='~ # #6 _" ": $  $8 $%S* &S*n"

"*     ]]5 5  " L L\ 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     sI     ; ; 5 K K + ) 	Yz7#4#4 Y Yr,   