Here are the examples of the python api bokeh.models.Div taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
62 Examples
3
Source : trending_arccheck.py
with MIT License
from cutright
with MIT License
from cutright
def __create_divs(self):
self.div_center_line = Div(text='', width=175)
self.div_ucl = Div(text='', width=175)
self.div_lcl = Div(text='', width=175)
def update_plot(self):
3
Source : trending_delta4.py
with MIT License
from cutright
with MIT License
from cutright
def __create_divs(self):
self.div_summary = {grp: Div() for grp in GROUPS}
self.div_center_line = {grp: Div(text='', width=175) for grp in GROUPS}
self.div_ucl = {grp: Div(text='', width=175) for grp in GROUPS}
self.div_lcl = {grp: Div(text='', width=175) for grp in GROUPS}
def __create_widgets(self):
3
Source : trending_delta4.py
with MIT License
from cutright
with MIT License
from cutright
def __do_layout(self):
# TODO: Generalize for 1 or 2 groups
self.layout = column(row(self.select_y, self.select_linac[1], self.select_linac[2], self.avg_len_input,
self.percentile_input, self.bins_input),
row(self.select_energies[1], self.select_energies[2]),
row(self.start_date_picker, self.end_date_picker),
row(Div(text='Gamma Criteria: '), self.checkbox_button_group),
self.div_summary[1],
self.div_summary[2],
row(Spacer(width=10), self.fig),
Spacer(height=50),
row(Spacer(width=10), self.histogram),
Spacer(height=50),
row(Spacer(width=10), self.ichart),
row(self.div_center_line[1], self.div_ucl[1], self.div_lcl[1]),
row(self.div_center_line[2], self.div_ucl[2], self.div_lcl[2]))
def update_source_ticker(self, attr, old, new):
3
Source : log.py
with Apache License 2.0
from Drajan
with Apache License 2.0
from Drajan
def show(self, title=None):
title = title or self.title
if len(self.figures) > 0:
plot = column(
Div(text=' < h1 align="center">{} < /h1>'.format(title)), *self.figures)
show(plot)
def plot(self, *kargs, **kwargs):
3
Source : source.py
with GNU General Public License v3.0
from happydasch
with GNU General Public License v3.0
from happydasch
def _get_panel(self):
title = Paragraph(
text='Source Code',
css_classes=['panel-title'])
child = column(
[title,
Div(text=self._getSource(),
css_classes=['source-pre'],
sizing_mode='stretch_width')],
sizing_mode='stretch_width')
return child, 'Source Code'
3
Source : test_card.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_card_get_root(document, comm):
div1 = Div()
div2 = Div()
layout = Card(div1, div2)
model = layout.get_root(document, comm=comm)
ref = model.ref['id']
header = layout._header_layout._models[ref][0]
assert isinstance(model, CardModel)
assert model.children == [header, div1, div2]
assert header.children[0].text == "​"
def test_card_get_root_title(document, comm):
3
Source : test_card.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_card_get_root_header(document, comm):
div1 = Div()
div2 = Div()
div3 = Div()
layout = Card(div1, div2, header=div3)
model = layout.get_root(document, comm=comm)
ref = model.ref['id']
header = layout._header_layout._models[ref][0]
assert isinstance(model, CardModel)
assert model.children == [header, div1, div2]
assert header.children[0] is div3
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_integer_setitem():
div = Div()
gspec = GridSpec()
gspec[0, 0] = div
assert list(gspec.objects) == [(0, 0, 1, 1)]
def test_gridspec_clone():
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_clone():
div = Div()
gspec = GridSpec()
gspec[0, 0] = div
clone = gspec.clone()
assert gspec.objects == clone.objects
assert gspec.param.values() == clone.param.values()
def test_gridspec_slice_setitem():
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_slice_setitem():
div = Div()
gspec = GridSpec()
gspec[0, :] = div
assert list(gspec.objects) == [(0, None, 1, None)]
def test_gridspec_setitem_int_overlap():
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_setitem_int_overlap():
div = Div()
gspec = GridSpec(mode='error')
gspec[0, 0] = div
with pytest.raises(IndexError):
gspec[0, 0] = 'String'
def test_gridspec_setitem_slice_overlap():
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_setitem_slice_overlap():
div = Div()
gspec = GridSpec(mode='error')
gspec[0, :] = div
with pytest.raises(IndexError):
gspec[0, 1] = div
def test_gridspec_setitem_cell_override():
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_setitem_cell_override():
div = Div()
div2 = Div()
gspec = GridSpec()
gspec[0, 0] = div
gspec[0, 0] = div2
assert (0, 0, 1, 1) in gspec.objects
assert gspec.objects[(0, 0, 1, 1)].object is div2
def test_gridspec_setitem_span_override():
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_setitem_span_override():
div = Div()
div2 = Div()
gspec = GridSpec()
gspec[0, :] = div
gspec[0, 0] = div2
assert (0, 0, 1, 1) in gspec.objects
assert gspec.objects[(0, 0, 1, 1)].object is div2
def test_gridspec_fixed_with_int_setitem(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_fixed_with_int_setitem(document, comm):
div1 = Div()
div2 = Div()
gspec = GridSpec(width=800, height=500)
gspec[0, 0] = div1
gspec[1, 1] = div2
model = gspec.get_root(document, comm=comm)
assert model.children == [(div1, 0, 0, 1, 1), (div2, 1, 1, 1, 1)]
assert div1.width == 400
assert div1.height == 250
assert div2.width == 400
assert div2.height == 250
def test_gridspec_fixed_with_slice_setitem(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_fixed_with_slice_setitem(document, comm):
div1 = Div()
div2 = Div()
gspec = GridSpec(width=900, height=500)
gspec[0, 0:2] = div1
gspec[1, 2] = div2
model = gspec.get_root(document, comm=comm)
assert model.children == [(div1, 0, 0, 1, 2), (div2, 1, 2, 1, 1)]
assert div1.width == 600
assert div1.height == 250
assert div2.width == 300
assert div2.height == 250
def test_gridspec_fixed_with_upper_partial_slice_setitem(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_fixed_with_upper_partial_slice_setitem(document, comm):
div1 = Div()
div2 = Div()
gspec = GridSpec(width=900, height=500)
gspec[0, :2] = div1
gspec[1, 2] = div2
model = gspec.get_root(document, comm=comm)
assert model.children == [(div1, 0, 0, 1, 2), (div2, 1, 2, 1, 1)]
assert div1.width == 600
assert div1.height == 250
assert div2.width == 300
assert div2.height == 250
def test_gridspec_fixed_with_lower_partial_slice_setitem(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_fixed_with_lower_partial_slice_setitem(document, comm):
div1 = Div()
div2 = Div()
gspec = GridSpec(width=900, height=500)
gspec[0, 1:] = div1
gspec[1, 2] = div2
model = gspec.get_root(document, comm=comm)
assert model.children == [(div1, 0, 1, 1, 2), (div2, 1, 2, 1, 1)]
assert div1.width == 600
assert div1.height == 250
assert div2.width == 300
assert div2.height == 250
def test_gridspec_fixed_with_empty_slice_setitem(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_fixed_with_empty_slice_setitem(document, comm):
div1 = Div()
div2 = Div()
gspec = GridSpec(width=900, height=500)
gspec[0, :] = div1
gspec[1, 2] = div2
model = gspec.get_root(document, comm=comm)
assert model.children == [(div1, 0, 0, 1, 3), (div2, 1, 2, 1, 1)]
assert div1.width == 900
assert div1.height == 250
assert div2.width == 300
assert div2.height == 250
def test_gridspec_stretch_with_int_setitem(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_stretch_with_int_setitem(document, comm):
div1 = Div()
div2 = Div()
gspec = GridSpec(sizing_mode='stretch_both')
gspec[0, 0] = div1
gspec[1, 1] = div2
model = gspec.get_root(document, comm=comm)
assert model.children == [(div1, 0, 0, 1, 1), (div2, 1, 1, 1, 1)]
assert div1.sizing_mode == 'stretch_both'
assert div2.sizing_mode == 'stretch_both'
def test_gridspec_stretch_with_slice_setitem(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_stretch_with_slice_setitem(document, comm):
div1 = Div()
div2 = Div()
gspec = GridSpec(sizing_mode='stretch_both')
gspec[0, 0:2] = div1
gspec[1, 2] = div2
model = gspec.get_root(document, comm=comm)
assert model.children == [(div1, 0, 0, 1, 2), (div2, 1, 2, 1, 1)]
assert div1.sizing_mode == 'stretch_both'
assert div2.sizing_mode == 'stretch_both'
def test_gridspec_fixed_with_replacement_pane(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridbox_ncols(document, comm):
grid_box = GridBox(Div(), Div(), Div(), Div(), Div(), Div(), Div(), Div(), ncols=3)
model = grid_box.get_root(document, comm=comm)
assert len(model.children) == 8
coords = [
(0, 0, 1, 1), (0, 1, 1, 1), (0, 2, 1, 1),
(1, 0, 1, 1), (1, 1, 1, 1), (1, 2, 1, 1),
(2, 0, 1, 1), (2, 1, 1, 1)
]
for child, coord in zip(model.children, coords):
assert child[1:] == coord
def test_gridbox_nrows(document, comm):
3
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridbox_nrows(document, comm):
grid_box = GridBox(Div(), Div(), Div(), Div(), Div(), Div(), Div(), Div(), nrows=2)
model = grid_box.get_root(document, comm=comm)
assert len(model.children) == 8
coords = [
(0, 0, 1, 1), (0, 1, 1, 1), (0, 2, 1, 1), (0, 3, 1, 1),
(1, 0, 1, 1), (1, 1, 1, 1), (1, 2, 1, 1), (1, 3, 1, 1)
]
for child, coord in zip(model.children, coords):
assert child[1:] == coord
def test_gridspec_fixed_ncols():
3
Source : test_util.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_get_method_owner_instance():
div = Div()
assert get_method_owner(div.update) is div
def test_render_mimebundle(document, comm):
3
Source : test_util.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_render_mimebundle(document, comm):
div = Div()
data, metadata = render_mimebundle(div, document, comm)
assert metadata == {'application/vnd.holoviews_exec.v0+json': {'id': div.ref['id']}}
assert 'application/vnd.holoviews_exec.v0+json' in data
assert 'text/html' in data
assert data['application/vnd.holoviews_exec.v0+json'] == ''
def test_abbreviated_repr_dict():
3
Source : user_performance.py
with MIT License
from kurusugawa-computer
with MIT License
from kurusugawa-computer
def _create_div_element() -> bokeh.models.Div:
"""
HTMLページの先頭に付与するdiv要素を生成する。
"""
return bokeh.models.Div(
text=""" < h4>グラフの見方 < /h4>
< span style="color:red;">赤線 < /span>:平均値 < br>
< span style="color:blue;">青線 < /span>:四分位数 < br>
"""
)
@staticmethod
3
Source : whole_productivity_per_date.py
with MIT License
from kurusugawa-computer
with MIT License
from kurusugawa-computer
def _create_div_element() -> bokeh.models.Div:
"""
HTMLページの先頭に付与するdiv要素を生成する。
"""
return bokeh.models.Div(
text=""" < h4>用語 < /h4>
< p>「X日のタスク数」とは、X日に初めて受入完了状態になったタスクの個数です。 < /p>
"""
)
def plot(self, output_file: Path):
3
Source : uibokeh_well.py
with Apache License 2.0
from OpendTect
with Apache License 2.0
from OpendTect
def __init__(self, title, withsteps=True):
line_props = LinePropertyWidget()
field_title = bm.Div(text=title)
self.fields = {'visible': bm.CheckboxGroup(labels=[''], inline= True, active=[0], width_policy='min'),
'steps': bm.Spinner(title='Steps:',low=0,high=5, step=1)
}
self.fields.update(line_props.fields)
self.fields['visible'].on_change('active',self.visible)
self.layout = bl.column(bl.row(self.fields['visible'],field_title),
self.fields['steps'],
line_props.layout
)
def visible(self, attr, old, new):
3
Source : local_config.py
with MIT License
from phurwicz
with MIT License
from phurwicz
def dataset_help_widget():
text = 'Dataset Widgets < a href="https://phurwicz.github.io/hover/" target="_blank" rel="noreferrer noopener">Help < /a>'
return Div(text=text)
def dataset_default_sel_table_columns(feature_key):
3
Source : test_events.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_event_constructor_div():
model = Div()
event = events.Event(model)
assert event._model_id == model.id
def test_event_constructor_plot():
3
Source : test_events.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_pointevent_subclass_constructor_div():
model = Div()
for subcls in point_events:
with pytest.raises(ValueError):
subcls(model, sx=3, sy=-2, x=10, y=100)
# Testing event callback invocation
def test_buttonclick_event_callbacks():
3
Source : log.py
with MIT License
from shunithaviv
with MIT License
from shunithaviv
def show(self, title=None):
title = title or self.title
if len(self.figures) > 0:
plot = column(
Div(text=' < h1 align="center">{} < /h1>'.format(title)), *self.figures)
show(plot)
def plot(self, x, y, title=None, xlabel=None, ylabel=None, legend=None,
0
Source : month.py
with GNU Affero General Public License v3.0
from andrewcooke
with GNU Affero General Public License v3.0
from andrewcooke
def month(month):
f'''
# Month: {month}
'''
'''
$contents
'''
'''
## Preparation
'''
s = session('-v2')
output_file(filename='/dev/null')
map_size = 100
month_start = to_date(month).replace(day=1)
'''
## Generate Plot
'''
def days():
for i in Calendar().iterweekdays():
yield Div(text=f' < h2>{day_name[i]} < /h2>')
day = month_start - dt.timedelta(days=month_start.weekday())
while day.replace(day=1) < = month_start:
for weekday in range(7):
if day.month == month_start.month:
contents = [Div(text=f' < h1>{day.strftime("%d")} < /h1>')]
for a in s.query(ActivityJournal). \
filter(ActivityJournal.start >= local_date_to_time(day),
ActivityJournal.start < local_date_to_time(day + dt.timedelta(days=1))).all():
df = Statistics(s, activity_journal=a). \
by_name(ActivityReader, N.SPHERICAL_MERCATOR_X, N.SPHERICAL_MERCATOR_Y).df
contents.append(map_thumbnail(map_size, map_size, df, title=False))
df = Statistics(s, activity_journal=a). \
by_name(ActivityCalculator, N.ACTIVE_DISTANCE, N.ACTIVE_TIME).df
contents.append(Div(
text=f'{format_km(df[N.ACTIVE_DISTANCE][0])} {format_seconds(df[N.ACTIVE_TIME][0])}'))
else:
contents = [Spacer()]
yield column(contents)
day += dt.timedelta(days=1)
show(grid(list(days()), ncols=7))
0
Source : log.py
with Apache License 2.0
from Drajan
with Apache License 2.0
from Drajan
def save(self, title=None):
"""save the json file.
Parameters
----------
title: string
title of the HTML file
"""
title = title or self.title
if len(self.figures) > 0:
if os.path.isfile(self.plot_path):
os.remove(self.plot_path)
if self.first_save:
self.first_save = False
logging.info('Plot file saved at: {}'.format(
os.path.abspath(self.plot_path)))
output_file(self.plot_path, title=title)
plot = column(
Div(text=' < h1 align="center">{} < /h1>'.format(title)), *self.figures)
save(plot)
self.clear()
if self.data_format == 'json':
self.results.to_json(self.data_path, orient='records', lines=True)
else:
self.results.to_csv(self.data_path, index=False, index_label=False)
def load(self, path=None):
0
Source : variable_cell.py
with MIT License
from evdoxiataka
with MIT License
from evdoxiataka
def _initialize_toggle_div(self):
""""
Creates the toggle headers of each variable node.
"""
for space in self.spaces:
width = self.plot[space].plot_width
height = 40
sizing_mode = self.plot[space].sizing_mode
label = self.name + " ~ " + self._data.get_var_dist(self.name)
text = """parents: %s < br>dims: %s"""%(self._data.get_var_parents(self.name), list(self._data.get_idx_dimensions(self.name)))
if sizing_mode == 'fixed':
self._toggle[space] = Toggle(label = label, active = False,
width = width, height = height, sizing_mode = sizing_mode, margin = (0,0,0,0))
self._div[space] = Div(text = text,
width = width, height = height, sizing_mode = sizing_mode, margin = (0,0,0,0), background = BORDER_COLORS[0] )
elif sizing_mode == 'scale_width' or sizing_mode == 'stretch_width':
self._toggle[space] = Toggle(label = label, active = False,
height = height, sizing_mode = sizing_mode, margin = (0,0,0,0))
self._div[space] = Div(text = text,
height = height, sizing_mode = sizing_mode, margin = (0,0,0,0), background = BORDER_COLORS[0] )
elif sizing_mode == 'scale_height' or sizing_mode == 'stretch_height':
self._toggle[space] = Toggle(label = label, active = False,
width = width, sizing_mode = sizing_mode, margin = (0,0,0,0))
self._div[space] = Div(text = text,
width = width, sizing_mode = sizing_mode, margin = (0,0,0,0), background = BORDER_COLORS[0] )
else:
self._toggle[space] = Toggle(label = label, active = False,
sizing_mode = sizing_mode, margin = (0,0,0,0))
self._div[space] = Div(text = text, sizing_mode = sizing_mode, margin = (0,0,0,0), background = BORDER_COLORS[0] )
self._toggle[space].js_link('active', self.plot[space], 'visible')
def get_max_prob(self, space):
0
Source : test_card.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_card_get_root_title(document, comm):
div1 = Div()
div2 = Div()
layout = Card(div1, div2, title='Test')
model = layout.get_root(document, comm=comm)
ref = model.ref['id']
header = layout._header_layout._models[ref][0]
assert isinstance(model, CardModel)
assert model.children == [header, div1, div2]
assert header.children[0].text == "Test"
div3 = Div()
layout.header = div3
assert header.children[0] is div3
layout.header = None
assert header.children[0].text == "Test"
def test_card_get_root_header(document, comm):
0
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_fixed_with_replacement_pane(document, comm):
slider = IntSlider(start=0, end=2)
@depends(slider)
def div(value):
return Div(text=str(value))
gspec = GridSpec()
gspec[0, 0:2] = Div()
gspec[1, 2] = div
model = gspec.get_root(document, comm=comm)
((div1, _, _, _, _), (row, _, _, _, _)) = model.children
div2 = row.children[0]
assert div1.width == 400
assert div1.height == 300
assert div2.width == 200
assert div2.height == 300
slider.value = 1
assert row.children[0] is not div2
assert row.children[0].width == 200
assert row.children[0].height == 300
def test_gridspec_stretch_with_replacement_pane(document, comm):
0
Source : test_grid.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_gridspec_stretch_with_replacement_pane(document, comm):
slider = IntSlider(start=0, end=2)
@depends(slider)
def div(value):
return Div(text=str(value))
gspec = GridSpec(sizing_mode='stretch_width')
gspec[0, 0:2] = Div()
gspec[1, 2] = div
model = gspec.get_root(document, comm=comm)
((div1, _, _, _, _), (row, _, _, _, _)) = model.children
div2 = row.children[0]
assert div1.sizing_mode == 'stretch_width'
assert div1.height == 300
assert div2.sizing_mode == 'stretch_width'
assert div2.height == 300
slider.value = 1
assert row.children[0] is not div2
assert row.children[0].sizing_mode == 'stretch_width'
assert row.children[0].height == 300
def test_gridbox_ncols(document, comm):
0
Source : test_reactive.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_link_properties_nb(document, comm):
class ReactiveLink(Reactive):
text = param.String(default='A')
obj = ReactiveLink()
div = Div()
# Link property and check bokeh js property callback is defined
obj._link_props(div, ['text'], document, div, comm)
assert 'text' in div._callbacks
# Assert callback is set up correctly
cb = div._callbacks['text'][0]
assert isinstance(cb, partial)
assert cb.args == (document, div.ref['id'], comm, None)
assert cb.func == obj._comm_change
def test_link_properties_server(document):
0
Source : test_reactive.py
with BSD 3-Clause "New" or "Revised" License
from holoviz
with BSD 3-Clause "New" or "Revised" License
from holoviz
def test_link_properties_server(document):
class ReactiveLink(Reactive):
text = param.String(default='A')
obj = ReactiveLink()
div = Div()
# Link property and check bokeh callback is defined
obj._link_props(div, ['text'], document, div)
assert 'text' in div._callbacks
# Assert callback is set up correctly
cb = div._callbacks['text'][0]
assert isinstance(cb, partial)
assert cb.args == (document, div.ref['id'], None)
assert cb.func == obj._server_change
def test_text_input_controls():
0
Source : ui.py
with Apache License 2.0
from IntelLabs
with Apache License 2.0
from IntelLabs
def _create_header(train_dropdown, inference_dropdown, text_status) -> layouts.Row:
"""Utility function for creating and styling the header row in the UI layout."""
architect_logo = Div(
text=' < a href="https://intellabs.github.io/nlp-architect"> < img border="0" '
'src="style/nlp_architect.jpg" width="200"> < /a> by Intel® AI Lab',
style={
"margin-left": "500px",
"margin-top": "20px",
"font-size": "110%",
"text-align": "center",
},
)
css_link = Div(
text=" < link rel='stylesheet' type='text/css' href='style/lexicon_manager.css'>",
style={"font-size": "0%"},
)
js_script = Div(text=" < input type='file' id='inputOS' hidden='true'>")
title = Div(
text="ABSApp",
style={
"font-size": "300%",
"color": "royalblue",
"font-weight": "bold",
"margin-left": "500px",
},
)
return row(
column(
row(children=[train_dropdown, lexicons_dropdown, inference_dropdown], width=500),
row(text_status),
),
css_link,
js_script,
widgetbox(title, width=900, height=84),
widgetbox(architect_logo, width=400, height=84),
)
def empty_table(*headers):
0
Source : ui_main.py
with Apache License 2.0
from IntelLabs
with Apache License 2.0
from IntelLabs
def handle_selected_graph(selected):
logger.info("handle selected graph. selected = %s", str(selected))
label.text = "Please Wait..."
global apply_filter
if top_before is not None:
if apply_filter:
regenerate_graphs(int(top_n_dropdown.value), int(top_n_clusters_dropdown.value))
apply_filter = False
if selected == 0:
if trend_clustering is None:
graphs_area.children = [
Row(top_before, top_after),
Row(hot_trends, cold_trends),
Row(custom_trends),
]
else:
graphs_area.children = [
Row(top_before, top_after),
Row(hot_trends, cold_trends),
Row(trend_clustering, custom_trends),
Row(topic_clustering_before, topic_clustering_after),
]
if selected == 1:
graphs_area.children = [Row(top_before, top_after)]
if selected == 2:
graphs_area.children = [Row(hot_trends, cold_trends)]
if selected == 3:
if trend_clustering is None:
graphs_area.children = [Div(text="no word embedding data")]
else:
graphs_area.children = [trend_clustering]
if selected == 4:
graphs_area.children = [custom_trends]
if selected == 5:
if topic_clustering_before is None:
graphs_area.children = [Div(text="no word embedding data")]
else:
graphs_area.children = [Row(topic_clustering_before, topic_clustering_after)]
if selected == 6:
filter_topics_table_source.data = {"topics": filter_rows}
filter_topics_table_source.selected.indices = get_valid_indices()
filter_custom_table_source.data = {"topics": filter_rows}
filter_custom_table_source.selected.indices = get_custom_indices()
refresh_filter_area()
apply_filter = False
label.text = ""
def draw_ui(top_n_phrases, top_n_clusters, active_area):
0
Source : child_benefits.py
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
def child_benefits(plot_dict, data):
def setup_plot(kindergeld_df):
"""
Create the kindergeld plot.
Parameters
(pd.Dataframe): Returned by the data preparation function
"""
# Plot for kindergeld params
source = ColumnDataSource(kindergeld_df)
p = figure(
title="Kindergeld per Child",
plot_height=400,
plot_width=800,
y_range=(0, 270),
x_range=(min(kindergeld_df.index), max(kindergeld_df.index) + 1),
background_fill_color="#efefef",
tooltips="$name: @$name €",
)
kig_params = list(kindergeld_df.columns)
for i in kig_params:
p.step(
x="index",
y=i,
line_width=2,
color=Category10[len(kig_params)][kig_params.index(i)],
legend_label=i,
alpha=0.8,
muted_color=Category10[len(kig_params)][kig_params.index(i)],
muted_alpha=0.2,
source=source,
name=i,
mode="after",
)
p.circle(
x="index",
y=i,
line_width=2,
color=Category10[len(kig_params)][kig_params.index(i)],
legend_label=i,
alpha=0.8,
muted_color=Category10[len(kig_params)][kig_params.index(i)],
muted_alpha=0.2,
source=source,
name=i,
)
plot = plotstyle(p, plot_dict)
return plot
p = setup_plot(data)
description = Div(text=plot_dict["description"], width=1000,)
layout = column(description, p)
tab = Panel(child=layout, title="Child benefits")
return tab
0
Source : deductions.py
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
def deductions(plot_dict, data):
def setup_plot(src):
"""
Create the deduction plot.
Parameters
src: ColumnDataSource returned by the data preparation function
"""
# Plot for the most important deductions
p = figure(
plot_height=400,
plot_width=800,
y_range=(0, 10500),
x_range=(min(src.data["index"]), max(src.data["index"]) + 1),
tooltips="$name: $y{0} €",
)
deduct_labels = {
"beitr_erz_ausb": "Income Tax Allowance for children education",
"sächl_existenzmin": "Basic Income Tax Allowance for children",
"sparerpauschbetrag": "Allowance for Capital Gains",
"werbungskostenpauschale": "Lump-sum deduction for employment income",
"alleinerz_freibetrag": "Income Tax Allowance for Single Parents",
"grundfreibetrag": "Basic allowance",
}
for count, i in enumerate(
list(set(src.column_names) & set(deduct_labels.keys()))
):
color = Category10[len(deduct_labels.keys())][count]
p.step(
x="index",
y=i,
line_width=2,
alpha=0.8,
color=color,
legend_label=deduct_labels[i],
muted_color=color,
muted_alpha=0.2,
source=src,
name=deduct_labels[i],
mode="after",
)
p.circle(
x="index",
y=i,
line_width=2,
alpha=0.8,
color=color,
legend_label=deduct_labels[i],
muted_color=color,
muted_alpha=0.2,
source=src,
name=deduct_labels[i],
)
plot = plotstyle(p, plot_dict)
return plot
src = ColumnDataSource(data)
p = setup_plot(src)
description = Div(text=plot_dict["description"], width=1000,)
layout = column(description, p)
tab = Panel(child=layout, title="Income tax deductions")
return tab
0
Source : social_assistance.py
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
def social_assistance(plot_dict, data):
def setup_plot(src):
p = figure(
plot_width=750,
plot_height=400,
y_range=(0, 500),
x_range=(2005, 2022),
tooltips="$name: @$name €",
)
labels = list(src.data.keys())[1:]
colors = Category10[len(labels)]
for i in range(len(labels)):
p.step(
"index",
labels[i],
source=src,
line_color=colors[i],
line_width=2,
legend_label=labels[i],
alpha=0.8,
muted_color=colors[i],
muted_alpha=0.2,
name=labels[i],
mode="after",
)
p.circle(
"index",
labels[i],
source=src,
fill_color=colors[i],
line_width=2,
legend_label=labels[i],
alpha=0.8,
muted_color=colors[i],
muted_alpha=0.2,
line_color=colors[i],
name=labels[i],
)
p.xaxis.bounds = (2004, max(src.data["index"]) + 1)
p.xaxis.ticker.desired_num_ticks = 4
plot = plotstyle(p, plot_dict)
return plot
data = data.rename(
columns={
"ein_erwachsener": "Single Adult",
"zwei_erwachsene": "Adults in Couple",
"weitere_erwachsene": "Adults not in Couple",
"kinder_14_24": "Child 14 to 17 years",
"kinder_7_13": "Child 6 to 13 years",
"kinder_0_6": "Child < 6 years",
}
)
src = ColumnDataSource(data)
p = setup_plot(src)
description = Div(text=plot_dict["description"], width=1000,)
layout = column(description, p)
tab = Panel(child=layout, title="Social Assistance Rate")
return tab
0
Source : social_security.py
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
def social_security(plot_dict, data):
def setup_plot(src):
p = figure(
plot_width=900,
plot_height=400,
x_range=(1984, 2022 + 8),
tooltips="$name: @$name{0.00%}",
)
labels = list(src.data.keys())[1:]
colors = Category10[len(labels)]
for i in range(len(labels)):
p.step(
"index",
labels[i],
source=src,
line_color=colors[i],
line_width=2,
legend_label=labels[i],
alpha=0.8,
muted_color=colors[i],
muted_alpha=0.2,
name=labels[i],
mode="after",
)
p.circle(
"index",
labels[i],
source=src,
fill_color=colors[i],
line_width=2,
legend_label=labels[i],
alpha=0.8,
muted_color=colors[i],
muted_alpha=0.2,
line_color=colors[i],
name=labels[i],
)
p.xaxis.bounds = (1984, max(src.data["index"]) + 1)
plot = plotstyle(p, plot_dict)
return plot
src = ColumnDataSource(data)
p = setup_plot(src)
description = Div(text=plot_dict["description"], width=1000,)
layout = column(description, p)
tab = Panel(child=layout, title="Social security contributions")
return tab
0
Source : tax_rate.py
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
def tax_rate(plot_dict, data): # noqa: U100
def make_dataset(sel_year, tax_rate_dict_full):
dataset = tax_rate_dict_full[sel_year]
return ColumnDataSource(dataset)
def setup_plot(src):
p = figure(plot_width=800, plot_height=400, y_range=(-0.01, 0.5),)
taxplot_dict = {
"tax_rate": {"label": "Average Tax Rate", "color": "blue"},
"overall_tax_rate": {
"label": "Average Tax Rate incl. Soli",
"color": "black",
},
"marginal_rate": {"label": "Marginal Tax Rate", "color": "red"},
"overall_marginal_rate": {
"label": "Marginal Tax Rate incl. Soli",
"color": "green",
},
}
for yvar in taxplot_dict.keys():
p.line(
x="income",
y=yvar,
source=src,
line_width=2,
line_color=taxplot_dict[yvar]["color"],
legend_label=taxplot_dict[yvar]["label"],
)
plot = plotstyle(p, plot_dict)
return plot
def update_plot(attr, old, new): # noqa: U100
sel_year = year_selection.value
new_src = make_dataset(sel_year, tax_rate_dict_full)
src.data.update(new_src.data)
tax_rate_dict_full = data
year_selection = Slider(start=2002, end=2021, value=2021, step=1, title="Year")
year_selection.on_change("value", update_plot)
src = make_dataset(2021, tax_rate_dict_full)
p = setup_plot(src)
description = Div(text=plot_dict["description"], width=800,)
layout = column(description, year_selection, p)
tab = Panel(child=layout, title="Tax rate per taxable income")
return tab
0
Source : wohngeld.py
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
with GNU Affero General Public License v3.0
from iza-institute-of-labor-economics
def wohngeld(plot_dict, data):
def make_dataset(sel_year, hh_size, wg_dict):
dataset = wg_dict[sel_year][hh_size]
heatmap_source = pd.DataFrame(
dataset.stack(), columns=["Wohngeld"]
).reset_index()
heatmap_source.columns = ["Miete", "Einkommen", "Wohngeld"]
return ColumnDataSource(heatmap_source)
def update_plot(attr, old, new): # noqa: U100
sel_year = [1992, 2001, 2009, 2016, 2020, 2021][year_selection.active]
hh_size = hh_size_selection.value
new_src = make_dataset(sel_year, hh_size, wg_dict)
src.data.update(new_src.data)
def setup_plot(src):
"""
Create the heatmap plot.
src: ColumnDataSource
"""
# Prepare a color pallete and color mapper
mapper = LinearColorMapper(
# force 0 to be mapped with white color
palette=tuple(
itertools.chain(["#FFFFFF"], tuple(reversed(Viridis256[1:])))
),
low=0,
high=1000,
)
# Actual figure setup
p = figure(
plot_width=800,
plot_height=400,
x_range=(src.data["Miete"].min(), src.data["Miete"].max()),
y_range=(src.data["Einkommen"].min(), src.data["Einkommen"].max()),
tools="hover",
tooltips="Housing Benefit: @Wohngeld{0.0f}€",
)
p.rect(
x="Miete",
y="Einkommen",
width=25,
height=src.data["Einkommen"][1] - src.data["Einkommen"][0],
source=src,
line_color=transform("Wohngeld", mapper),
fill_color=transform("Wohngeld", mapper),
)
color_bar = ColorBar(
color_mapper=mapper,
location=(0, 0),
ticker=BasicTicker(desired_num_ticks=20),
formatter=NumeralTickFormatter(format="0€"),
label_standoff=12,
)
p.add_layout(color_bar, "right")
plot = plotstyle(p, plot_dict)
return plot
wg_dict = data
year_selection = RadioButtonGroup(
labels=[str(i) for i in [1992, 2001, 2009, 2016, 2020, 2021]], active=5
)
year_selection.on_change("active", update_plot)
hh_size_selection = Slider(start=1, end=12, value=4, step=1, title="Household Size")
hh_size_selection.on_change("value", update_plot)
src = make_dataset(2021, 4, wg_dict)
p = setup_plot(src)
description = Div(text=plot_dict["description"], width=1000,)
year_label = Div(text="Year")
layout = column(description, year_label, year_selection, hh_size_selection, p)
tab = Panel(child=layout, title="Housing benefits")
return tab
0
Source : whole_productivity_per_date.py
with MIT License
from kurusugawa-computer
with MIT License
from kurusugawa-computer
def plot(self, output_file: Path):
"""
全体の生産量や生産性をプロットする
"""
def add_velocity_and_weekly_moving_average_columns(df):
for column in [
"input_data_count",
"worktime_hour",
"annotation_worktime_hour",
"inspection_worktime_hour",
"acceptance_worktime_hour",
]:
df[f"{column}{WEEKLY_MOVING_AVERAGE_COLUMN_SUFFIX}"] = get_weekly_moving_average(df[column])
for denominator in ["input_data_count", "annotation_count"]:
for numerator in ["worktime", "annotation_worktime", "inspection_worktime", "acceptance_worktime"]:
df[f"{numerator}_minute/{denominator}"] = df[f"{numerator}_hour"] * 60 / df[denominator]
df[f"{numerator}_minute/{denominator}{WEEKLY_MOVING_AVERAGE_COLUMN_SUFFIX}"] = (
get_weekly_sum(df[f"{numerator}_hour"]) * 60 / get_weekly_sum(df[denominator])
)
def create_div_element() -> bokeh.models.Div:
"""
HTMLページの先頭に付与するdiv要素を生成する。
"""
return bokeh.models.Div(
text=""" < h4>注意 < /h4>
< p>「X日の作業時間」とは、「X日に教師付開始したタスクにかけた作業時間」です。
「X日に作業した時間」ではありません。
< /p>
"""
)
def create_figure(title: str, y_axis_label: str) -> bokeh.plotting.Figure:
return figure(
plot_width=1200,
plot_height=600,
title=title,
x_axis_label="教師開始日",
x_axis_type="datetime",
y_axis_label=y_axis_label,
)
def create_input_data_figure():
y_range_name = "worktime_axis"
fig_input_data = create_figure(title="日ごとの入力データ数と作業時間", y_axis_label="入力データ数")
fig_input_data.add_layout(
LinearAxis(
y_range_name=y_range_name,
axis_label="作業時間[hour]",
),
"right",
)
y_overlimit = 0.05
fig_input_data.extra_y_ranges = {
y_range_name: DataRange1d(end=df["worktime_hour"].max() * (1 + y_overlimit))
}
self._plot_and_moving_average(
fig=fig_input_data,
x_column_name="dt_first_annotation_started_date",
y_column_name="input_data_count",
legend_name="入力データ数",
source=source,
color=get_color_from_small_palette(0),
)
self._plot_and_moving_average(
fig=fig_input_data,
x_column_name="dt_first_annotation_started_date",
y_column_name="worktime_hour",
legend_name="作業時間",
source=source,
color=get_color_from_small_palette(1),
y_range_name=y_range_name,
)
return fig_input_data
if not self._validate_df_for_output(output_file):
return
df = self.df.copy()
df["dt_first_annotation_started_date"] = df["first_annotation_started_date"].map(lambda e: parse(e).date())
add_velocity_and_weekly_moving_average_columns(df)
logger.debug(f"{output_file} を出力します。")
fig_list = [
create_figure(title="教師付開始日ごとの作業時間", y_axis_label="作業時間[hour]"),
create_figure(title="教師付開始日ごとの入力データあたり作業時間", y_axis_label="入力データあたり作業時間[minute/input_data]"),
create_figure(title="教師付開始日ごとのアノテーションあたり作業時間", y_axis_label="アノテーションあたり作業時間[minute/annotation]"),
]
fig_info_list = [
{
"x": "dt_first_annotation_started_date",
"y_info_list": [
{"column": "worktime_hour", "legend": "作業時間"},
{"column": "annotation_worktime_hour", "legend": "教師付作業時間"},
{"column": "inspection_worktime_hour", "legend": "検査作業時間"},
{"column": "acceptance_worktime_hour", "legend": "受入作業時間"},
],
},
{
"x": "dt_first_annotation_started_date",
"y_info_list": [
{"column": "worktime_minute/input_data_count", "legend": "入力データあたり作業時間"},
{"column": "annotation_worktime_minute/input_data_count", "legend": "入力データあたり教師付作業時間"},
{"column": "inspection_worktime_minute/input_data_count", "legend": "入力データあたり検査作業時間"},
{"column": "acceptance_worktime_minute/input_data_count", "legend": "入力データあたり受入作業時間"},
],
},
{
"x": "dt_date",
"y_info_list": [
{"column": "worktime_minute/annotation_count", "legend": "アノテーション作業時間"},
{"column": "annotation_worktime_minute/annotation_count", "legend": "アノテーションあたり教師付作業時間"},
{"column": "inspection_worktime_minute/annotation_count", "legend": "アノテーションあたり検査作業時間"},
{"column": "acceptance_worktime_minute/annotation_count", "legend": "アノテーションあたり受入作業時間"},
],
},
]
source = ColumnDataSource(data=df)
for fig, fig_info in zip(fig_list, fig_info_list):
y_info_list: list[dict[str, str]] = fig_info["y_info_list"] # type: ignore
for index, y_info in enumerate(y_info_list):
color = get_color_from_small_palette(index)
self._plot_and_moving_average(
fig=fig,
x_column_name="dt_first_annotation_started_date",
y_column_name=y_info["column"],
legend_name=y_info["legend"],
source=source,
color=color,
)
tooltip_item = [
"first_annotation_started_date",
"task_count",
"input_data_count",
"annotation_count",
"worktime_hour",
"annotation_worktime_hour",
"inspection_worktime_hour",
"acceptance_worktime_hour",
"worktime_minute/input_data_count",
"annotation_worktime_minute/input_data_count",
"inspection_worktime_minute/input_data_count",
"acceptance_worktime_minute/input_data_count",
"worktime_minute/annotation_count",
"annotation_worktime_minute/annotation_count",
"inspection_worktime_minute/annotation_count",
"acceptance_worktime_minute/annotation_count",
]
hover_tool = create_hover_tool(tooltip_item)
fig_list.insert(0, create_input_data_figure())
for fig in fig_list:
fig.add_tools(hover_tool)
add_legend_to_figure(fig)
output_file.parent.mkdir(exist_ok=True, parents=True)
bokeh.plotting.reset_output()
bokeh.plotting.output_file(output_file, title=output_file.stem)
bokeh.plotting.save(bokeh.layouts.column([create_div_element()] + fig_list))
0
Source : _bokeh_utils.py
with MIT License
from metriculous-ml
with MIT License
from metriculous-ml
def title_div(title_rows: Sequence[str]) -> Div:
return Div(
text="".join(
f"""
< div style="
color: rgba(0,0,0,0.7);
text-align: center;
font-size: {FONT_SIZE};
font-weight: bold;
">
{title_row}
< /div>
"""
for title_row in title_rows
),
sizing_mode="stretch_width",
align="center",
)
def add_title_rows(p: Figure, title_rows: Sequence[str]) -> None:
See More Examples