U
    Y»{jù‡  ã                   @   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ddd	g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)ÚutilsZ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
   ú[/var/www/html/bwave/python/venv/lib/python3.8/site-packages/plotly/figure_factory/_gantt.pyÚ_get_corner_points   s    r   c                 C   sÌ   t r†t| t jjjƒr†tD ]"}|| krt d d 	t¡¡¡‚qt
| jƒ}g }t|ƒD ].}i }| D ]}| j| | ||< q^| |¡ qR|S t| tƒsšt d¡‚t
| ƒdkr°t d¡‚t| d tƒsÈt 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ÚframeZ	DataFrameÚREQUIRED_GANTT_KEYSr   ÚPlotlyErrorÚformatÚjoinÚlenÚindexÚrangeZilocÚappendÚlistÚdict)ÚdfÚkeyZnum_of_rowsÚchartr   Z	task_dictr
   r
   r   Úvalidate_gantt   s6    ÿÿ

ÿÿ
r"   FTc                    sn  |dkrg }|	dkrg }	|
dkr$g }
t t| ƒƒD ]P}t| | d | | d | | d d�}d| | krv| | d |d< | |¡ q0tƒ ‰tƒ ‰ |r˜d}nd	}g g d
d|dœ}g g dg tdddd�dddœ}t t|ƒƒD ]&}|| d }|rò||	krÖ|	 |¡ qÖ|�r|	 ¡  d}t t|ƒƒD �]d}|| d }|| d= |}|�rL|	 |¡}|| || d< || || d< |t|ƒk�r~d}|| || d< || d }|ˆk�r²t |¡ˆ|< |ˆ| d< t|ƒˆ| d< |ˆ| d< tˆ| d ƒdk�r ˆ| d  ˆ| d d ¡ ˆ| d  d¡ t	|| d || d || d || d ƒ\}}ˆ| d  |7  < ˆ| d  |7  < |ˆ k�r®t |¡ˆ |< |ˆ | d d< |ˆ | d< ˆ | d  || d ¡ ˆ | d  || d ¡ ˆ | d  |¡ ˆ | d  |¡ d|| k�rTˆ | 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ÚsizeZopacityF©r*   r+   r,   ÚtextÚmarkerr$   Ú
showlegendr   r   Ú	fillcolorÚlegendgroupr*   éÿÿÿÿr+   r   r   r7   r3   r6   Úclosest©ÚshowgridZticktextZtickvalsr   Z	autorangeÚzerolineé   Ú1wÚdayÚbackward©ÚcountÚlabelÚstepZstepmodeÚ1mÚmonthé   Ú6mÚYTDÚyearÚtodateÚ1yÚall©rG   ©ZbuttonsÚdate©r>   r?   ZrangeselectorÚtype©Útitler8   ÚheightÚwidthZshapesZ	hovermodeZyaxisZxaxisc                    s   g | ]}ˆ | ‘qS r
   r
   ©Ú.0Úk©Úscatter_data_dictr
   r   Ú
<listcomp>÷   s     zgantt.<locals>.<listcomp>c                    s   g | ]}ˆ | ‘qS r
   r
   rZ   ©Úmarker_data_dictr
   r   r_   ø   s     ©ÚdataÚlayout)r   r   r   r   Úreverser   ÚcopyÚdeepcopyÚstrr   r   ÚsortedÚgoÚFigure)r!   ÚcolorsrW   Ú	bar_widthÚ
showgrid_xÚ
showgrid_yrX   rY   ÚtasksÚ
task_namesrc   Úgroup_tasksÚshow_hover_fillÚshow_colorbarr   Útaskr.   Úscatter_data_templateÚmarker_data_templateÚtnZcolor_indexÚgroupIDÚcolor_idÚxsÚysr8   rd   Úfigr
   ©ra   r^   r   ÚganttF   sö    


ýû	ù


ÿ



ü
úúÿÿññ"r   c           &         s	  |
dkrg }
|dkrg }|dkr$g }d}t t| ƒƒD ]P}t| | d | | d | | d d�}d| | krz| | d |d< |
 |¡ q4tƒ ‰tƒ ‰ |rœd	}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 ]&}| | | |krä| | | | ¡ qä| ¡  t| d | tƒ�rŠt|ƒdk �r@t d¡‚t t|
ƒƒD ],}|
| d	 }|�rl||k�rL| |¡ �qL|�rˆ| 	¡  t t|
ƒƒD �]¦}|
| d	 }|
| d	= |}|�rÄ| 
|¡}|| |
| d< || |
| d< t |tj¡}|d }|d }| | | d }t |||¡}t |tj¡}||
| d< |
| d }|ˆk�r^t |¡ˆ|< |ˆ| d< t| | | ƒˆ| d	< |ˆ| d< t |tj¡}tˆ| d ƒdk�râˆ| d  ˆ| d d ¡ ˆ| d  d¡ t|
| d |
| d |
| d |
| d ƒ\}}ˆ| d  |7  < ˆ| d  |7  < |ˆ k�rpt |¡ˆ |< |ˆ | d  d!< |ˆ | d< ˆ | d  |
| d ¡ ˆ | d  |
| d ¡ ˆ | d  |¡ ˆ | d  |¡ d|
| k�rˆ | d"  |
| d ¡ ˆ | d"  |
| d ¡ |
| d= n$ˆ | d"  d¡ ˆ | d"  d¡ �q”|d#k�rŠtˆ  ¡ ƒd } ˆ |  d   td|d gd|d ggd#d$dd%�¡ t| d | tƒ�r"g }t t|
ƒƒD ]*}| | | |k�r®| | | | ¡ �q®| ¡  t|ƒt|ƒk �rþt d&¡‚i }!d}"|D ]0}#|"t|ƒd k�r$d}"||" |!|#< |"d7 }"�q
t t|
ƒƒD ],}|
| d	 }|�rh||k�rH| |¡ �qH|�r„| 	¡  t t|
ƒƒD �]h}|
| d	 }|
| d	= |}|�rÀ| 
|¡}|| |
| d< || |
| d< |!| | |  |
| d< |
| d }|ˆk�rt |¡ˆ|< |ˆ| d< |ˆ| d< t| | | ƒˆ| d	< t |tj¡}tˆ| d ƒdk�r ˆ| d  ˆ| d d ¡ ˆ| d  d¡ t|
| d |
| d |
| d |
| d ƒ\}}ˆ| d  |7  < ˆ| d  |7  < |ˆ k�r.t |¡ˆ |< |ˆ | d  d!< |ˆ | d< ˆ | d  |
| d ¡ ˆ | d  |
| d ¡ ˆ | d  |¡ ˆ | d  |¡ d|
| k�rÔˆ | d"  |
| d ¡ ˆ | d"  |
| d ¡ |
| d= n$ˆ | d"  d¡ ˆ | d"  d¡ �q�|d#k�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)   r0   )r*   r+   r,   r-   r8   r.   r:   r/   r1   r   r2   )r*   r+   r,   r6   r7   r$   r8   r:   é   z®You 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@r9   r:   r*   r;   r+   r   r   r7   r3   r6   Téd   )Z
colorscaleZ	showscaleZcmaxZcminztError. The number of colors in 'colors' must be no less than the number of unique index values in your group column.r8   r<   r=   r@   rA   rB   rC   rD   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rV   c                    s   g | ]}ˆ | ‘qS r
   r
   rZ   r]   r
   r   r_   M  s     z$gantt_colorscale.<locals>.<listcomp>c                    s   g | ]}ˆ | ‘qS r
   r
   rZ   r`   r
   r   r_   N  s     rb   )r   r   r   r   Úsortr   r   r   r   re   r   ÚclrsZcolor_parserZunlabel_rgbZfind_intermediate_colorZ	label_rgbrf   rg   rh   r   r   ÚkeysÚupdateri   rj   rk   )&r!   rl   rW   Ú	index_colrt   rm   rn   ro   rX   rY   rp   rq   rc   rr   rs   r8   r   ru   r.   rv   rw   Ú
index_valsÚrowrx   ry   ZlowcolorZ	highcolorZintermedZintermed_colorrz   r{   r|   r\   Zindex_vals_dictZc_indexr    rd   r}   r
   r~   r   Úgantt_colorscale  s¶   


ýùøÿ


ÿ



ü

üÿ	ÿ


ÿ



ü

úúÿÿññ"rŠ   c                     sÞ  |
dkrg }
|dkrg }|dkr$g }d}t t| ƒƒD ]P}t| | d | | d | | d d�}d| | krz| | d |d< |
 |¡ q4tƒ ‰tƒ ‰ |rœd	}nd
}g g dd|ddœ}g g dg tdddd�dddœ}g }t t|
ƒƒD ]&}| | | |krà| | | | ¡ qà| ¡  |D ]}||k�rt d¡‚�qt t|
ƒƒD ],}|
| d	 }|�r\||k�r<| |¡ �q<|�rx| ¡  t t|
ƒƒD �]B}|
| d	 }|
| d	= |}|�r´| |¡}|| |
| d< || |
| d< || | |  |
| d< |
| d }|ˆk�rt	 
|¡ˆ|< |ˆ| d< |ˆ| d< tˆ| d ƒdk�rnˆ| d  ˆ| d d ¡ ˆ| d  d¡ t|
| d |
| d |
| d |
| d ƒ\}}ˆ| d  |7  < ˆ| d  |7  < |ˆ k�rüt	 
|¡ˆ |< |ˆ | d d< |ˆ | d< ˆ | d  |
| d ¡ ˆ | d  |
| d ¡ ˆ | d  |¡ ˆ | d  |¡ d|
| k�r¢ˆ | d   |
| d ¡ ˆ | d   |
| d ¡ |
| d= n$ˆ | d   d¡ ˆ | d   d¡ �q„|d!k�rØd!}|D ]}t|ƒˆ||  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)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)   r0   )r*   r+   r,   r-   r.   r:   r/   r1   r   r2   r5   zdIf you are using colors as a dictionary, all of its keys must be all the values in the index column.r   r   r9   r:   r*   r;   r+   r   r   r7   r3   r6   Tr<   r=   r@   rA   rB   rC   rD   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rV   c                    s   g | ]}ˆ | ‘qS r
   r
   rZ   r]   r
   r   r_     s     zgantt_dict.<locals>.<listcomp>c                    s   g | ]}ˆ | ‘qS r
   r
   rZ   r`   r
   r   r_     s     rb   )r   r   r   r   rƒ   r   r   re   r   rf   rg   r   rh   r   ri   rj   rk   ) r!   rl   rW   r‡   rt   rm   rn   ro   rX   rY   rp   rq   rc   rr   rs   r8   r   ru   r.   rv   rw   rˆ   r‰   r    rx   ry   rz   r{   r|   Zindex_valuerd   r}   r
   r~   r   Ú
gantt_dictW  s
   


ýú
ù

ÿ


ÿ



ü

úúÿÿññ"r‹   úGantt Chartçš™™™™™É?éX  c                 C   s  t | ƒ}|rH||d kr"t d¡‚g }|D ]}| || ¡ q*t |¡ t|tƒr`t 	|d¡}nt 
|d¡}|dkr|| ¡  |s¼t|tƒr”t d¡‚t|||||||	|
ddd|||d�}|S t|tƒsðt|||||||||	|
ddd||d�}|S t|||||||||	|
ddd||d�}|S 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   z·In 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.ÚrgbTzŸError. 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)rp   rq   rc   rr   rs   rt   )rp   rq   rc   rr   rs   )r"   r   r   r   r   Zvalidate_indexr   r   r„   Zvalidate_colors_dictZvalidate_colorsre   r   rŠ   r‹   )r   rl   r‡   rt   Zreverse_colorsrW   rm   rn   ro   rX   rY   rp   rq   rc   rr   rs   r!   Z
index_listÚ
dictionaryr}   r
   r
   r   Úcreate_gantt#  s–     ÿ


ÿò
ññr‘   )NNNFTT)NNNFT)NNNFT)NNFFrŒ   r�   FFrŽ   NNNNFT)Ú
__future__r   Únumbersr   rf   Zplotlyr   r   Zplotly.colorsrl   r„   Zplotly.figure_factoryr   Zplotly.graph_objectsZgraph_objectsrj   Z
get_moduler   r   r   r"   r   rŠ   r‹   r‘   r
   r
   r
   r   Ú<module>   sb   

0      ò
 G     ñ
  c     ñ
 O               ð