
    -Ph)                     h    d dl mZ d dlmZ d dlmZ dZdZd Zd Z	d Z
ddZ G d de          Zd	S )    )
exceptions)
graph_objs)utilsz#3D9970z#FF4136c                 n   | ||fD ]G}t          t          |                    D ](}||         ||         k     rt          j        d          )H| ||fD ]G}t          t          |                    D ](}||         ||         k    rt          j        d          )Hd}||vrt          j        d          dS )a  
    ohlc and candlestick specific validations

    Specifically, this checks that the high value is the greatest value and
    the low value is the lowest value in each unit.

    See FigureFactory.create_ohlc() or FigureFactory.create_candlestick()
    for params

    :raises: (PlotlyError) If the high value is not the greatest value in
        each unit.
    :raises: (PlotlyError) If the low value is not the lowest value in each
        unit.
    :raises: (PlotlyError) If direction is not 'increasing' or 'decreasing'
    zOops! Looks like some of your high values are less the corresponding open, low, or close values. Double check that your data is entered in O-H-L-C orderzOops! Looks like some of your low values are greater than the corresponding high, open, or close values. Double check that your data is entered in O-H-L-C order)
increasing
decreasingbothzBdirection must be defined as 'increasing', 'decreasing', or 'both'N)rangelenr   PlotlyError)	openhighlowclose	directionkwargslstindexdirection_optss	            [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/plotly/figure_factory/_ohlc.pyvalidate_ohlcr      s
     c5! 
 
3t99%% 		 		EE{SZ'' ,2   (		 dE" 
 
3s88__ 		 		E5zCJ&& ,2   '		 :N&&$V
 
 	
 '&    c           	      :   t          | ||||                                          \  }}}d|v rd}	n|                    dd           d}	|                    dt          t          d                     |                    d|           t          dd	||d
|	d|}
|
S )a  
    Makes increasing ohlc sticks

    _make_increasing_ohlc() and _make_decreasing_ohlc separate the
    increasing trace from the decreasing trace so kwargs (such as
    color) can be passed separately to increasing or decreasing traces
    when direction is set to 'increasing' or 'decreasing' in
    FigureFactory.create_candlestick()

    :param (list) open: opening values
    :param (list) high: high values
    :param (list) low: low values
    :param (list) close: closing values
    :param (list) dates: list of datetime objects. Default: None
    :param kwargs: kwargs to be passed to increasing trace via
        plotly.graph_objs.Scatter.

    :rtype (trace) ohlc_incr_data: Scatter trace of all increasing ohlc
        sticks.
    nameT
IncreasingFline   colorwidthtextscatterlines)typexymode
showlegend )_OHLCget_increase
setdefaultdict_DEFAULT_INCREASING_COLOR)r   r   r   r   datesr   flat_increase_xflat_increase_ytext_increaser(   	ohlc_incrs              r   make_increasing_ohlcr4   :   s    * 9>dC9 9lnn 6_o} 

&,///

fd)B!LLLMMM
fm,,, 

   I r   c                 R   t          | ||||                                          \  }}}|                    dt          t          d                     |                    d|           |                    dd           |                    dd           t          dd	||d
d|}	|	S )a  
    Makes decreasing ohlc sticks

    :param (list) open: opening values
    :param (list) high: high values
    :param (list) low: low values
    :param (list) close: closing values
    :param (list) dates: list of datetime objects. Default: None
    :param kwargs: kwargs to be passed to increasing trace via
        plotly.graph_objs.Scatter.

    :rtype (trace) ohlc_decr_data: Scatter trace of all decreasing ohlc
        sticks.
    r   r   r   r!   r(   Fr   
Decreasingr"   r#   )r$   r%   r&   r'   r)   )r*   get_decreaser,   r-   _DEFAULT_DECREASING_COLOR)
r   r   r   r   r/   r   flat_decrease_xflat_decrease_ytext_decrease	ohlc_decrs
             r   make_decreasing_ohlcr=   g   s     9>dC9 9lnn 6_o} fd)B!LLLMMM
fm,,,
lE***
fl+++ /_7 NT I r   Nr	   c                    |t          j        | ||||           nt          j        | |||           t          | ||||fi | |dk    rt          | ||||fi |}|g}nA|dk    rt	          | ||||fi |}	|	g}n&t          | ||||fi |}t	          | ||||fi |}	||	g}t          j        t          d          d          }
t          j        ||
          S )	aU  
    **deprecated**, use instead the plotly.graph_objects trace
    :class:`plotly.graph_objects.Ohlc`

    :param (list) open: opening values
    :param (list) high: high values
    :param (list) low: low values
    :param (list) close: closing
    :param (list) dates: list of datetime objects. Default: None
    :param (string) direction: direction can be 'increasing', 'decreasing',
        or 'both'. When the direction is 'increasing', the returned figure
        consists of all units where the close value is greater than the
        corresponding open value, and when the direction is 'decreasing',
        the returned figure consists of all units where the close value is
        less than or equal to the corresponding open value. When the
        direction is 'both', both increasing and decreasing units are
        returned. Default: 'both'
    :param kwargs: kwargs passed through plotly.graph_objs.Scatter.
        These kwargs describe other attributes about the ohlc Scatter trace
        such as the color or the legend name. For more information on valid
        kwargs call help(plotly.graph_objs.Scatter)

    :rtype (dict): returns a representation of an ohlc chart figure.

    Example 1: Simple OHLC chart from a Pandas DataFrame

    >>> from plotly.figure_factory import create_ohlc
    >>> from datetime import datetime

    >>> import pandas as pd
    >>> df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
    >>> fig = create_ohlc(df['AAPL.Open'], df['AAPL.High'], df['AAPL.Low'], df['AAPL.Close'], dates=df.index)
    >>> fig.show()
    Nr   r   F)zerolineclosest)xaxis	hovermode)datalayout)	r   validate_equal_lengthr   r4   r=   r   Layoutr-   Figure)r   r   r   r   r/   r   r   r3   rC   r<   rD   s              r   create_ohlcrH      s8   F #D$UEBBBB#D$U;;;$c5)>>v>>>L  (tS%QQ&QQ	{	l	"	"(tS%QQ&QQ	{(tS%QQ&QQ	(tS%QQ&QQ	9%T5%9%9%9YOOOF$v6666r   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )r*   zF
    Refer to FigureFactory.create_ohlc_increase() for docstring.
    c                     || _         || _        || _        || _        d gt	          |          z  | _        || _        g | _        g | _        g | _	        g | _
        g | _        g | _        |                                  |                                  d S N)r   r   r   r   r   emptyr/   all_xall_y
increase_x
increase_y
decrease_x
decrease_y
get_all_xyseparate_increase_decrease)selfr   r   r   r   r/   r   s          r   __init__z_OHLC.__init__   s    		
Vc$ii'



'')))))r   c                    t          t          | j        | j        | j        | j        | j        | j        | j                            | _        | j        g }t          t          | j                  dz
            D ]3}|                    | j        |dz            | j        |         z
             4t          |          dz  fd| j        D             | _        dS d t          t          | j                            D             | _        dS )a  
        Zip data to create OHLC shape

        OHLC shape: low to high vertical bar with
        horizontal branches for open and close values.
        If dates were added, the smallest date difference is calculated and
        multiplied by .2 to get the length of the open and close branches.
        If no date data was provided, the x-axis is a list of integers and the
        length of the open and close branches is .2.
        Nr      c           	      .    g | ]}|z
  |||||z   d gS rK   r)   ).0r%   date_dif_mins     r   
<listcomp>z$_OHLC.get_all_xy.<locals>.<listcomp>   sB        \!1aAq</?F  r   c           	      ,    g | ]}|d z
  |||||d z   dgS )g?Nr)   )rZ   r%   s     r   r\   z$_OHLC.get_all_xy.<locals>.<listcomp>   s<       9:S!Q1a#gt4  r   )listzipr   r   r   r   rL   rN   r/   r
   r   appendminrM   )rU   date_difir[   s      @r   rS   z_OHLC.get_all_xy   s    			


 

 


 :!H3tz??Q.// C C
1q5 1DJqM ABBBBMMQ.L     DJJJ
 >CC	NN>S>S  DJJJr   c                    t          t          | j                            D ]}| j        |         | j        |         | j        |         k    rK| j                            | j        |                    | j                            | j        |                    w| j	                            | j        |                    | j
                            | j        |                    dS )z
        Separate data into two groups: increase and decrease

        (1) Increase, where close > open and
        (2) Decrease, where close <= open
        N)r
   r   r   r   rO   r`   rM   rP   rN   rQ   rR   )rU   r   s     r   rT   z _OHLC.separate_increase_decrease   s     3ty>>** 	: 	:Ez% (E"TYu%555&&tz%'8999&&tz%'89999&&tz%'8999&&tz%'89999	: 	:r   c                     t          j        | j                  }t          j        | j                  }dt	          | j                  z  }|||fS )a  
        Flatten increase data and get increase text

        :rtype (list, list, list): flat_increase_x: x-values for the increasing
            trace, flat_increase_y: y=values for the increasing trace and
            text_increase: hovertext for the increasing trace
        Openrg   HighLowCloserj    )r   flattenrO   rP   r   )rU   r0   r1   r2   s       r   r+   z_OHLC.get_increase	  L      -88-88M  
 >>r   c                     t          j        | j                  }t          j        | j                  }dt	          | j                  z  }|||fS )a  
        Flatten decrease data and get decrease text

        :rtype (list, list, list): flat_decrease_x: x-values for the decreasing
            trace, flat_decrease_y: y=values for the decreasing trace and
            text_decrease: hovertext for the decreasing trace
        rf   )r   rl   rQ   rR   r   )rU   r9   r:   r;   s       r   r7   z_OHLC.get_decrease  rm   r   N)	__name__
__module____qualname____doc__rV   rS   rT   r+   r7   r)   r   r   r*   r*      sj         * * *"" " "H: : :"? ? ? ? ? ? ? ?r   r*   )Nr	   )plotlyr   plotly.graph_objsr   plotly.figure_factoryr   r.   r8   r   r4   r=   rH   objectr*   r)   r   r   <module>rw      s          ( ( ( ( ( ( ' ' ' ' ' ' & % ,
 ,
 ,
^* * *Z  <67 67 67 67ri? i? i? i? i?F i? i? i? i? i?r   