Skip to content

Allow to override non-visual glyph data properties - #13554

Merged
mattpap merged 26 commits into
branch-3.4from
mattpap/2367_inherited_data
Dec 2, 2023
Merged

mattpap merged 26 commits into
branch-3.4from
mattpap/2367_inherited_data

Conversation

@mattpap

@mattpap mattpap commented Nov 28, 2023 •

Copy link
Copy Markdown
Contributor

This PR has the following goals:

  1. Clean up definitions of data, visual and mapped properties of glyph views (set by set_data(), set_visuals() and map_data()), by removing all definitions that can auto-generated, fixing any issues and bugs along the way.
  2. Allow derived glyphs to override non-visual data properties from the base glyph and/or allow derived glyphs to be unrelated to the base glyph, under the assumption that any hit testing, indexing, etc. will still be done only on the base glyph.

Example of a derived hover glyph with 2x the radius:

Screencast.from.28.11.2023.21.38.10.webm

and with selection glyph unrelated to the base glyph:

image

Example usage:

import numpy as np

from bokeh.core.properties import field
from bokeh.models import Rect
from bokeh.plotting import figure, show

N = 1000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
radii_big = radii * 2
colors = np.array([(r, g, 150) for r, g in zip(50+2*x, 30+2*y)], dtype="uint8")

p = figure()
p.add_tools("hover", "box_select")

gr = p.circle(x, y, radius=radii,
    fill_color=colors, fill_alpha=0.8, line_color=None, hover_fill_alpha=0.5)

gr.hover_glyph.radius = field("radii_big")
gr.data_source.data["radii_big"] = radii_big

gr.selection_glyph = Rect(
    line_color=None,
    fill_color=field("fill_color"),
    width=field("radii_big"),
    height=field("radius"),
)

show(p)

fixes #2367

@mattpap mattpap added this to the 3.4 milestone Nov 28, 2023
@mattpap mattpap added the grant: SDG 2023 Funded from NumFOCUS Small Development Grant 2023 label Nov 28, 2023
@codecov

codecov Bot commented Nov 28, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #13554 (6b1c22d) into branch-3.4 (93488e5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           branch-3.4   #13554   +/-   ##
===========================================
  Coverage       92.57%   92.57%           
===========================================
  Files             322      323    +1     
  Lines           20461    20463    +2     
===========================================
+ Hits            18941    18944    +3     
+ Misses           1520     1519    -1     

@bryevdv

bryevdv commented Nov 28, 2023

Copy link
Copy Markdown
Member
export type Data = p.GlyphDataOf<Props>

👏 👏 👏

@bryevdv

bryevdv commented Nov 29, 2023

Copy link
Copy Markdown
Member

Also, just FYI, IIRC there are some explicit admonitions in the docs about non-visual props not working on sub-glyphs, so it would be go to go through and remove those as well, once this PR is closer to completion.

@mattpap
mattpap force-pushed the mattpap/2367_inherited_data branch 2 times, most recently from 5f3f2b0 to ba5d553 Compare November 30, 2023 12:17
@mattpap

mattpap commented Dec 1, 2023

Copy link
Copy Markdown
Contributor Author

Although tests pass, I expect there will be a long tail of small tweaks needed as a follow-up, to handle corner cases and unlock full potential of this change in all glyphs. I would like this to be merged soon though, given the extent of changes in this PR.

@bryevdv bryevdv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, I had a very brief look, mostly just scanning for any copy-pasta in the bulk updates. I won't claim to fully understand the details of the the new glyph inheritance. If you have a chance to write a couple of paragraphs about the design, that would be appreciated.

Agree it's best to get this in sooner rather than later in 3.4 cycle. I'd like to see the following things along with this PR:

  • new issue for 3.4 to update docs and choose some examples to show this new capability off with
  • a dev build as soon as feasible so we can do a quick scan over rendered docs

@mattpap
mattpap force-pushed the mattpap/2367_inherited_data branch from ba5d553 to 6b1c22d Compare December 2, 2023 06:57
@mattpap
mattpap merged commit dfa84da into branch-3.4 Dec 2, 2023
@mattpap
mattpap deleted the mattpap/2367_inherited_data branch December 2, 2023 08:20
Chiemezuo pushed a commit to Chiemezuo/bokeh that referenced this pull request Aug 27, 2024
* Simplify CircleView._map_data()

* Include ScreenSizeSpec in max_* attrs processing

* Add data attribute inference for all properties

* Infer data attributes in all glyphs

* Move *Data types under glyphs' namespaces

* Robustify data overrides in glyph render methods

* Update glyphs in custom extensions

* Rename coordinate attrs from e.g. _x to x

* Allow to inherit data properties

* Rename RaggedArray.{array->data}

* Allow to inherit mapped attributes

* Add conditional mapping in _{set,map}_data()

* Don't duplicate _map_data() in {H,V}Area* glyphs

* More conditional mapping in _map_data()

* Resolve nullablity of ImageBaseView.image_data

* Update unit tests in test_glyphs.py

* Update bokeh's examples

* Protect against not implemented equality

* Fix code quality in {h,v}area_step.ts

* Fix definition of HAreaStep.x2 property

* Improve ImageURL's regression unit tests

* Inherit data/mapped data in ImageURL

* Force correct API usage with 'readonly' properties

* Finalize property inheritance in _map_data()

* Remove warnings about non-visual overrides

* Add release notes
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

grant: SDG 2023 Funded from NumFOCUS Small Development Grant 2023 status: accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Different sizes not used for selection & nonselection glyphs

2 participants