UNPKG

@bokeh/bokehjs

Version:

Interactive, novel data visualization

73 lines 2.74 kB
import { ActionTool, ActionToolView } from "./action_tool"; import { CustomJS } from "../../callbacks/customjs"; import { execute } from "../../../core/util/callbacks"; import { isBoolean } from "../../../core/util/types"; import * as icons from "../../../styles/icons.css"; import { logger } from "../../../core/logging"; export class CustomActionView extends ActionToolView { static __name__ = "CustomActionView"; async _update_active() { const { active_callback } = this.model; if (active_callback == "auto") { this.model.active = !this.model.active; } else if (active_callback != null) { const active = await execute(active_callback, this.model); if (isBoolean(active)) { this.model.active = active; } else { logger.warn(`${this.model}.active_callback (${active_callback}) must return a boolean value, got ${typeof active}`); } } } async lazy_initialize() { await super.lazy_initialize(); const { active_callback } = this.model; if (!(active_callback == "auto" || active_callback == null)) { await this._update_active(); } } async _execute() { const { callback, active_callback } = this.model; if (callback != null) { const result = await execute(callback, this.model); if (active_callback != null) { await this._update_active(); } else if (isBoolean(result)) { this.model.active = result; } else if (result !== undefined) { logger.warn(`${this.model}.callback (${callback}) must return a boolean value or void, got ${typeof result}`); } } } doit() { this._await_ready(this._execute()); } } export class CustomAction extends ActionTool { static __name__ = "CustomAction"; constructor(attrs) { super(attrs); } static { this.prototype.default_view = CustomActionView; this.define(({ Func, Nullable, Ref, Or, Auto }) => ({ callback: [Nullable(Or(Ref(CustomJS), Func())), null], active_callback: [Nullable(Or(Ref(CustomJS), Func(), Auto)), null], })); this.override({ description: "Perform a Custom Action", }); // `active` and `disabled` are defined in `Tool` model as internal properties this.override_options({ active: { internal: false }, disabled: { internal: false }, }); } tool_name = "Custom Action"; tool_icon = icons.tool_icon_unknown; } //# sourceMappingURL=custom_action.js.map