o
    d                     @   s   d dl mZ d dlmZ d dlZd dlmZmZ d dlm	Z
 d dlmZ d dlmZ edZg dZdd	 Zd
d Z						dddZ					dddZ					dddZ															dddZdS )    )absolute_import)NumberN)
exceptionsoptional_imports)utilspandas)TaskStartFinishc                 C   s   | ||| g||||gfS )z
    Returns the corner points of a scatter rectangle

    :param x0: x-start
    :param y0: y-lower
    :param x1: x-end
    :param y1: y-upper
    :return: ([x], [y]), tuple of lists containing the x and y values
     )x0y0x1y1r   r   a/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/plotly/figure_factory/_gantt.py_get_corner_points   s   r   c                 C   s   t rCt| t jjjrCtD ]}|| vrtdd	tqt
| j}g }t|D ]}i }| D ]}| j| | ||< q/|| q)|S t| tsMtdt
| dkrXtdt| d tsdtd| S )z2
    Validates the inputted dataframe or list
    zBThe columns in your dataframe must include the following keys: {0}z, z<You must input either a dataframe or a list of dictionaries.r   z<Your list is empty. It must contain at least one dictionary.z)Your list must only include dictionaries.)pd
isinstancecoreframe	DataFrameREQUIRED_GANTT_KEYSr   PlotlyErrorformatjoinlenindexrangeilocappendlistdict)dfkeynum_of_rowschartr   	task_dictr   r   r   validate_gantt   s6   


r'   FTc                    sd  |du rg }|	du rg }	|
du rg }
t t| D ](}t| | d | | d | | d d}d| | v r;| | d |d< || qt t  |rLd}nd	}g g d
d|d}g g dg tddddddd}t t|D ]}|| d }|ry||	vr~|	| qk|r|	  d}t t|D ].}|| d }|| d= |}|r|	|}|| || d< || || d< |t|krd}|| || d< || d }|vrt||< || d< t|| d< || d< t| d dkr| d | d d  | d d t	|| d || d || d || d \}}| d  |7  < | d  |7  < | vrSt| |< | | d d< | | d<  | d || d   | d || d   | d |  | d | d|| v r | d || d   | d || d  || d= n | d d  | d d |d7 }q|}t||||g d t||	t
t t|	dt|	d gddd!t|dtt
td"d#d$d%d&tdd'd(d%d&td)d*d(d%d&tdd+d,d-d&tdd.d,d%d&td/d0gd1d2d3d4}fd5d6tD }
|
 fd7d6t D 7 }
tj|
|d8}|S )9z/
    Refer to create_gantt() for docstring
    Nr	   r
   r   r   r   nameDescriptiondescriptionr)   skipnonetoself)xymodefill	hoverinfomarkers    r   colorsizeopacityFr/   r0   r1   textmarkerr)   
showlegendr   r   	fillcolorlegendgroupr/   r0   r   r   r=   r8   r<   closestshowgridticktexttickvalsr   	autorangezeroline   1wdaybackwardcountlabelstepstepmode1mmonth   6mYTDyeartodate1yallrP   buttonsdaterD   rH   rangeselectortypetitler>   heightwidthshapes	hovermodeyaxisxaxisc                       g | ]} | qS r   r   .0kscatter_data_dictr   r   
<listcomp>       zgantt.<locals>.<listcomp>c                    rj   r   r   rk   marker_data_dictr   r   rp      rq   datalayout)r   r   r!   r   reverser   copydeepcopystrr   r    sortedgoFigure)r%   colorsrc   	bar_width
showgrid_x
showgrid_yrd   re   tasks
task_namesru   group_tasksshow_hover_fillshow_colorbarr   taskr3   scatter_data_templatemarker_data_templatetncolor_indexgroupIDcolor_idxsysr>   rv   figr   rs   ro   r   ganttF   s   


	








"r   c           &         s  |
du rg }
|du rg }|du rg }d}t t| D ](}t| | d | | d | | d d}d| | v r=| | d |d< |
| qt t  |rNd	}nd
}g g ddd|dd}g g dg tdddddddd}g }t t|
D ]}| | | |vr|| | |  qr|  t| d | tr>t|dk rtdt t|
D ]}|
| d	 }|r||vr|| q|r|	  t t|
D ]Q}|
| d	 }|
| d	= |}|r|
|}|| |
| d< || |
| d< t|tj}|d }|d }| | | d }t|||}t|tj}||
| d< |
| d }|vr)t||< || d< t| | | | d	< || d< t|tj}t| d dkrk| d | d d  | d d t|
| d |
| d |
| d |
| d \}}| d  |7  < | d  |7  < | vrt| |< | | d  d!< | | d<  | d |
| d   | d |
| d   | d |  | d | d|
| v r | d" |
| d   | d" |
| d  |
| d= qň | d" d  | d" d q|d#u r>t  d }  |  d  td|d gd|d ggd#d$dd% t| d | trg }t t|
D ]}| | | |vrd|| | |  qP|  t|t|k rxtd&i }!d}"|D ]}#|"t|d krd}"||" |!|#< |"d7 }"q~t t|
D ]}|
| d	 }|r||vr|| q|r|	  t t|
D ]5}|
| d	 }|
| d	= |}|r|
|}|| |
| d< || |
| d< |!| | |  |
| d< |
| d }|vrt||< || d< || d< t| | | | d	< t|tj}t| d dkrI| d | d d  | d d t|
| d |
| d |
| d |
| d \}}| d  |7  < | d  |7  < | vrt| |< | | d  d!< | | d<  | d |
| d   | d |
| d   | d |  | d | d|
| v r | d" |
| d   | d" |
| d  |
| d= q | d" d  | d" d q|d#u rd#}D ]	} ||  d'< qt||||	g d(t||tt t|dt|d gddd)t|dtttd*d+d,d-d.tdd/d0d-d.td1d2d0d-d.tdd3d4d5d.tdd6d4d-d.td7d8gd9d:d;d<}$fd=d>tD }| fd?d>t D 7 }tj||$d@}%|%S )A=
    Refer to FigureFactory.create_gantt() for docstring
    NFr	   r
   r   r(   r*   r+   r)   r,   r-   r.   r5   )r/   r0   r1   r2   r>   r3   r@   r4   r6   r   r7   )r/   r0   r1   r<   r=   r)   r>   r@      zYou must use at least 2 colors in 'colors' if you are using a colorscale. However only the first two colors given will be used for the lower and upper bounds on the colormap.r   r   g      Y@r?   r@   r/   rA   r0   r   r   r=   r8   r<   Td   )
colorscale	showscalecmaxcminztError. The number of colors in 'colors' must be no less than the number of unique index values in your group column.r>   rB   rC   rI   rJ   rK   rL   rM   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r^   r_   rb   c                    rj   r   r   rk   rn   r   r   rp   M  rq   z$gantt_colorscale.<locals>.<listcomp>c                    rj   r   r   rk   rr   r   r   rp   N  rq   rt   )r   r   r!   r   sortr   r   r   r   rw   r   clrscolor_parserunlabel_rgbfind_intermediate_color	label_rgbrx   ry   rz   r   r    keysupdater{   r|   r}   )&r%   r~   rc   	index_colr   r   r   r   rd   re   r   r   ru   r   r   r>   r   r   r3   r   r   
index_valsrowr   r   lowcolor	highcolorintermedintermed_colorr   r   r   rm   index_vals_dictc_indexr#   rv   r   r   r   r   gantt_colorscale  s  












	









"r   c                     s  |
du rg }
|du rg }|du rg }d}t t| D ](}t| | d | | d | | d d}d| | v r=| | d |d< |
| qt t  |rNd	}nd
}g g dd|dd}g g dg tddddddd}g }t t|
D ]}| | | |vr|| | |  qp|  |D ]}||vrtdqt t|
D ]}|
| d	 }|r||vr|| q|r|  t t|
D ]}|
| d	 }|
| d	= |}|r||}|| |
| d< || |
| d< || | |  |
| d< |
| d }|vrt	
||< || d< || d< t| d dkr0| d | d d  | d d t|
| d |
| d |
| d |
| d \}}| d  |7  < | d  |7  < | vrwt	
| |< | | d d< | | d<  | d |
| d   | d |
| d   | d |  | d | d|
| v rʈ | d  |
| d   | d  |
| d  |
| d= q | d  d  | d  d q|d!u rd!}|D ]}t|||  d	< qt||||	g d"t||tt t|dt|d gddd#t|dtttd$d%d&d'd(tdd)d*d'd(td+d,d*d'd(tdd-d.d/d(tdd0d.d'd(td1d2gd3d4d5d6}fd7d8tD }| fd9d8t D 7 }tj||d:}|S );r   NFr	   r
   r   r(   r*   r+   r)   r,   r-   r.   r5   )r/   r0   r1   r2   r3   r@   r4   r6   r   r7   r;   zdIf you are using colors as a dictionary, all of its keys must be all the values in the index column.r   r   r?   r@   r/   rA   r0   r   r   r=   r8   r<   TrB   rC   rI   rJ   rK   rL   rM   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r^   r_   rb   c                    rj   r   r   rk   rn   r   r   rp     rq   zgantt_dict.<locals>.<listcomp>c                    rj   r   r   rk   rr   r   r   rp     rq   rt   )r   r   r!   r   r   r   r   rw   r   rx   ry   r   rz   r    r{   r|   r}   ) r%   r~   rc   r   r   r   r   r   rd   re   r   r   ru   r   r   r>   r   r   r3   r   r   r   r   r#   r   r   r   r   r   index_valuerv   r   r   r   r   
gantt_dictW  s  














"r   Gantt Chart皙?X  c                 C   s  t | }|r$||d vrtdg }|D ]	}|||  qt| t|tr0t	|d}nt
|d}|du r>|  |s^t|trJtdt|||||||	|
ddd|||d}|S t|tsxt|||||||||	|
ddd||d}|S t|||||||||	|
ddd||d}|S )	a  
    **deprecated**, use instead
    :func:`plotly.express.timeline`.

    Returns figure for a gantt chart

    :param (array|list) df: input data for gantt chart. Must be either a
        a dataframe or a list. If dataframe, the columns must include
        'Task', 'Start' and 'Finish'. Other columns can be included and
        used for indexing. If a list, its elements must be dictionaries
        with the same required column headers: 'Task', 'Start' and
        'Finish'.
    :param (str|list|dict|tuple) colors: either a plotly scale name, an
        rgb or hex color, a color tuple or a list of colors. An rgb color
        is of the form 'rgb(x, y, z)' where x, y, z belong to the interval
        [0, 255] and a color tuple is a tuple of the form (a, b, c) where
        a, b and c belong to [0, 1]. If colors is a list, it must
        contain the valid color types aforementioned as its members.
        If a dictionary, all values of the indexing column must be keys in
        colors.
    :param (str|float) index_col: the column header (if df is a data
        frame) that will function as the indexing column. If df is a list,
        index_col must be one of the keys in all the items of df.
    :param (bool) show_colorbar: determines if colorbar will be visible.
        Only applies if values in the index column are numeric.
    :param (bool) show_hover_fill: enables/disables the hovertext for the
        filled area of the chart.
    :param (bool) reverse_colors: reverses the order of selected colors
    :param (str) title: the title of the chart
    :param (float) bar_width: the width of the horizontal bars in the plot
    :param (bool) showgrid_x: show/hide the x-axis grid
    :param (bool) showgrid_y: show/hide the y-axis grid
    :param (float) height: the height of the chart
    :param (float) width: the width of the chart

    Example 1: Simple Gantt Chart

    >>> from plotly.figure_factory import create_gantt

    >>> # Make data for chart
    >>> df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-30'),
    ...       dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
    ...       dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')]

    >>> # Create a figure
    >>> fig = create_gantt(df)
    >>> fig.show()


    Example 2: Index by Column with Numerical Entries

    >>> from plotly.figure_factory import create_gantt

    >>> # Make data for chart
    >>> df = [dict(Task="Job A", Start='2009-01-01',
    ...            Finish='2009-02-30', Complete=10),
    ...       dict(Task="Job B", Start='2009-03-05',
    ...            Finish='2009-04-15', Complete=60),
    ...       dict(Task="Job C", Start='2009-02-20',
    ...            Finish='2009-05-30', Complete=95)]

    >>> # Create a figure with Plotly colorscale
    >>> fig = create_gantt(df, colors='Blues', index_col='Complete',
    ...                    show_colorbar=True, bar_width=0.5,
    ...                    showgrid_x=True, showgrid_y=True)
    >>> fig.show()


    Example 3: Index by Column with String Entries

    >>> from plotly.figure_factory import create_gantt

    >>> # Make data for chart
    >>> df = [dict(Task="Job A", Start='2009-01-01',
    ...            Finish='2009-02-30', Resource='Apple'),
    ...       dict(Task="Job B", Start='2009-03-05',
    ...            Finish='2009-04-15', Resource='Grape'),
    ...       dict(Task="Job C", Start='2009-02-20',
    ...            Finish='2009-05-30', Resource='Banana')]

    >>> # Create a figure with Plotly colorscale
    >>> fig = create_gantt(df, colors=['rgb(200, 50, 25)', (1, 0, 1), '#6c4774'],
    ...                    index_col='Resource', reverse_colors=True,
    ...                    show_colorbar=True)
    >>> fig.show()


    Example 4: Use a dictionary for colors

    >>> from plotly.figure_factory import create_gantt
    >>> # Make data for chart
    >>> df = [dict(Task="Job A", Start='2009-01-01',
    ...            Finish='2009-02-30', Resource='Apple'),
    ...       dict(Task="Job B", Start='2009-03-05',
    ...            Finish='2009-04-15', Resource='Grape'),
    ...       dict(Task="Job C", Start='2009-02-20',
    ...            Finish='2009-05-30', Resource='Banana')]

    >>> # Make a dictionary of colors
    >>> colors = {'Apple': 'rgb(255, 0, 0)',
    ...           'Grape': 'rgb(170, 14, 200)',
    ...           'Banana': (1, 1, 0.2)}

    >>> # Create a figure with Plotly colorscale
    >>> fig = create_gantt(df, colors=colors, index_col='Resource',
    ...                    show_colorbar=True)

    >>> fig.show()

    Example 5: Use a pandas dataframe

    >>> from plotly.figure_factory import create_gantt
    >>> import pandas as pd

    >>> # Make data as a dataframe
    >>> df = pd.DataFrame([['Run', '2010-01-01', '2011-02-02', 10],
    ...                    ['Fast', '2011-01-01', '2012-06-05', 55],
    ...                    ['Eat', '2012-01-05', '2013-07-05', 94]],
    ...                   columns=['Task', 'Start', 'Finish', 'Complete'])

    >>> # Create a figure with Plotly colorscale
    >>> fig = create_gantt(df, colors='Blues', index_col='Complete',
    ...                    show_colorbar=True, bar_width=0.5,
    ...                    showgrid_x=True, showgrid_y=True)
    >>> fig.show()
    r   zIn order to use an indexing column and assign colors to the values of the index, you must choose an actual column name in the dataframe or key if a list of dictionaries is being used.rgbTzError. You have set colors to a dictionary but have not picked an index. An index is required if you are assigning colors to particular values in a dictionary.N)r   r   ru   r   r   r   )r   r   ru   r   r   )r'   r   r   r   r   validate_indexr   r!   r   validate_colors_dictvalidate_colorsrw   r   r   r   )r"   r~   r   r   reverse_colorsrc   r   r   r   rd   re   r   r   ru   r   r   r%   
index_list
dictionaryr   r   r   r   create_gantt#  s    



r   )NNNFTT)NNNFT)NNFFr   r   FFr   NNNNFT)
__future__r   numbersr   rx   plotlyr   r   plotly.colorsr~   r   plotly.figure_factoryr   plotly.graph_objectsgraph_objectsr|   
get_moduler   r   r   r'   r   r   r   r   r   r   r   r   <module>   sd    
0
 G
  c
 O