o
    tf                     @  s   d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dl
Z
e
dZ							d&d'ddZG dd de	ZG dd deZG dd deZejd(d!d"ZeG d#d dZe Ze Zed$e ed%e ed$ dS ))    )annotationsN)	dataclassfield)Protocola  
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="https://esm.sh/higlass@{{ higlass_version }}/dist/hglib.css">
    <script src="https://unpkg.com/requirejs-toggle"></script>
    {% for plugin_url in plugin_urls %}
    <script src="{{ plugin_url }}"></script>
    {% endfor %}
    <script src="https://unpkg.com/requirejs-toggle"></script>
  </head>
  <body>
    <div id="{{ output_div }}"></div>
  </body>
  <script type="module">
    import hglib from "https://esm.sh/higlass@{{ higlass_version }}?deps=react@{{ react_version }},react-dom@{{ react_version }},pixi.js@{{ pixijs_version }}";
    hglib.viewer(
      document.getElementById('{{ output_div }}'),
      {{ viewconf }},
    );
    </script>
</html>
1.12176visviewconfdicthiglass_versionstrreact_versionpixijs_version
output_div	json_kwdsdict | Noneplugin_urlslist[str] | Nonec                 C  s,   t jtj| fi |p
i |||||pg dS )a`  Embed the viewconf into an HTML template.

    The HTML template includes imports for HiGlass and any specified plugins
    and will display an interactive visualization of the embedded viewconf
    when loaded in the web browser.

    Parameters
    ----------

    viewconf : dict
        The top-level HiGlass viewconf.

    higlass_version : str, optional
        The HiGlass client version.

    react_version : str, optional
        The react and react-dom peer dependency versions.

    pixijs_version : str, optional
        The pixi.js perr dependency version.

    output_div : str, optional
        An id for the div which the visualization renders.

    json_kwds : dict, optional
        Additional arguments to pass to `json.dumps`.

    plugin_urls : list[str], optional
        URLs for plugin tracks or data fetchers to be loaded on the page.
    )r
   r   r   r   r   r   )HTML_TEMPLATErenderjsondumps)r
   r   r   r   r   r   r    r   Y/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/higlass/_display.pyviewconf_to_html&   s   'r   c                   @  s   e Zd ZdZdddZdS )	RendererProtocolz>A callable that converts a dict viewconf into full mimebundle.r
   r   returnc                 K  s   dS )a  Creates a full mimebundle from a dictionary viewconf.

        Parameters
        ----------

        viewconf : dict
            A top-level HiGlass viewconf (e.g., `hg.Viewconf.dict()`))

        **metadata : dict
            Any extra metadata for the renderer.

        Returns
        -------

        mimebundle : a full mimebundle containing the mapping from all
            mimetypes to data. See return type of `_repr_mimebundle_`
            method in IPython documentation.


        Examples
        --------

        >>> def render_text(viewconf: dict):
        >>>     return {
        >>>         "text/plain": "Viewconf(...)",
        >>>     }

        Nr   selfr
   metadatar   r   r   __call__Z   s   zRendererProtocol.__call__N)r
   r   r   r   )__name__
__module____qualname____doc__r!   r   r   r   r   r   W   s    r   c                   @  s.   e Zd ZddddZedd Zdd
dZdS )BaseRendererjupyter-hg-{}r   r   c                 K  s   || _ || _d S N)_output_divkwargs)r   r   r*   r   r   r   __init__{   s   
zBaseRenderer.__init__c                 C  s   | j t jS )z@Creates a unique id for the output div each time it is accessed.)r)   formatuuiduuid4hexr   r   r   r   r      s   zBaseRenderer.output_divr
   r   c                 K  s   t  r(   )NotImplementedErrorr   r   r   r   r!      s   zBaseRenderer.__call__N)r'   )r   r   r
   r   )r"   r#   r$   r+   propertyr   r!   r   r   r   r   r&   z   s
    
r&   c                   @  s   e Zd ZdddZdS )HTMLRendererr
   r   c                 K  s2   | j  }|| td|| jd|}d|iS )N)r
   r   z	text/htmlr   )r*   copyupdater   r   )r   r
   r    r*   htmlr   r   r   r!      s   

zHTMLRenderer.__call__Nr2   )r"   r#   r$   r!   r   r   r   r   r4      s    r4   registryRendererRegistryreset
str | Nonec                 c  s"    z|   V  W || _dS || _w )zTemporarily enables a renderer.

    Parameters
    ----------
    registry : PluginRegistry
        The plugin registry to potentially reset the active plugin.

    reset : str | None
        The previous name of the active plugin.
    N)getactive)r8   r:   r   r   r   managed_enable   s   r>   c                   @  sL   e Zd ZU dZeedZded< dZded< dddZ	dddZ
dd ZdS )r9   a{  A registery for multiple HiGlass renderers.

    Allows for multiple renders to be registered, and dynamically enabled/disabled
    for the viewconf.

    Examples
    --------

    >>> import higlass as hg
    >>> hg.renderers.register("my-renderer", MyRenderer())
    >>> hg.renderers.enable("my-renderer")
    >>> hg.view(hg.track("heatmap")) # calls the custom renderer

    )default_factoryzdict[str, RendererProtocol]	renderersNr;   r=   namer   rendererr   c                 C  s   || j |< dS )zReigster a custom renderer.

        Parameters
        ----------

        name : str
            A uniquely identifiable name.

        renderer : RendererProtocol
            A Callable that implements the RendererProtocol.
        N)r@   )r   rA   rB   r   r   r   register   s   zRendererRegistry.registerc                 C  s0   || j vrtd| d| j}|| _t| |S )zExamples a previously registered renderer.

        Parameters
        ----------

        name : str
            The name of a previously registered renderer.
        z
Renderer 'z' has not been registered.)r@   
ValueErrorr=   r>   )r   rA   prevr   r   r   enable   s
   
	
zRendererRegistry.enablec                 C  s   | j du r	td| j| j  S )zGet the enabled renderer.NzNo renderer enabled.)r=   rD   r@   r0   r   r   r   r<      s   
zRendererRegistry.get)rA   r   rB   r   )rA   r   )r"   r#   r$   r%   r   r   r@   __annotations__r=   rC   rF   r<   r   r   r   r   r9      s   
 

defaultr7   )r   r   r   r	   NN)r
   r   r   r   r   r   r   r   r   r   r   r   r   r   )r8   r9   r:   r;   )
__future__r   
contextlibr   r-   dataclassesr   r   typingr   Zjinja2Templater   r   r   r&   r4   contextmanagerr>   r9   Zhtml_rendererr@   rC   rF   r   r   r   r   <module>   s:    1#7