
    .i1                         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y)    )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       Y/opt/house_gps_flutter/.venv/lib/python3.12/site-packages/plotly/figure_factory/_gantt.py_get_corner_pointsr      s!     Rr2r2.//    c                    t         rt        | t         j                  j                  j                        rt
        D ]=  }|| vst        j                  dj                  dj                  t
                           | D ci c]  }|| |   j                   }}t        | j                        }g }t        | j                        }t        |      D ])  }|D ci c]  }|||   |    }}|j!                  |       + |S t        | t              st        j                  d      t        |       dk  rt        j                  d      t        | d   t"              st        j                  d      | S c c}w c c}w )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valueslenindexlistcolumnsrangeappenddict)dfkeyr"   num_of_rowschartkeysr    	task_dicts           r   validate_ganttr,      sa    
jRWW]]445& 	C"} ,,**0&;N1O*P 	 355333&55"((mBJJ;' 	$E=ABcgcl511BIBLL#	$  b$$$J
 	

 2w!|$$J
 	
 beT"$$%PQQI1 6 Cs   ?E/E4c                    |g }|	g }	|
g }
t        t        |             D ]E  }t        | |   d   | |   d   | |   d         }d| |   v r| |   d   |d<   |j                  |       G t               }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s|	j                  |       $ |r|	j	                          d}t        t        |            D ]B  }||   d   }||   d= |}|r|	j                  |      }||z
  ||   d<   ||z   ||   d<   |t        |      k\  rd}||   ||   d<   ||   d   }||vrt        j                  |      ||<   |||   d<   t        |      ||   d<   |||   d<   t        ||   d         dkD  r7||   d   j                  ||   d   d          ||   d   j                  d       t        ||   d   ||   d   ||   d   ||   d         \  }}||   dxx   |z  cc<   ||   dxx   |z  cc<   ||vr+t        j                  |      ||<   |||   d   d<   |||   d<   ||   d   j                  ||   d          ||   d   j                  ||   d          ||   d   j                  |       ||   d   j                  |       d||   v rA||   d   j                  ||   d          ||   d   j                  ||   d          ||   d= n.||   d   j                  d       ||   d   j                  d       |dz  }E |}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      }t        |      D cg c]  }||   	 }
}|
t        |      D cg c]  }||   	 c}z  }
t        j                  |
|5      }|S c c}w c c}w )6z/
    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r5   r6   r7   textmarkerr/   
showlegendr   r   	fillcolorlegendgroupr5   r6   r   r   rC   r>   rB   closestshowgridticktexttickvalsr#   	autorangezeroline   1wdaybackwardcountlabelstepstepmode1mmonth   6mYTDyeartodate1yallrV   buttonsdaterJ   rN   rangeselectortypetitlerD   heightwidthshapes	hovermodeyaxisxaxisdatalayout)r#   r   r%   r$   reverser    copydeepcopystrr   r!   sortedgoFigure)r)   colorsri   	bar_width
showgrid_x
showgrid_yrj   rk   tasks
task_namesrq   group_tasksshow_hover_fillshow_colorbarr    taskscatter_data_dictmarker_data_dictr9   scatter_data_templatemarker_data_templatetncolor_indexgroupIDcolor_idxsysrD   rr   kfigs                                  r   ganttr   E   s   & }
|s5z" U|G$U|H%uf%

 E%L("',}"=DT v		  Ra3 s5z" "5\&! b
2b!" Ks5z" >5\&!%L   &&r*G$y0eT$y0eT #f+%K$*;$7e[!<,,,*.--8M*Nh'3;(#K0.1"g(#F+5=(#M2  *3/014h',33!(+C04 h',33D9#%L%L%L%L	
B 	(#C(B.((#C(B.( ++)-7K)LX&<DX&x098@X&}5"3'..uU|D/AB"3'..uU|D/AB"3'..w7"3'..w7E%L(X&v.55eEl=6QRX&v.55eEl=6QRe]+X&v.55d;X&v.55d;q}>@ J%J01s:*+
 1DuzR1DwT1DwT1ER1Dv
S%(	 
 FD +11B*CDQa DDD&1A*BCQa CCD
 ))f
-CJ ECs   Q0Qc                    |
g }
|g }|g }d}t        t        |             D ]E  }t        | |   d   | |   d   | |   d         }d| |   v r| |   d   |d<   |
j                  |       G t               }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 ]$  }| |   |   |vs|j                  | |   |          & |j	                          t        | d   |   t              rt        |      dk  rt        j                  d      t        t        |
            D ]"  }|
|   d	   }|r||vs|j                  |       $ |r|j                          t        t        |
            D ]  }|
|   d	   }|
|   d	= |}|r|j                  |      }||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kD  r7||   d   j                  ||   d   d          ||   d   j                  d       t'        |
|   d   |
|   d   |
|   d   |
|   d         \  } }!||   dxx   | z  cc<   ||   dxx   |!z  cc<   ||vr+t!        j"                  |      ||<   |||   d    d!<   |||   d<   ||   d   j                  |
|   d          ||   d   j                  |
|   d          ||   d   j                  |       ||   d   j                  |       d|
|   v rB||   d"   j                  |
|   d          ||   d"   j                  |
|   d          |
|   d= ||   d"   j                  d       ||   d"   j                  d        |d#u rLt)        |j+                               d   }"||"   d    j-                  t        d|d   gd|d   ggd#d$d%             t        | d   |   t$              rzg }t        t        |
            D ]$  }| |   |   |vs|j                  | |   |          & |j	                          t        |      t        |      k  rt        j                  d&      i }#d}$|D ]"  }%|$t        |      dz
  kD  rd}$||$   |#|%<   |$dz  }$$ t        t        |
            D ]"  }|
|   d	   }|r||vs|j                  |       $ |r|j                          t        t        |
            D ]^  }|
|   d	   }|
|   d	= |}|r|j                  |      }||z
  |
|   d<   ||z   |
|   d<   |#| |   |      |
|   d<   |
|   d   }||vrt!        j"                  |      ||<   |||   d<   |||   d<   t%        | |   |         ||   d	<   t        j                  |t        j                        }t        ||   d         dkD  r7||   d   j                  ||   d   d          ||   d   j                  d       t'        |
|   d   |
|   d   |
|   d   |
|   d         \  } }!||   dxx   | z  cc<   ||   dxx   |!z  cc<   ||vr+t!        j"                  |      ||<   |||   d    d!<   |||   d<   ||   d   j                  |
|   d          ||   d   j                  |
|   d          ||   d   j                  |       ||   d   j                  |       d|
|   v rB||   d"   j                  |
|   d          ||   d"   j                  |
|   d          |
|   d= 1||   d"   j                  d       ||   d"   j                  d       a |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:;      <      }&t/        |      D "cg c]  }"||"   	 }}"|t/        |      D "cg c]  }"||"   	 c}"z  }t1        j2                  ||&=      }'|'S c c}"w c c}"w )>=
    Refer to FigureFactory.create_gantt() for docstring
    NFr	   r
   r   r.   r0   r1   r/   r2   r3   r4   r;   )r5   r6   r7   r8   rD   r9   rF   r:   r<   r   r=   )r5   r6   r7   rB   rC   r/   rD   rF      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@rE   rF   r5   rG   r6   r   r   rC   r>   rB   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.rD   rH   rI   rO   rP   rQ   rR   rS   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rd   re   rh   rp   )r#   r   r%   r$   sortr   r   r   r   rs   r    clrscolor_parserunlabel_rgbfind_intermediate_color	label_rgbrt   ru   rv   r   r!   r*   updaterw   rx   ry   )(r)   rz   ri   	index_colr   r{   r|   r}   rj   rk   r~   r   rq   r   r   rD   r    r   r   r   r9   r   r   
index_valsrowr   r   lowcolor	highcolorintermedintermed_colorr   r   r   r   index_vals_dictc_indexr'   rr   r   s(                                           r   gantt_colorscaler      sd   ( }
|Js5z" U|G$U|H%uf%

 E%L("',}"=DT v		  Ra3	 JSZ  5:i 
2eCj345 OO %(9%v.v;?((*  3u:& 	&Euf%B "J"6!!"%	&  3u:& 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9(IxXN!..~t~~NN(6E%L%U|K0H00.2mm<Q.R!(+7?h'425eEl96M2Nh'/9Ah'6 &&vt~~>F $X.s34q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 *@H *84W=<D *=9X&s+225<3EFX&s+225<3EFX&s+227;X&s+227;e, *6299%,}:UV *6299%,}:UV%L/ *6299$? *6299$?ID	@N D %**,-a0AQ)00!"F1IF1I?"	 %(9%s+
U$ 	9CSz)$J6!!%*Y"78	9 	v;Z(((   	CVq(#)'?OC qLG		 3u:& 	&Euf%B "J"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.2mm<Q.R!(+7?h'49Ah'625eEl96M2Nh'/ &&vt~~>F $X.s34q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 *@H *84W=<D *=9X&s+225<3EFX&s+225<3EFX&s+227;X&s+227;e, *6299%,}:UV *6299%,}:UV%L/ *6299$? *6299$?y<	@| D J& @5?!!$\2@ %J01s:*+
 1DuzR1DwT1DwT1ER1Dv
S%(	 
 FD +11B*CDQa DDD&1A*BCQa CCD
 ))f
-CJ ECs   e
 ec                 	   |
g }
|g }|g }d}t        t        |             D ]E  }t        | |   d   | |   d   | |   d         }d| |   v r| |   d   |d<   |
j                  |       G t               }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 ]$  }| |   |   |vs|j                  | |   |          & |j	                          |D ]  }||vst        j                  d       t        t        |
            D ]"  }|
|   d	   }|r||vs|j                  |       $ |r|j                          t        t        |
            D ]#  }|
|   d	   }|
|   d	= |}|r|j                  |      }||z
  |
|   d<   ||z   |
|   d<   || |   |      |
|   d<   |
|   d   }||vrt        j                  |      ||<   |||   d<   |||   d<   t        ||   d         dkD  r7||   d   j                  ||   d   d          ||   d   j                  d       t        |
|   d   |
|   d   |
|   d   |
|   d         \  }}||   dxx   |z  cc<   ||   dxx   |z  cc<   ||vr+t        j                  |      ||<   |||   d   d<   |||   d<   ||   d   j                  |
|   d          ||   d   j                  |
|   d          ||   d   j                  |       ||   d   j                  |       d|
|   v rB||   d    j                  |
|   d          ||   d    j                  |
|   d          |
|   d= ||   d    j                  d       ||   d    j                  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      } t        |      D !cg c]  }!||!   	 }}!|t        |      D !cg c]  }!||!   	 c}!z  }t        j                   || 7      }"|"S c c}!w c c}!w )8r   NFr	   r
   r   r.   r0   r1   r/   r2   r3   r4   r;   )r5   r6   r7   r8   r9   rF   r:   r<   r   r=   rA   zdIf you are using colors as a dictionary, all of its keys must be all the values in the index column.r   r   rE   rF   r5   rG   r6   r   r   rC   r>   rB   TrH   rI   rO   rP   rQ   rR   rS   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rd   re   rh   rp   )r#   r   r%   r$   r   r   r   rs   r    rt   ru   r   rv   r!   rw   rx   ry   )#r)   rz   ri   r   r   r{   r|   r}   rj   rk   r~   r   rq   r   r   rD   r    r   r   r   r9   r   r   r   r   r'   r   r   r   r   r   index_valuerr   r   r   s#                                      r   
gantt_dictr   V  s$   * }
|Js5z" U|G$U|H%uf%

 E%L("',}"=DT v		  Ra3 JSZ  5:i 
2eCj345 OO  f((C  s5z" "5\&! b
2b!" s5z" 8<5\&!%L   &&r*G$y0eT$y0eT$*5<	+B$Ce[!<,,,*.--8M*Nh'5=(#M23;(#K0  *3/014h',33!(+C04 h',33D9#%L%L%L%L	
B 	(#C(B.((#C(B.( ++)-7K)LX&<DX&x098@X&}5"3'..uU|D/AB"3'..uU|D/AB"3'..w7"3'..w7E%L(X&v.55eEl=6QRX&v.55eEl=6QRe]+X&v.55d;X&v.55d;q8<t 
! J9<[9I&-.v6J %J01s:*+
 1DuzR1DwT1DwT1ER1Dv
S%(	 
 FD +11B*CDQa DDD&1A*BCQa CCD
 ))f
-CJ ECs   SSc                 n   t        |       }|rN||d   vrt        j                  d      g }|D ]  }|j                  ||           t	        j
                  |       t        |t              rt        j                  |d      }nt        j                  |d      }|du r|j                          |s@t        |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   rq   r   r   r   )r~   r   rq   r   r   )r,   r   r   r$   r   validate_indexr   r%   r   validate_colors_dictvalidate_colorsrs   r   r   r   )r&   rz   r   r   reverse_colorsri   r{   r|   r}   rj   rk   r~   r   rq   r   r   r)   
index_list
dictionaryr   s                       r   create_ganttr   "  s   b 2EE!H$((.  
 	5Jj34	5Z( &$**659%%fe4fd#((I 
 #+'
  
&$'"' /C" J' /C" Jr   )NNNFTT)NNNFT)NNFFzGantt Chartg?FFiX  NNNNFT)numbersr   rt   plotlyr   r   plotly.colorsrz   r   plotly.figure_factoryr   plotly.graph_objectsgraph_objectsrx   
get_moduler   r   r   r,   r   r   r   r   r   r   r   <module>r      s      /  ' !   *1 0%b 	xL 	SB 	I\ 


	!ir   