echoshader 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
echoshader/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ from .core import Echoshader
2
+
3
+ __all__ = ["Echoshader"]
4
+
5
+
6
+ from ._echoshader_version import version as __version__ # noqa
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ # file generated by setuptools_scm
3
+ # don't change, don't track in version control
4
+ version = '0.1.0'
5
+ version_tuple = (0, 1, 0)
echoshader/box.py ADDED
@@ -0,0 +1,167 @@
1
+ import holoviews
2
+ import numpy
3
+
4
+ from .utils import gram_opts
5
+
6
+
7
+ def get_box_stream(source_pic, bounds: tuple = None):
8
+ """
9
+ Get a Holoviews BoundsXY stream for a source plot with optional default bounds.
10
+
11
+ This function creates a Holoviews BoundsXY stream for the specified `source_pic`,
12
+ which is a Holoviews plot object. The `BoundsXY` stream allows users to interactively
13
+ select a rectangular region on the plot by dragging a box with their mouse.
14
+
15
+ Parameters
16
+ ----------
17
+ source_pic : holoviews.element
18
+ The source plot for which the BoundsXY stream will be created.
19
+ bounds : tuple, optional
20
+ The initial default bounds of the selected rectangular region (box).
21
+ If not provided, the default bounds are set to the left, bottom, right,
22
+ and top corners of the `source_pic` plot.
23
+
24
+ Returns
25
+ -------
26
+ holoviews.streams.BoundsXY
27
+ A Holoviews BoundsXY stream associated with the `source_pic` plot.
28
+ The stream allows users to interactively select a rectangular region (box)
29
+ on the plot and get the selected bounds as an output.
30
+
31
+ Examples
32
+ --------
33
+ # Assuming source_pic is a Holoviews plot object (e.g., hvplot.Image or hvplot.Scatter)
34
+ box_stream = get_box_stream(source_pic)
35
+
36
+ # Alternatively, provide custom default bounds
37
+ # custom_bounds = (0, 0, 10, 10) # (left, bottom, right, top)
38
+ box_stream = get_box_stream(source_pic, bounds=custom_bounds)
39
+
40
+ # The box_stream can be used to interactively select a rectangular region (box)
41
+ # on the plot and access the selected bounds.
42
+ # For example, you can access the bounds using:
43
+ # bounds = box_stream.bounds
44
+ # where bounds is a tuple containing the selected (left, bottom, right, top) coordinates.
45
+ """
46
+ box_stream = holoviews.streams.BoundsXY(
47
+ source=source_pic,
48
+ # define left, bottom, right, top corner of source plot as default bounds
49
+ bounds=(
50
+ (
51
+ source_pic.lbrt[0],
52
+ source_pic.lbrt[1],
53
+ source_pic.lbrt[2],
54
+ source_pic.lbrt[3],
55
+ )
56
+ if bounds is None
57
+ else bounds
58
+ ),
59
+ )
60
+
61
+ return box_stream
62
+
63
+
64
+ def get_lasso_stream(source_pic: holoviews.element, geometry: numpy.array = None):
65
+ """
66
+ Get a Holoviews Lasso stream for a source plot with optional default geometry.
67
+
68
+ This function creates a Holoviews Lasso stream for the specified `source_pic`,
69
+ which is a Holoviews plot object. The `Lasso` stream allows users to interactively
70
+ draw free-form polygonal shapes (lasso) on the plot using their mouse.
71
+
72
+ Parameters
73
+ ----------
74
+ source_pic : holoviews.element
75
+ The source plot for which the Lasso stream will be created.
76
+ geometry : numpy.array, optional
77
+ The initial default geometry of the lasso shape as an Nx2 NumPy array.
78
+ The array should contain a list of (x, y) coordinate pairs forming the
79
+ vertices of the lasso shape. If not provided, a default lasso shape will
80
+ be set using the left, bottom, right, and top corners of the `source_pic` plot.
81
+
82
+ Returns
83
+ -------
84
+ holoviews.streams.Lasso
85
+ A Holoviews Lasso stream associated with the `source_pic` plot.
86
+ The stream allows users to interactively draw lasso shapes on the plot
87
+ and get the drawn lasso geometry as an output.
88
+
89
+ Examples
90
+ --------
91
+ # Assuming source_pic is a Holoviews plot object (e.g., hvplot.Image or hvplot.Scatter)
92
+ # Create a Lasso stream with default geometry using the plot's corners
93
+ lasso_stream = get_lasso_stream(source_pic)
94
+
95
+ # Alternatively, provide custom default geometry
96
+ custom_geometry = np.array([[0, 0], [5, 5], [10, 0]])
97
+ # (x, y) coordinate pairs forming the lasso shape
98
+ lasso_stream = get_lasso_stream(source_pic, geometry=custom_geometry)
99
+
100
+ # The lasso_stream can be used to interactively draw lasso shapes on the plot
101
+ # and access the drawn lasso geometry.
102
+ """
103
+ lasso_stream = holoviews.streams.Lasso(
104
+ source=source_pic,
105
+ geometry=(
106
+ numpy.array(
107
+ [
108
+ [
109
+ source_pic.lbrt[0],
110
+ source_pic.lbrt[0],
111
+ source_pic.lbrt[2],
112
+ source_pic.lbrt[2],
113
+ ],
114
+ [
115
+ source_pic.lbrt[1],
116
+ source_pic.lbrt[3],
117
+ source_pic.lbrt[1],
118
+ source_pic.lbrt[3],
119
+ ],
120
+ ]
121
+ )
122
+ if geometry is None
123
+ else geometry
124
+ ),
125
+ )
126
+
127
+ return lasso_stream
128
+
129
+
130
+ def get_box_plot(box_stream: holoviews.streams):
131
+ """
132
+ Create a Holoviews DynamicMap for a box plot based on the given box_stream.
133
+
134
+ This function generates a Holoviews DynamicMap representing a box plot based on the provided
135
+ `box_stream`, which is a Holoviews BoundsXY stream. The box plot will dynamically update based
136
+ on the user's interaction with the `box_stream`, allowing them to select a rectangular region
137
+ on the plot.
138
+
139
+ Parameters
140
+ ----------
141
+ box_stream : holoviews.streams.BoundsXY
142
+ The Holoviews BoundsXY stream used to interactively select the box on the plot.
143
+
144
+ Returns
145
+ -------
146
+ holoviews.core.DynamicMap
147
+ A Holoviews DynamicMap representing the box plot. The box plot will be updated dynamically
148
+ based on the user's interaction with the `box_stream`.
149
+
150
+ Examples
151
+ --------
152
+ # Assuming box_stream is a Holoviews BoundsXY stream obtained from get_box_stream function
153
+ # Create a DynamicMap for the box plot based on the box_stream
154
+ box_plot = get_box_plot(box_stream)
155
+
156
+ # Display the box plot using panel
157
+ Panel.Row(box_plot)
158
+
159
+ # When the user interacts with the box_stream (selecting a rectangular region on the plot),
160
+ # the box plot will be dynamically updated to show the selected region as a box.
161
+ """
162
+ box_plot = holoviews.DynamicMap(
163
+ lambda bounds: holoviews.Bounds(bounds).opts(gram_opts),
164
+ streams=[box_stream],
165
+ )
166
+
167
+ return box_plot