Ë
    úmxiéJ  ã                  ó‚  — U d dl mZ d dlmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZ d dl m!Z! er2d dl"Z"d dl#m$Z$ e"jJ                  dk\  rd d	lm&Z& nd d	l'm&Z& d d
l(m)Z) d dl*m+Z+ e,e-df   Z.de/d<   e0e,e1e.f   e,e1e.f   f   Z2de/d<   eeeeeeefeeeefeeee	feeeefeeeefe
e
eefiZ3e	 	 d	 	 	 	 	 	 	 dd„«       Z4e	 	 d	 	 	 	 	 	 	 dd„«       Z4dd„Z4dd„Z5d d„Z6	 d!	 	 	 	 	 	 	 d"d„Z7	 	 	 	 	 	 d#d„Z8d$d„Z9	 	 	 	 	 	 	 	 d%d„Z:d&d'd„Z;	 	 	 	 	 	 d(d„Z<	 d&	 	 	 	 	 	 	 	 	 d)d„Z=y)*é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚoverload)ÚChartÚConcatChartÚConcatSpecGenericSpecÚ
FacetChartÚFacetedUnitSpecÚ	FacetSpecÚHConcatChartÚHConcatSpecGenericSpecÚ
LayerChartÚ	LayerSpecÚNonNormalizedSpecÚTopLevelConcatSpecÚTopLevelFacetSpecÚTopLevelHConcatSpecÚTopLevelLayerSpecÚTopLevelUnitSpecÚTopLevelVConcatSpecÚUnitSpecÚUnitSpecWithFrameÚVConcatChartÚVConcatSpecGenericSpecÚdata_transformers)Úget_inline_tablesÚimport_vegafusion)Ú	UndefinedN)ÚIterable)é   é
   )Ú	TypeAlias)Ú	ChartType)ÚDataFrameLike.r#   ÚScopeÚFacetMappingc                 ó   — y ©N© ©ÚchartÚ	row_limitÚexcludes      úU/home/htdocs/ttos/venv/lib/python3.12/site-packages/altair/utils/_transformed_data.pyÚtransformed_datar0   C   s   € ð
 ó    c                 ó   — y r)   r*   r+   s      r/   r0   r0   K   s   € ð
 r1   c                ó`  — t        «       }t        | t        «      r#| j                  t        k(  r| j                  «       } | j                  d¬«      } t        | d|¬«      }t        j                  d«      5  | j                  dddi¬	«      }t        |«      }d
d
d
«       t        «      }t        |||«      }g }	|D ]'  }
|
|v r|	j                  ||
   «       Œd}t        |«      ‚ |j                   j#                  ||	|¬«      \  }}t        | t        t$        f«      r|sy
|d   S |S # 1 sw Y   Œ‘xY w)aý  
    Evaluate a Chart's transforms.

    Evaluate the data transforms associated with a Chart and return the
    transformed data as one or more DataFrames

    Parameters
    ----------
    chart : Chart, FacetChart, LayerChart, HConcatChart, VConcatChart, or ConcatChart
        Altair chart to evaluate transforms on
    row_limit : int (optional)
        Maximum number of rows to return for each DataFrame. None (default) for unlimited
    exclude : iterable of str
        Set of the names of charts to exclude

    Returns
    -------
    DataFrame or list of DataFrames or None
        If input chart is a Chart or Facet Chart, returns a DataFrame of the
        transformed data. Otherwise, returns a list of DataFrames of the
        transformed data
    T)Údeepr   )r.   Ú
vegafusionÚvegaÚpre_transformF)ÚformatÚcontextNzFailed to locate all datasets)r-   Úinline_datasets)r   Ú
isinstancer   Úmarkr   Ú
mark_pointÚcopyÚ
name_viewsr   ÚenableÚto_dictr   Úget_facet_mappingÚget_datasets_for_view_namesÚappendÚ
ValueErrorÚruntimeÚpre_transform_datasetsr
   )r,   r-   r.   ÚvfÚchart_namesÚ	vega_specr:   Úfacet_mappingÚdataset_mappingÚdataset_namesÚ
chart_nameÚmsgÚdatasetsÚ_s                 r/   r0   r0   S   sE  € ô. 
Ó	€Bä�%œÔ E§J¡J´)Ò$;Ø× Ñ Ó"ˆð �J‰J˜DˆJÓ!€Eô ˜U A¨wÔ7€Kô 
×	!Ñ	! ,Ó	/ñ 7Ø—M‘M¨¸/È5Ð9Q�MÓRˆ	Ü+¨IÓ6ˆ÷7ô
 & iÓ0€MÜ1°)¸[È-ÓX€Oð €MØ!ò "ˆ
Ø˜Ñ(Ø× Ñ  °Ñ!<Õ=à1ˆCÜ˜S“/Ð!ð"ð —*‘*×3Ñ3ØØØØ'ð	 4ó �K€Hˆaô �%œ%¤Ð,Ô-áØà˜A‘;Ðð ˆ÷E7ð 7ús   Á3!D$Ä$D-c                ón  — | j                   dt        hv r¡t        | d«      r| j                  «       | _         y| j                  j
                  j                  «       }|j                  dd«      j                  dd«      j                  dd«      }|j                  d«      }d|› dt        | «      d	›�| _         yy)
z0Assign a name to a chart if it doesn't have one.NÚ_get_view_hash_nameÚspecÚ ÚgenericÚconcatrQ   Úview_Úx)
Únamer   ÚhasattrrS   Ú	__class__Ú__name__ÚlowerÚreplaceÚremovesuffixÚid)r,   Ú
chart_types     r/   Ú_assign_chart_namerc   ¦   s¨   € à‡z�z�dœIÐ&Ñ&ä�5Ð/Ô0Ø×2Ñ2Ó4ˆE�Jð Ÿ™×1Ñ1×7Ñ7Ó9ˆJð ×"Ñ" 6¨2Ó.ß‘˜ BÓ'ß‘˜ 2Ó&ð ð
 $×0Ñ0°Ó5ˆJà   ¨A¬b°«i¸¨]Ð;ˆE�Jð! 'r1   c                óL  — t        | t        t           «      r| j                  S t        | t        t           «      r| j
                  S t        | t        t           «      r| j                  S t        | t        t           «      r| j                  S dt        | «      › �}t        |«      ‚)z(Get the subcharts for a composite chart.zŠtransformed_data accepts an instance of Chart, FacetChart, LayerChart, HConcatChart, VConcatChart, or ConcatChart
Received value of type: )r;   Ú_chart_class_mappingr   Úlayerr   Úhconcatr   Úvconcatr   rW   ÚtyperE   )r,   rO   s     r/   Ú_get_subchartsrj   »   sŽ   € ä�%Ô-¬jÑ9Ô:Ø�{‰{ÐÜ	�EÔ/´Ñ=Ô	>Ø�}‰}ÐÜ	�EÔ/´Ñ=Ô	>Ø�}‰}ÐÜ	�EÔ/´Ñ<Ô	=Ø�|‰|Ðð'ä'+¨E£{ mð5ð 	ô
 ˜‹oÐr1   c                óT  — |�t        |«      n	t        «       }t        | t        t           t        t           f«      r(| j
                  |vrt        | «       | j
                  gS g S t        | «      }g }|D ]2  }t        ||t        |«      z   |¬«      D ]  }|j                  |«       Œ Œ4 |S )aM  
    Name unnamed chart views.

    Name unnamed charts views so that we can look them up later in
    the compiled Vega spec.

    Note: This function mutates the input chart by applying names to
    unnamed views.

    Parameters
    ----------
    chart : Chart, FacetChart, LayerChart, HConcatChart, VConcatChart, or ConcatChart
        Altair chart to apply names to
    i : int (default 0)
        Starting chart index
    exclude : iterable of str
        Names of charts to exclude

    Returns
    -------
    list of str
        List of the names of the charts and subcharts
    )Úir.   )Úsetr;   re   r   r
   rZ   rc   rj   r?   ÚlenrD   )r,   rl   r.   Ú	subchartsrI   ÚsubchartrZ   s          r/   r?   r?   Î   sµ   € ð4 &Ð1Œc�'Œl´s³u€Gô ØÔ$¤UÑ+Ô-AÄ*Ñ-MÐNôð �:‰:˜WÑ$Ü˜uÔ%Ø—J‘J�<ÐØˆ	ô ˜uÓ%€IØ€KØò %ˆÜ˜x¨1¬s°;Ó/?Ñ+?ÈÔQò 	%ˆDØ×Ñ˜tÕ$ñ	%ð%ð Ðr1   c                ó    — | }|D ]F  }d}d}|j                  dg «      D ]%  }|j                  d«      dk(  sŒ||k(  r|} n|dz  }Œ' |€ y|}ŒH |S )aF  
    Get the group mark at a particular scope.

    Parameters
    ----------
    vega_spec : dict
        Top-level Vega specification dictionary
    scope : tuple of int
        Scope tuple. If empty, the original Vega specification is returned.
        Otherwise, the nested group mark at the scope specified is returned.

    Returns
    -------
    dict or None
        Top-level Vega spec (if scope is empty)
        or group mark (if scope is non-empty)
        or None (if group mark at scope does not exist)

    Examples
    --------
    >>> spec = {
    ...     "marks": [
    ...         {"type": "group", "marks": [{"type": "symbol"}]},
    ...         {"type": "group", "marks": [{"type": "rect"}]},
    ...     ]
    ... }
    >>> get_group_mark_for_scope(spec, (1,))
    {'type': 'group', 'marks': [{'type': 'rect'}]}
    r   NÚmarksri   Úgroupé   )Úget)rJ   Úscopers   Úscope_valueÚgroup_indexÚchild_groupr<   s          r/   Úget_group_mark_for_scoperz   ü   s�   € ð@ €Eð ò ˆØˆØˆØ—I‘I˜g rÓ*ò 	!ˆDØ�x‰x˜Ó 7Ó*Ø +Ò-Ø"&�KÙØ˜qÑ ‘ð	!ð ÐÙØ‰ðð €Lr1   c                ó
  — t        | |«      xs i }g }|j                  dg «      D ]  }|j                  |d   «       Œ |j                  di «      j                  di «      j                  dd«      }|r|j                  |«       |S )aM  
    Get the names of the datasets that are defined at a given scope.

    Parameters
    ----------
    vega_spec : dict
        Top-level Vega specification
    scope : tuple of int
        Scope tuple. If empty, the names of top-level datasets are returned
        Otherwise, the names of the datasets defined in the nested group mark
        at the specified scope are returned.

    Returns
    -------
    list of str
        List of the names of the datasets defined at the specified scope

    Examples
    --------
    >>> spec = {
    ...     "data": [{"name": "data1"}],
    ...     "marks": [
    ...         {
    ...             "type": "group",
    ...             "data": [{"name": "data2"}],
    ...             "marks": [{"type": "symbol"}],
    ...         },
    ...         {
    ...             "type": "group",
    ...             "data": [
    ...                 {"name": "data3"},
    ...                 {"name": "data4"},
    ...             ],
    ...             "marks": [{"type": "rect"}],
    ...         },
    ...     ],
    ... }

    >>> get_datasets_for_scope(spec, ())
    ['data1']

    >>> get_datasets_for_scope(spec, (0,))
    ['data2']

    >>> get_datasets_for_scope(spec, (1,))
    ['data3', 'data4']

    Returns empty when no group mark exists at scope
    >>> get_datasets_for_scope(spec, (1, 3))
    []
    ÚdatarZ   ÚfromÚfacetN)rz   ru   rD   )rJ   rv   rs   rP   ÚdatasetÚfacet_datasets         r/   Úget_datasets_for_scoper�   /  s‡   € ôh % Y°Ó6Ò<¸"€Eð €HØ—9‘9˜V RÓ(ò )ˆØ�‰˜ ™Õ(ð)ð —I‘I˜f bÓ)×-Ñ-¨g°rÓ:×>Ñ>¸vÀtÓL€MÙØ�‰˜Ô&Ø€Or1   c                ó€   — t        t        t        |«      dz   «      «      D ]  }|d| }t        | |«      }||v sŒ|c S  y)aR  
    Return the scope that a dataset is defined at, for a given usage scope.

    Parameters
    ----------
    vega_spec: dict
        Top-level Vega specification
    data_name: str
        The name of a dataset reference
    usage_scope: tuple of int
        The scope that the dataset is referenced in

    Returns
    -------
    tuple of int
        The scope where the referenced dataset is defined,
        or None if no such dataset is found

    Examples
    --------
    >>> spec = {
    ...     "data": [{"name": "data1"}],
    ...     "marks": [
    ...         {
    ...             "type": "group",
    ...             "data": [{"name": "data2"}],
    ...             "marks": [
    ...                 {
    ...                     "type": "symbol",
    ...                     "encode": {
    ...                         "update": {
    ...                             "x": {"field": "x", "data": "data1"},
    ...                             "y": {"field": "y", "data": "data2"},
    ...                         }
    ...                     },
    ...                 }
    ...             ],
    ...         }
    ...     ],
    ... }

    data1 is referenced at scope [0] and defined at scope []
    >>> get_definition_scope_for_data_reference(spec, "data1", (0,))
    ()

    data2 is referenced at scope [0] and defined at scope [0]
    >>> get_definition_scope_for_data_reference(spec, "data2", (0,))
    (0,)

    If data2 is not visible at scope [] (the top level),
    because it's defined in scope [0]
    >>> repr(get_definition_scope_for_data_reference(spec, "data2", ()))
    'None'
    rt   N)ÚreversedÚrangern   r�   )rJ   Ú	data_nameÚusage_scoperl   rv   rP   s         r/   Ú'get_definition_scope_for_data_referencer‡   q  sQ   € ôr ”eœC Ó,¨qÑ0Ó1Ó2ò ˆØ˜B˜Q�ˆÜ)¨)°UÓ;ˆØ˜Ò ØŠLð	ð
 r1   c                ó¤  — i }d}t        | |«      xs i }|j                  dg «      D ]¦  }|j                  dd«      dk(  sŒg |¢|‘­}|j                  di «      j                  dd«      }|�@|j                  dd«      }|j                  d	d«      }	|�|	�t        | |	|«      }
|
�	|	|
f|||f<   t        | |¬
«      }|j	                  |«       |dz  }Œ¨ |S )a‡  
    Create mapping from facet definitions to source datasets.

    Parameters
    ----------
    group : dict
        Top-level Vega spec or nested group mark
    scope : tuple of int
        Scope of the group dictionary within a top-level Vega spec

    Returns
    -------
    dict
        Dictionary from (facet_name, facet_scope) to (dataset_name, dataset_scope)

    Examples
    --------
    >>> spec = {
    ...     "data": [{"name": "data1"}],
    ...     "marks": [
    ...         {
    ...             "type": "group",
    ...             "from": {
    ...                 "facet": {
    ...                     "name": "facet1",
    ...                     "data": "data1",
    ...                     "groupby": ["colA"],
    ...                 }
    ...             },
    ...         }
    ...     ],
    ... }
    >>> get_facet_mapping(spec)
    {('facet1', (0,)): ('data1', ())}
    r   rr   ri   Nrs   r}   r~   rZ   r|   ©rv   rt   )rz   ru   r‡   rB   Úupdate)rs   rv   rK   rx   Ú
mark_groupr<   Úgroup_scoper~   Ú
facet_nameÚ
facet_dataÚdefinition_scopeÚchild_mappings               r/   rB   rB   ²  s
  € ðH €MØ€KÜ)¨%°Ó7Ò=¸2€JØ—‘˜w¨Ó+ò ˆØ�8‰8�F˜DÓ! WÓ,à/˜EÐ/ ;Ñ/ˆKØ—H‘H˜V RÓ(×,Ñ,¨W°dÓ;ˆEØÐ Ø"ŸY™Y v¨tÓ4�
Ø"ŸY™Y v¨tÓ4�
ØÐ)¨jÐ.DÜ'NØ˜z¨5ó(Ð$ð (Ð3à&Ø,ðB˜ j°+Ð&=Ñ>ô .¨e¸;ÔGˆMØ× Ñ  Ô/Ø˜1Ñ‰Kð+ð. Ðr1   c                ó"   — | |v r
||    } | |v rŒ
| S )aÌ  
    Apply facet mapping to a scoped dataset.

    Parameters
    ----------
    scoped_dataset : (str, tuple of int)
        A dataset name and scope tuple
    facet_mapping : dict from (str, tuple of int) to (str, tuple of int)
        The facet mapping produced by get_facet_mapping

    Returns
    -------
    (str, tuple of int)
        Dataset name and scope tuple that has been mapped as many times as possible

    Examples
    --------
    Facet mapping as produced by get_facet_mapping
    >>> facet_mapping = {
    ...     ("facet1", (0,)): ("data1", ()),
    ...     ("facet2", (0, 1)): ("facet1", (0,)),
    ... }
    >>> get_from_facet_mapping(("facet2", (0, 1)), facet_mapping)
    ('data1', ())
    r*   )Úscoped_datasetrK   s     r/   Úget_from_facet_mappingr“   ó  s&   € ð8 ˜MÑ
)Ø& ~Ñ6ˆð ˜MÒ
)àÐr1   c                óâ  — i }d}t        | |«      xs i }|j                  dg «      D �]D  }|D ]a  }|j                  dd«      |› d�k(  sŒ|j                  di «      j                  dd«      j                  d	d«      }	|	|f}
t        |
|«      ||<    n |j                  dd«      }|j                  d
d«      dk(  rDt        | ||g |¢|‘­¬«      }|j	                  «       D ]  \  }}|j                  ||«       Œ |dz  }ŒÕ|D ]k  }|j                  |«      sŒ|j                  d«      sŒ'|j                  di «      j                  d	d«      }	t        | |	|«      }|€ŒYt        |	|f|«      ||<    �ŒD �ŒG |S )aH  
    Get the Vega datasets that correspond to the provided Altair view names.

    Parameters
    ----------
    group : dict
        Top-level Vega spec or nested group mark
    vl_chart_names : list of str
        List of the Vega-Lite
    facet_mapping : dict from (str, tuple of int) to (str, tuple of int)
        The facet mapping produced by get_facet_mapping
    scope : tuple of int
        Scope of the group dictionary within a top-level Vega spec

    Returns
    -------
    dict from str to (str, tuple of int)
        Dict from Altair view names to scoped datasets
    r   rr   rZ   rU   Ú_cellr}   r~   Nr|   ri   rs   r‰   rt   Ú_marks)	rz   ru   r“   rC   ÚitemsÚ
setdefaultÚ
startswithÚendswithr‡   )rs   Úvl_chart_namesrK   rv   rP   rx   r‹   r<   Úvl_chart_namer…   Úscoped_data_namerZ   Úgroup_data_namesÚkÚvÚscoped_datas                   r/   rC   rC     s®  € ð2 €HØ€KÜ)¨%°Ó7Ò=¸2€JØ—‘˜w¨Ó+ó ˆØ+ò 	ˆMØ�x‰x˜ Ó#¨-¨¸Ð'>Ó>Ø ŸH™H V¨RÓ0×4Ñ4°W¸dÓC×GÑGÈÐPTÓU�	Ø$-¨uÐ#5Ð Ü*@Ø$ mó+�˜Ñ'ñ ð	ð �x‰x˜ Ó#ˆØ�8‰8�F˜BÓ 7Ò*Ü:Ø�~ }Ð<Q¸eÐ<QÀ[Ñ<Qô Ðð )×.Ñ.Ó0ò *‘��1Ø×#Ñ# A qÕ)ð*à˜1Ñ‰Kà!/ò 
�Ø—?‘? =Õ1°d·m±mÀHÕ6MØ $§¡¨°Ó 4× 8Ñ 8¸ÀÓ F�IÜ"IØ˜y¨%ó#�Kð #Ñ.Ü2HØ&¨Ð4°mó3˜ Ñ/ò ò
ð'ð> €Or1   )NN)r,   zChart | FacetChartr-   ú
int | Noner.   úIterable[str] | NoneÚreturnzDataFrameLike | None)r,   z6LayerChart | HConcatChart | VConcatChart | ConcatChartr-   r¢   r.   r£   r¤   zlist[DataFrameLike])r,   r$   r¤   ÚNone)r,   r$   r¤   z	list[Any])r   N)r,   r$   rl   Úintr.   r£   r¤   ú	list[str])rJ   údict[str, Any]rv   r&   r¤   zdict[str, Any] | None)rJ   r¨   rv   r&   r¤   r§   )rJ   r¨   r…   Ústrr†   r&   r¤   zScope | None)r*   )rs   r¨   rv   r&   r¤   r'   )r’   útuple[str, Scope]rK   r'   r¤   rª   )
rs   r¨   r›   r§   rK   r'   rv   r&   r¤   zdict[str, tuple[str, Scope]])>Ú
__future__r   Útypingr   r   r   Úaltairr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Úaltair.utils._vegafusion_datar   r   Úaltair.utils.schemapir   ÚsysÚcollections.abcr    Úversion_infor#   Útyping_extensionsÚaltair.typingr$   Úaltair.utils.corer%   Útupler¦   r&   Ú__annotations__Údictr©   r'   re   r0   rc   rj   r?   rz   r�   r‡   rB   r“   rC   r*   r1   r/   ú<module>r¹      s^  ðÞ "ç /Ñ /÷÷ ÷ ÷ ÷ ÷ ÷0 OÝ +áÛÝ(à
×Ñ˜7Ò"Þ$å/å'Ý/à˜˜c˜‘?€€yÓ "Ø˜u S¨% ZÑ0°%¸¸U¸
Ñ2CÐCÑD€ˆiÓ Dð 
ØØØØØØðð �Ð.°	Ð:Ø�+Ð1Ð3HÐIØ�<Ð!4Ð6LÐMØ�<Ð!4Ð6LÐMØ�Ð.°	Ð:ðÐ ð" 
ð !Ø$(ðØðàðð "ðð ò	ó 
ðð 
ð !Ø$(ðØAðàðð "ðð ò	ó 
ðóFóf<ó*ð( CGð+Øð+Øð+Ø+?ð+àó+ð\0Øð0Ø&+ð0àó0óf?ðD>Øð>Ø*-ð>Ø<Að>àó>ôB>ðBØ%ðØ6BðàóðJ ð	;Øð;àð;ð  ð;ð ð	;ð
 "ô;r1   