bokeh.models.Line

Here are the examples of the python api bokeh.models.Line taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

0 View Source File : figures.py
License : GNU General Public License v3.0
Project Creator : gotzl

def getTrackMap(target, reference=None, mode='speed', view='lapsdelta'):
    if reference is None:
        df_, df_r = target, None
    else:
        df_, df_r = acctelemetry.lapdelta(reference, target)

    ds = ColumnDataSource(df_)
    p0 = figure(plot_height=400, plot_width=800,
                tools="crosshair,pan,reset,save,wheel_zoom")

    colors = itertools.cycle(palette)
    col0, col1 = next(colors), next(colors)

    # create the velo vs dist plot
    r0 = p0.line(x='dist_lap', y='speedkmh', source=ds, color=col0, line_width=2)

    # overwrite the (non)selection glyphs with the base line style
    # the style for the hover will be set below
    nonselected_ = Line(line_alpha=1, line_color=col0, line_width=2)
    r0.selection_glyph = nonselected_
    r0.nonselection_glyph = nonselected_

    if reference is not None:
        # create the dt vs dist plot with extra y axis, set the (non)selection glyphs
        lim = max(df_.dt.abs())
        lim += lim*.2
        p0.extra_y_ranges = {"dt": Range1d(start=-lim, end=lim)}
        p0.add_layout(LinearAxis(
            y_range_name='dt',
            axis_label='dt [s]'), 'right')
        r1 = p0.line(x='dist_lap', y='dt', source=ds, y_range_name='dt', color=col1, line_width=2)
        r1.selection_glyph = Line(line_alpha=1, line_color='red', line_width=5)
        r1.nonselection_glyph = Line(line_alpha=1, line_color=col1, line_width=2)

        # create reference velo vs dist plot
        p0.line(df_r.dist_lap, df_r.speedkmh, color=next(colors), line_width=2)

    # create an invisible renderer for velo vs dist
    # this is used to trigger the hover, thus the size is large
    c0 = p0.circle(x='dist_lap', y='speedkmh', source=ds, size=10, fill_alpha=0.0, alpha=0.0)
    c0.selection_glyph = Circle(fill_color='red', fill_alpha=1., line_color=None)
    c0.nonselection_glyph = Circle(fill_alpha=0, line_color=None)

    # create figure for track map
    p1 = figure(plot_height=400, plot_width=800, tools="crosshair,pan,reset,save,wheel_zoom")

    # create map of the track
    c1 = getLapFigure(p1, df_, ds, mode, hasref=(reference is not None))

    # add some lap tangents to guide the eye when comparing map and refmap
    if reference is not None and mode not in ['absolut', 'gainloss']:
        x0 = df_.x.values
        y0 = df_.y.values
        h = df_.heading.values
        x1 = x0 + 30*np.cos(h+np.pi/2)
        y1 = y0 + 30*np.sin(h+np.pi/2)
        p1.segment(x0=x0, y0=y0, x1=x1, y1=y1, color="#F4A582", line_width=1)

        # calculate points for the reference map drawn 'outside' of the other track map
        getLapFigure(p1, df_, ds , mode, ref=True)

    # Toooltips that show some information for each point, triggered via slider.onchange JS
    tools = ['time','dist','speedkmh']
    if reference is not None:
        tools.append('speedkmh_r')
        if mode not in ['absolut', 'gainloss', 'pedals', 'speed']:
            tools.extend([mode, '%s_r'%mode])
        elif mode in ['pedals']:
            tools.extend(['throttle', 'throttle_r', 'brake', 'brake_r'])
        tools.append('dt')
    elif mode == 'pedals':
        tools.extend(['throttle', 'brake'])
    elif mode != 'speed':
        tools.append(mode)

    hover0 = createHoverTool(tools)
    # a small hack to show only one tooltip (hover selects multiple points)
    # TODO: doesn't work anymore with recent bokeh
    # hover0.tooltips[-1] = (hover0.tooltips[-1][0], hover0.tooltips[-1][1]+"""
    #       <  style>
    #         .bk-tooltip>div:not(:first-child) {display:none;}
    #      < /style>""")
    hover0.renderers = [r0]
    hover0.mode = 'vline'
    hover0.line_policy='interp'

    # selection change via button and slider. Tooltips 'hover0' will be rendered in 'p0' using rederer 'r0'
    slider = getLapSlider(ds, p0, r0, hover0, view=view)
    btns = getLapControls(ds, slider)

    # Hovertools, that emit a selection change by modifying the slider value
    callback = CustomJS(args=dict(slider=slider), code=
    """
    let val = cb_data['index'].indices[0]
    if (val!=0 && !isNaN(val))
        slider.value = cb_data['index'].indices[0];
    """)
    p0.add_tools(HoverTool(tooltips=None, renderers=[c0],
                           callback=callback,
                           line_policy='interp', mode='vline'))
    p1.add_tools(HoverTool(tooltips=None, renderers=[c1],
                           callback=callback,
                           line_policy='interp', mode='mouse', point_policy='snap_to_data'))

    p0.add_tools(hover0)
    # p1.add_tools(hover1)

    return column(btns, slider, p0, p1, sizing_mode='scale_width')




def getTrackMapPanel(df):