bokeh icon indicating copy to clipboard operation
bokeh copied to clipboard

[BUG] text_outline_color should stroke before fill

Open solstag opened this issue 3 years ago • 3 comments

Software versions

Python version : 3.9.9 (main, Jan 1 1970, 00:00:01) IPython version : 8.2.0 Tornado version : 5.1.1 Bokeh version : 3.0.3 BokehJS static path : /home/user/.local/lib/python3.9/site-packages/bokeh/server/static node.js version : (not installed) npm version : (not installed) Operating system : Linux-6.0.10-x86_64-with-glibc2.33

Browser name and version

No response

Jupyter notebook / Jupyter Lab version

No response

Expected behavior

Outlining text should not render it unreadable under default, and most reasonable, conditions.

Observed behavior

The fix to issue https://github.com/bokeh/bokeh/issues/12179 applies fill before stroke, making text unreadable even for default font sizes. The test provided overlooked this because it uses a large font size.

Example code

import bokeh
cds = bokeh.models.ColumnDataSource(dict(rtext=['Red text over black background should be readable regardless of its outline.'], stext=['1em text should be readable too!']))
fig = bokeh.plotting.figure(background_fill_color="red", x_range=(-2, 2), y_range=(-2, 2), width=1000)
fig.text(0, 1, text='rtext', text_color='blue', text_outline_color='red', text_align='center', source=cds)
fig.text(0, -1, text='stext', text_font_size='1em', text_color='white', text_outline_color='blue', text_align='center', source=cds)
bokeh.plotting.output_file('test_text_outline_color.html', mode='inline')
bokeh.plotting.save(fig)

Stack traceback or browser console output

The patch should be trivial so I won't bother offering a pull request, but if it helps motivate you folks let me know.

Screenshots

This is what it looks like today: Screenshot from 2022-12-21 04-18-00

This is what you get with stroke before fill: Screenshot from 2022-12-21 04-17-46

solstag avatar Dec 21 '22 03:12 solstag

Fill (and hatch) then stroke is the paint order we use across bokehjs. If we would go ahead with a different order in text painting, then we may also consider this in other cases. Perhaps we could make it configurable (similarly to SVG), though that would be quite a bit more work.

mattpap avatar Dec 24 '22 09:12 mattpap

Ni! So, another possibility would be to allow setting the stroke's lineWidth through a "text_outline_width" argument. Then having a default value that works well with default font size. I suspect this could actually provide the best solution, but requires some experimentation.

solstag avatar Dec 24 '22 11:12 solstag

Ni! So, another possibility would be to allow setting the stroke's lineWidth through a "text_outline_width" argument. Then having a default value that works well with default font size. I suspect this could actually provide the best solution, but requires some experimentation.

I think this should definitely be added; basically all other decorations have widths associated with them.

As of right now, now being able to specify the outline width makes the outline option essentially useless; for me, at least, a light gray outline around black text looks horrible

Screen Shot 2024-06-27 at 10 08 17 AM

Yet without the ability to change the outline width, I see no solutions other than scaling up the font or trying different font families, both of which are far from ideal

peekxc avatar Jun 27 '24 14:06 peekxc