Bokeh: [BUG] Jitter caching too aggressively

Created on 4 Dec 2020  路  3Comments  路  Source: bokeh/bokeh

Versions

bokeh 2.2.3 (via conda 4.8.3); Mac OS X 10.15.7

Description of expected behavior and the observed behavior

Scatter points jittered on a categorical axis don't move when the categorical factor range (provided as range parameter) is modified. In a Discourse thread, Bryan put this down to a "deficiency in the current caching behavior of the jitter transform".

Below is a brief example where a button reverses a categorical axis: red jittered points move, blue jittered ones don鈥檛.

Example

from bokeh.transform import jitter
from bokeh.models import ColumnDataSource, FactorRange, CustomJS
from bokeh.models.widgets import Button
from bokeh.layouts import column
from bokeh.plotting import figure
from bokeh.io import show

source = ColumnDataSource({
    'name': ['a', 'a', 'a', 'a', 'a'],
    'val': [1, 1, 1, 1, 1],
})

p = figure(x_range=FactorRange(factors=['a', 'b']),  
           y_range=(0, 2), plot_width=200, plot_height=200)

p.scatter(x=jitter('name', 0.5, range=p.x_range), y='val', size=5, alpha=0.5, color='blue', source=source)
p.scatter(x='name', y=jitter('val', 0.5), size=5, color='red', alpha=0.5, source=source)

button = Button(label='Reorder factors')
button.js_on_click(CustomJS(args={'x_range': p.x_range}, code="""
    const factors = [...x_range.factors];
    const reversed = factors.reverse();
    x_range.factors = reversed;
"""))
column = column(button, p)
show(column)

Screenshots or screencasts of the bug in action

Before click (original x axis):
before_click
After click (x axis factors reversed):
after_click

good first issue tag bokehjs bug

Most helpful comment

@YosephKS not anyone that I am aware so please submit a PR!

All 3 comments

Jitter should cache the offsets, not the final values with offsets baked in.

@bryevdv @sggaffney hey guys, is anyone working on this issue? I am new to this repo and would love to contribute first time.

@YosephKS not anyone that I am aware so please submit a PR!

Was this page helpful?
0 / 5 - 0 ratings