U
    TZf@                     @   sb   d dl Z d dlZd dlZddlmZ ddlmZ G dd deZG dd	 d	eZ	dddZ
dZdS )    N   )Renderer   )Exporterc                   @   s:   e Zd Zdd Zdd ZdddZddd	Zdd
dZdS )VegaRendererc                 C   sN   || _ t|d |d  | _t|d |d  | _g | _g | _g | _g | _d S )NfigwidthZdpi	figheight)propsintr   r   datascalesaxesmarks)selffigr	    r   [/tmp/pip-unpacked-wheel-5ksk5baj/plotly/matplotlylib/mplexporter/renderers/vega_renderer.pyopen_figure	   s    zVegaRenderer.open_figurec                 C   sd   t | jdkrtd tddddtddddg| _td|d dd	d
td|d ddd
g| _d S )Nr   zmultiple axes not yet supportedx
   )typescaleZticksyZxlimZlinearwidth)namedomainr   rangeZylimheight)lenr   warningswarndictr   )r   Zaxr	   r   r   r   	open_axes   s$    
zVegaRenderer.open_axesNc                 C   s   |dkrt d dt| jd }| j|dd |D d | jdd|id	d
diddddddd
|d id
|d id
|d idid d S )Nr   .Only data coordinates supported. Skipping thistable{0:03d}r   c                 S   s    g | ]}t |d  |d dqS r   r   )r   r   r!   .0dr   r   r   
<listcomp>/   s     z*VegaRenderer.draw_line.<locals>.<listcomp>r   valueslineentervaluemonotoner   data.xr   fieldr   data.ycoloralphaZ	linewidth)interpolater   r   strokestrokeOpacitystrokeWidthr   fromZ
propertiesr   r    formatr   r   appendr   r   r   coordinatesstylelabelmplobjZdatanamer   r   r   	draw_line(   s(    



zVegaRenderer.draw_linec                 C   s   |dkrt d dt| jd }| j|dd |D d | jdd|id	d
diddddddd
|d id
|d id
|d id
|d id
|d idid d S )Nr   r#   r$   r   c                 S   s    g | ]}t |d  |d dqS r%   r&   r'   r   r   r   r*   I   s     z-VegaRenderer.draw_markers.<locals>.<listcomp>r+   symbolr.   r/   r0   r   r1   r2   r   r4   Z	facecolorr6   Z	edgecolorZ	edgewidth)r7   r   r   fillZfillOpacityr8   r9   r:   r;   r=   r@   r   r   r   draw_markersB   s,    





zVegaRenderer.draw_markersc                 C   s2   |dkr|| j d d< n|dkr.|| j d d< d S )NZxlabelr   titleZylabelr   )r   )r   textpositionrA   rB   	text_typerD   r   r   r   	draw_text^   s    zVegaRenderer.draw_text)N)N)NN)__name__
__module____qualname__r   r"   rE   rH   rM   r   r   r   r   r      s   	

   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )VegaHTMLc                 C   s&   t |j|j|j|j|j|jd| _d S )N)r   r   r   r   r   r   )r!   r   r   r   r   r   r   specification)r   rendererr   r   r   __init__h   s    zVegaHTML.__init__c                 C   s@   t dd}d| }|d7 }|tt| j|f 7 }|d7 }|S )z*Build the HTML representation for IPython.r   i   z<div id="vis%d"></div>z	<script>
z
</script>
)randomrandintVEGA_TEMPLATEjsondumpsrR   )r   idhtmlr   r   r   r[   r   s    zVegaHTML.htmlc                 C   s   |   S )N)r[   )r   r   r   r   _repr_html_{   s    zVegaHTML._repr_html_N)rN   rO   rP   rT   r[   r\   r   r   r   r   rQ   g   s   
	rQ   Fc                 C   s0   t  }t||  t|}|r$|S | S dS )zConvert a matplotlib figure to vega dictionary

    if notebook=True, then return an object which will display in a notebook
    otherwise, return an HTML string.
    N)r   r   runrQ   r[   )r   ZnotebookrS   Z	vega_htmlr   r   r   fig_to_vega   s    r^   a:  
( function() {
  var _do_plot = function() {
    if ( (typeof vg == 'undefined') && (typeof IPython != 'undefined')) {
      $([IPython.events]).on("vega_loaded.vincent", _do_plot);
      return;
    }
    vg.parse.spec(%s, function(chart) {
      chart({el: "#vis%d"}).update();
    });
  };
  _do_plot();
})();
)F)r   rX   rU   baser   Zexporterr   r   objectrQ   r^   rW   r   r   r   r   <module>   s   _
