Updated the transient streams section
"cell_type": "markdown",
"metadata": {},
"source": [
- "In the basic [Streams](Streams.ipynb) tutorial we already discovered the idea of transient streams, which reset their values to ``None`` when the stream is not active. Transient streams are particularly useful when you are subscribed to multiple streams sending discrete events. A good example are the ``Tap`` and ``DoubleTap`` streams; while you sometimes just want to know the last tapped position, we can only tell the two events apart if their values are ``None`` when not active. \n",
+ "In the basic [Streams](Streams.ipynb) tutorial we saw that stream parameters can be updated and those values are then passed to the callback. This model works well for many different types of streams that have a well-defined values at all times.\n",
+ "\n",
+ "This approach is not suitable for certain events which only have a well defined value at a particular point in time. For instance, when you hover your mouse over a plot, the hover position always has a well-defined value but the click position is only defined when a click occurs (if it occurs).\n",
+ "\n",
+ "This latter case are what are called 'transient' streams. These streams are supplied new values only when they occur and fall back to a default value at all other times. This default value is typically ``None`` to indicate that the event is not occuring and therefore has no data.\n",
+ "\n",
+ "\n",
+ "Transient streams are particularly useful when you are subscribed to multiple streams, some of which are only occasionally triggered. A good example are the ``Tap`` and ``DoubleTap`` streams; while you sometimes just want to know the last tapped position, we can only tell the two events apart if their values are ``None`` when not active. \n",
"\n",
"We'll start by declaring a ``Tap`` and a ``DoubleTap`` stream as ``transient``. Since both streams supply 'x' and 'y' parameters, we will rename the ``DoubleTap`` parameters to 'x2' and 'y2'."
]
"taps = []\n",
"\n",
"def record_taps(x, y, x2, y2):\n",
- " if x and y:\n",
+ " if None not in [x,y]:\n",
" taps.append((x, y, 1))\n",
- " elif x2 and y2:\n",
+ " elif None not in [x2, y2]:\n",
" taps.append((x2, y2, 2))\n",
" return hv.Points(taps, vdims=['Taps'])"
]
"cell_type": "markdown",
"metadata": {},
"source": [
- "Now try single- and double-tapping within the plot area, each time you tap a new point is appended to the list and displayed. We can also inspect the list of taps directly:"
+ "Now try single- and double-tapping within the plot area, each time you tap a new point is appended to the list and displayed. Single taps show up in red and double taps show up in grey. We can also inspect the list of taps directly:"
]
},
{
