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

Add size to Scatter #13958

Merged
merged 13 commits into from
Sep 11, 2024
Merged

Add size to Scatter #13958

merged 13 commits into from
Sep 11, 2024

Conversation

mosc9575
Copy link
Contributor

@mosc9575 mosc9575 commented Jul 2, 2024

This PR fixes the explicit selection glyph example by adding size parameter to the Scatter model, which is by default 4.

Here the result with the fix using bokeh 3.4.2 in a jupyter notebook after a click.

grafik

@mosc9575 mosc9575 added this to the 3.6 milestone Jul 2, 2024
@bryevdv
Copy link
Member

bryevdv commented Jul 2, 2024

I think the best solution here is for the scatter sub-glyphs to inherit size by default if the user does not override it explicitly. I.e. it should be possible but not required to override the main glyph value, for sub-glyphs. That's how other properties work for sub-glyphs.

@mattpap mattpap changed the base branch from branch-3.5 to branch-3.6 July 4, 2024 10:41
@mosc9575 mosc9575 force-pushed the fix_explicit_selection_glyph_example branch from c292ab4 to 63955e5 Compare July 13, 2024 12:12
@mosc9575
Copy link
Contributor Author

mosc9575 commented Jul 13, 2024

I tried to solve the problem and updated the javascript code to inherit from the base glyph.

For the example the visual output meets my expectations.

from bokeh.models import Scatter, Circle, ColumnDataSource
from bokeh.resources import Resources
from bokeh.plotting import figure, show, output_notebook

source = ColumnDataSource(dict(xx=[1, 2, 3, 4, 5],yy=[2, 5, 8, 2, 7]))

plot = figure(width=400, height=400, tools="tap", title="Select a circle")
renderer = plot.scatter('xx', 'yy', size=50, source=source)

selected_scatter = Circle(fill_alpha=1, fill_color="firebrick", radius=0.1)
nonselected_scatter = Scatter(fill_alpha=0.2, fill_color="blue", line_color="firebrick")

renderer.selection_glyph = selected_scatter
renderer.nonselection_glyph = nonselected_scatter

show(plot)

select_a_circle

The problem is, that the models on the Python side are not updated and I don't know how I can solve this.

@bryevdv and @mattpap Help is needed. Any suggestions on the code and how to solve this for python are welcome. I will try finish this PR afterwards.

@bryevdv
Copy link
Member

bryevdv commented Aug 25, 2024

@mosc9575 thanks for your patience, please take a look at #13957 (comment) for what I think is a better short-term "python only" solution that does not burden the user with manually keeping properties in sync, and does not burden us with technical lifts.

To fully implement this, we'll want to search and update all examples that set sub-glyphs using the bokeh.models API to follow that pattern with clone. Please let me know whether you have the bandwidth continue with these updates here. I understand, if not, but then I will close this PR.

@mosc9575
Copy link
Contributor Author

@bryevdv I will try to do this task in the next few days.

Comment on lines +4 to +5
from bokeh.models import (BasicTickFormatter, ColumnDataSource, CustomJSTickFormatter,
Div, FixedTicker, LinearAxis, LinearColorMapper, Range1d)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While working on some examples I also fixed some PEP-Warnings and had to rearange some lines for the code style checks. This is why some files have "many" changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would nice if we could enable the same style of imports, that we use under src/, for when we need to import a lot of models, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change the style of the imports the pre-push-hook test_isort fails.

We could add -m=3 to the line below

proc = run(["isort", "--gitignore", "--diff", "-c", dir], capture_output=True)

but this woul mean, we have to change all import in all files. This would be worth a new issue. Is it okey for you if I open a seperate PR, to make this change to all import in this project?

Copy link
Member

@bryevdv bryevdv Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import style under examples was made different from that under src on purpose. We can discuss whether that should be the case or not any longer, but we should not take any action regarding that in this PR. In any was there should be an issue to discuss and decide the course of action first.

Comment on lines +30 to +31
selection_glyph=quad.clone(fill_color='blue'),
nonselection_glyph=quad.clone(fill_color='gray'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change and adding the "TapTool" to the tools, this example makes more sense to me. In the newer version a click on a renderer has a visual effect.

@@ -369,7 +369,7 @@ def harea_stack(self, stackers, **kw):
Examples:

Assuming a ``ColumnDataSource`` named ``source`` with columns
*2016* and *2017*, then the following call to ``harea_stack`` will
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consecutive "will" is fixed, but this fix is unrelated to the original issue.

rearange imports
@mosc9575 mosc9575 merged commit 360e38e into branch-3.6 Sep 11, 2024
22 checks passed
@mattpap mattpap deleted the fix_explicit_selection_glyph_example branch September 11, 2024 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explicit selection glyph example broken
3 participants