Esempio n. 1
0
def highlight(
    fig: Figure,
    x_start: Any,
    x_end: Any,
    color: str = "#FF3936",
    redirect_to: str = None,
):
    """Add a box highlight to an area above the x axis.
    If a redirection URL is given, it can open the URL on double-click (this assumes datetimes are used on x axis!).
    It will pass the year, month, day, hour and minute as parameters to the URL."""
    ba = BoxAnnotation(
        left=x_start, right=x_end, fill_alpha=0.1, line_color=color, fill_color=color
    )
    fig.add_layout(ba)

    if redirect_to is not None:
        if isinstance(x_start, datetime):

            def open_order_book(
                o_url: str, box_start: datetime, box_end: datetime
            ) -> CustomJS:
                return CustomJS(
                    code="""
                    var boxStartDate = new Date("%s");
                    var boxEndDate = new Date("%s");
                    var clickedDate = new Date(cb_obj["x"]);
                    // This quick-fixes some localisation behaviour in bokeh JS (a bug?). Bring back to UTC.
                    clickedDate = new Date(clickedDate.getTime() + clickedDate.getTimezoneOffset() * 60000);
                    console.log("tapped!!");
                    if (boxStartDate <= clickedDate && clickedDate <= boxEndDate) {
                        // TODO: change this to a URL which fits the order book once we actually make it work
                        var urlPlusParams = "%s" + "?year=" + clickedDate.getUTCFullYear()
                                                 + "&month=" + (clickedDate.getUTCMonth()+1)
                                                 + "&day=" + clickedDate.getUTCDate()
                                                 + "&hour=" + clickedDate.getUTCHours()
                                                 + "&minute=" + clickedDate.getMinutes();
                        $(location).attr("href", urlPlusParams);
                    }
                """
                    % (
                        box_start.replace(tzinfo=None),
                        box_end.replace(tzinfo=None),
                        o_url,
                    )
                )

        else:
            raise NotImplementedError(
                "Highlighting only works for datetime ranges"
            )  # TODO: implement for other x-range types
        fig.js_on_event(events.DoubleTap, open_order_book(redirect_to, x_start, x_end))
Esempio n. 2
0
    options=hOptions,  #list of options
    value="KO Counts per Player"  #default value  
)

vSelect = Select(
    title="Vertical Data",
    options=vOptions,  #list of options
    value="Win Counts per Player"  #default value  
)

#layout

widgets = row(hSelect, vSelect)
layout = column(widgets, p)

curdoc().add_root(layout)
curdoc().title = "Player Plot"

#interactivity

p.js_on_event(MouseEnter,
              callbackPlot)  #plot whichever axes are currently selected

hSelect.js_on_change('value', callbackUpdateHAxis)
vSelect.js_on_change('value', callbackUpdateVAxis)

hSelect.js_on_change('value', callbackPlot)
vSelect.js_on_change('value', callbackPlot)

#show(layout)
save(layout)
Esempio n. 3
0
            data['y'].splice(move_point, 1, cb_obj.y);
            source_datapoints_JS.change.emit();

            //Limit spline calculations only when point has moved more than a distance
            if ( distance( [cb_obj.sx, cb_obj.sy], [pan_x, pan_y] )>15 ){
                source_datapoints_JS.data = {'x':data['x'], 'y':data['y']};
                pan_x=cb_obj.sx
                pan_y=cb_obj.sy
            }
        }
    }else if (cb_obj.event_name == 'panend'){
        source_datapoints_JS.data = {'x':data['x'], 'y':data['y']};
        move_point = -1;
    }

    """ % (CIRCLE_RADIUS))


for event in ['tap', 'pan', 'panstart', 'panend']:
    p.js_on_event(event, display_event())

source_datapoints.on_change('data', update_div_note)
source_datapoints.on_change('data', update_source_spline)

select_degree.on_change('value', update_div_note)
select_degree.on_change('value', update_source_spline)

# slider_knots.on_change('value', update_source_spline)

curdoc().add_root(column(div_instr, p, slider_smooth, select_degree, div_note))
Esempio n. 4
0
    title="Select Model Parameter",
    options=options,
    value="",
)

callbackGenerateDropdown = CustomJS(args=dict(select=select),
                                    code="""
    let options = [];
    for (let m = 0; m < parameters.length - 2; m++){ //excluding slop
        options.push("a" + m.toString());
    }
    select.options = options;
""")

widgets = row(select)
layout = column(widgets, p)

p.js_on_event(MouseEnter, callbackGenerateDropdown)
p.js_on_event(MouseEnter, callback_plot)

select.js_on_event(MouseEnter, callbackGenerateDropdown)
select.js_on_change('value', callbackSelectHistParam)
select.js_on_change('value', callback_plot)

curdoc().add_root(
    layout)  #any changes to layout will trigger on_change callbacks
curdoc().title = "Histogram of Parameter Distributions"

#show(layout)
save(layout)
Esempio n. 5
0
        players[i] = players_result[i];
        wins[i] = wins_result[i];
        KOs[i] = KOs_result[i];
    }

    console.log(players,wins,KOs)

    data['players'] = players;
    data['wins'] = wins;
    data['KOs'] = KOs;

    src.change.emit();   
    p.change.emit();
""")

# layout & callbacks

p.js_on_event(MouseEnter, callbackKOWin)

buttonKOWin = Button(label = "KO counts vs. Win counts per player (default)", button_type = "primary")
buttonKOWin.js_on_click(callbackKOWin)

#p.xgrid.grid_line_color = None
#p.y_range.start = 0

buttons = row(buttonKOWin)

layout = column(buttons, p)

#show(layout)
save(layout)