Streaming Pie Chart Legend Title Update Issue

I’m hoping someone here might be able to point out what I’m doing wrong. Otherwise it might just be a bug.

I started an issue here: https://github.com/bokeh/bokeh/issues/3333

I know that the devs are likely busy with the new release coming up so I’m hoping someone here might have an idea. This is with Bokeh 0.10.0.

A recap of the issue is that I am streaming to a chart made of wedges that resembles a pie chart. When I initially load it within Firefox 42.0 everything looks correct. However when I attempt to update the plot, the title and legend get messed up. If I refresh the page the legend looks correct. Note, I will be dynamically adding wedges to the plot which is not part of this example. I also don’t want to refresh the page. : )

Code:

import time

from numpy import pi
import random

from bokeh.plotting import figure, output_server, push
from bokeh.embed import autoload_server
from bokeh.session import Session

# Setup Charts
results = {'test1': 10, 'test2': 32, 'test3': 18, 'test4': 144}

session = Session('test', load_from_config=False)
output_server('test', session=session)

plot = None

# create a figure and add a wedge glyph to it
plot = figure(toolbar_location=None,
              plot_width=800,
              plot_height=400,
              title='test title',
              x_range=(-1.5, 3),
              y_range=(-2, 2),
              min_border=10,
              min_border_left=50,
              title_text_font_size='12pt')
plot.xaxis.visible = None
plot.xgrid.grid_line_color = None
plot.yaxis.visible = None
plot.ygrid.grid_line_color = None

push()
script = autoload_server(plot, session=session, public=True)
with open('bokeh_pie.html', 'w') as of:
      of.write("<html><head><title>Test</title></head><body>\n")
      of.write('<link href="http://cdn.pydata.org/bokeh/release/bokeh-0.10.0.min.css" rel="stylesheet" type="text/css">\n')
      of.write('<script src="http://cdn.pydata.org/bokeh/release/bokeh-0.10.0.min.js"></script>\n')
      of.write(script+'\n')
      of.write('</body></html>')
while True:
    total = sum(results.values())
    colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
    wedges = []
    wedge_sum = 0
    for i, (key, val) in enumerate(results.iteritems()):
        wedge = {}
        wedge['start'] = 2*pi*wedge_sum
        wedge_sum = (val/float(total)) + wedge_sum
        wedge['end'] = 2*pi*wedge_sum
        wedge['name'] = '{:.40} ({:.2f} %)'.format(key, val/float(total))
        wedge['color'] = colors[i%len(colors)]
        wedges.append(wedge)

    plot._renderers = []

    for i, wedge in enumerate(wedges):
        plot.wedge(x=0, y=0, radius=1,
                   legend=wedge['name'],
                   start_angle=wedge['start'],
                   end_angle=wedge['end'],
                   color=wedge['color'],
                   line_color='black',
                   radius_units='data')
    plot.legend.glyph_width = 10
    #print 'after', data[question[0]].__dict__
    session.store_objects(plot)

    time.sleep(10)
    # change results
    for key in results:
        results[key] = random.randint(0, 100)
    print results

``

To run do the following (probably in 3 separate terminals):

  1. bokeh-server
  2. python bokeh_pie.py
  3. python -m SimpleHTTPServer 1234

Then open firefox and go to the bokeh_pie.html page.

Thanks,

Brian