-
-
Notifications
You must be signed in to change notification settings - Fork 416
fix: add tools directly to Overlay #6713
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
Open
Azaya89
wants to merge
26
commits into
main
Choose a base branch
from
fix-6240
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+400
−38
Open
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5d1a553
add specified tools directly on overlay
Azaya89 769c838
add tool_id helper fxn and address sub_cordinate_y plots
Azaya89 025d4fd
add tests
Azaya89 961ce93
Merge branch 'main' into fix-6240
Azaya89 dbd03ed
Merge branch 'main' into fix-6240
Azaya89 7cdb736
refactor init_tools
Azaya89 8dfb343
small refactoring
hoxbro 5d579a3
parameterize the tests
Azaya89 93bd708
add more identifiers
Azaya89 31d3e04
Merge branch 'main' into fix-6240
Azaya89 42761e6
no need to check for tuples
Azaya89 a725c8d
deduplicate by multiple properties
Azaya89 9d9d756
add docstring
Azaya89 cdfbfe3
Merge branch 'main' into fix-6240
Azaya89 83af7f4
Merge branch 'main' into fix-6240
Azaya89 5fb2bb2
refactor get_tool_id
Azaya89 99fa3ab
Merge branch 'main' into fix-6240
Azaya89 ddccdea
Merge branch 'main' into fix-6240
Azaya89 21d6328
small test improvement
Azaya89 e1dac52
Merge branch 'main' into fix-6240
Azaya89 e2d73dc
Merge branch 'main' into fix-6240
Azaya89 1f796b6
refactor get_tool_id and init_tools
Azaya89 436bfaf
add more tests
Azaya89 c60cdb4
Merge branch 'main' into fix-6240
Azaya89 1ad8d75
Merge branch 'main' into fix-6240
Azaya89 b2f65ad
use hv. imports
Azaya89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1263,3 +1263,107 @@ def get_ticker_axis_props(ticker): | |
| if labels is not None: | ||
| axis_props['major_label_overrides'] = dict(zip(ticks, labels, strict=None)) | ||
| return axis_props | ||
|
|
||
|
|
||
| _DIRECTIONAL_TOOL_BASES = { | ||
| 'wheel_zoom': 'both', | ||
| 'pan': 'both', | ||
| 'zoom_in': 'both', | ||
| 'zoom_out': 'both', | ||
| 'box_zoom': 'both', | ||
| 'wheel_pan': 'both', | ||
| 'box_select': 'both', | ||
| 'crosshair': 'both', | ||
| } | ||
|
|
||
| _TOOL_ALIAS_IDS = { | ||
| 'tap': 'tap', | ||
| 'click': 'inspect', | ||
| 'doubletap': 'doubletap', | ||
| 'auto_box_zoom': 'auto', | ||
| } | ||
|
|
||
|
|
||
| def _get_tool_id_from_str( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the str check into a separate helper fxn |
||
| tool: str, | ||
| tool_type: type[tools.Tool], | ||
| ) -> tuple[type[tools.Tool], str | None]: | ||
| """Return (tool_type, identifier) for a string tool name.""" | ||
| if tool in _DIRECTIONAL_TOOL_BASES: | ||
| return tool_type, _DIRECTIONAL_TOOL_BASES[tool] | ||
| if tool.startswith(('x', 'y')) and tool[1:] in _DIRECTIONAL_TOOL_BASES: | ||
| dimension = 'width' if tool.startswith('x') else 'height' | ||
| return tool_type, dimension | ||
| if tool in _TOOL_ALIAS_IDS: | ||
| return tool_type, _TOOL_ALIAS_IDS[tool] | ||
| return tool_type, None | ||
|
|
||
|
|
||
| def get_tool_id( | ||
| tool: str | tools.Tool, | ||
| *, | ||
| properties: tuple[str, ...] = ( | ||
| 'dimensions', | ||
| 'dimension', | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added 'dimension' for WheenPanTool specifically |
||
| 'tags', | ||
| 'name', | ||
| 'description', | ||
| 'icon', | ||
| ), | ||
| skip_tags: set[str] | None = None, | ||
| ) -> tuple[type[tools.Tool], str | tuple | None]: | ||
| """ | ||
| Returns the tool type and an identifier for a given tool. | ||
|
|
||
| The identifier allows distinguishing tools of the same type but with | ||
| different properties. This function checks all disambiguation properties | ||
| and returns a composite identifier if multiple properties are present. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| tool : str or Bokeh Tool class | ||
| Tool specification as string name or Tool class instance | ||
| properties : tuple of str, optional | ||
| Properties to check for disambiguation (default: dimensions, dimension, | ||
| tags, name, description, icon) | ||
| skip_tags : set of str or None, optional | ||
| Tag values to ignore during identification (default: {'hv_created'}) | ||
|
|
||
| Returns | ||
| ------- | ||
| tuple[type[tools.Tool], str | tuple | None] | ||
| Tuple of (tool_type, identifier). The identifier can be: | ||
| - str: Single property value (e.g., 'both', 'width') | ||
| - tuple: Multiple property values as tuple of tuples | ||
| - None: No distinguishing properties | ||
| """ | ||
| if skip_tags is None: | ||
| skip_tags = {'hv_created'} | ||
|
|
||
| if isinstance(tool, str): | ||
| tool_type = TOOL_TYPES.get(tool) | ||
| return _get_tool_id_from_str(tool, tool_type) | ||
|
|
||
| tool_type = type(tool) | ||
| identifiers = {} | ||
| for prop_name in properties: | ||
| value = getattr(tool, prop_name, None) | ||
| if value is None: | ||
| continue | ||
| # Filter out internal tags; skip if nothing user-visible remains | ||
| if prop_name == 'tags': | ||
| visible = [t for t in value if t not in skip_tags] | ||
| if not visible: | ||
| continue | ||
| value = tuple(visible) | ||
| # Convert lists to tuples for hashability | ||
| elif isinstance(value, list): | ||
| value = tuple(value) | ||
|
|
||
| identifiers[prop_name] = value | ||
|
|
||
| if not identifiers: | ||
| return tool_type, None | ||
| if len(identifiers) == 1: | ||
| return tool_type, next(iter(identifiers.values())) | ||
| return tool_type, tuple(identifiers.items()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more tools and tool aliases that were missed before.