B
    Y                 @   sR   d Z ddlmZ ddlmZ ddlmZ ddlmZ dd	d
Z	G dd deZ
dS )zThis is the Bokeh charts interface. It gives you a high level API to build
complex plot is a simple way.

This is the Step class which lets you build your Step charts just
passing the arguments to the Chart class and calling the proper functions.
    )absolute_import   )create_and_build   )LineBuilder)	StepGlyphNc             K   s   ||d< ||d< t t| f|S )a   Create a step chart using :class:`StepBuilder
    <bkcharts.builder.step_builder.StepBuilder>` to render the geometry
    from the inputs.

    .. note::
        Only the x or y axis can display multiple variables, while the other is used
        as an index.

    Args:
        data (list(list), numpy.ndarray, pandas.DataFrame, list(pd.Series)): a 2d data
            source with columns of data for each stepped line.
        x (str or list(str), optional): specifies variable(s) to use for x axis
        y (str or list(str), optional): specifies variable(s) to use for y axis

    In addition to the parameters specific to this chart,
    :ref:`userguide_charts_defaults` are also accepted as keyword parameters.

    .. note::
        This chart type differs on input types as compared to other charts,
        due to the way that series-type charts typically are plotting labeled series.
        For example, a column for AAPL stock prices over time. Another way this could be
        plotted is to have a DataFrame with a column of `stock_label` and columns of
        `price`, which is the stacked format. Both should be supported, but the former
        is the expected one. Internally, the latter format is being derived.

    Returns:
        :class:`Chart`: includes glyph renderers that generate the stepped lines

    Examples:

    .. bokeh-plot::
        :source-position: above

        from bkcharts import Step, show, output_file

        # build a dataset where multiple columns measure the same thing
        data = dict(
                   stamp=[.33, .33, .34, .37, .37, .37, .37, .39, .41, .42,
                          .44, .44, .44, .45, .46, .49, .49],
                   postcard=[.20, .20, .21, .23, .23, .23, .23, .24, .26, .27,
                             .28, .28, .29, .32, .33, .34, .35]
               )

        # create a step chart where each column of measures receives a unique color and dash style
        step = Step(data, y=['stamp', 'postcard'],
                    dash=['stamp', 'postcard'],
                    color=['stamp', 'postcard'],
                    title="U.S. Postage Rates (1999-2015)",
                    ylabel='Rate per ounce', legend=True)

        output_file("steps.html")

        show(step)

    xy)r   StepBuilder)datar   r	   Zkws r   =lib/python3.7/site-packages/bkcharts/builders/step_builder.pyStep   s    8r   c               @   s   e Zd ZdZdd ZdS )r
   a}  This is the Step builder and it is in charge of plotting
    Step charts in an easy and intuitive way.

    Essentially, we provide a way to ingest the data, make the proper
    calculations and push the references into a source object.

    We additionally make calculations for the ranges, and finally add the
    needed stepped lines taking the references from the source.

    c             c   sl   xf| j jf | jD ]R}t|| jj|| jj|d |d d}| || x|j	D ]
}|V  qVW qW d S )NZcolordash)r   r	   Z
line_colorr   )
_datagroupbyZ
attributesr   Z
get_valuesr   Z	selectionr	   Z	add_glyphZ	renderers)selfgroupZglyphZrendererr   r   r   yield_renderersg   s    zStepBuilder.yield_renderersN)__name__
__module____qualname____doc__r   r   r   r   r   r
   [   s   
r
   )NNN)r   Z
__future__r   Zbuilderr   Zline_builderr   Zglyphsr   r   r
   r   r   r   r   <module>   s   
=