@quartic/bokehjs
Version:
Interactive, novel data visualization
75 lines (58 loc) • 1.92 kB
text/coffeescript
import * as $ from "jquery"
import "bootstrap/tab"
import * as p from "core/properties"
import {zip, findIndex} from "core/util/array"
import tabs_template from "./tabs_template"
import {Widget, WidgetView} from "./widget"
export class TabsView extends WidgetView
render: () ->
super()
for own _key, child of
child.el.parentNode?.removeChild(child.el)
@$el.empty()
tabs = .tabs
active = .active
children = .children
html = $(tabs_template({
tabs: tabs
active_tab_id: tabs[active].id
}))
that = this
html.find(".bk-bs-nav a").click (event) ->
event.preventDefault()
$(this).tab('show')
panelId = $(this).attr('href').replace('#tab-','')
tabs = that.model.tabs
panelIdx = findIndex(tabs, (panel) -> panel.id == panelId)
that.model.active = panelIdx
that.model.callback?.execute(that.model)
$panels = html.find(".bk-bs-tab-pane")
for [child, panel] in zip(children, $panels)
$(panel).html([child.id].el)
@$el.append(html)
return @
export class Tabs extends Widget
type: "Tabs"
default_view: TabsView
{
tabs: [ p.Array, [] ]
active: [ p.Number, 0 ]
callback: [ p.Instance ]
}
{
children: () -> (tab.child for tab in )
}
get_layoutable_children: () ->
return
get_edit_variables: () ->
edit_variables = super()
# Go down the children to pick up any more constraints
for child in
edit_variables = edit_variables.concat(child.get_edit_variables())
return edit_variables
get_constraints: () ->
constraints = super()
# Go down the children to pick up any more constraints
for child in
constraints = constraints.concat(child.get_constraints())
return constraints