o
    Xi%)                     @  s   d Z ddlmZ ddlmZ ddlmZmZmZ dZ	dZ
dZdZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZg dZdd Zdd ZdZddddd ZdS )!zModule to generate ascii charts.

This module provides a single function `plot` that can be used to generate an
ascii chart from a series of numbers. The chart can be configured via several
options to tune the output.
    )annotations)Mapping)ceilfloorisnanz[30mz[31mz[32mz[33mz[34mz[35mz[36mz[37mz[39mz[90mz[91mz[92mz[93mz[94mz[95mz[96mz[97mz[0m)plotblackredgreenyellowbluemagentacyan	lightgraydefaultdarkgraylightred
lightgreenlightyellow	lightbluelightmagenta	lightcyanwhiteresetc                 C  s
   t |  S Nr   n r   T/home/ubuntu/.local/lib/python3.10/site-packages/onnx_ir/_thirdparty/asciichartpy.py_isnumR   s   
r    c                 C  s   |s| S ||  t  S r   )r   )charcolorr   r   r   coloredV   s   r#   )
u   ┼u   ┤u   ╶u   ╴u   ─u   ╰u   ╭u   ╮u   ╯u   │N)	bin_edgescfgc          *        s.  t | dkrdS t| d tstdd | D rdS | g} |dur*t|ts*td|p-i }|ddg}|dttt	d	d
 | D |dt
tt	dd
 | D |dt}krctd }|dd}|d|}|dkr{|| ndt t }fdd  fdd}	| }
d| D ]	}t
t |q|7 |dd}|dd}fdd
t|
d D }t|d D ]6}|| | |
r|
nd  }|||  t
|t | d< |dkr|d n|d ||  |d < q| d d }t	|r|d ||
|	|  |d < t| D ]\}}||t |  }tt |d D ]}||d  }||d  }t|rPt|rPq6t|rmt	|rmt|d |||
|	|  || < q6t	|rt|rt|d |||
|	|  || < q6|	|}|	|}||krt|d |||
|  || < q6||krt|d |nt|d |||
|  || < ||krt|d  |nt|d! |||
|  || < t||d }t
||}t||D ]}t|d" |||
|  || < qq6q"d#d$d
 |D }|du st |dkr|S d}|t | }||d }t |}t
d|| }g } |d  }!d}"||"  }#t |}$t|$|#}%|%d }&t
|"|!|%|  |& }'||!k rt||! |$ }(|||( }| | |t ||' 7 }||!k sed%| d%|' |  })|d# |) S )&u  Generate an ascii chart for a series of numbers.

    `series` should be a list of ints or floats. Missing data values in the
    series can be specified as a NaN. In Python versions less than 3.5, use
    float("nan") to specify an NaN. With 3.5 onwards, use math.nan to specify a
    NaN.

        >>> series = [1,2,3,4,float("nan"),4,3,2,1]
        >>> print(plot(series))
            4.00  ┤  ╭╴╶╮
            3.00  ┤ ╭╯  ╰╮
            2.00  ┤╭╯    ╰╮
            1.00  ┼╯      ╰

    `series` can also be a list of lists to support multiple data series.

        >>> series = [[10,20,30,40,30,20,10], [40,30,20,10,20,30,40]]
        >>> print(plot(series, cfg={'height': 3}))
           40.00  ┤╮ ╭╮ ╭
           30.00  ┤╰╮╯╰╭╯
           20.00  ┤╭╰╮╭╯╮
           10.00  ┼╯ ╰╯ ╰

    `bin_edges` is an optional list of bin edges to display on the x-axis. If
    provided, the x-axis will be labeled with the bin edges. If there are too
    many bin edges to fit on the x-axis, some labels will be dropped and they
    will be spaced out evenly to fit the width of the chart.
    The labels will be formatted using the `x_format` option in `cfg`.

    `cfg` is an optional dictionary of various parameters to tune the appearance
    of the chart. `min` and `max` will clamp the y-axis and all values:

        >>> series = [1,2,3,4,float("nan"),4,3,2,1]
        >>> print(plot(series, cfg={'min': 0}))
            4.00  ┼  ╭╴╶╮
            3.00  ┤ ╭╯  ╰╮
            2.00  ┤╭╯    ╰╮
            1.00  ┼╯      ╰
            0.00  ┤

        >>> print(plot(series, cfg={'min': 2}))
            4.00  ┤  ╭╴╶╮
            3.00  ┤ ╭╯  ╰╮
            2.00  ┼─╯    ╰─

        >>> print(plot(series, cfg={'min': 2, 'max': 3}))
            3.00  ┤ ╭─╴╶─╮
            2.00  ┼─╯    ╰─

    `height` specifies the number of rows the graph should occupy. It can be
    used to scale down a graph with large data values:

        >>> series = [10,20,30,40,50,40,30,20,10]
        >>> print(plot(series, cfg={'height': 4}))
           50.00  ┤   ╭╮
           40.00  ┤  ╭╯╰╮
           30.00  ┤ ╭╯  ╰╮
           20.00  ┤╭╯    ╰╮
           10.00  ┼╯      ╰

    `format` specifies a Python format string used to format the labels on the
    y-axis. The default value is "{:8.2f} ". This can be used to remove the
    decimal point:

        >>> series = [10,20,30,40,50,40,30,20,10]
        >>> print(plot(series, cfg={'height': 4, 'format':'{:8.0f}'}))
              50 ┤   ╭╮
              40 ┤  ╭╯╰╮
              30 ┤ ╭╯  ╰╮
              20 ┤╭╯    ╰╮
              10 ┼╯      ╰
    r    c                 s  s    | ]}t |V  qd S r   r   ).0r   r   r   r   	<genexpr>   s    zplot.<locals>.<genexpr>Nz cfg must be a dictionary or Nonecolorsminc                 S     g | ]	}|D ]}|qqS r   r   r'   ijr   r   r   
<listcomp>       zplot.<locals>.<listcomp>maxc                 S  r+   r   r   r,   r   r   r   r/      r0   symbolsz*The min value cannot exceed the max value.offset   height   c                   s   t t|  S r   )r*   r1   r   )maximumminimumr   r   clamp   s   zplot.<locals>.clampc                   s   t t |   S r   )intround)y)r9   min2ratior   r   scaled   s   zplot.<locals>.scaledformatz{:8.2f} x_formatz{:4.4f}c                   s   g | ]}d g  qS ) r   )r'   r-   )widthr   r   r/      s                      	   
c                 S  s   g | ]	}d  | qS )r&   )joinrstrip)r'   rowr   r   r   r/     r0   rB   )len
isinstancelistallr   	TypeErrorgetr*   filterr    r1   _DEFAULT_SYMBOLS
ValueErrorr   r   ranger@   	enumerater   r#   rL   r:   append)*seriesr$   r%   r)   r2   intervalr3   r5   max2r?   rowsseries_iplaceholderx_placeholderresultr<   labeld0r-   r"   xd1y0y1startendthe_plotcurrent_locationleading_spacex_labelx_label_sizex_leading_spacex_labelsworkable_widthmin_spacingnum_labels_can_fitlabels_countnum_labels_to_display
num_spacesspacing	bin_indexx_labels_textr   )r9   r7   r=   r8   r>   rC   r   r   `   s   I  "*
""
$$
"!



r   ) __doc__
__future__r   collections.abcr   mathr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __all__r    r#   rV   r   r   r   r   r   <module>   s6   