What are you trying to do?
I have a user-request to implement “scale binning” based on the plotted data. Let me elaborate on what that means as it’s a weird hybrid between Range1d and DataRange1d and best explained as an example:
If the computed bounds (it’ll have to be in both x and y dims but keeping it one dimensional for illustration) for a set of renderers are both between 0 and 10, I want to set the figure’s range to be from 0 to 10 (i.e. assign a Range1d w start/end 0/10. If the computed bounds change to say between 10 and 100, I want to hard set the figure’s range to 0 to 100.
Essentially I want 3-4 pre-cooked scales (e.g. 0-10, 0-100, 0-500 etc.), and based on the extent of the current renderers I want the appropriate scale selected and set.
What have you tried that did NOT work as expected?
My idea was:
Within a CustomJS callback that updates when the renderer data sources change → e.g. trigger it with renderer.data_source.js_on_change('data')
for every renderer I want considered) …
//Instantiate a DataRange1d object and set its renderers property
var dr_ctr = Bokeh.Models._known_models.get('DataRange1d')
var dtr = new dr_ctr({renderers:renderers})
//assign that object to the figure's x_range
fig.x_range = dtr
//somehow trigger the datarange1d to compute the plot bounds/range
//??????
//retrieve that range
var rng = [dtr.min,dtr.max] //might not be these props even but this info is stored on it
//then based on that range figure out what scale bin it falls into...
//then instantiate a Range1d model with that scale
//then assign that Range1d model to the figure's x_range
Where I’m lost (and I’ve looked deep into the BokehJS internals for DataRange1d to try and figure this out), is how the heck DataRange1d computes the range/bounds/extent and how to get it to do that successfully within a CustomJS callback. If I console.log(dtr) after assignment to the figure within the CustomJS, the min/max/start/end/_computed_bounds are all undefined/NaN.
I’ve tried .update()
and I get an exception in _compute_plot_bounds
because (I believe) it needs a Bounds
type as the second argument:
and that is undefined for my instantiated DataRange1d. This kinda indicates to me that I’m missing assignment of some key properties on my instantiation of DataRange1d (i.e. it needs more than just a renderers argument given to it). It’s either that, or I’m missing some method/function call I should do instead…
Any help/thoughts appreciated…