
    ʯei                        d Z ddlmZ ddlmZmZ ddlZddlZ	ddl
Z	 ddlmZ 	 ej                   j#                  d       deeef   fd	Zd
eeej.                  ej0                  f   dee   fdZdeej.                  ej0                  ef   deej.                  ej0                  f   dedeej.                  ej0                  f   fdZ	 	 	 	 	 	 	 	 	 d3dede	j6                  deej.                  ef   deej0                  ef   deeej8                  ef      deeej:                  ef      deeej>                  ef      dee    dee   dee    dee    de!de!dejD                  fdZ#d4d e!ddfd!Z$d" Z%d5d#Z& e%e$d$d%&      Z' e%e$d'd(&      Z( e%e$d)d*&      Z) e%e)d+d,-      Z* e%e'dd./      Z+ e%e)dd0/      Z, e%e*dd1/      Z- e%e(dd2/      Z.y# e$ r
 ddlmZ Y w xY w# e$ r  eej$                  d      e_        Y w xY w)6z>Chart functions for Altex - a simple wrapper on top of Altair.    )partial)OptionalUnionN)NoSuchEntryPoint	streamlit)themeiterablec                     t        | t              r'| j                         D ci c]  \  }}|	|| c}}S t        | t              r| D cg c]  }||	 c}S t	        dt        |        d      c c}}w c c}w )a  Remove nones for iterable.
    If dict, drop keys when value is None
    If list, drop values when value equal None

    Args:
        iterable: Input iterable

    Raises:
        TypeError: When iterable type is not supported

    Returns:
        Input iterable without Nones
    zIterable of type z is not supported)
isinstancedictitemslist	TypeErrortype)r	   kvxs       N/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/altex/charts.py_drop_nonesr      su     (D!!)!1CAQ]1CC(D!#5aq}55
'X'77HI
JJ D5s   
A3A3A9A9paramreturnc                 D    | yt        | t              s| j                  S | S )zGet Altair shorthand from parameter, if exists.

    Args:
        param: Parameter x/y

    Returns:
        Parameter itself or shorthand when alt.X/alt.Y object
    N)r   str	shorthand)r   s    r   _get_shorthandr   +   s%     }eS!L    axisoutput_typeupdatesc                 
   t        | t        j                  t        j                  f      r5| j	                         }|j                         D ]
  \  }}|||<     |di |S t        | t              r
 |dd| i|S t        d      )a  Update x and y configs.

    Args:
        axis: Chart input for x
        output_type: Chart input for y
        updates: Dictionary of updates to apply

    Raises:
        TypeError: When input has invalid type

    Returns:
        Updated config for x/y
    r   z/Input x/y must be of type str or alt.X or alt.Y )r   altXYto_dictr   r   r   )r   r   r   axis_configkeyvalues         r   _update_axis_configr)   ;   s      $'lln!--/ 	%JC$K	%)[))$5T5W55
E
FFr   mark_functiondatar   ycoloropacitycolumnrollingtitlewidthheightsparkautoscale_yc           
         t        |      }t        |      }t        |      }t        |||g      }t        ||| |	|
d      }t        j                  di |}|8| d| d}| d}|d| dd| d	gd
t	        |      gi} |j
                  di |}|r^|j                  d	      j                  dd      }t        |t        j                  ddi      }t        |t        j                  ddi      }n|}|}|r1t        |t        j                  dt        j                  d      i      }t        ||||t        |t              rt        j                  |      n||d      } |j                  di |S )a  Create an Altair chart with a simple API.

    Supported charts include line, bar, point, area, histogram, sparkline,
    sparkbar, sparkarea.

    Args:
        mark_function: Altair mark function, example line/bar/point
        data: Dataframe to use for the chart
        x: Column for the x axis
        y: Column for the y axis
        color: Color a specific group of your data. Defaults to None.
        opacity: Change opacity of marks. Defaults to None.
        column: Groupby a specific column. Defaults to None.
        rolling: Rolling average window size. Defaults to None.
        title: Title of the chart. Defaults to None.
        width: Width of the chart. Defaults to None.
        height: Height of the chart. Defaults to None.
        spark: Whether or not to make spark chart, i.e. a chart without
            axes nor ticks nor legend. Defaults to False.
        autoscale_y: Whether or not to autoscale the y axis. Defaults to False.

    Returns:
        Altair chart
    )r+   r1   markr2   r3   Nz (z	-average)z:Qzmean()framer   groupby)strokeWidthF)griddomainr   scale)zero)r   r,   r-   tooltipr.   r/   r!   )r   r   r"   Chartr   transform_windowconfigure_viewconfigure_axisr)   r#   r$   Scaler   floatr(   encode)r*   r+   r   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   x_y_color_tooltip_configchart_configchartrolling_columntransform_configx_axisy_axisencode_configs                           r   _chartrS   U   s   N 
	B		BE"F "b&!12N!	
L II%%E4r')4b!eB4qMwh]E
|

 '&&:)9:$$$3BBu C 
 %Q~>$Q~>$VSUUWciiU>S4TU%-7-Gsyy)W	
	M 5<<(-((r   Tuse_container_widthc                 T    t        di |}d|v rd} t        j                  ||        y)zDisplay an Altair chart in Streamlit.

    Args:
        use_container_width: Whether or not the displayed chart uses all
            available width. Defaults to True.
        **kwargs: See function _chart()
    r2   F)rT   Nr!   )rS   staltair_chart)rT   kwargs	chart_objs      r   rM   rM      s1       I&#OO/r   c                  N    |j                  dd      }t        | i |}||_        |S )zAlternative to 'functools.partial' where __name__ attribute
    can be set manually, since the default partial does not create it.
    __name__foo)popr   r[   )argsrX   r[   funcs       r   _partialr`      s/     zz*e,HD#F#DDMKr   c                      t        dddi| S )zOCreate a scatter chart.

    Args:
        **kwargs: See function _chart()
    r*   pointr!   )rM   )rX   s    r   scatter_chartrc      s     1w1&11r   line
line_chart)r*   r[   area
area_chartbar	bar_chartzcount()
hist_chart)r,   r[   sparkline_chart)r4   r[   sparkbar_chartsparkhist_chartsparkarea_chart)	NNNNNNNFF)T)r   N)/__doc__	functoolsr   typingr   r   altairr"   pandaspdr   rV   altair.utils.plugin_registryr   ImportErrorentrypointsthemesenablerW   r   r   r   r   r#   r$   r   r)   	DataFrameColorr(   rF   ColumnintboolrA   rS   rM   r`   rc   re   rg   ri   rj   rk   rl   rm   rn   r!   r   r   <module>r      s   D  "   -=BJJk"
K%d
+ K*%SUUCEE 12 x}  G
suuc!
"G16suucee|1DGOSG
355#%%<G> .215/3! [)[)
,,[) SUUCZ[) SUUCZ	[)
 E#))S.)*[) eCIIu,-.[) U3::s?+,[) c][) C=[) C=[) SM[) [) [) 	YY[)|t  &2 e6LI
e6LI
U%+F	i9|D
:T<MN)4:JK:T<MN:T<MNi  -,,-
  Bboo[ABOBs"   G G! GG!HH