U
    td+3                  
   @   s"   d dl Z d dlmZ dd
dZdS )    N)BoundingBoxautolabelcolorshape
   width   c           *         sf  |dkr|dkrd}d}n|dkr(|}n|dkr4|}|dksD|dkrLt dt|trh| j|f||}t|trz| j|}W q tk
r   dd t|  D }Y qX n|dkrdg|   }t|trz| j|}W n$ tk
r   dg|   }Y nX t|trJz| j|}W n$ tk
rH   d	g|   }Y nX t|	trz| j	|	}	W n$ tk
r   d
g| 
  }	Y nX t|
trz| j	|
}
W n$ tk
r   dg| 
  }
Y nX t|tsdt| }nd|krt d|  }|dd tt||D  |dg|t|   t|trTt|d}d}n|}d}t|  |d  |d  g} j j }}g |dkrd n|d |  |dkrЈd n|d	 |   fdd|D }|  }td|d td|d t|d td|d td||d|d i }td|d t|	D ]}|dkrpd}ntt|}td|d td ||d td!|d td"|d td#|d td$||d td%|d td&|d td'||d td(||d td)|d td*|d td+|d d,|||< q\td-|d td.|d t| j	D ]L\}}|j}||d  d }||d  d	 }||d	  d }||d	  d	 }t|| || }|t| 8 }|t| 8 }td/|d td0|	| |rd1||	|  nd|
| |d td2|||||d td3||d td4|d td5|d td6|j|d td7|d td8|j|d td9|d qdtd:|d t|d td;|d td<|d td=d |D rtddl } ddl!}!|"d>r$t#|dd? }"n,zt#|}"W n t$k
rN   t d@Y nX |!% }#| j&j'|#dA|"| j&j(fdB}$nd}#t|  D ]}%tdC|%||% d ||% d	 |d ||% d	krLt||% }&d|&kr*|&)d}&t}'tdD|'|&d |d tdE|'|&d	 |d tdF|'|d n tdGtt||% |d n||% dkr|tdHd |%||% |d n\||% dIkr|$*t||% d |$+dJd  }(})tdK|(dL |)dL |(|)|%||% |d tdMdL |%||d tdNdL |%t||% |d tdO|d qtdP|d t|d tdQ|d |rT|,  |#rb|#-  dS )Ram  Saves the graph as an SVG (Scalable Vector Graphics) file

    The file will be Inkscape (http://inkscape.org) compatible.
    In Inkscape, as nodes are rearranged, the edges auto-update.

    @param fname: the name of the file or a Python file handle
    @param layout: the layout of the graph. Can be either an
      explicitly specified layout (using a list of coordinate
      pairs) or the name of a layout algorithm (which should
      refer to a method in the L{Graph} object, but without
      the C{layout_} prefix.
    @param width: the preferred width in pixels (default: 400)
    @param height: the preferred height in pixels (default: 400)
    @param labels: the vertex labels. Either it is the name of
      a vertex attribute to use, or a list explicitly specifying
      the labels. It can also be C{None}.
    @param colors: the vertex colors. Either it is the name of
      a vertex attribute to use, or a list explicitly specifying
      the colors. A color can be anything acceptable in an SVG
      file.
    @param shapes: the vertex shapes. Either it is the name of
      a vertex attribute to use, or a list explicitly specifying
      the shapes as integers. Shape 0 means hidden (nothing is drawn),
      shape 1 is a circle, shape 2 is a rectangle and shape 3 is a
      rectangle that automatically sizes to the inner text.
    @param vertex_size: vertex size in pixels
    @param edge_colors: the edge colors. Either it is the name
      of an edge attribute to use, or a list explicitly specifying
      the colors. A color can be anything acceptable in an SVG
      file.
    @param edge_stroke_widths: the stroke widths of the edges. Either
      it is the name of an edge attribute to use, or a list explicitly
      specifying the stroke widths. The stroke width can be anything
      acceptable in an SVG file.
    @param font_size: font size. If it is a string, it is written into
      the SVG file as-is (so you can specify anything which is valid
      as the value of the C{font-size} style). If it is a number, it
      is interpreted as pixel size and converted to the proper attribute
      value accordingly.
    Ni  r   z!width and height must be positivec                 S   s   g | ]}|d  qS )    .0xr   r   I/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/igraph/io/images.py
<listcomp>P   s     z'_write_graph_to_svg.<locals>.<listcomp> redr
   black   z%spx;z#font size can't contain a semicolonc                 s   s   | ]}t |d  V  qdS )r
   N)str)r   ir   r   r   	<genexpr>s   s     z&_write_graph_to_svg.<locals>.<genexpr>wTFg      ?c                    s@   g | ]8}|d   j  d    |d  j d   gqS )r   r
   )lefttop)r   rowZbboxratiosvertex_sizer   r   r      s   z6<?xml version="1.0" encoding="UTF-8" standalone="no"?>)filez/<!-- Created by igraph (http://igraph.org/) -->a]  <svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"zwidth="{0}px" height="{1}px"> )endr    z<defs id="defs3">z#000000z<markerz#   inkscape:stockid="Arrow2Lend{0}"z   orient="auto"z   refY="0.0"z   refX="0.0"z   id="Arrow2Lend{0}"z   style="overflow:visible;">z  <pathz     id="pathArrow{0}"zd     style="font-size:12.0;fill-rule:evenodd;stroke-width:0.62500000;stroke-linejoin:round;fill:{0}"z     d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "z9     transform="scale(1.1) rotate(180) translate(1,0)" />z	</marker>zArrow2Lend{0}z</defs>z]<g inkscape:groupmode="layer" id="layer2" inkscape:label="Lines" sodipodi:insensitive="true">z<pathz    style="fill:none;stroke:{0};stroke-width:{2};stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none{1}"z;marker-end:url(#{0})z    d="M {0},{1} {2},{3}"z    id="path{0}"z&    inkscape:connector-type="polyline"z$    inkscape:connector-curvature="0"z%    inkscape:connection-start="#g{0}"z(    inkscape:connection-start-point="d4"z#    inkscape:connection-end="#g{0}"z)    inkscape:connection-end-point="d4" />z  </g>zW  <g inkscape:label="Nodes"                     inkscape:groupmode="layer" id="layer1">z  <!-- Vertices -->c                 s   s   | ]}|d kV  qdS )   Nr   r   r   r   r   r      s     Zpxzqfont sizes must be specified in pixels when any of the nodes has shape=3 (i.e. node size determined by text size)ZSans)rootfontz0    <g id="g{0}" transform="translate({1},{2})">zb     <path d="M -{0},0 A{0},{0} 0 0,0 {0},0 L                                 -{0},0" fill="{1}"/>zb     <path d="M -{0},0 A{0},{0} 0 0,1 {0},0 L                                 -{0},0" fill="{1}"/>z0     <circle cx="0" cy="0" r="{0}" fill="none"/>z/     <circle cx="0" cy="0" r="{0}" fill="{1}"/>zf      <rect x="-{0}" y="-{0}" width="{1}" height="{1}" id="rect{2}" style="fill:{3};fill-opacity:1" />r#   Z	linespacezt      <rect ry="5" rx="5" x="-{0}" y="-{1}" width="{2}" height="{3}" id="rect{4}" style="fill:{5};fill-opacity:1" />g       @a        <text sodipodi:linespacing="125%" y="{0}" x="0" id="text{1}" style="font-size:{2};font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans">zJ<tspan y="{0}" x="0" id="tspan{1}" sodipodi:role="line">{2}</tspan></text>z    </g>z</g>z</svg>).
ValueError
isinstancer   layoutvsZget_attribute_valuesKeyErrorrangevcountesZecountextendlenopenr   Zbounding_boxr   heightappendZis_directedprintformatset	enumeratetuplemathatan2cossinsourcetargetanyZtkinter.fonttkinterendswithint	ExceptionZTkr&   ZFontZNORMALsplitmeasureZmetricsclosedestroy)*graphfnamer)   r   r2   labelscolorsZshapesr   Zedge_colorsZedge_stroke_widthsZ	font_sizeargskwdsr-   fZour_filesizesr   hZdirectedZedge_color_dictZe_colZmarker_indexZeidxedgeZvidxsx1y1Zx2y2Zangler@   ZtkZfont_size_in_pixelsZ	tk_windowr&   Zvidxcr*   Zvertex_widthZvertex_heightr   r   r   _write_graph_to_svg   s   8








	

  
 


   
   
  	  

rV   )
r   NNr   r   r   r   r   r   r	   )r9   Zigraph.drawingr   rV   r   r   r   r   <module>   s             