Skip to content

Commit

Permalink
Add ability to set active tools (#3251)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Dec 7, 2018
1 parent bf0f51d commit 964b82f
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 66 deletions.
2 changes: 1 addition & 1 deletion examples/reference/streams/bokeh/Bounds.ipynb
Expand Up @@ -45,7 +45,7 @@
" kdims=[], streams=[sel])\n",
"\n",
"# Declare a Bounds stream and DynamicMap to get box_select geometry and draw it\n",
"box = streams.Bounds(source=points, bounds=(0,0,0,0))\n",
"box = streams.BoundsXY(source=points, bounds=(0,0,0,0))\n",
"bounds = hv.DynamicMap(lambda bounds: hv.Bounds(bounds), streams=[box])\n",
"\n",
"# Declare DynamicMap to apply bounds selection\n",
Expand Down
6 changes: 3 additions & 3 deletions examples/reference/streams/bokeh/BoundsX.ipynb
Expand Up @@ -33,8 +33,6 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Curve[tools=['xbox_select']]\n",
"\n",
"n=200\n",
"xs = np.linspace(0, 1, n)\n",
"ys = np.cumsum(np.random.randn(n))\n",
Expand All @@ -45,7 +43,9 @@
" sub = df.set_index('x').loc[boundsx[0]:boundsx[1]]\n",
" return hv.Table(sub.describe().reset_index().values, 'stat', 'value')\n",
"\n",
"curve + hv.DynamicMap(make_from_boundsx, streams=[streams.BoundsX(source=curve, boundsx=(0,0))])"
"dmap = hv.DynamicMap(make_from_boundsx, streams=[streams.BoundsX(source=curve, boundsx=(0,0))])\n",
"\n",
"curve.options(tools=['xbox_select']) + dmap"
]
},
{
Expand Down
12 changes: 8 additions & 4 deletions examples/reference/streams/bokeh/BoundsY.ipynb
Expand Up @@ -22,7 +22,8 @@
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import streams\n",
"from holoviews import opts, streams\n",
"\n",
"hv.extension('bokeh')"
]
},
Expand All @@ -32,8 +33,6 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Curve[tools=['ybox_select']]\n",
"\n",
"xs = np.linspace(0, 1, 200)\n",
"ys = xs*(1-xs)\n",
"curve = hv.Curve((xs,ys))\n",
Expand All @@ -48,8 +47,13 @@
" times = [\"{0:.2f}\".format(x) for x in sorted(np.roots([-1,1,-boundsy[0]])) + sorted(np.roots([-1,1,-boundsy[1]]))]\n",
" return hv.ItemTable(sorted(zip(['1_entry', '2_exit', '1_exit', '2_entry'], times)))\n",
"\n",
"area_dmap = hv.DynamicMap(make_area, streams=[bounds_stream])\n",
"table_dmap = hv.DynamicMap(make_items, streams=[bounds_stream])\n",
"\n",
"curve * hv.DynamicMap(make_area, streams=[bounds_stream]) + hv.DynamicMap(make_items, streams=[bounds_stream])"
"(curve * area_dmap + table_dmap).options(\n",
" opts.Layout(merge_tools=False),\n",
" opts.Overlay(tools=['ybox_select'], active_tools=['ybox_select'])\n",
")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/reference/streams/bokeh/BoxEdit.ipynb
Expand Up @@ -57,10 +57,10 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Polygons [width=400 height=400 default_tools=[]] (fill_alpha=0.5)\n",
"boxes = hv.Polygons([hv.Box(0, 0, 1), hv.Box(2, 1, 1.5), hv.Box(0.5, 1.5, 1)])\n",
"box_stream = streams.BoxEdit(source=boxes, num_objects=2)\n",
"boxes"
"boxes.options(\n",
" active_tools=['box_edit'], fill_alpha=0.5, height=400, width=400)"
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions examples/reference/streams/bokeh/FreehandDraw.ipynb
Expand Up @@ -34,9 +34,11 @@
"metadata": {},
"outputs": [],
"source": [
"path = hv.Path([]).options(width=400, height=400, default_tools=[], line_width=10)\n",
"path = hv.Path([])\n",
"freehand = streams.FreehandDraw(source=path, num_objects=3)\n",
"path"
"\n",
"path.options(\n",
" active_tools=['freehand_draw'], height=400, line_width=10, width=400)"
]
},
{
Expand Down
15 changes: 11 additions & 4 deletions examples/reference/streams/bokeh/PointDraw.ipynb
Expand Up @@ -21,7 +21,9 @@
"outputs": [],
"source": [
"import holoviews as hv\n",
"from holoviews import streams\n",
"from holoviews import opts, streams\n",
"from holoviews.plotting.links import DataLink\n",
"\n",
"hv.extension('bokeh')"
]
},
Expand Down Expand Up @@ -59,12 +61,17 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Points (color='color' size=10) [tools=['hover'] width=400 height=400] \n",
"%%opts Layout [shared_datasource=True] Table (editable=True)\n",
"data = ([0, 0.5, 1], [0, 0.5, 0], ['red', 'green', 'blue'])\n",
"points = hv.Points(data, vdims='color').redim.range(x=(-.1, 1.1), y=(-.1, 1.1))\n",
"point_stream = streams.PointDraw(data=points.columns(), num_objects=10, source=points, empty_value='black')\n",
"points + hv.Table(points, ['x', 'y'], 'color')"
"table = hv.Table(points, ['x', 'y'], 'color')\n",
"DataLink(points, table)\n",
"\n",
"(points + table).options(\n",
" opts.Layout(merge_tools=False),\n",
" opts.Points(active_tools=['point_draw'], color='color', height=400,\n",
" size=10, tools=['hover'], width=400),\n",
" opts.Table(editable=True))"
]
},
{
Expand Down
8 changes: 5 additions & 3 deletions examples/reference/streams/bokeh/PolyDraw.ipynb
Expand Up @@ -21,7 +21,7 @@
"outputs": [],
"source": [
"import holoviews as hv\n",
"from holoviews import streams\n",
"from holoviews import opts, streams\n",
"\n",
"hv.extension('bokeh')"
]
Expand Down Expand Up @@ -58,12 +58,14 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Path [width=400 height=400] (line_width=5 color='red') Polygons (fill_alpha=0.3)\n",
"path = hv.Path([[(1, 5), (9, 5)]])\n",
"poly = hv.Polygons([[(2, 2), (5, 8), (8, 2)]])\n",
"path_stream = streams.PolyDraw(source=path, drag=True, show_vertices=True)\n",
"poly_stream = streams.PolyDraw(source=poly, drag=True, num_objects=2, show_vertices=True)\n",
"path * poly"
"\n",
"(path * poly).options(\n",
" opts.Path(color='red', height=400, line_width=5, width=400),\n",
" opts.Polygons(fill_alpha=0.3, active_tools=['poly_draw']))"
]
},
{
Expand Down
7 changes: 4 additions & 3 deletions examples/reference/streams/bokeh/PolyEdit.ipynb
Expand Up @@ -22,7 +22,7 @@
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import streams\n",
"from holoviews import opts, streams\n",
"\n",
"hv.extension('bokeh')"
]
Expand Down Expand Up @@ -59,14 +59,15 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Polygons [width=400 height=400] (fill_alpha=0.4)\n",
"polys = hv.Polygons([hv.Box(*i, spec=np.random.rand()/3)\n",
" for i in np.random.rand(10, 2)])\n",
"ovals = hv.Polygons([hv.Ellipse(*i, spec=np.random.rand()/3)\n",
" for i in np.random.rand(10, 2)])\n",
"poly_edit = streams.PolyEdit(source=polys, vertex_style={'color': 'red'}, shared=True)\n",
"poly_edit2 = streams.PolyEdit(source=ovals, shared=True)\n",
"polys * ovals"
"\n",
"(polys * ovals).options(\n",
" opts.Polygons(active_tools=['poly_edit'], fill_alpha=0.4, height=400, width=400))"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions examples/reference/streams/bokeh/RangeXY.ipynb
Expand Up @@ -22,6 +22,7 @@
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"\n",
"hv.extension('bokeh')"
]
},
Expand Down
9 changes: 5 additions & 4 deletions examples/reference/streams/bokeh/Selection1D_paired.ipynb
Expand Up @@ -22,7 +22,8 @@
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import streams\n",
"from holoviews import opts, streams\n",
"\n",
"hv.extension('bokeh')"
]
},
Expand All @@ -32,8 +33,6 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Points [tools=['box_select', 'lasso_select', 'tap']]\n",
"\n",
"# Declare two sets of points generated from multivariate distribution\n",
"points = hv.Points(np.random.multivariate_normal((0, 0), [[1, 0.1], [0.1, 1]], (1000,)))\n",
"points2 = hv.Points(np.random.multivariate_normal((3, 3), [[1, 0.1], [0.1, 1]], (1000,)))\n",
Expand All @@ -47,7 +46,9 @@
"hline2 = hv.DynamicMap(lambda index: hv.HLine(points2['y'][index].mean() if index else -10), streams=[sel2])\n",
"\n",
"# Combine points and dynamic HLines\n",
"points * points2 * hline1 * hline2"
"(points * points2 * hline1 * hline2).options(\n",
" opts.Points(active_tools=['box_select', 'tap'], height=400,\n",
" tools=['box_select', 'lasso_select', 'tap'], width=400))"
]
},
{
Expand Down
13 changes: 9 additions & 4 deletions examples/reference/streams/bokeh/Tap.ipynb
Expand Up @@ -23,6 +23,8 @@
"import pandas as pd\n",
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import opts\n",
"\n",
"hv.extension('bokeh', width=90)"
]
},
Expand All @@ -32,9 +34,6 @@
"metadata": {},
"outputs": [],
"source": [
"%opts HeatMap [width=700 height=500 logz=True fontsize={'xticks': '6pt'}, tools=['hover'] xrotation=90] (cmap='RdBu_r') \n",
"%opts Curve [width=375 height=500 yaxis='right'] (line_color='black') {+framewise}\n",
"\n",
"# Declare dataset\n",
"df = pd.read_csv('http://assets.holoviews.org/data/diseases.csv.gz', compression='gzip')\n",
"dataset = hv.Dataset(df, vdims=('measles','Measles Incidence'))\n",
Expand All @@ -51,7 +50,13 @@
" return hv.Curve(dataset.select(State=y, Year=int(x)), kdims='Week',\n",
" label='Year: %s, State: %s' % (x, y))\n",
"\n",
"heatmap + hv.DynamicMap(tap_histogram, kdims=[], streams=[posxy])"
"tap_dmap = hv.DynamicMap(tap_histogram, streams=[posxy])\n",
"\n",
"(heatmap + tap_dmap).options(\n",
" opts.Curve(framewise=True, height=500, line_color='black', width=375, yaxis='right'),\n",
" opts.HeatMap(cmap='RdBu_r', fontsize={'xticks': '6pt'}, height=500,\n",
" logz=True, tools=['hover'], width=700, xrotation=90)\n",
")"
]
},
{
Expand Down
11 changes: 6 additions & 5 deletions examples/user_guide/Linking_Plots.ipynb
Expand Up @@ -37,7 +37,7 @@
"\n",
"dlink = DataLink(scatter1, scatter2)\n",
"\n",
"(scatter1 + scatter2).options('Scatter', tools=['box_select', 'lasso_select'], clone=False)"
"(scatter1 + scatter2).options('Scatter', tools=['box_select', 'lasso_select'])"
]
},
{
Expand Down Expand Up @@ -75,12 +75,12 @@
"\n",
"data = np.random.randn(1000).cumsum()\n",
"\n",
"source = hv.Curve(data).options(width=800, height=100, axiswise=True)\n",
"target = hv.Curve(data).options(width=800, labelled=['y'])\n",
"source = hv.Curve(data).options(width=800, height=125, axiswise=True, default_tools=[])\n",
"target = hv.Curve(data).options(width=800, labelled=['y'], toolbar=None)\n",
"\n",
"rtlink = RangeToolLink(source, target)\n",
"\n",
"(target + source).cols(1)"
"(target + source).options(merge_tools=False).cols(1)"
]
},
{
Expand Down Expand Up @@ -228,7 +228,8 @@
"source": [
"options = dict(\n",
" selection_fill_color='firebrick', alpha=0.4, line_color='black', size=8,\n",
" tools=['lasso_select', 'box_select'], width=500, height=500\n",
" tools=['lasso_select', 'box_select'], width=500, height=500,\n",
" active_tools=['lasso_select']\n",
")\n",
"scatter = hv.Scatter(np.random.randn(500, 2)).options(**options)\n",
"vline = hv.VLine(scatter['x'].mean()).options(color='black')\n",
Expand Down

0 comments on commit 964b82f

Please sign in to comment.