
    Le                        d dl Z d dlZd dlmZ d dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d
dlmZmZ ddlmZ ddlmZmZmZ ddlmZ  edddddii          Z G d de          Z dS )    N)BytesIO)Document)curdoc)Model)Theme)render_mimebundle)state)
bothmethod   )HoloMapStore   )Plot)	HTML_TAGS
MIME_TYPESRenderer   )compute_plot_sizeattrsTitleblack12pt)
text_colortext_font_size)jsonc                   t    e Zd Z ej        dd          Z ej        dg dd          Z ej        dg dd	          Z ej	        e
eefd
d          Z ej        d
d          Zg dg ddZdZd
Zed             Zed fd	            ZddZed             Zed             Zedd            Z xZS )BokehRendererbokehzThe backend name.)defaultdocauto)htmlr   r!   pngzc
        Output render format for static figures. If None, no figure
        rendering will occur. )r   objectsr    )widgetsscrubberNgifr!   zu
        Output render multi-frame (typically animated) format. If
        None, no multi-frame rendering will occur.Tz3
       The applicable Bokeh Theme object (if any).)r   class_
allow_Noner    z8
        Whether to render plots with WebGL if available)r"   r!   r#   )r%   r&   r'   r!   N)figholomapFc                     dS )z7Hook to prefix content for instance JS when saving HTMLN )self_or_clsexts     Alib/python3.11/site-packages/holoviews/plotting/bokeh/renderer.py_save_prefixzBokehRenderer._save_prefix8   s	     	    Nc                      t                      j        |||fi |}|j        (| j        rt	                      nt                      |_        | j        r| j        |j        _        |S )z
        Given a HoloViews Viewable return a corresponding plot instance.
        Allows supplying a document attach the plot to, useful when
        combining the bokeh model with another plot.
        )superget_plotdocumentnotebook_contextr   r   theme)r.   objr    rendererkwargsplot	__class__s         r0   r5   zBokehRenderer.get_plot=   sg      uwwS(==f=== *5*FTHJJJFHHDM 	4"-"3DMr2   c                    |j         }||j        }n||_        |                                D ]	}d|_        
| j        |_        |                    |           t          j        t          j	        j
        j        j                  }d|_        d}	|dk    r&ddlm}
 ddlm} t           j        |                                }nt           j        }t)          |          }g }t+          |          D ]>}|                    |            |
|j         |          }|                    |           ?t           j        |                                 t3                      }d| j        z  d	z  }|d                             |d
|dd         d|d           |                    d           |                                }	n|dk    r\ddlm}
  |
|j         t           j                  }t3                      }|                    |d           |                                }	n't?          |j         ||j                   d         d         }|r|dv r{tC          j"        |	          #                    d          }tH          |         tJ          |         }}tJ          d         &                    ||          }|&                    ||d          }||_        |s|	|S |	S )z
        Given a plot instance, an output format and an optional bokeh
        document, return the corresponding data. If as_script is True,
        the content will be split in an HTML and a JS component.
        NTr'   r   )get_screenshot_as_png)webdriver_control)driverg      ?i  GIFr   )formatappend_imagessave_alldurationloopr#   PNG)rC   z	text/html)r#   r'   zutf-8base64)	mime_typeb64 )srcrJ   css)'r	   r6   
references	_documentr8   add_rootlogging	getLoggerr   core
validationcheck__file__disabledbokeh.io.exportr?   bokeh.io.webdriverr@   	webdrivercreatelenrangeupdateappendcloser   fpssaveseekreadgetvaluer   commrI   	b64encodedecoder   r   rC   )selfr<   fmtr    	as_scriptr;   modelmloggerdatar?   r@   r[   nframesframesiimgbiorF   
imgByteArrdivrK   rJ   tagrM   s                            r0   _figure_datazBokehRenderer._figure_dataK   s    
;-CCDM!!## 	 	AAKKJ	U "5:#8#>#GHH%<<======<<<<<<&-4466		!O	$iiGF7^^ # #A++DJyIIIc""""*!!!))C48T)H1INN3uF122J$(8!  E E EHHQKKK88::DDE\\======''
5?KKKC JHHZH...&&((DD#DJTY??B;OC 	C.."4((//88C)#	#YH%,,yc,JJC**	r*BBC 	JKr2   c                    t          |t                    r|j        n|}t          j        | j                                     t          |          d          }t          |d          rt          |d          sddl	m
} |}|                    |d          j        }|                    d|j                  }|                    d|j                  }|t          |          |d<   |t          |          |d<   t!          |          S )aA  
        Given a holoviews object and a percentage size, apply heuristics
        to compute a suitable figure size. For instance, scaling layouts
        and grids linearly can result in unwieldy figure sizes when there
        are a large number of elements. As ad hoc heuristics are used,
        this functionality is kept separate from the plotting classes
        themselves.

        Used by the IPython Notebook display hooks and the save
        utility. Note that this can be overridden explicitly per object
        using the fig_size and size plot options.
        Nwidthheightr   )	BokehPlotr<   )
isinstancer   lastr   registrybackendgettypehasattrr<   r}   lookup_optionsoptionsr{   r|   intdict)clsr9   percent_sizer<   r}   r   r{   r|   s           r0   plot_optionszBokehRenderer.plot_options   s     %S'22;chh~ck*..tCyy$??tW%% 	WT8-D-D 	''''''D%%c622:GTZ00Xt{33"5zzGG #FGHG}}r2   c                     t          |t                    r|j        }n$t          |t                    st	          d          t          |          S )z
        Return the display size associated with a plot before
        rendering to any particular format. Used to generate
        appropriate HTML display.

        Returns a tuple of (width, height) in pixels.
        z<Can only compute sizes for HoloViews and bokeh plot objects.)r~   r   r	   r   
ValueErrorr   )r.   r<   s     r0   get_sizezBokehRenderer.get_size   sV     dD!! 	8:DDD%(( 	8 7 8 8 8 &&&r2   c                     d| _         d S )NT)_loaded)r   inlines     r0   load_nbzBokehRenderer.load_nb   s    r2   )NN)NF)T)__name__
__module____qualname__paramStringr   ObjectSelectorr*   r+   ClassSelectordefault_themer   strr8   Booleanwebglmode_formatsr   _render_with_panelr
   r1   r5   ry   classmethodr   r   r   __classcell__)r=   s   @r0   r   r      s       el70CDDDG %
v7V7V7V ]" # # #C #e"6,A ,A ,AG67 7 7G  Eucl+/ 667 7 7E EM$ -; < < <E 322KKKM ML G  Z      ZC C C CJ   [6 ' ' Z'    [    r2   r   )!rI   rR   ior   r   r   bokeh.documentr   bokeh.ior   bokeh.modelsr   bokeh.themes.themer   panel.io.notebookr   panel.io.stater	   param.parameterizedr
   rT   r   r   r<   r   r:   r   r   r   utilr   r   r   r-   r2   r0   <module>r      s             # # # # # #             $ $ $ $ $ $ / / / / / /             * * * * * * " " " " " " " "       6 6 6 6 6 6 6 6 6 6 # # # # # #6BB   c c c c cH c c c c cr2   