简体   繁体   English

在 canvas 中拖动鼠标时,BokehJS FreehandDrawTool 没有 plot 行

[英]BokehJS FreehandDrawTool does not plot line when dragging mouse in canvas

In BokehJS 2.4.2 the FreehandDrawTool documentation is showing in the toolbar, but no line is drawn when dragging the mouse in the canvas.在BokehJS 2.4.2 中, FreehandDrawTool 文档显示在工具栏中,但在canvas 中拖动鼠标时没有绘制任何线条。

Here is a minimal example to reproduce the problem.这是重现该问题的最小示例。 This example is so minimalistic it is hard to figure out what could possibly be wrong.这个例子太简单了,很难弄清楚哪里可能出了问题。

let plot = Bokeh.Plotting.figure({
    tools: ['freehand_draw'],
    x_range: [0, 100],
    y_range: [0, 100],
});

Output of the minimal code to reproduce the problem重现问题的最少代码 Output

输出最少的代码来重现问题

Example from the FreehandDrawTool documentation FreehandDrawTool 文档中的示例

FreehandDrawTool 文档中的示例

What could prevent the line to be drawn when dragging the mouse in the canvas?在canvas中拖动鼠标时,什么可以阻止绘制线?

The goal is to have a working FreehandDrawTool.目标是拥有一个可用的 FreehandDrawTool。

UPDATE 1更新 1

Modified example according to Python example from @mosc9575 as follows and it works, The tool should be inactive by default.根据来自 @mosc9575 的 Python 示例修改后的示例如下并且有效,默认情况下该工具应处于非活动状态。 it will not work when the tool is active by default.默认情况下该工具处于活动状态时它将不起作用。 When the FreehandDrawTool is active by default you need de deactivate and activate the tool again for it to work.当 FreehandDrawTool 默认处于活动状态时,您需要停用并再次激活该工具才能使其工作。

let source = new Bokeh.ColumnDataSource({
    data : {
        xs: [[0,50,100]],
        ys: [[0,50,0]],
    },
});

let r = plot.multi_line({
    'xs': { field: 'xs' },
    'ys': { field: 'ys' },
    source: source,
});

let freehand_draw = new Bokeh.FreehandDrawTool({
    active: false,
    empty_value: 1,
    renderers: [r],
});

plot.add_tools(freehand_draw);

在此处输入图像描述

You neew to create a renderer to make your example work.您需要创建一个渲染器来使您的示例工作。 Without this renderer the draw tool has no option to add this values.没有这个渲染器,绘图工具就没有添加这个值的选项。

Python example Python 例子

from bokeh.plotting import figure, show, output_notebook
from bokeh.models import FreehandDrawTool, ColumnDataSource
output_notebook()

plot = figure(
    x_range =  [0, 100],
    y_range =  [0, 100],
    width=400,
    height=400,
    tools = ""
)

source = ColumnDataSource(dict(xs=[[0,0]], ys=[[0,0]]))

r = plot.multi_line('xs', 'ys', source=source)
tool = FreehandDrawTool(renderers=[r], empty_value=1)
plot.add_tools(tool)
show(plot)

It looks like your are doing this in JS and not in python, therefore this copy will not work as copy'n'paste, but it ilustrates the concept.看起来您是在 JS 而不是在 python 中执行此操作,因此此副本不能用作复制粘贴,但它说明了这个概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM