Legend Item Centering

For a legend, is there any way to center the LegendItem(s) when the title is longer than the legend items?

For example:

I added one and only one line:
p.legend.title = "AAAAAAAAAAAAAAAAAAA"

Notice how the legend glyphs are anchored to the left like so:
Screenshot
I want the three LegendItems to be centered, but I cannot find a way to do this.

Just to add, I’ve tried the below, but none of them work:

  • p.legend.label_text_align = 'center' : doesn’t seem to do anything

  • p.legend.label_standoff = x : moves the label but the glyph is still anchored on the left

My speculation is that the text box always abuts the right hand side of the legend item, but that the text box width is left unspecified so it auto sizes to exactly the text width. In that case, “centering” means centering inside a box exactly the width of the text which is not so useful. It’s possible that we can set the text box width explicitly to the width of the legend area instead, so that centering would be useful here. But I don’t have any immediate workarounds or suggestions except to submit a GitHub Issue with full details.

Edit: looking at the code maybe it’s not exactly that but still seems like a bug to report in any case.

Thank you for your reply Bryan, it’s given me an idea for a really rough workaround.

For instance, in the above example, making three separate Legends and adding them manually by calculating their position.
Since each Legend only contains the LegendItem, it will be centered horiziontally.
Obviously extremely inelegant and inefficient, but it’s a brute force method to do what I want

p.text(text=title)
Legend1 = Legend(items=[LegendItem1])
Legend2 = Legend(items=[LegendItem2])
Legend2 = Legend(items=[LegendItem3])

#Calculate each Legend position (x,y) and add them manually to the figure

If I come up with an elegant workaround, I’ll post it here!