Exemple #1
0
def figure_constructor(tool, loader, node):
    #print('Figureeeee: /n')
    fig = loader.construct_mapping(node, deep=True)
    fmt = tool.formats.get('Figure', {})

    elements = fig.pop('elements', [])
    #print('Figureeeee2: /n', elements)
    cmds = []
    ref = fig.pop("ref", "")
    callback = fig.pop("on_change", [])
    axis = tool.formats.get("Axis", {})

    for key in fig:
        val = fig[key]
        #print('Figureeeee3: /n', val,key)
        if key in ['text', 'add_tools']:
            cmds.append((key, val))
        else:
            fmt[key] = val

    figure = Figure(**fmt)

    for key, cmd in cmds:
        if key == 'add_tools':
            figure.add_tools(*cmd)
        elif key == 'text':
            figure.text(*cmd.pop('loc'), **cmd)

    for element in elements:
        key = element.pop('kind')
        if key == 'line':
            line_fmt = tool.formats.get('Line', {})
            line_fmt.update(element)
            figure.line('x', 'y', **line_fmt)
            #print('PLOT LINE: ', line_fmt, line_fmt.update(element))
        elif key == 'circle':
            circle_fmt = tool.formats.get('Circle', {})
            circle_fmt.update(element)
            figure.circle('x', 'y', **circle_fmt)
        elif key == 'image':
            print('HElooooo!!')
            image_fmt = tool.formats.get('Image', {})
            image_fmt.update(element)
            figure.image('value', 'x', 'y', 'dw', 'dh', **image_fmt)
            #print('PLOT image: ', image_fmt, image_fmt.update(element))

    for attr, val in axis.items():
        #change axis attributes, hopefully
        setattr(figure.axis, attr, val)

    if ref:
        tool.refs[ref] = figure
    if callback:
        figure.on_change(*callback)

    yield figure
Exemple #2
0
 def add_figure_attributes(self, fig: figure, selected_keys: List):
     """
     add some annotations to the figure
     :param fig:
     :param selected_keys:
     :return:
     """
     # only show legend if at least one plot is active
     if self.active_plot_raw or self.active_plot_average or self.active_plot_trend:
         fig.legend.location = "top_left"
         fig.legend.click_policy = "hide"
     fig.xaxis.formatter = DATETIME_TICK_FORMATTER
     fig.add_tools(self.generate_tool_tips(selected_keys))
Exemple #3
0
def add_tools(plot: figure, img_directory: path):
    '''
        configure which additional tools are shown on the Bokeh page
    '''
    api = "http://localhost:5000/api/v0.1/"
    next_path = path.join(img_directory, "Right.png")
    prev_path = path.join(img_directory, "Left.png")
    approve_path = path.join(img_directory, "Check.png")
    reject_path = path.join(img_directory, "Cross.png")
    update_path = path.join(img_directory, "eye.jpeg")
    plot.add_tools(
        create_navigate_to_updated_button(update_path),
        create_nav_tool(plot, "Previous Annotation", api + "prev", prev_path),
        create_nav_tool(plot, "Next Annotation", api + "next", next_path), 
        create_approval_tool(plot, "Approval Tool", api + 'approve/true', api + "next", approve_path),
        create_approval_tool(plot, "Reject Tool", api + 'approve/false', api + "next", reject_path),
        create_poly_edit_tool(plot),
        create_poly_draw_tool(plot)
    )

    tap_tool_callback(plot)
def plot_circles(
    mol_plot: figure,
    source: ColumnDataSource,
    categorical_colour: bool = False,
    factors: Optional[List[Any]] = None,
    colormap=palettes.Category10_10,
) -> figure:
    """Add the points to a bokeh figure to render the trimer molecule.

    This enables the trimer molecules to be drawn on the figure using only
    the position and the orientations of the central molecule.

    """
    glyph_args = dict(
        x="x", y="y", fill_alpha=1, line_alpha=0, radius="radius", fill_color="colour"
    )
    if categorical_colour:
        if factors is None:
            factors = np.unique(source.data["colour"]).astype(str)
        colour_categorical = factor_cmap(
            field_name="colour", factors=factors, palette=colormap
        )
        glyph_args["fill_color"] = colour_categorical

    glyph = Circle(**glyph_args)

    mol_plot.add_glyph(source, glyph=glyph)
    mol_plot.add_tools(
        HoverTool(
            tooltips=[
                ("index", "$index"),
                ("x:", "@x"),
                ("y:", "@y"),
                ("orientation:", "@orientation"),
            ]
        )
    )
    mol_plot.toolbar.active_inspect = None
    return mol_plot
def setup_timeline_tools(plot: figure) -> None:
    """

    :param plot:
    :return:
    """
    timeline_hover = HoverTool(tooltips=[('PEP', '@PEP'), ('Title', '@Title'),
                                         ('Type', '@Type'),
                                         ('Status', '@Status'),
                                         ('Created', '@Created'),
                                         ('Python-Version', '@PythonVersion')],
                               names=["circle"])

    release_hover = HoverTool(tooltips=[('Version', '@release_number'),
                                        ('Release Date', '@release_date_str')],
                              names=["release_label"])
    plot.add_tools(timeline_hover, release_hover, BoxZoomTool(), ResetTool(),
                   SaveTool())
    url = 'https://www.python.org/dev/peps/pep-@index/'
    taptool = plot.select(type=TapTool)
    taptool.callback = OpenURL(url=url)
    taptool.names = ['circle']