Ë
    Ìia2  ã                   óÆ   — d dl Z d dlZd dlmc mZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZmZmZ d dlmZmZ d dlmZmZmZmZ d dlmZmZmZmZm Z   G d	„ d
«      Z!y)é    N)Útheme)ÚAxis)ÚDateÚDateTime)ÚLinearÚScaleÚTemporal)ÚCategorySeriesÚSeries)ÚBarsÚColumnsÚDotsÚLine)ÚDIMENSION_NAMESÚBoxÚ
IPythonSVGÚXÚYc                   óŽ   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zdd„Zdd„Zd„ Zdd„Zdd„Zdd„Zdd„Zd„ Zdd„Zdd„Zy)ÚChartz„
    Container for all chart types.

    :param title:
        An optional title that will be rendered at the top of the chart.
    Nc                 ó€   — || _         t        j                  | _        g | _        d d g| _        d d g| _        d d g| _        y ©N)Ú_titler   Údefault_series_colorsÚ_series_colorsÚ_layersÚ_typesÚ_scalesÚ_axes)ÚselfÚtitles     úN/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/leather/chart.pyÚ__init__zChart.__init__   s?   € ØˆŒÜ#×9Ñ9ˆÔàˆŒØ˜T�lˆŒØ˜d�|ˆŒØ˜D�\ˆ�
ó    c                 ó(   — d„ | j                   D «       S )z7
        Return a generator for series colors.
        c              3   ó    K  — | ]  }|–— Œ y ­wr   © )Ú.0Úcolors     r"   ú	<genexpr>z!Chart._palette.<locals>.<genexpr>#   s   è ø€ Ò7˜%”Ñ7ùs   ‚)r   )r    s    r"   Ú_palettezChart._palette   s   € ñ 8 4×#6Ñ#6Ô7Ð7r$   c                 ó*   — || j                   t        <   y)z;
        Set the X :class:`.Scale` for this chart.
        N)r   r   ©r    Úscales     r"   Úset_x_scalezChart.set_x_scale%   ó   € ð  ˆ�‰”QŠr$   c                 ó*   — || j                   t        <   y)z1
        See :meth:`.Chart.set_x_scale`.
        N)r   r   r-   s     r"   Úset_y_scalezChart.set_y_scale+   r0   r$   c                 ó´   — t         }t        |t        j                  «      st        |t        j                  «      rt
        }| j                   |||«      «       y)aG  
        Create and add a :class:`.Scale`.

        If the provided domain values are :class:`date` or :class:`datetime`
        then a :class:`.Temporal` scale will be created, otherwise it will
        :class:`.Linear`.

        If you want to set a custom scale class use :meth:`.Chart.set_x_scale`
        instead.
        N)r   Ú
isinstancer   Útypesr   r	   r/   ©r    Ú
domain_minÚ
domain_maxÚ
scale_types       r"   Úadd_x_scalezChart.add_x_scale1   s>   € ô ˆ
ä�j¤$§*¡*Ô-´¸JÌÏÉÔ1WÜ!ˆJà×Ñ™ J°
Ó;Õ<r$   c                 ó´   — t         }t        |t        j                  «      st        |t        j                  «      rt
        }| j                   |||«      «       y)z1
        See :meth:`.Chart.add_x_scale`.
        N)r   r4   r   r5   r   r	   r2   r6   s       r"   Úadd_y_scalezChart.add_y_scaleC   s>   € ô ˆ
ä�j¤$§*¡*Ô-´¸JÌÏÉÔ1WÜ!ˆJà×Ñ™ J°
Ó;Õ<r$   c                 ó*   — || j                   t        <   y)z=
        Set an :class:`.Axis` class for this chart.
        N)r   r   ©r    Úaxiss     r"   Ú
set_x_axiszChart.set_x_axisN   ó   € ð ˆ�
‰
”1Šr$   c                 ó*   — || j                   t        <   y)z0
        See :meth:`.Chart.set_x_axis`.
        N)r   r   r>   s     r"   Ú
set_y_axiszChart.set_y_axisT   rA   r$   c                 ó@   — t        |||«      | j                  t        <   y)z”
        Create and add an X :class:`.Axis`.

        If you want to set a custom axis class use :meth:`.Chart.set_x_axis`
        instead.
        N)r   r   r   ©r    ÚticksÚtick_formatterÚnames       r"   Ú
add_x_axiszChart.add_x_axisZ   s   € ô ˜U N°DÓ9ˆ�
‰
”1Šr$   c                 ó@   — t        |||«      | j                  t        <   y)z0
        See :meth:`.Chart.add_x_axis`.
        N)r   r   r   rE   s       r"   Ú
add_y_axiszChart.add_y_axisc   s   € ô ˜U N°DÓ9ˆ�
‰
”1Šr$   c                 ó  — | j                   r+t        | j                   d   d   t        «      rt        d«      ‚t        |t        «      r|j                  | _        n†t
        t        fD ]w  }| j                  |   s|j                  |   | j                  |<   Œ/|j                  |   | j                  |   usŒNt        d|j                  |   › d| j                  |   › �«      ‚ |j                  |«       | j                   j                  ||f«       y)at  
        Add a data :class:`.Series` to the chart. The data types of the new
        series must be consistent with any series that have already been added.

        There are several shortcuts for adding different types of data series.
        See :meth:`.Chart.add_bars`, :meth:`.Chart.add_columns`,
        :meth:`.Chart.add_dots`, and :meth:`.Chart.add_line`.
        r   zDAdditional series can not be added to a chart with a CategorySeries.zCan't mix axis-data types: z and N)
r   r4   r
   ÚRuntimeErrorr   r   r   Ú	TypeErrorÚvalidate_seriesÚappend)r    ÚseriesÚshapeÚdims       r"   Ú
add_serieszChart.add_seriesi   sô   € ð �<Š<œJ t§|¡|°A¡°qÑ'9¼>ÔJÜÐeÓfÐfä�fœnÔ-Ø Ÿ-™-ˆD�Käœ1�vò p�Ø—{‘{ 3Ò'Ø'-§}¡}°SÑ'9�D—K‘K Ò$Ø—]‘] 3Ñ'¨t¯{©{¸3Ñ/?Ò?Ü#Ð&BÀ6Ç=Á=ÐQTÑCUÐBVÐV[Ð\`×\gÑ\gÐhkÑ\lÐ[mÐ$nÓoÐoð	pð 	×Ñ˜fÔ%à�‰×ÑØØð
õ 	r$   c           	      óx   — | j                  t        t        t        |«      «      |||¬«      t	        |«      «       y)ag  
        Create and add a :class:`.Series` rendered with :class:`.Bars`.

        Note that when creating bars in this way the order of the series data
        will be reversed so that the first item in the series is displayed
        as the top-most bar in the graphic. If you don't want this to happen
        use :meth:`.Chart.add_series` instead.
        ©ÚxÚyrH   N)rT   r   ÚlistÚreversedr   ©r    ÚdatarW   rX   rH   Ú
fill_colors         r"   Úadd_barszChart.add_bars…   s/   € ð 	�‰Ü”4œ ›Ó'¨1°¸Ô=Ü�Óõ	
r$   c                 óT   — | j                  t        ||||¬«      t        |«      «       y)zT
        Create and add a :class:`.Series` rendered with :class:`.Columns`.
        rV   N)rT   r   r   r[   s         r"   Úadd_columnszChart.add_columns“   s&   € ð 	�‰Ü�4˜1 ¨Ô-Ü�JÓõ	
r$   c                 óV   — | j                  t        ||||¬«      t        ||«      «       y)zQ
        Create and add a :class:`.Series` rendered with :class:`.Dots`.
        rV   N)rT   r   r   )r    r\   rW   rX   rH   r]   Úradiuss          r"   Úadd_dotszChart.add_dotsœ   s(   € ð 	�‰Ü�4˜1 ¨Ô-Ü�˜VÓ$õ	
r$   c                 óX   — | j                  t        ||||¬«      t        |||«      «       y)zQ
        Create and add a :class:`.Series` rendered with :class:`.Line`.
        rV   N)rT   r   r   )r    r\   rW   rX   rH   Ústroke_colorÚwidthÚstroke_dasharrays           r"   Úadd_linezChart.add_line¥   s+   € ð 	�‰Ü�4˜1 ¨Ô-Ü�˜uÐ&6Ó7õ	
r$   c                 ó®  — | j                   |   }| j                  |   }|s/t        j                  | j                  || j
                  |   «      }nw| j                  D ]h  \  }}|j                  |j                  |«      «      r!|j                  |j                  |«      «      rŒGt        |   }t        j                  d|z  «        n |s
t        «       }||fS )zÂ
        Validates that the given scale and axis are valid for the data that
        has been added to this chart. If a scale or axis has not been set,
        generates automated ones.
        z^Data contains values outside %s scale domain. All data points may not be visible on the chart.)r   r   r   Úinferr   r   ÚcontainsÚminÚmaxr   ÚwarningsÚwarnr   )r    Ú	dimensionr.   r?   rQ   rR   Úds          r"   Ú_validate_dimensionzChart._validate_dimension®   sÆ   € ð —‘˜YÑ'ˆØ�z‰z˜)Ñ$ˆáÜ—K‘K §¡¨i¸¿¹ÀYÑ9OÓP‰Eà!%§¡ò 	‘�˜Ø—~‘~ f§j¡j°Ó&;Ô<ÀEÇNÁNÐSY×S]ÑS]Ð^gÓShÕDiÜ'¨	Ñ2�AÜ—M‘MðKØMNñOôñ ð	ñ Ü“6ˆDà�tˆ}Ðr$   c                 ó  — |xs t         j                  }|xs t         j                  }| j                  st	        d«      ‚t        t         j                  t        «      r#|t         j                  z  }t        ||||¬«      }n7t        t        «      rt        ||||«      }nt        |t        «      st        |Ž }t        j                  d«      }|j                  t        j                  dt        d«      t        d«      t        |«      t        |«      t         j                  ¬«      «       t        j                  d«      }|j                  dt!        j"                  |j$                  |j&                  «      «       ||j$                  |j(                  z   z
  }||j&                  |j*                  z   z
  }|j                  |«       t        j                  d«      }	d}
| j,                  rÑt        j                  dt        d«      t        d«      t         j.                  ¬	«      }|j                  d
t         j0                  «       |j                  dt        t         j2                  «      «       t        | j,                  «      |_        |	j                  |«       |
t         j6                  t         j8                  z   z  }
t;        | j                  «      dkD  s!t        | j                  d   d   t<        «      �r)t        j                  d«      }|j                  dt!        j"                  d|
«      «       d}d}| j?                  «       }| j                  D ]‘  \  }}|jA                  ||«      D ]w  \  }}||z   |kD  rd}|dz  }|dz
  t         jB                  t         jD                  z   z  }|j                  dt!        j"                  ||«      «       ||z  }|j                  |«       Œy Œ“ |t         jB                  t         jD                  z   z  }|
|z  }
|	j                  |«       |j                  |	«       t        j                  d«      }|j                  dt!        j"                  d|
«      «       |}||
z
  }|j                  |«       | jG                  tH        «      \  }}| jG                  tJ        «      \  }}|jM                  |d«      }|jM                  |d«      }||z
  }||z
  } t        j                  d«      }!|!j                  dt!        j"                  |d«      «       |!j                  |jO                  || |d«      «       |!j                  |jO                  || |d«      «       |	j                  dt!        j"                  |d«      «       |j                  |!«       t        j                  d«      }"| j?                  «       }| j                  D ]*  \  }}|"j                  |jO                  || ||||«      «       Œ, |!j                  |"«       |S )zÓ
        Render this chart to an SVG group element.

        This can then be placed inside an :code:`<svg>` tag to make a complete
        SVG graphic.

        See :meth:`.Chart.to_svg` for arguments.
        z?You must add at least one series to the chart before rendering.)ÚtopÚrightÚbottomÚleftÚgÚrectr   )rW   rX   rf   ÚheightÚfillÚ	transformÚtext)rW   rX   r{   zfont-familyz	font-sizeé   rv   rw   )(r   Údefault_widthÚdefault_heightr   Ú
ValueErrorr4   ÚmarginÚfloatr   ÚintÚETÚElementrP   ÚstrÚbackground_colorÚsetÚsvgÚ	translaterw   rt   ru   rv   r   Útitle_colorÚtitle_font_familyÚtitle_font_sizer}   Útitle_font_char_heightÚ	title_gapÚlenr
   r+   Úlegend_to_svgÚlegend_font_char_heightÚ
legend_gaprr   r   r   Úestimate_label_marginÚto_svg)#r    rf   rz   Údefault_marginr‚   Ú
root_groupÚmargin_groupÚmargin_widthÚmargin_heightÚheader_groupÚheader_marginÚlabelÚlegend_groupÚindentÚrowsÚpaletterQ   rR   Ú
item_groupÚ
item_widthrX   Úlegend_heightÚ
body_groupÚ
body_widthÚbody_heightÚx_scaleÚx_axisÚy_scaleÚy_axisÚbottom_marginÚleft_marginÚcanvas_widthÚcanvas_heightÚ
axes_groupÚseries_groups#                                      r"   Úto_svg_groupzChart.to_svg_groupÊ   sè  € ð Ò,œ×,Ñ,ˆØÒ/œ5×/Ñ/ˆà�|Š|ÜÐ^Ó_Ð_ä”e—l‘l¤EÔ*Ø"¤U§\¡\Ñ1ˆNäØ"Ø$Ø%Ø#ô	‰Fô ˜¤Ô$Ü˜ ¨°Ó8‰FÜ˜F¤CÔ(Ü˜&�\ˆFô —Z‘Z “_ˆ
à×Ñœ"Ÿ*™*ØÜ�!‹fÜ�!‹fÜ�e“*Ü�v“;Ü×'Ñ'ô
ô 	ô —z‘z #“ˆØ×Ñ˜¤c§m¡m°F·K±KÀÇÁÓ&LÔMà §¡¨f¯l©lÑ :Ñ;ˆØ &§*¡*¨v¯}©}Ñ"<Ñ=ˆà×Ñ˜,Ô'ô —z‘z #“ˆàˆà�;Š;Ü—J‘JØÜ�a“&Ü�a“&Ü×&Ñ&ô	ˆEð �I‰I�m¤U×%<Ñ%<Ô=Ø�I‰I�k¤3¤u×'<Ñ'<Ó#=Ô>Ü˜TŸ[™[Ó)ˆEŒJà×Ñ Ô&ØœU×9Ñ9¼E¿O¹OÑKÑKˆMô ˆt�|‰|Ó˜qÒ ¤J¨t¯|©|¸A©¸qÑ/AÄ>Õ$RÜŸ:™: c›?ˆLØ×Ñ˜[¬#¯-©-¸¸=Ó*IÔJàˆFØˆDØ—m‘m“oˆGà!%§¡ò 4‘�˜Ø.3×.AÑ.AÀ&È'Ó.Rò 
4Ñ*�J 
Ø 
Ñ*¨UÒ2Ø!"˜Ø ™	˜à ™¤e×&CÑ&CÄe×FVÑFVÑ&VÑW�AØ—N‘N ;´·±¸fÀaÓ0HÔIà˜jÑ(�Fà ×'Ñ'¨
Õ3ñ
4ð4ð !¤E×$AÑ$AÄE×DTÑDTÑ$TÑUˆMà˜]Ñ*ˆMØ×Ñ Ô-à×Ñ˜LÔ)ô —Z‘Z “_ˆ
Ø�‰�{¤C§M¡M°!°]Ó$CÔDà!ˆ
Ø# mÑ3ˆà×Ñ˜JÔ'ð ×2Ñ2´1Ó5‰ˆ�Ø×2Ñ2´1Ó5‰ˆ�à×4Ñ4°W¸hÓGˆØ×2Ñ2°7¸FÓCˆà! KÑ/ˆØ# mÑ3ˆä—Z‘Z “_ˆ
Ø�‰�{¤C§M¡M°+¸qÓ$AÔBà×Ñ˜&Ÿ-™-¨°mÀWÈhÓWÔXØ×Ñ˜&Ÿ-™-¨°mÀWÈfÓUÔVà×Ñ˜¤c§m¡m°KÀÓ&CÔDà×Ñ˜*Ô%ô —z‘z #“ˆà—-‘-“/ˆà!Ÿ\™\ò 	n‰MˆF�EØ×Ñ §¡¨\¸=È'ÐSZÐ\bÐdkÓ lÕmð	nð 	×Ñ˜,Ô'àÐr$   c                 óæ  — |xs t         j                  }|xs t         j                  }t        j                  dt        |«      t        |«      dd¬«      }| j                  ||«      }|j                  |«       t        j                  |«      }d}|r¼d}	 t        |d«      r|}d}nat        j                  j                  |«      }	|	r4t        j                  j                  |	«      st        j                  |	«       t!        |d	«      }|j#                  t        j$                  «       |j#                  |«       |r|�|j'                  «        yyyt)        |«      S # |r|�|j'                  «        w w w xY w)
aÞ  
        Render this chart to an SVG document.

        The :code:`width` and :code:`height` are specified in SVG's
        "unitless" units, however, it is usually convenient to specify them
        as though they were pixels.

        :param path:
            Filepath or file-like object to write to. If omitted then the SVG
            will be returned as a string. If running within IPython, then this
            will return a SVG object to be displayed.
        :param width:
            The output width, in SVG user units. Defaults to
            :data:`.theme.default_chart_width`.
        :param height:
            The output height, in SVG user units. Defaults to
            :data:`.theme.default_chart_height`.
        rŠ   z1.1zhttp://www.w3.org/2000/svg)rf   rz   ÚversionÚxmlnsTNÚwriteFÚw)r   Údefault_chart_widthÚdefault_chart_heightr…   r†   r‡   r³   rP   rŠ   Ú	stringifyÚhasattrÚosÚpathÚdirnameÚexistsÚmakedirsÚopenr·   ÚHEADERÚcloser   )
r    r¾   rf   rz   ÚrootÚgroupÚsvg_textrÄ   ÚfÚdirpaths
             r"   r–   zChart.to_svgU  s3  € ð& Ò2œ×2Ñ2ˆØÒ5œ5×5Ñ5ˆä�z‰zØÜ�e“*Ü�v“;ØØ.ô
ˆð ×!Ñ! %¨Ó0ˆØ�‰�EÔä—=‘= Ó&ˆØˆáØˆAðÜ˜4 Ô)Ø�AØ!‘Eä Ÿg™gŸo™o¨dÓ3�Gá¤r§w¡w§~¡~°gÔ'>ÜŸ™ GÔ,ä˜T 3›�Aà—‘œŸ
™
Ô#Ø—‘˜Ô!á˜Q˜]Ø—G‘G•Ið +�5ô ˜hÓ'Ð'øñ ˜Q˜]Ø—G‘G•Ið +�5ús   ÂB"E ÅE0r   )NNN)NNNN)NNNNN)NNNNNN)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r+   r/   r2   r:   r<   r@   rC   rI   rK   rT   r^   r`   rc   rh   rr   r³   r–   r'   r$   r"   r   r      sc   „ ñó"ò8ò ò ò=ò$	=òòó:ó:òó8
ó
ó
ó
òó8IôV9(r$   r   )"r½   rn   Úxml.etree.ElementTreeÚetreeÚElementTreer…   Úleather.svgrŠ   Úleatherr   Úleather.axisr   Úleather.data_typesr   r   Úleather.scalesr   r   r	   Úleather.seriesr
   r   Úleather.shapesr   r   r   r   Úleather.utilsr   r   r   r   r   r   r'   r$   r"   ú<module>rÙ      s>   ðÛ 	Û ß "Ð "å Ý Ý ß -ß 2Ñ 2ß 1ß 4Ó 4ß @Õ @÷(ò (r$   