Edits to 'Explicit linking' section
"cell_type": "markdown",
"metadata": {},
"source": [
- "The ``DynamicMap`` we defined above simply defines returns a ``Points`` object composed of a single point that marks the current ``x`` and ``y`` position supplied by our ``PointerXY`` stream. The stream is linked whenever this ``DynamicMap`` object is displayed:"
+ "The ``DynamicMap`` we defined above simply defines returns a ``Points`` object composed of a single point that marks the current ``x`` and ``y`` position supplied by our ``PointerXY`` stream. The stream is linked whenever this ``DynamicMap`` object is displayed as it is the stream source:"
]
},
{
"source": [
"#### Explicit linking\n",
"\n",
- "In the example above we just let took advantage of the automatic linking to the object we attached the stream to. If we want to link the Stream to a different object we can pass an explicit source. Here we will create a 2D Image of sine gratings, declare that object as the ``source`` of the ``PointerXY`` stream, and then use the pointer stream to define a single point showing the cursor position on the image."
+ "In the example above, we took advantage of the fact that a ``DynamicMap`` automatically becomes the stream source if a source isn't explicitly specified. If we want to link the stream instance to a different object we can specify our our source explicitly. Here we will create a 2D ``Image`` of sine gratings, declare that is then declared as the ``source`` of the ``PointerXY`` stream. This pointer stream is then used to generate a single point that tracks the cursor when hovering over the image:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "Now if we display the ``Image`` and the ``DynamicMap`` together in a ``Layout``, the plot on the right will track the cursor position on image plot to the left, which we designated as the source:"
+ "Now if we display a ``Layout`` consisting of the ``Image`` acting as the source together with the ``DynamicMap``, the point shown on the right tracks the cursor position when hovering voer the image on the left:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "This will even work across different cells. If we add the stream to another object and display it, the new plot will be linked to the cursor position on the image plot. \n",
+ "This will even work across different cells. If we use this particular stream instance in another ``DynamicMap`` and display it, this new visualization will also be supplied with the cursor position when hovering over the image. \n",
"\n",
- "We will use the pointer x and y position to take cross-sections of the image at the hover location using the ``Image.sample`` method. We also ensure that the position does not go out of bounds."
+ "To illustrate this, we will now use the pointer ``x`` and ``y`` position to generate cross-sections of the image at the cursor position on the ``Image``, making use of the ``Image.sample`` method. Note the use of ``np.clip`` to make sure the cross-section is well defined when the cusor goes out of bounds:"
]
},
{
"outputs": [],
"source": [
"%%opts Curve {+framewise}\n",
- "hv.DynamicMap(lambda x, y: img.sample(y=y if -.5<y<.5 else 0), streams=[pointer]) +\\\n",
- "hv.DynamicMap(lambda x, y: img.sample(x=x if -.5<x<.5 else 0), streams=[pointer])"
+ "hv.DynamicMap(lambda x, y: img.sample(y=np.clip(y,-.49,.49)), streams=[pointer]) +\\\n",
+ "hv.DynamicMap(lambda x, y: img.sample(x=np.clip(x,-.49,.49)), streams=[pointer])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "Now try hovering over the ``Image`` above again and watch the cross-sections update as you move the cursor."
+ "Now when you hover over the ``Image`` above, you will see the cross-sections update while the point position to the right of the ``Image`` simultaneously updates."
]
},
{
