
    #Yh`G                    ,   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r.d dl"Z"d dl#m$Z$ e"j%        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	 	 d7d8d            Z4e	 	 d7d9d            Z4d7dZ4	 d:d;d!Z5d<d&Z6d=d'Z7d>d,Z8d?d@d/Z9dAd3Z:	 d?dBd6Z;dS )C    )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FacetMappingchartChart | FacetChart	row_limit
int | NoneexcludeIterable[str] | NonereturnDataFrameLike | Nonec                    d S N r(   r*   r,   s      fD:\DownLoads\facial_attendance_system-main\venv311\Lib\site-packages\altair/utils/_transformed_data.pytransformed_datar5   C   s	    
 3    6LayerChart | HConcatChart | VConcatChart | ConcatChartlist[DataFrameLike]c                    d S r1   r2   r3   s      r4   r5   r5   K   s	    
 #r6   c                   t                      }t          | t                    r$| j        t          k    r|                                 } |                     d          } t          | d|          }t          j	        d          5  | 
                    dddi	          }t          |          }d
d
d
           n# 1 swxY w Y   t          |          }t          |||          }g }	|D ]2}
|
|v r|	                    ||
                    "d}t          |          |j                            ||	||          \  }}t          | t          t$          f          r|sd
S |d         S |S )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_specrA   facet_mappingdataset_mappingdataset_names
chart_namemsgdatasets_s                 r4   r5   r5   S   s   . 
		B% #EJ)$;$;  "" JJDJ!!E UAw777K 
	!,	/	/ 7 7MM/59QMRR	+I667 7 7 7 7 7 7 7 7 7 7 7 7 7 7
 &i00M1)[-XXO M! " "
((  !<====1CS//! *33'	 4  KHa %%,--  	4A; s   )B99B= B=r$   iint	list[str]c                "   |t          |          nt                      }t          | t          t                   t          t                   f          r;| j        |vr0| j        dt          hv rt          j                    | _        | j        gS g S t          | t          t                             r| j	        }nt          | t          t                             r| j        }nqt          | t          t                             r| j        }nIt          | t          t                             r| j        }n!dt!          |            }t#          |          g }|D ]<}t%          ||t'          |          z   |          D ]}|                    |           =|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
    Nztransformed_data accepts an instance of Chart, FacetChart, LayerChart, HConcatChart, VConcatChart, or ConcatChart
Received value of type: )rY   r,   )setrB   _chart_class_mappingr   r
   namer   	_get_namer   layerr   hconcatr   vconcatr   concattyperL   rF   lenrK   )r(   rY   r,   	subchartsrV   rP   subchartr_   s           r4   rF   rF      s   4 &1c'lllsuuG$U+-A*-MN    :W$$zdI..."_..
J<I e1*=>> 	"II3LABB 	"II3LABB 
	"II3K@AA 	"II9+/;;9 9 
 S//!!#! 	) 	)H"8q3{3C3C/CWUUU ) )""4(((()r6   rQ   dict[str, Any]scopedict[str, Any] | Nonec                    | }|D ]N}d}d}|                     dg           D ]*}|                     d          dk    r||k    r|} n|dz  }+| dS |}O|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marksre   group   )get)rQ   rj   rn   scope_valuegroup_indexchild_grouprC   s          r4   get_group_mark_for_scopert      s    @ E   IIgr** 	! 	!Dxx7**+--"&KEq 44Lr6   c                @   t          | |          pi }g }|                    dg           D ]}|                    |d                    |                    di                               di                               dd          }|r|                    |           |S )aL  
    Get the names of the datasets that are defined at a given scope.

    Parameters
    ----------
    vega_spec : dict
        Top-leve 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))
    []
    datar_   fromfacetN)rt   rp   rK   )rQ   rj   rn   rW   datasetfacet_datasets         r4   get_datasets_for_scoper{     s    h %Y66<"E H99VR(( ) )(((( IIfb))--gr::>>vtLLM '&&&Or6   	data_namestrusage_scopeScope | Nonec                    t          t          t          |          dz                       D ]$}|d|         }t          | |          }||v r|c S %dS )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'
    ro   N)reversedrangerf   r{   )rQ   r|   r~   rY   rj   rW   s         r4   'get_definition_scope_for_data_referencer   Y  sk    r eC,,q01122  BQB))U;;  LLL !4r6   r2   rn   c                   i }d}t          | |          pi }|                    dg           D ]}|                    dd          dk    rg ||R }|                    di                               dd          }|L|                    dd          }|                    d	d          }	||	t          | |	|          }
|
	|	|
f|||f<   t          | |
          }|                    |           |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   rm   re   Nrn   rw   rx   r_   rv   rj   ro   )rt   rp   r   rI   update)rn   rj   rR   rr   
mark_grouprC   group_scoperx   
facet_name
facet_datadefinition_scopechild_mappings               r4   rI   rI     s5   H MK)%77=2Jw++  88FD!!W,,/E/;//KHHVR((,,Wd;;E "YYvt44
"YYvt44
)j.D'Nz5( ($ (3&,Bj+&=> .e;GGGM  ///1Kr6   scoped_datasettuple[str, Scope]rR   c                &    | |v r||          } | |v | 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', ())
    r2   )r   rR   s     r4   get_from_facet_mappingr     s,    8 M
)
)&~6 M
)
)r6   vl_chart_namesdict[str, tuple[str, Scope]]c                \   i }d}t          | |          pi }|                    dg           D ]}}|D ]v}|                    dd          | dk    rW|                    di                               dd                              d	d          }	|	|f}
t          |
|          ||<    nw|                    dd          }|                    d
d          dk    rNt          | ||g ||R           }|                                D ]\  }}|                    ||           |dz  }|D ]}|                    |          ri|                    d          rT|                    di                               d	d          }	t          | |	|          }|t          |	|f|          ||<    n|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   rm   r_    _cellrw   rx   Nrv   re   rn   r   ro   _marks)	rt   rp   r   rJ   items
setdefault
startswithendswithr   )rn   r   rR   rj   rW   rr   r   rC   vl_chart_namer|   scoped_data_namer_   group_data_nameskvscoped_datas                   r4   rJ   rJ     s   2 HK)%77=2Jw++  + 	 	Mxx##-'>'>'>>> HHVR0044WdCCGGPTUU	$-u#5 *@$m+ +'  ? xx##88FB7**:~}<Qe<Q[<Q<Q      )..00 * *1##Aq))))1KK!/ 
 
??=11 	dmmH6M6M 	 $ 4 4 8 8 F FI"Iy%# #K #.2H&4m3 3/ Or6   )NN)r(   r)   r*   r+   r,   r-   r.   r/   )r(   r7   r*   r+   r,   r-   r.   r8   )r   N)r(   r$   rY   rZ   r,   r-   r.   r[   )rQ   ri   rj   r&   r.   rk   )rQ   ri   rj   r&   r.   r[   )rQ   ri   r|   r}   r~   r&   r.   r   )r2   )rn   ri   rj   r&   r.   r'   )r   r   rR   r'   r.   r   )
rn   ri   r   r[   rR   r'   rj   r&   r.   r   )<
__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%   tuplerZ   r&   __annotations__dictr}   r'   r^   r5   rF   rt   r{   r   rI   r   rJ   r2   r6   r4   <module>r      s   " " " " " " " / / / / / / / / / /                                               0 O N N N N N N N + + + + + + 
0JJJ((((((
7""$$$$$$$//////''''''//////c? " " " "uS%Z0%U
2CCD D D D D 
 .	:+13HI<!46LM<!46LM.	: " 
 !$(    
 
 !$(    
F F F Fh CG; ; ; ; ;|0 0 0 0f? ? ? ?D> > > >B> > > > >B   J 	; ; ; ; ; ; ;r6   