def _add_layer(cls, plot: figure, layer_document: ChartLayerDocument) -> None: """ Create circle on a plot figure. Method creates circle and adjusts it based on configuration. The circle is appended to the provided plot. :param layer_document: (LayerDocument) layer document object containing ingredients and configuration. :param plot: (bokeh.plotting.figure) bokeh figure to create circle on. :return: None """ layer_model = layer_document.model layer_figure = layer_model.figure axis = layer_model.axis axis.name = axis.name or axis.data_field plot.yaxis.axis_label = axis.name plot.yaxis.axis_label = axis.name or axis.data_field plot.circle(layer_document.x_axis.data_field, axis.data_field, color=layer_figure.colour, alpha=layer_figure.opacity, legend=axis.name, size=layer_figure.size * cls._scale, source=layer_document.data_source)
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
def create_poly_edit_tool(plot: figure): p1 = plot.patches([], [], fill_alpha=0.4) c1 = plot.circle([], [], size=10, color='red') return PolyEditTool(renderers = [p1], vertex_renderer = c1)