散景自定义保存工具 [英] Bokeh Custom Save Tool

查看:55
本文介绍了散景自定义保存工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  Class NewSaveTool(Tool):JS_CODE ="从核心/属性"中导入*作为p从模型/工具/动作/action_tool"导入{ActionTool,ActionToolView}导出类NewSaveToolView扩展了ActionToolView做:()->save_name = @ model.source@ plot_view.save(保存名称)导出类NewSaveTool扩展了ActionTooldefault_view:NewSaveToolView类型:"SaveTool"tool_name:保存"图标:"bk-tool-icon-save"@定义 {来源:[p.String]}"源=字符串__实现__ = JS_CODE 

该工具会加载并位于工具栏中,但是当我单击该按钮时,我会得到

 未捕获的TypeError:this.plot_view.save不是函数 

这是源代码中保存工具使用的确切功能,所以有人知道为什么它在这种情况下不起作用吗?

解决方案

回答得很晚,因为它花费了我太多的时间才能使它起作用.
主要的更改是从做"到做",尽管老实说我不确定指定的错误来自哪里,这是我从未遇到过的少数错误之一.

一个有效的实现(至少在bokeh 12.13上)是:

  JS_CODE_SAVE ="从核心/属性"中导入*作为p从模型/工具/动作/action_tool"导入{ActionTool,ActionToolView}导出类NewSaveView扩展了ActionToolView#单击按钮时执行doit:()->@ plot_view.save(@ model.save_name)导出类NewSave扩展了ActionTooldefault_view:NewSaveView类型:"NewSave"tool_name:保存"图标:"bk-tool-icon-save"@define {save_name:[p.String]}"NewSave(Tool)类:"使用自定义名称保存图.用法:NewSaveTool(save_name =名称)"__实现__ = JS_CODE_SAVEsave_name =字符串() 

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

要实际动态更改保存名称,必须更改savename属性,例如,在小部件回调函数中: plot.tools [0] .save_name ='new save name'

I'm Trying to create a custom Save tool in bokeh, and here's what I have:

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

The tool loads and is in the toolbar, but when I click the button, I get

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

This is the exact function that the save tool in the source uses, so does anyone know why it didn't work in this instance?

解决方案

Answering this late on since it took me far too much time to make it work.
The main change here is 'do' to 'doit', though I'm honestly not sure where the specified error is from, one of the few I never got.

A working implementation (on bokeh 12.13 at least) is:

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 NewSave extends ActionTool
  default_view: NewSaveView
  type: "NewSave"

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

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

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

Implemented as: tools = [CustomSaveTool(savename='custom name')]

To actually dynamically change the save name, you have to change the savename attribute, so eg in a widget callback function: plot.tools[0].save_name = 'new save name'

这篇关于散景自定义保存工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆