@bokeh/bokehjs
Version:
Interactive, novel data visualization
90 lines • 2.86 kB
JavaScript
import { Annotation, AnnotationView } from "./annotation";
import { Toolbar } from "../tools/toolbar";
import { build_view } from "../../core/build_views";
import { SideLayout } from "../../core/layout/side_panel";
export class ToolbarPanelView extends AnnotationView {
static __name__ = "ToolbarPanelView";
update_layout() {
this.layout = new SideLayout(this.panel, () => this.get_size(), true);
}
after_layout() {
this.toolbar_view.after_render();
}
has_finished() {
return super.has_finished() && this.toolbar_view.has_finished();
}
children_views() {
return [...super.children_views(), this.toolbar_view];
}
toolbar_view;
async lazy_initialize() {
await super.lazy_initialize();
this.toolbar_view = await build_view(this.model.toolbar, { parent: this.canvas });
}
connect_signals() {
super.connect_signals();
this.plot_view.mouseenter.connect(() => {
this.toolbar_view.set_visibility(true);
});
this.plot_view.mouseleave.connect(() => {
this.toolbar_view.set_visibility(false);
});
this.plot_view.canvas.ui_event_bus.focus.connect(() => {
this.toolbar_view.toggle_auto_scroll(true);
});
this.plot_view.canvas.ui_event_bus.blur.connect(() => {
this.toolbar_view.toggle_auto_scroll(false);
});
}
remove() {
this.toolbar_view.remove();
super.remove();
}
render() {
super.render();
this.toolbar_view.render_to(this.shadow_el);
}
get is_horizontal() {
return this.toolbar_view.model.horizontal;
}
_paint() {
const { style } = this.toolbar_view.el;
if (this.is_horizontal) {
style.width = "100%";
style.height = "unset";
}
else {
style.width = "unset";
style.height = "100%";
}
// allow shrinking past content size in flex layouts
if (this.is_horizontal) {
this.el.style.minWidth = "0";
this.el.style.minHeight = "unset";
}
else {
this.el.style.minWidth = "unset";
this.el.style.minHeight = "0";
}
}
_get_size() {
const { tools, logo } = this.model.toolbar;
return {
width: tools.length * 30 + (logo != null ? 25 : 0) + 15, // TODO: approximate, use a proper layout instead.
height: 30,
};
}
}
export class ToolbarPanel extends Annotation {
static __name__ = "ToolbarPanel";
constructor(attrs) {
super(attrs);
}
static {
this.prototype.default_view = ToolbarPanelView;
this.define(({ Ref }) => ({
toolbar: [Ref(Toolbar)],
}));
}
}
//# sourceMappingURL=toolbar_panel.js.map