Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unable to update plot.title in BokehJS #10774

Closed
oviquezr opened this issue Dec 11, 2020 · 3 comments
Closed

[BUG] Unable to update plot.title in BokehJS #10774

oviquezr opened this issue Dec 11, 2020 · 3 comments

Comments

@oviquezr
Copy link
Contributor

Version info

bokeh-*-2.2.3.js, including bokeh-api

Description of expected behavior and the observed behavior

  • plot.title = "new title" fails to update rendered title
  • the instruction does update the object records as scoped via console
  • changingplot.title_location doesn't move title as expected (see caveat)

A caveat to these two behaviors:

  • the title_location change does eventually move the text to its new location after using plot.width = <new width> to resize the plot.
  • the rendered title does not update to the new string when using the same process to try triggering the update.

Self-contained example code

Relates to:

Expand on the BokehJS Minimal Example by adding the following to the end of the script, after the two calls to addPoint(); :


function addTitle() {
    // add [new title]
    console.log(plot.title)
    plot.title = plot.title+'1';
    console.log(plot.title)

    // notify the [plot object] of "in-place" changes
    // after initial failures, tried calling plot.change.emit() thinking to mimic 
    // the source.change.emit() used for updating ColumnDataSource
    plot.change.emit()
}


var addDataButton2 = document.createElement("Button");
addDataButton2.appendChild(document.createTextNode("Add Some Text!!!"));
document.currentScript.parentElement.appendChild(addDataButton2);
addDataButton2.addEventListener("click", addTitle);

Stack traceback and/or browser JavaScript console output

Pressing the button to change the title logs the following to console:

Example of Random data
Example of Random data1
@bryevdv
Copy link
Member

bryevdv commented Dec 11, 2020

Plot titles are objects, not simple strings. You have to change plot.title.text = "new title" (in fact this is exactly what was demonstrated in the links above). As a gentle suggestion, please consider visiting the community support forums first in cases where it is not 100% certain something is a bug. If something is determined to be a bug we will recommend opening an issue with details.

@oviquezr
Copy link
Contributor Author

The title certainly behaves as an object in Python, where I can change plot.title.text = "new title" without issue.
However, I'm trying to do this with BokehJS alone, where I get that var plot = Bokeh.Plotting.figure(title="some title") yields:

typeof plot.title
"string"
typeof plot.title.text
"undefined"

I tried assigning a Title() object instead of a string when creating the plot, but I got no title rendered in that scenario.

@bryevdv
Copy link
Member

bryevdv commented Dec 11, 2020

@oviquezr evidently the JS side handles plain string init differently from the python side. You will need to initialize with a title object. This works for me in the fiddle:

 title: new Bokeh.Title({text:"A test line plot"}),

including an update in a callback with p.title.text = ...

As this is really a usage question I ask that any further discussion happen on the discourse, and not here on the tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants