o
    AeF                     @   s   d Z ddlmZ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ZddlZddlZeeZdd	d
Zdd ZdddZdd Zdd Zdd Zdd Zdd Zdd ZdddZedkrnddlZee  dS dS ) z;Visualize DesignSpaceDocument and resulting VariationModel.    )VariationModelsupportScalar)DesignSpaceDocument)pyplot)axes3d)cycleN
   c                    sD   | \  fddt D fddt D  g S )Nc                        g | ]}   |   qS  r
   .0i)abcountr
   V/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/fontTools/varLib/plot.py
<listcomp>        zstops.<locals>.<listcomp>c                    r	   r
   r
   r   )r   cr   r
   r   r      r   )range)supportr   r
   )r   r   r   r   r   stops   s   
r   c                 K   s   t | ttjjjD ]I\}}t|dkr*|j||d dgdgdfd|i| q
t|dkrN|j||d dg||d dgdgdfd|i| q
t	t|d S )N   r         ?ocolor   )
zipr   r   cmSet1colorslenplotgetAssertionError)	locationsaxessubplotkwargslocr   r
   r
   r   _plotLocationsDots   s    ,	r*   c                    s   t | }t|d }t|| }d u rd gt |  t|   fddtt D t| d  }t |dkrOt |d |||fdi| d S t |dkret ||||fdi| d S t	d)	Ng      ?c                    s   g | ]	} j |  qS r
   )ZreverseMappingr   modelnamesr
   r   r   3   s    z!plotLocations.<locals>.<listcomp>r   r   r-   r   Only 1 or 2 axes are supported)
r!   mathceilr   r   sortedkeys_plotLocations2D_plotLocations3D
ValueError)r%   figr-   r(   ncolsrowsr&   r
   r+   r   plotLocations*   s   $ r:   c                 K   s   | d}tt| jttjjjt|D ]R\}\}	}
}|d ur%|	| |
| tdd |	|d}g g }}t|D ]}t||i|	}|| || q?|j||fd|
i| t| j|g| qd S )No         r   r<   g        r   r   )add_subplot	enumerater   supportsr   r   r   r   r    	set_title
set_xlabelxlimr#   r   r   appendr"   r*   r%   )r,   axisr6   r8   r9   r-   r(   r'   r   r   r   nameXsXYxyr
   r
   r   r3   >   s"   




r3   c                 K   s  |\}}|j ddd}	tt| jttjjjt|D ]\}
\}}}|d ur+|		| |	
| |	| tdd tdd ||d}||d}t|D ]4}g g g }}}|D ]}t||||i|}|| || || q]|	j|||fd|i| qQt|D ]4}g g g }}}|D ]}t||||i|}|| || || q|	j|||fd|i| qt| j||g|	 qd S )Nr;   3dZ
projectionr<   r   r=   r   )r>   r?   r   r@   r   r   r   r   r    rA   rB   Z
set_ylabelrC   Zylimr#   r   r   rD   r"   r*   r%   )r,   r&   r6   r9   r8   r-   r(   Zax1Zax2axis3Dr   r   r   rF   rG   ZYsrJ   rH   rI   ZrK   zr
   r
   r   r4   S   s>   






r4   c                 K   s@   |    dd | jD }dd | jD }t|||fi | d S )Nc                 S      g | ]}|j qS r
   )locationr   sr
   r
   r   r   y       z plotDocument.<locals>.<listcomp>c                 S   rQ   r
   )rF   rS   r
   r
   r   r   z   rU   )	normalizesourcesr:   )docr6   r(   r%   r-   r
   r
   r   plotDocumentw   s   rY   c                    s   t | jdks	J | jd  t fdd| jD }t fdd| jD }dd l}||||| d }g }|D ]}	 |	i}
| |
|}|| q9|	d}|j
||dfi | d S )	Nr   r   c                 3       | ]	}|  d V  qdS r   Nr#   r   r)   rE   r
   r   	<genexpr>       z*_plotModelFromMasters2D.<locals>.<genexpr>c                 3   rZ   r[   r\   r]   r^   r
   r   r_      r`   d   r;   -)r!   	axisOrderminr%   maxnumpyarangeinterpolateFromMastersrD   r>   r"   )r,   masterValuesr6   r(   Zaxis_minZaxis_maxnprH   rI   rJ   r)   vr'   r
   r^   r   _plotModelFromMasters2D~   s   

rl   c                    sZ  t | jdks	J | jd | jd  t fdd| jD }t fdd| jD }tfdd| jD }tfdd| jD }dd l}||||| d	 }	||||| d	 }
||	|
\}	}
g }t|	|
D ]&\}}g }|	| t||D ]\}} ||i}| 
||}|	| q}qm||}|jd
dd}|j|	|
|fi | d S )Nr   r   r   c                 3   rZ   r[   r\   r]   axis1r
   r   r_      r`   z*_plotModelFromMasters3D.<locals>.<genexpr>c                 3   rZ   r[   r\   r]   rm   r
   r   r_      r`   c                 3   rZ   r[   r\   r]   axis2r
   r   r_      r`   c                 3   rZ   r[   r\   r]   ro   r
   r   r_      r`   ra   r;   rL   rM   )r!   rc   rd   r%   re   rf   rg   Zmeshgridr   rD   rh   arrayr>   Zplot_surface)r,   ri   r6   r(   Z	axis1_minZ	axis1_maxZ	axis2_minZ	axis2_maxrj   rH   rI   rO   Zrow_xZrow_yZz_rowrJ   rK   r)   rk   rN   r
   )rn   rp   r   _plotModelFromMasters3D   s,   

rr   c                 K   sT   t | jdkrt| ||fi | dS t | jdkr&t| ||fi | dS td)zPlot a variation model and set of master values corresponding
    to the locations to the model into a pyplot figure.  Variation
    model must have axisOrder of size 1 or 2.r   r   r.   N)r!   rc   rl   rr   r5   )r,   ri   r6   r(   r
   r
   r   plotModelFromMasters   s
   rs   c              
      s  ddl m} | d u rtjdd  } |  t| dk r<tdtjd td tdtjd td tdtjd td t	 }|
d	 t| dkrb| d d
rbt }|| d  t|| nadd ttdtdd D  d| d vr fdd| D }t|| n<g }g }| D ]"}|d\}}	|tt dd |dD  |t|	 qt| d t|d  }
t|
|| t  d S )Nr   )configLoggerr   z/usage: fonttools varLib.plot source.designspace)filez  orz4usage: fonttools varLib.plot location1 location2 ...zBusage: fonttools varLib.plot location1=value1 location2=value2 ...Tz.designspacec                 S   s   g | ]}t |qS r
   )chr)r   r   r
   r
   r   r      s    zmain.<locals>.<listcomp>ArO   =c              	      s*   g | ]}t t d d |dD qS )c                 s       | ]}t |V  qd S Nfloatr   rk   r
   r
   r   r_          z"main.<locals>.<listcomp>.<genexpr>,)dictr   splitrS   r&   r
   r   r      s   * c                 s   ry   rz   r{   r}   r
   r
   r   r_      r~   zmain.<locals>.<genexpr>r   )Z	fontToolsrt   sysargvr!   printstderrexitr   ZfigureZset_tight_layoutendswithr   readrY   r   ordr:   r   rD   r   r   r|   r   rs   show)argsrt   r6   rX   Zlocsr%   ri   argr)   rk   r,   r
   r   r   main   sB   

 $r   __main__)r   rz   )__doc__ZfontTools.varLib.modelsr   r   ZfontTools.designspaceLibr   Z
matplotlibr   Zmpl_toolkits.mplot3dr   	itertoolsr   r/   loggingr   	getLogger__name__logr   r*   r:   r3   r4   rY   rl   rr   rs   r   r   r
   r
   r
   r   <module>   s0    



$
/