
    -Phч                         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j        d          Zg dZd Zd Z	 	 	 	 	 	 ddZ	 	 	 	 	 ddZ	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdS )    )NumberN)
exceptionsoptional_imports)utilspandas)TaskStartFinishc                     | ||| 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y1s       \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/plotly/figure_factory/_gantt.py_get_corner_pointsr      s!     Rr2r2.//    c                    t           rt          | t           j        j        j                  rt
          D ]E}|| vr?t          j        d                    d	                    t
                                        Ft          | j                  }g }t          |          D ]4}i }| D ]}| j        |         |         ||<   |                    |           5|S t          | t                    st          j        d          t          |           dk    rt          j        d          t          | d         t                     st          j        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_dicts         r   validate_ganttr*      si    
 jRW]455 & 	 	C"}} ,**0&;N1O1O*P*P    "(mm;'' 	$ 	$EI 5 5!#!4	#LL#### b$ 
$M
 
 	

 2ww!||$M
 
 	
 beT"" U$%STTTIr   FTc                    |g }|	g }	|
g }
t          t          |                     D ]h}t          | |         d         | |         d         | |         d                   }d| |         v r| |         d         |d<   |                    |           it                      t                      |rd}nd	}g g d
d|d}g g dg t          ddd          ddd}t          t          |                    D ]+}||         d         }|r||	vr|	                    |           ,|r|	                                 d}t          t          |                    D ]8}||         d         }||         d= |}|r|	                    |          }||z
  ||         d<   ||z   ||         d<   |t          |          k    rd}||         ||         d<   ||         d         }|vrt          j        |          |<   ||         d<   t          |          |         d<   ||         d<   t          |         d                   dk    rT|         d                             |         d         d                    |         d                             d           t          ||         d         ||         d         ||         d         ||         d                   \  }}|         dxx         |z  cc<   |         dxx         |z  cc<   |vr3t          j        |          |<   ||         d         d<   ||         d<   |         d                             ||         d                    |         d                             ||         d                    |         d                             |           |         d                             |           d||         v rd|         d                             ||         d                    |         d                             ||         d                    ||         d= nB|         d                             d           |         d                             d           |dz  }:|}t          ||||g d t          ||	t          t          t          |	                              dt          |	          dz   gdd!          t          |dt          t          t          d"d#d$d%&          t          dd'd(d%&          t          d)d*d(d%&          t          dd+d,d-&          t          dd.d,d%&          t          d/0          g          1          d23          4          }fd5t                    D             }
|
fd6t                    D             z  }
t          j        |
|7          }|S )8z/
    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r3   r4   r5   textmarkerr-   
showlegendr   r   	fillcolorlegendgroupr3   r4   r   r   rA   r<   r@   closestshowgridticktexttickvalsr    	autorangezeroline   1wdaybackwardcountlabelstepstepmode1mmonth   6mYTDyeartodate1yallrT   buttonsdaterH   rL   rangeselectortypetitlerB   heightwidthshapes	hovermodeyaxisxaxisc                      g | ]
}|         S r   r   .0kscatter_data_dicts     r   
<listcomp>zgantt.<locals>.<listcomp>       DDDQa DDDr   c                      g | ]
}|         S r   r   rp   rq   marker_data_dicts     r   rs   zgantt.<locals>.<listcomp>       CCCQa CCCr   datalayout)r    r   r$   r"   reverser   copydeepcopystrr   r#   sortedgoFigure)r(   colorsrg   	bar_width
showgrid_x
showgrid_yrh   ri   tasks
task_namesrz   group_tasksshow_hover_fillshow_colorbarr   taskr7   scatter_data_templatemarker_data_templatetncolor_indexgroupIDcolor_idxsysrB   r{   figrw   rr   s                               @@r   ganttr   D   s   & }
|s5zz""  U|G$U|H%uf%
 
 

 E%L(("',}"=DT vv 			   Ra333  s5zz"" " "5\&!  	"b
22b!!!  Ks5zz"" > >5\&!%L   	+ &&r**G$y0eT$y0eT #f++%%K$*;$7e[!<,,,,*.-8M*N*Nh'3;(#K0.1"gg(#F+5=(#M2  *3/00144h',33!(+C04   h',33D999#%L%L%L%L	
 
B 	(#C(((B.((((#C(((B.((( +++)-7K)L)LX&<DX&x098@X&}5"3'..uU|D/ABBB"3'..uU|D/ABBB"3'..w777"3'..w777E%L((X&v.55eEl=6QRRRX&v.55eEl=6QRRRe]++X&v.55d;;;X&v.55d;;;qJ%J0011s:*+
 
 
 1DuzRRR1DwTTT1DwTTT1ERRR1Dv
SSS%(((	 	   
 
 
     FD EDDD&1B*C*CDDDDCCCC&1A*B*BCCCCD
 )f
-
-
-CJr   c                   &' |
g }
|g }|g }d}t          t          |                     D ]h}t          | |         d         | |         d         | |         d                   }d| |         v r| |         d         |d<   |
                    |           it                      't                      &|rd	}nd
}g g ddd|dd}g g dg t          ddd          dddd}g }t          t          |
                    D ]3}| |         |         |vr!|                    | |         |                    4|                                 t          | d         |         t                    rt          |          dk     rt          j        d          t          t          |
                    D ]+}|
|         d	         }|r||vr|                    |           ,|r|	                                 t          t          |
                    D ]}|
|         d	         }|
|         d	= |}|r|
                    |          }||z
  |
|         d<   ||z   |
|         d<   t          j        |t          j                  }|d         }|d         }| |         |         dz  }t          j        |||          }t          j        |t          j                  }||
|         d<   |
|         d         }|'vrt!          j        |          '|<   |'|         d<   t%          | |         |                   '|         d	<   |'|         d<   t          j        |t          j                  }t          '|         d                   dk    rT'|         d                             '|         d         d                    '|         d                             d           t'          |
|         d         |
|         d         |
|         d         |
|         d                   \  }}'|         dxx         |z  cc<   '|         dxx         |z  cc<   |&vr3t!          j        |          &|<   |&|         d          d!<   |&|         d<   &|         d                             |
|         d                    &|         d                             |
|         d                    &|         d                             |           &|         d                             |           d|
|         v re&|         d"                             |
|         d                    &|         d"                             |
|         d                    |
|         d= w&|         d"                             d           &|         d"                             d           |d#u rkt)          &                                          d         } &|          d                              t          d|d         gd|d         ggd#d$d%                     t          | d         |         t$                    rg }t          t          |
                    D ]3}| |         |         |vr!|                    | |         |                    4|                                 t          |          t          |          k     rt          j        d&          i }!d}"|D ]*}#|"t          |          dz
  k    rd}"||"         |!|#<   |"dz  }"+t          t          |
                    D ]+}|
|         d	         }|r||vr|                    |           ,|r|	                                 t          t          |
                    D ]V}|
|         d	         }|
|         d	= |}|r|
                    |          }||z
  |
|         d<   ||z   |
|         d<   |!| |         |                  |
|         d<   |
|         d         }|'vrt!          j        |          '|<   |'|         d<   |'|         d<   t%          | |         |                   '|         d	<   t          j        |t          j                  }t          '|         d                   dk    rT'|         d                             '|         d         d                    '|         d                             d           t'          |
|         d         |
|         d         |
|         d         |
|         d                   \  }}'|         dxx         |z  cc<   '|         dxx         |z  cc<   |&vr3t!          j        |          &|<   |&|         d          d!<   |&|         d<   &|         d                             |
|         d                    &|         d                             |
|         d                    &|         d                             |           &|         d                             |           d|
|         v re&|         d"                             |
|         d                    &|         d"                             |
|         d                    |
|         d= &|         d"                             d           &|         d"                             d           X|d#u rd#}'D ]} |'|          d'<   t          ||||	g d(t          ||t)          t          t          |                              dt          |          dz   gdd)          t          |dt          t)          t          d*d+d,d-.          t          dd/d0d-.          t          d1d2d0d-.          t          dd3d4d5.          t          dd6d4d-.          t          d78          g          9          d:;          <          }$'fd=t/          '          D             }|&fd>t/          &          D             z  }t1          j        ||$?          }%|%S )@=
    Refer to FigureFactory.create_gantt() for docstring
    NFr	   r
   r   r,   r.   r/   r-   r0   r1   r2   r9   )r3   r4   r5   r6   rB   r7   rD   r8   r:   r   r;   )r3   r4   r5   r@   rA   r-   rB   rD      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@rC   rD   r3   rE   r4   r   r   rA   r<   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.rB   rF   rG   rM   rN   rO   rP   rQ   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rb   rc   rf   c                      g | ]
}|         S r   r   ro   s     r   rs   z$gantt_colorscale.<locals>.<listcomp>K  rt   r   c                      g | ]
}|         S r   r   rv   s     r   rs   z$gantt_colorscale.<locals>.<listcomp>L  rx   r   ry   )r    r   r$   r"   sortr   r   r   r   r|   r   clrscolor_parserunlabel_rgbfind_intermediate_color	label_rgbr}   r~   r   r   r#   keysupdater   r   r   )(r(   r   rg   	index_colr   r   r   r   rh   ri   r   r   rz   r   r   rB   r   r   r7   r   r   
index_valsrowr   r   lowcolor	highcolorintermedintermed_colorr   r   r   rq   index_vals_dictc_indexr&   r{   r   rw   rr   s(                                         @@r   gantt_colorscaler      s   ( }
|Js5zz""  U|G$U|H%uf%
 
 

 E%L(("',}"=DT vv 			   Ra333	 	 JSZZ   5 5:i 
22eCj3444OO %(9%v.. gv;;??(*   3u::&& 	& 	&Euf%B  &"J"6"6!!"%%%  	!   3u::&& D	@ D	@Euf%BeV$ G /$**2..!(9!4E%L!(9!4E%L &vt/?@@FayHq	IeY/58H!9(IxXXN!.~t~NNN(6E%L%U|K0H000.2m<Q.R.R!(+7?h'425eEl96M2N2Nh'/9Ah'6 &vt~>>F $X.s344q88!(+C077%h/4R8   "(+C077==='eT"eT"eT"eT"	 FB h',,,2,,,h',,,2,,, ///-1];O-P-P *@H *84W=<D *=9X&s+225<3EFFFX&s+225<3EFFFX&s+227;;;X&s+227;;;e,, *6299%,}:UVVV *6299%,}:UVVV%L// *6299$??? *6299$???? D  %**,,--a0AQ)00!"F1IF1I?"	     %(9%s++ g@
U$$ 	9 	9CSz)$J66!!%*Y"7888v;;Z(((    	 	CVq((#)'?OC qLGG 3u::&& 	& 	&Euf%B  &"J"6"6!!"%%%  	!   3u::&& <	@ <	@Euf%BeV$ G /$**2..!(9!4E%L!(9!4E%L(7eY8O(PE%L%U|K0H000.2m<Q.R.R!(+7?h'49Ah'625eEl96M2N2Nh'/ &vt~>>F $X.s344q88!(+C077%h/4R8   "(+C077==='eT"eT"eT"eT"	 FB h',,,2,,,h',,,2,,, ///-1];O-P-P *@H *84W=<D *=9X&s+225<3EFFFX&s+225<3EFFFX&s+227;;;X&s+227;;;e,, *6299%,}:UVVV *6299%,}:UVVV%L// *6299$??? *6299$????D  J& @ @5?!!$\22 %J0011s:*+
 
 
 1DuzRRR1DwTTT1DwTTT1ERRR1Dv
SSS%(((	 	   
 
 
     FD EDDD&1B*C*CDDDDCCCC&1A*B*BCCCCD
 )f
-
-
-CJr   c                    ! |
g }
|g }|g }d}t          t          |                     D ]h}t          | |         d         | |         d         | |         d                   }d| |         v r| |         d         |d<   |
                    |           it                      !t                       |rd	}nd
}g g dd|dd}g g dg t          ddd          ddd}g }t          t          |
                    D ]3}| |         |         |vr!|                    | |         |                    4|                                 |D ]}||vrt          j        d          t          t          |
                    D ]+}|
|         d	         }|r||vr|                    |           ,|r|                                 t          t          |
                    D ]}|
|         d	         }|
|         d	= |}|r|                    |          }||z
  |
|         d<   ||z   |
|         d<   || |         |                  |
|         d<   |
|         d         }|!vrt          j
        |          !|<   |!|         d<   |!|         d<   t          !|         d                   dk    rT!|         d                             !|         d         d                    !|         d                             d           t          |
|         d         |
|         d         |
|         d         |
|         d                   \  }}!|         dxx         |z  cc<   !|         dxx         |z  cc<   | vr3t          j
        |           |<   | |         d         d<   | |         d<    |         d                             |
|         d                     |         d                             |
|         d                     |         d                             |            |         d                             |           d|
|         v re |         d                              |
|         d                     |         d                              |
|         d                    |
|         d= щ |         d                              d            |         d                              d           |d!u rd!}|D ] }t          |          !||                  d	<   !t          ||||	g d"t          ||t          t          t          |                              dt          |          dz   gdd#          t          |dt          t          t          d$d%d&d'(          t          dd)d*d'(          t          d+d,d*d'(          t          dd-d.d/(          t          dd0d.d'(          t          d12          g          3          d45          6          }!fd7t          !          D             }| fd8t                     D             z  }t          j        ||9          }|S ):r   NFr	   r
   r   r,   r.   r/   r-   r0   r1   r2   r9   )r3   r4   r5   r6   r7   rD   r8   r:   r   r;   r?   zdIf you are using colors as a dictionary, all of its keys must be all the values in the index column.r   r   rC   rD   r3   rE   r4   r   r   rA   r<   r@   TrF   rG   rM   rN   rO   rP   rQ   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rb   rc   rf   c                      g | ]
}|         S r   r   ro   s     r   rs   zgantt_dict.<locals>.<listcomp>  rt   r   c                      g | ]
}|         S r   r   rv   s     r   rs   zgantt_dict.<locals>.<listcomp>  rx   r   ry   )r    r   r$   r"   r   r   r   r|   r   r}   r~   r   r   r#   r   r   r   )"r(   r   rg   r   r   r   r   r   rh   ri   r   r   rz   r   r   rB   r   r   r7   r   r   r   r   r&   r   r   r   r   r   index_valuer{   r   rw   rr   s"                                   @@r   
gantt_dictr   U  s}   * }
|Js5zz""  U|G$U|H%uf%
 
 

 E%L(("',}"=DT vv 			   Ra333  JSZZ   5 5:i 
22eCj3444OO   f(C    s5zz"" " "5\&!  	"b
22b!!!  s5zz"" 8< 8<5\&!%L   	+ &&r**G$y0eT$y0eT$*5<	+B$Ce[!<,,,,*.-8M*N*Nh'5=(#M23;(#K0  *3/00144h',33!(+C04   h',33D999#%L%L%L%L	
 
B 	(#C(((B.((((#C(((B.((( +++)-7K)L)LX&<DX&x098@X&}5"3'..uU|D/ABBB"3'..uU|D/ABBB"3'..w777"3'..w777E%L((X&v.55eEl=6QRRRX&v.55eEl=6QRRRe]++X&v.55d;;;X&v.55d;;;;
! J J9<[9I9I&-.v66%J0011s:*+
 
 
 1DuzRRR1DwTTT1DwTTT1ERRR1Dv
SSS%(((	 	   
 
 
     FD EDDD&1B*C*CDDDDCCCC&1A*B*BCCCCD
 )f
-
-
-CJr   Gantt Chart皙?X  c                    t          |           }|rT||d         vrt          j        d          g }|D ]}|                    ||                    t	          j        |           t          |t                    rt          j	        |d          }nt          j
        |d          }|du r|                                 |sHt          |t                    rt          j        d          t          |||||||	|
ddd|||          }|S t          |t                    s t          |||||||||	|
ddd||          }|S t          |||||||||	|
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   rz   r   r   r   )r   r   rz   r   r   )r*   r   r   r"   r   validate_indexr   r$   r   validate_colors_dictvalidate_colorsr|   r   r   r   )r%   r   r   r   reverse_colorsrg   r   r   r   rh   ri   r   r   rz   r   r   r(   
index_list
dictionaryr   s                       r   create_ganttr   !  s   b 2E )E!H$$(.   
 	5 	5Jj34444Z((( &$ 5*6599%fe44 >fd## 	(I  
 #+'
 
 
  
&$'' %	"' /  C" J' /  C" Jr   )NNNFTT)NNNFT)NNFFr   r   FFr   NNNNFT)numbersr   r}   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   <module>r      s          / / / / / / / /       ' ' ' ' ' ' ! ! ! ! ! !  **111 0 0 0$ $ $` 	x x x xL 	S S S SB 	I I I I\ 


	!i i i i i ir   