Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Bokeh自定义保存工具_Javascript_Python_Coffeescript_Bokeh - Fatal编程技术网

Javascript Bokeh自定义保存工具

Javascript Bokeh自定义保存工具,javascript,python,coffeescript,bokeh,Javascript,Python,Coffeescript,Bokeh,我正试图在bokeh中创建一个自定义保存工具,以下是我所拥有的: class NewSaveTool(Tool): JS_CODE = """ import * as p from "core/properties" import {ActionTool, ActionToolView} from "models/tools/actions/action_tool" export class NewSaveToolView extends

我正试图在bokeh中创建一个自定义保存工具,以下是我所拥有的:

class NewSaveTool(Tool):
    JS_CODE = """
        import * as p from "core/properties"
        import {ActionTool, ActionToolView} from "models/tools/actions/action_tool"
        export class NewSaveToolView extends ActionToolView
            do: () -> 
                save_name = @model.source
                @plot_view.save(save_name)

        export class NewSaveTool extends ActionTool
            default_view: NewSaveToolView
            type: "SaveTool"
            tool_name: "Save"
            icon: "bk-tool-icon-save"
            @define {
                source: [ p.String ]
            }
    """
    source = String
    __implementation__ = JS_CODE
该工具将加载并位于工具栏中,但当我单击按钮时,我会看到

Uncaught TypeError: this.plot_view.save is not a function

这正是源代码中的“保存”工具所使用的函数,所以有人知道为什么它在这个实例中不起作用吗?

我很晚才回答这个问题,因为我花了太多时间才使它起作用。
这里的主要变化是“do”改为“doit”,尽管我真的不确定指定的错误是从哪里来的,这是我从未得到的少数错误之一

工作实施(至少在bokeh 12.13上)是:

实现为:
tools=[CustomSaveTool(savename='customname')]

要真正动态更改保存名称,必须更改savename属性,例如在小部件回调函数中:
plot.tools[0]。save\u name='new save name'
太好了!它起作用了! 关于上面的用法示例,只需一句话:

tools = [NewSave(savename='custom name')]
下面是一个完整的工作示例(使用CustomSaveTool作为类名):


不是答案,只是澄清一下——我认为“do”在JS中是一个保留字,是do的一部分……在循环构造时。
tools = [NewSave(savename='custom name')]
from bokeh.models import Tool, String
from bokeh.plotting import figure
from bokeh.io import show

JS_CODE_SAVE = """
import * as p from "core/properties"
import {ActionTool, ActionToolView} from "models/tools/actions/action_tool"

export class NewSaveView extends ActionToolView

  # this is executed when the button is clicked
  doit: () ->
    @plot_view.save(@model.save_name)

export class CustomSaveTool extends ActionTool
  default_view: NewSaveView
  type: "CustomSaveTool"

  tool_name: "Save"
  icon: "bk-tool-icon-save"

  @define { save_name: [ p.String ] } """

class CustomSaveTool(Tool):
    """
    Save a plot with a custom name.
    Usage: CustomSaveTool(save_name = name)
    """
    __implementation__ = JS_CODE_SAVE
    save_name = String()

tools = [CustomSaveTool(save_name = 'custom name 1')]
plot = figure(x_range = (0, 10), y_range = (0, 10), tools = tools)
plot.line(x = [1, 2, 3], y = [4, 5, 6])
plot.tools[0].save_name = 'custom name 2'
show(plot)