function get_nested_streams
Recursively traverses a DynamicMap object to extract and return all unique Stream objects found within it and its nested DynamicMaps.
/tf/active/vicechatdev/patches/spaces.py
648 - 657
simple
Purpose
This function is used to discover all Stream objects associated with a DynamicMap hierarchy. It's particularly useful in visualization frameworks (like HoloViews) where DynamicMaps can contain nested structures, and you need to collect all streams for event handling, parameter tracking, or interactive visualization setup. The function ensures no duplicate streams are returned by using a set internally.
Source Code
def get_nested_streams(dmap):
"""Recurses supplied DynamicMap to find all streams
Args:
dmap: DynamicMap to recurse to look for streams
Returns:
List of streams that were found
"""
return list({s for dmap in get_nested_dmaps(dmap) for s in dmap.streams})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
dmap |
- | - | positional_or_keyword |
Parameter Details
dmap: A DynamicMap object to be recursively searched. DynamicMap is typically a HoloViews data structure that can contain nested DynamicMaps. The function will traverse through all nested levels to find streams. Expected to have a 'streams' attribute and be compatible with the get_nested_dmaps function.
Return Value
Returns a list of unique Stream objects found within the provided DynamicMap and all its nested DynamicMaps. The list contains no duplicates due to the internal set conversion. If no streams are found, returns an empty list. Stream objects are typically used for interactive parameter updates and event handling in visualization contexts.
Dependencies
paramnumpy
Required Imports
from streams import Stream
Usage Example
# Assuming HoloViews context with DynamicMap and Stream objects
import holoviews as hv
from holoviews.streams import Stream, PointerXY
# Create a stream
pointer = PointerXY(x=0, y=0)
# Create a DynamicMap with the stream
def plot_function(x, y):
return hv.Points([(x, y)])
dmap = hv.DynamicMap(plot_function, streams=[pointer])
# Get all streams from the DynamicMap
streams = get_nested_streams(dmap)
print(f"Found {len(streams)} stream(s)")
print(streams) # [PointerXY(x=0, y=0)]
Best Practices
- Ensure the input is a valid DynamicMap object with a 'streams' attribute to avoid AttributeError
- The function depends on get_nested_dmaps being available in scope - ensure this dependency is met
- The returned list contains unique streams only, so multiple references to the same stream in different nested DynamicMaps will appear only once
- This function is read-only and does not modify the input DynamicMap or its streams
- Consider caching results if calling repeatedly on the same DynamicMap structure for performance optimization
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_nested_dmaps 79.6% similar
-
function dimensioned_streams 71.2% similar
-
function dynamicmap_memoization 56.7% similar
-
class DynamicMap 56.4% similar
-
function unbound_dimensions 51.7% similar