line.glyph.visible doesn't act immediately

The code below shows a minimum working example. It’s run with bokeh serve --show <filename> (Bokeh v0.11.0). Here is the problem: when the curdoc().add_periodic_callback is not active, clicking on the “Line visible” checkbox does not affect whether the line is visible in the plot. However, as soon as the button is clicked, which sets curdoc().add_periodic_callback, the line becomes visible or not depending on the state of line.glyph.visible.

Note that if I uncomment the two lines in the function checkbox_group_handler that set line.glyph.line_alpha, then checking and unchecking the checkbox causes the line to immediately become visible or invisible, respectively.

Why doesn’t setting line.glyph.visible immediately act on the line? Is there something else I need to call to make it immediately render the line according to its visible property?

Thanks,

Greg

from bokeh.plotting import figure, curdoc, vplot,  hplot

from bokeh.models.widgets import Toggle, CheckboxGroup

import numpy as np

ii = 0

periodic_callback_time_ms = 100

x = np.linspace(0,6,501)

y = np.cos(2*np.pi*x)

p = figure(x_range=(0,6), y_range=(-1.1,1.4))

ll = p.line(x, y, line_width=2, color="blue")

tt = p.text(0.5, 1.2, text=['counter = {}'.format(ii)],

			text_align="left", text_font_size="10pt")

# Set up checkboxes to show/hide line

def checkbox_group_handler(active):

	if 0 in active:

		ll.glyph.visible = True

		#ll.glyph.line_alpha = 1.0

	else:

		ll.glyph.visible = False

		#ll.glyph.line_alpha = 0.0

checkbox_group = CheckboxGroup(labels=["Line visible"], active=[0])

checkbox_group.on_click(checkbox_group_handler)

# Set up toggle button & callback function

def toggle_handler(active):

	if active:

		toggle.label = 'Stop'

		checkbox_group.disabled = True

		curdoc().add_periodic_callback(update, periodic_callback_time_ms)

	else:

		toggle.label = 'Start'

		checkbox_group.disabled = False

		curdoc().remove_periodic_callback(update)

toggle = Toggle(label="Start", type="success")

toggle.on_click(toggle_handler)

toggle.active = False

layout = vplot(toggle, checkbox_group, p)

def update():

	global ii

	ii += 1

	tt.data_source.data["text"] = ['counter = {}'.format(ii)]

Why doesn't setting `line.glyph.visible` immediately act on the line?

It's a bug / missing feature, the plumbing around triggering re-renders from glyph properties needs a little love:

  https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/renderer/glyph/glyph_renderer.coffee#L53

Two comments:

* The alpha setting seems like an OK workaround for the time being

* But, if you'd like to submit a PR that adds something like:

  @listenTo(@mget('glyph'), 'visible', () ->
          @request_render()
      )

in the place I linked above (that you test works, but it should) then I would be amenable to adding it as a "quick fix" pending some more comprehensive cleanup and refactoring around properties, because having "visible" work would be extremely useful in many areas. Ideally a PR would also have an example that shows it being used and/or documentation support in the user guide.

Thanks,

Bryan

···

On Jan 13, 2016, at 1:43 AM, Greg Nordin <[email protected]> wrote:

The code below shows a minimum working example. It's run with `bokeh serve --show <filename>` (Bokeh v0.11.0). Here is the problem: when the `curdoc().add_periodic_callback` is not active, clicking on the "Line visible" checkbox does not affect whether the line is visible in the plot. However, as soon as the button is clicked, which sets `curdoc().add_periodic_callback`, the line becomes visible or not depending on the state of `line.glyph.visible`.

Note that if I uncomment the two lines in the function `checkbox_group_handler` that set `line.glyph.line_alpha`, then checking and unchecking the checkbox causes the line to immediately become visible or invisible, respectively.

Is there something else I need to call to make it immediately render the line according to its `visible` property?

Thanks,
Greg

  from bokeh.plotting import figure, curdoc, vplot, hplot
  from bokeh.models.widgets import Toggle, CheckboxGroup
  import numpy as np

  ii = 0
  periodic_callback_time_ms = 100

  x = np.linspace(0,6,501)
  y = np.cos(2*np.pi*x)

  p = figure(x_range=(0,6), y_range=(-1.1,1.4))
  ll = p.line(x, y, line_width=2, color="blue")
  tt = p.text(0.5, 1.2, text=['counter = {}'.format(ii)],
        text_align="left", text_font_size="10pt")

  # Set up checkboxes to show/hide line
  def checkbox_group_handler(active):
    if 0 in active:
      ll.glyph.visible = True
      #ll.glyph.line_alpha = 1.0
    else:
      ll.glyph.visible = False
      #ll.glyph.line_alpha = 0.0
  checkbox_group = CheckboxGroup(labels=["Line visible"], active=[0])
  checkbox_group.on_click(checkbox_group_handler)

  # Set up toggle button & callback function
  def toggle_handler(active):
    if active:
      toggle.label = 'Stop'
      checkbox_group.disabled = True
      curdoc().add_periodic_callback(update, periodic_callback_time_ms)
    else:
      toggle.label = 'Start'
      checkbox_group.disabled = False
      curdoc().remove_periodic_callback(update)
  toggle = Toggle(label="Start", type="success")
  toggle.on_click(toggle_handler)
  toggle.active = False

  layout = vplot(toggle, checkbox_group, p)

  def update():
    global ii
    ii += 1
    tt.data_source.data["text"] = ['counter = {}'.format(ii)]

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/4d8331ba-63f5-4d45-961a-15d0b01b25de%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.