a
    
d1%                     @   s   d Z ddlmZ ddlmZmZmZmZm	Z
 ddlmZ ddlmZ ddlmZmZ ddd	d
ddZddddddZejjZdddZdS )zHModule that provides a GUI-based editor for Matplotlib's figure options.    )chain)cbookcmcolorsmarkersimage)QtGui)_formlayout)DateConverternum2dateZSolidZDashedZDashDotZDottedNone)-z--z-.:r   ZDefaultzSteps (Pre)zSteps (Mid)zSteps (Post))defaultz	steps-preZstepsz	steps-midz
steps-postNc                    sD  d
dd  j  fdd D d  f
gt
fdd D d	}d
d  D dd  D g   D ]$}| }|dkrq||f qg }dd }D ]\}}tj	t
| | dd}tj	t
| | dd}tj	t
| | dd}	d|f
dd|t| fd|t| fd| fd|f
dd|t| fd| fd|	fd|fg}
||
|dg qt|g 	g  j jD ]8}| }|dks| du rq	||f qg }dd ttj D }	D ]\}}| }|tj vrD||j fg|}|! \}}d|fd|j g| fd |fd!|fg}t"|d"rd#d tt#j$D }|d$|% g|f |||dg qt||d%dfg}|r||d&df |r ||d'df  	fd(d)}t&j'|d*|t()t*t+,d+d,|d- dS ).zEdit matplotlib figure options)NNc                 S   s   t |trtt| S tt| S )z.Convert axis limits for correct input editors.)
isinstancer
   mapr   float)lim	converter r   t/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/matplotlib/backends/qt_editor/figureoptions.pyconvert_limits#   s    

z#figure_edit.<locals>.convert_limitsc              
      s2   i | ]*\}}|t t d | d |jqS get_r   )tuplegetattrr   .0nameaxis)axesr   r   r   
<dictcomp>+   s   zfigure_edit.<locals>.<dictcomp>ZTitlec                    sf   g | ]^\}}d d|   dfd | d fd | d fd|  fd| d	d
ddgffqS )Nz<b>z	-Axis</b>ZMinr   ZMax   LabelZScaleZlinearlogZsymlogZlogit)title	get_labelZget_text	get_scaler   )axis_limitssepr   r   
<listcomp>4   s   
zfigure_edit.<locals>.<listcomp>)z(Re-)Generate automatic legendFc                 S   s   i | ]\}}||j qS r   )r   r   r   r   r   r!   D   s   c                 S   s   i | ]\}}||  qS r   )Z	get_unitsr   r   r   r   r!   H   s   Z
_nolegend_c                 S   sf   || vri | |t |i} dd |  D }dd | D }|| |  }|gt| dd d S )a  
        Prepare entry for FormLayout.

        *d* is a mapping of shorthands to style names (a single style may
        have multiple shorthands, in particular the shorthands `None`,
        `"None"`, `"none"` and `""` are synonyms); *init* is one shorthand
        of the initial style.

        This function returns an list suitable for initializing a
        FormLayout combobox, namely `[initial_name, (shorthand,
        style_name), (shorthand, style_name), ...]`.
        c                 S   s   i | ]\}}||qS r   r   )r   shortr   r   r   r   r!   g       z5figure_edit.<locals>.prepare_data.<locals>.<dictcomp>c                 S   s   i | ]\}}||qS r   r   )r   r   r+   r   r   r   r!   i   r,   c                 S   s   | d S )Nr"   r   )Zshort_and_namer   r   r   <lambda>o   r,   z3figure_edit.<locals>.prepare_data.<locals>.<lambda>)key)stritemssorted)dinitZ
name2shortZ
short2nameZcanonical_initr   r   r   prepare_dataV   s    z!figure_edit.<locals>.prepare_dataT)Z
keep_alphar#   )Nz<b>Line</b>z
Line stylez
Draw styleZWidthzColor (RGBA))Nz<b>Marker</b>StyleSizezFace color (RGBA)zEdge color (RGBA) Nc                 S   s   g | ]\}}||fqS r   r   )r   r   cmapr   r   r   r*      r,   ZColormapz
Min. valuez
Max. valueget_interpolationc                 S   s   g | ]}||fqS r   r   r   r   r   r   r   r*      s   InterpolationZAxesZCurveszImages, etc.c           &   
      s   fddD }|  d}r*|  dng }r<|  dng }| rLtd| d} | |  }t D ]\}\}}	|d|  }
|d| d  }|d| d  }|d| d  }|	 |krt d	| d
| |	j|
|dd |	| | |	_	|	
|  qtt|D ]\}}| d }|\	}}}}}}}}}|| || || || t|}|d || |dkr|| || || || qt|D ]~\}}| d }t|dkr|\}}}}} ||  nt|dkr|\}}}}|| || |jt||g  q|rd}!d}" jdurz  }#|#jdu}!|#j}" j |"d}$|$r|$!|!  " }%|%j#$  D ]6}t d| d || kr|%j#j%&   qqdS )zA callback to apply changes.c                    s"   i | ]}|t  d | d qS r   )r   r:   )r    r   r   r!      s   z7figure_edit.<locals>.apply_callback.<locals>.<dictcomp>r   zUnexpected field   r"         set_ZscaleF)autoNnone   )ncolsr   r   )'pop
ValueError	set_title	enumerater0   r'   r   Z_set_limZset_label_textr   Z	set_unitsZ	set_labelZset_linestyleZset_drawstyleZset_linewidthmcolorsto_rgbaZ	set_alphaZ	set_colorZ
set_markerZset_markersizeZset_markerfacecolorZset_markeredgecolorlenZset_interpolationZset_cmapZset_climr1   Zlegend_Z
get_legendZ
_draggableZ_ncolsZlegendZset_draggableZ
get_figureZcanvasZdrawZtoolbarZpush_current)&dataZorig_limitsgeneralcurves	mappablesr%   Zgenerate_legendir   r   Zaxis_minZaxis_maxZ
axis_labelZ
axis_scaleindexZcurvelinelabelZ	linestyleZ	drawstyleZ	linewidthcolormarkerZ
markersizeZmarkerfacecolorZmarkeredgecolorZrgbaZmappable_settingsmappabler8   lowhighinterpolationZ	draggablerC   Z
old_legendZ
new_legendfigure)r    axis_converteraxis_map
axis_units	has_curvehas_smlabeled_lineslabeled_mappablesr   r   apply_callback   s    





















z#figure_edit.<locals>.apply_callbackzFigure optionsimageszqt4_editor_options.svg)r%   parentZiconapply)-Z	_axis_mapr0   Z	get_titler   from_iterable	get_linesr&   appendrH   Zto_hexrI   Z	get_colorZ	get_alphaZget_markeredgecolorZget_markerfacecolor
LINESTYLESZget_linestyle
DRAWSTYLESZget_drawstyleZget_linewidthMARKERSZ
get_markerZget_markersizeboolrb   collectionsZ	get_arrayr1   r   Z
_colormapsZget_cmapvaluesr   Zget_climhasattrmimageZinterpolations_namesr9   r	   Zfeditr   ZQIconr/   r   Z_get_data_path)r    rc   rL   rQ   rR   rM   r4   rS   ZecZfcZ	curvedatarU   rN   Zcmapsr8   rV   rW   ZmappabledataZinterpolationsZdatalistra   r   )r    rZ   r(   r[   r\   r   r]   r^   r_   r`   r)   r   figure_edit   s    



Rrp   )N)__doc__	itertoolsr   Z
matplotlibr   r   r   rH   r   r   ro   Zmatplotlib.backends.qt_compatr   Zmatplotlib.backends.qt_editorr	   Zmatplotlib.datesr
   r   rh   ri   ZMarkerStylerj   rp   r   r   r   r   <module>   s$   