
    -Ph                         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dS )    )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          
                    d          Z  ed          
                    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$             Z9e9j:        d%             Z9e;d&             Z<e;d.d(            Z=e;d/d)            Z> xZ?S )0BaseFigureWidgetza
    Base class for FigureWidget. The FigureWidget class is code-generated as a
    subclass
    package_datazwidgetbundle.jssyncT)
allow_noner   )r   FNc                 T    t          t          |           j        d||||d| | j        rt                                           d| _        d| _        g | _        d| _        d| _	        d| _
        t          | j        j                  | _        t          | j                  | _        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_countr   _layout_obj_props_widget_layout_data_widget_data)selfr   layoutr   r   kwargs	__class__s         Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/plotly/basewidget.pyr   zBaseFigureWidget.__init__Z   s     	/%%. 	
 %		
 	

 	
 	
 	
  	522444 %&!
 (-$
 (*$ $% 
 ',#  't'7'>??$TZ00    c                     | S Nr   )r+   argsr-   s      r/   showzBaseFigureWidget.show   s    r0   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_datar8   r7   msg_datas        r/   _send_relayout_msgz#BaseFigureWidget._send_relayout_msg   sP     2Q6$2!'+$
 ),,
 
  (#r0   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_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D 2Q6$2!'+$014#0 &*#
 )+*,,
 
 *"r0   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_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   sm     2Q6$2!'+$014#0 &*#
 **,
 
 !/ $r0   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 "*!%r0   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_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D 014#0 &*#2Q6$2!'+$
 '()*,,
 

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

 $. #'   r0   _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_deltasr@   uidc                     g | ]	}|j         
S r   )ri   ).0traces     r/   
<listcomp>z?BaseFigureWidget._handler_js2py_traceDeltas.<locals>.<listcomp>  s    ???Eei???r0   )remove_traceremove_propsF)re   r#   r   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_uidstrace_index	uid_tracedelta_transformro   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 #'r0   _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
        rg   Nlayout_deltar7   ro   r   F)r   r    r   rq   _layout_defaultsrs   r(   _py2js_removeLayoutPropsr,   _subplot_re_match!_dispatch_layout_change_callbacksr!   r$   r"   rv   )r+   rw   r;   r   r7   r}   removed_propsremove_props_msgproppathpropmatchs              r/   _handler_js2py_layoutDeltaz+BaseFigureWidget._handler_js2py_layoutDelta  so    %= 	&*D#F/!"23 T666 />>%| O !::#T%: 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 #'r0   _js2py_restylec                     |d         }|s	d| _         dS |d         }|d         }|d         }|                     |||           d| _         dS )zB
        Process Plotly.restyle message from the frontend
        rg   NrU   rV   r8   )r>   rC   r8   )r   plotly_restyle)r+   rw   rD   rU   rV   r8   s         r/   _handler_js2py_restylez'BaseFigureWidget._handler_js2py_restyle'  sy     Um 	"&DF .
">2$%56 	#&) 	 	
 	
 	
 #r0   _js2py_updatec                     |d         }|s	d| _         dS |d         }|d         }|d         }|d         }|                     ||||           d| _         dS )zA
        Process Plotly.update message from the frontend
        rg   NrU   rV   r:   r8   )r>   r6   rC   r8   )r   plotly_update)r+   rw   rX   stylerC   r,   r8   s          r/   _handler_js2py_updatez&BaseFigureWidget._handler_js2py_updateC  s     E]
 	!%DF<(">2M*#$45 	 ')	 	 	
 	
 	
 "r0   _js2py_relayoutc                     |d         }|s	d| _         dS |d         }|d         }d|v r|                    d           |                     ||           d| _         dS )zC
        Process Plotly.relayout message from the frontend
        rg   Nr6   r8   lastInputTime)r6   r8   )r   rv   plotly_relayout)r+   rw   relayout_msgr6   r8   s        r/   _handler_js2py_relayoutz(BaseFigureWidget._handler_js2py_relayouta  s     e} 	#'D F$_5%&67m++ o... 	=XXX#r0   _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
        rg   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_namer{   )
_data_objsname)rk   	trace_indr+   s     r/   
<dictcomp>zBBaseFigureWidget._handler_js2py_pointsCallback.<locals>.<dictcomp>  sN     	
 	
 	
   "oi8=( 	
 	
 	
r0   r   r   point_indexesrC   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+   rw   callback_datar   selector_dataselector_typer   r   device_state_datastatepoints_datatrace_pointsxy	point_indr   
trace_dicttrace_points_datar   rl   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%)"""r0   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_  s\     	)***
 't'7'>??$TZ006!"!" N9 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                 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BDDDDDr0   c                     | j         S r2   )r   r   s    r/   r   zBaseFigureWidget.frames  s    
 r0   c                 @    |rt                                            d S d S r2   )r   r   )r+   
new_framess     r/   r   zBaseFigureWidget.frames  s,     	52244444	5 	5r0   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r0   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
        ri   )
isinstancedictr   r
   _is_dict_listr   rs   extendrv   r   list	enumerater   )

input_data
delta_data	prop_pathremovedp	delta_val	input_valrecur_prop_pathrecur_removedis
             r/   rs   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r0   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   rq   r   _vals_equalsetkeys
differencerv   r   r   r   r   )r   r   r   r   r6   	from_propfrom_valr   relayout_path_propremove_propr   s              r/   rq   z BaseFigureWidget._transform_datay  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&:;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   rt   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   rs   rq   __classcell__)r.   s   @r/   r   r      s"        
 7<!!(>9<MMD  TTVVZ@@T@-?@@N4466:>>4>+=>>L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:1 :1 :1 :1 :1 :1x  
$ $ $ $@,# ,# ,# ,#\% % %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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"     s           2 2 2 2 2 2 2 2 2 2 2 2 A A A A A A 5 5 5 5 5 5 5 5 K K K K K K K K K K K K + + + + + +    ^ ^ ^ ^ ^z9#6 ^ ^ ^ ^ ^r0   