fixed issue 1581
Handle condition where Param.parameters was set
Keep track whether parameters was explicitly set
Co-authored-by: Marc Skov Madsen <masma@orsted.dk> Co-authored-by: Philipp Rudiger <prudiger@anaconda.com>
1 | 2 |
from __future__ import absolute_import |
2 |
|
|
3 | 2 |
import datetime as dt |
4 | 2 |
from collections import OrderedDict |
5 |
|
|
6 | 2 |
import pytest |
7 | 2 |
import numpy as np |
8 |
|
|
9 | 2 |
try: |
10 | 2 |
import holoviews as hv |
11 |
except Exception: |
|
12 |
hv = None |
|
13 |
|
|
14 | 2 |
from bokeh.models import (Row as BkRow, Column as BkColumn, GlyphRenderer, |
15 |
Scatter, Line, GridBox, Select as BkSelect, |
|
16 |
Slider as BkSlider, Spacer as BkSpacer, |
|
17 |
ColumnDataSource) |
|
18 | 2 |
from bokeh.plotting import Figure |
19 |
|
|
20 | 2 |
from panel.layout import Column, Row |
21 | 2 |
from panel.pane import Pane, PaneBase, HoloViews |
22 | 2 |
from panel.widgets import FloatSlider, DiscreteSlider, Select |
23 | 2 |
from panel.tests.util import hv_available, mpl_available |
24 |
|
|
25 |
|
|
26 | 2 |
@hv_available
|
27 |
def test_get_holoviews_pane_type(): |
|
28 | 2 |
curve = hv.Curve([1, 2, 3]) |
29 | 2 |
assert PaneBase.get_pane_type(curve) is HoloViews |
30 |
|
|
31 |
|
|
32 | 2 |
@pytest.mark.usefixtures("hv_mpl") |
33 | 2 |
@mpl_available
|
34 | 2 |
@hv_available
|
35 |
def test_holoviews_pane_mpl_renderer(document, comm): |
|
36 | 2 |
curve = hv.Curve([1, 2, 3]) |
37 | 2 |
pane = Pane(curve) |
38 |
|
|
39 |
# Create pane
|
|
40 | 2 |
row = pane.get_root(document, comm=comm) |
41 | 2 |
assert isinstance(row, BkRow) |
42 | 2 |
assert len(row.children) == 1 |
43 | 2 |
model = row.children[0] |
44 | 2 |
assert pane._models[row.ref['id']][0] is model |
45 | 2 |
assert model.text.startswith('<img src=') |
46 |
|
|
47 |
# Replace Pane.object
|
|
48 | 2 |
scatter = hv.Scatter([1, 2, 3]) |
49 | 2 |
pane.object = scatter |
50 | 2 |
new_model = row.children[0] |
51 | 2 |
assert model.text != new_model.text |
52 |
|
|
53 |
# Cleanup
|
|
54 | 2 |
pane._cleanup(row) |
55 | 2 |
assert pane._models == {} |
56 |
|
|
57 |
|
|
58 | 2 |
@pytest.mark.usefixtures("hv_mpl") |
59 | 2 |
@pytest.mark.usefixtures("hv_bokeh") |
60 | 2 |
@mpl_available
|
61 | 2 |
@hv_available
|
62 |
def test_holoviews_pane_switch_backend(document, comm): |
|
63 | 2 |
curve = hv.Curve([1, 2, 3]) |
64 | 2 |
pane = Pane(curve) |
65 |
|
|
66 |
# Create pane
|
|
67 | 2 |
row = pane.get_root(document, comm=comm) |
68 | 2 |
assert isinstance(row, BkRow) |
69 | 2 |
assert len(row.children) == 1 |
70 | 2 |
model = row.children[0] |
71 | 2 |
assert pane._models[row.ref['id']][0] is model |
72 | 2 |
assert model.text.startswith('<img src=') |
73 |
|
|
74 |
# Replace Pane.object
|
|
75 | 2 |
pane.backend = 'bokeh' |
76 | 2 |
model = row.children[0] |
77 | 2 |
assert isinstance(model, Figure) |
78 |
|
|
79 |
# Cleanup
|
|
80 | 2 |
pane._cleanup(row) |
81 | 2 |
assert pane._models == {} |
82 |
|
|
83 |
|
|
84 | 2 |
@pytest.mark.usefixtures("hv_bokeh") |
85 | 2 |
@hv_available
|
86 |
def test_holoviews_pane_bokeh_renderer(document, comm): |
|
87 | 2 |
curve = hv.Curve([1, 2, 3]) |
88 | 2 |
pane = Pane(curve) |
89 |
|
|
90 |
# Create pane
|
|
91 | 2 |
row = pane.get_root(document, comm=comm) |
92 | 2 |
assert isinstance(row, BkRow) |
93 | 2 |
assert len(row.children) == 1 |
94 | 2 |
model = row.children[0] |
95 | 2 |
assert isinstance(model, Figure) |
96 | 2 |
assert pane._models[row.ref['id']][0] is model |
97 | 2 |
renderers = [r for r in model.renderers if isinstance(r, GlyphRenderer)] |
98 | 2 |
assert len(renderers) == 1 |
99 | 2 |
assert isinstance(renderers[0].glyph, Line) |
100 |
|
|
101 |
# Replace Pane.object
|
|
102 | 2 |
scatter = hv.Scatter([1, 2, 3]) |
103 | 2 |
pane.object = scatter |
104 | 2 |
model = row.children[0] |
105 | 2 |
assert isinstance(model, Figure) |
106 | 2 |
renderers = [r for r in model.renderers if isinstance(r, GlyphRenderer)] |
107 | 2 |
assert len(renderers) == 1 |
108 | 2 |
assert isinstance(renderers[0].glyph, Scatter) |
109 | 2 |
assert pane._models[row.ref['id']][0] is model |
110 |
|
|
111 |
# Cleanup
|
|
112 | 2 |
pane._cleanup(row) |
113 | 2 |
assert pane._models == {} |
114 |
|
|
115 |
|
|
116 | 2 |
@pytest.mark.usefixtures("hv_bokeh") |
117 | 2 |
@hv_available
|
118 |
def test_holoviews_pane_initialize_empty(document, comm): |
|
119 | 2 |
pane = HoloViews() |
120 |
|
|
121 |
# Create pane
|
|
122 | 2 |
row = pane.get_root(document, comm=comm) |
123 |
|
|
124 | 2 |
assert isinstance(row, BkRow) |
125 | 2 |
assert len(row.children) == 1 |
126 | 2 |
model = row.children[0] |
127 | 2 |
assert isinstance(model, BkSpacer) |
128 |
|
|
129 | 2 |
pane.object = hv.Curve([1, 2, 3]) |
130 | 2 |
model = row.children[0] |
131 | 2 |
assert isinstance(model, Figure) |
132 |
|
|
133 |
|
|
134 | 2 |
@hv_available
|
135 |
def test_holoviews_widgets_from_dynamicmap(document, comm): |
|
136 | 2 |
range_dim = hv.Dimension('A', range=(0, 10.)) |
137 | 2 |
range_step_dim = hv.Dimension('B', range=(0, 10.), step=0.2) |
138 | 2 |
range_default_dim = hv.Dimension('C', range=(0, 10.), default=3) |
139 | 2 |
value_dim = hv.Dimension('D', values=['a', 'b', 'c']) |
140 | 2 |
value_default_dim = hv.Dimension('E', values=['a', 'b', 'c', 'd'], default='b') |
141 | 2 |
value_numeric_dim = hv.Dimension('F', values=[1, 3, 10], default=3) |
142 | 2 |
kdims = [range_dim, range_step_dim, range_default_dim, |
143 |
value_dim, value_default_dim, value_numeric_dim] |
|
144 | 2 |
dmap = hv.DynamicMap(lambda A, B, C, D, E, F: hv.Curve([]), kdims=kdims) |
145 | 2 |
widgets, _ = HoloViews.widgets_from_dimensions(dmap) |
146 |
|
|
147 | 2 |
assert len(widgets) == len(kdims) |
148 |
|
|
149 | 2 |
assert isinstance(widgets[0], FloatSlider) |
150 | 2 |
assert widgets[0].name == 'A' |
151 | 2 |
assert widgets[0].start == range_dim.range[0] |
152 | 2 |
assert widgets[0].end == range_dim.range[1] |
153 | 2 |
assert widgets[0].value == range_dim.range[0] |
154 | 2 |
assert widgets[0].step == 0.1 |
155 |
|
|
156 | 2 |
assert isinstance(widgets[1], FloatSlider) |
157 | 2 |
assert widgets[1].name == 'B' |
158 | 2 |
assert widgets[1].start == range_step_dim.range[0] |
159 | 2 |
assert widgets[1].end == range_step_dim.range[1] |
160 | 2 |
assert widgets[1].value == range_step_dim.range[0] |
161 | 2 |
assert widgets[1].step == range_step_dim.step |
162 |
|
|
163 | 2 |
assert isinstance(widgets[2], FloatSlider) |
164 | 2 |
assert widgets[2].name == 'C' |
165 | 2 |
assert widgets[2].start == range_default_dim.range[0] |
166 | 2 |
assert widgets[2].end == range_default_dim.range[1] |
167 | 2 |
assert widgets[2].value == range_default_dim.default |
168 | 2 |
assert widgets[2].step == 0.1 |
169 |
|
|
170 | 2 |
assert isinstance(widgets[3], Select) |
171 | 2 |
assert widgets[3].name == 'D' |
172 | 2 |
assert widgets[3].options == value_dim.values |
173 | 2 |
assert widgets[3].value == value_dim.values[0] |
174 |
|
|
175 | 2 |
assert isinstance(widgets[4], Select) |
176 | 2 |
assert widgets[4].name == 'E' |
177 | 2 |
assert widgets[4].options == value_default_dim.values |
178 | 2 |
assert widgets[4].value == value_default_dim.default |
179 |
|
|
180 | 2 |
assert isinstance(widgets[5], DiscreteSlider) |
181 | 2 |
assert widgets[5].name == 'F' |
182 | 2 |
assert widgets[5].options == OrderedDict([(str(v), v) for v in value_numeric_dim.values]) |
183 | 2 |
assert widgets[5].value == value_numeric_dim.default |
184 |
|
|
185 |
|
|
186 | 2 |
@hv_available
|
187 |
def test_holoviews_with_widgets(document, comm): |
|
188 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
189 |
|
|
190 | 2 |
hv_pane = HoloViews(hmap) |
191 | 2 |
layout = hv_pane.get_root(document, comm) |
192 | 2 |
model = layout.children[0] |
193 | 2 |
assert len(hv_pane.widget_box.objects) == 2 |
194 | 2 |
assert hv_pane.widget_box.objects[0].name == 'X' |
195 | 2 |
assert hv_pane.widget_box.objects[1].name == 'Y' |
196 |
|
|
197 | 2 |
assert hv_pane._models[layout.ref['id']][0] is model |
198 |
|
|
199 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['A', 'B']) |
200 | 2 |
hv_pane.object = hmap |
201 | 2 |
assert len(hv_pane.widget_box.objects) == 2 |
202 | 2 |
assert hv_pane.widget_box.objects[0].name == 'A' |
203 | 2 |
assert hv_pane.widget_box.objects[1].name == 'B' |
204 |
|
|
205 |
|
|
206 | 2 |
@hv_available
|
207 |
def test_holoviews_updates_widgets(document, comm): |
|
208 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
209 |
|
|
210 | 2 |
hv_pane = HoloViews(hmap) |
211 | 2 |
layout = hv_pane.get_root(document, comm) |
212 |
|
|
213 | 2 |
hv_pane.widgets = {'X': Select} |
214 | 2 |
assert isinstance(hv_pane.widget_box[0], Select) |
215 | 2 |
assert isinstance(layout.children[1].children[0].children[0], BkSelect) |
216 |
|
|
217 | 2 |
hv_pane.widgets = {'X': DiscreteSlider} |
218 | 2 |
assert isinstance(hv_pane.widget_box[0], DiscreteSlider) |
219 | 2 |
assert isinstance(layout.children[1].children[0].children[0], BkColumn) |
220 | 2 |
assert isinstance(layout.children[1].children[0].children[0].children[1], BkSlider) |
221 |
|
|
222 | 2 |
@hv_available
|
223 |
def test_holoviews_widgets_update_plot(document, comm): |
|
224 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
225 |
|
|
226 | 2 |
hv_pane = HoloViews(hmap, backend='bokeh') |
227 | 2 |
layout = hv_pane.get_root(document, comm) |
228 |
|
|
229 | 2 |
cds = layout.children[0].select_one(ColumnDataSource) |
230 | 2 |
assert cds.data['y'] == np.array([0]) |
231 | 2 |
hv_pane.widget_box[0].value = 1 |
232 | 2 |
hv_pane.widget_box[1].value = chr(65+1) |
233 | 2 |
assert cds.data['y'] == np.array([1]) |
234 |
|
|
235 |
|
|
236 | 2 |
@hv_available
|
237 |
def test_holoviews_with_widgets_not_shown(document, comm): |
|
238 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
239 |
|
|
240 | 2 |
hv_pane = HoloViews(hmap, show_widgets=False) |
241 | 2 |
layout_obj = Column(hv_pane, hv_pane.widget_box) |
242 | 2 |
layout = layout_obj.get_root(document, comm) |
243 | 2 |
model = layout.children[0] |
244 | 2 |
assert len(hv_pane.widget_box.objects) == 2 |
245 | 2 |
assert hv_pane.widget_box.objects[0].name == 'X' |
246 | 2 |
assert hv_pane.widget_box.objects[1].name == 'Y' |
247 |
|
|
248 | 2 |
assert hv_pane._models[layout.ref['id']][0] is model |
249 |
|
|
250 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['A', 'B']) |
251 | 2 |
hv_pane.object = hmap |
252 | 2 |
assert len(hv_pane.widget_box.objects) == 2 |
253 | 2 |
assert hv_pane.widget_box.objects[0].name == 'A' |
254 | 2 |
assert hv_pane.widget_box.objects[1].name == 'B' |
255 |
|
|
256 |
|
|
257 | 2 |
@hv_available
|
258 |
def test_holoviews_layouts(document, comm): |
|
259 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
260 |
|
|
261 | 2 |
hv_pane = HoloViews(hmap, backend='bokeh') |
262 | 2 |
layout = hv_pane.layout |
263 | 2 |
model = layout.get_root(document, comm) |
264 |
|
|
265 | 2 |
for center in (True, False): |
266 | 2 |
for loc in HoloViews.param.widget_location.objects: |
267 | 2 |
hv_pane.param.set_param(center=center, widget_location=loc) |
268 | 2 |
if center: |
269 | 2 |
if loc.startswith('left'): |
270 | 2 |
assert len(layout) == 4 |
271 | 2 |
widgets, hv_obj = layout[0], layout[2] |
272 | 2 |
wmodel, hv_model = model.children[0], model.children[2] |
273 | 2 |
elif loc.startswith('right'): |
274 | 2 |
assert len(layout) == 4 |
275 | 2 |
hv_obj, widgets = layout[1], layout[3] |
276 | 2 |
wmodel, hv_model = model.children[3], model.children[1] |
277 | 2 |
elif loc.startswith('top'): |
278 | 2 |
assert len(layout) == 3 |
279 | 2 |
col = layout[1] |
280 | 2 |
cmodel = model.children[1] |
281 | 2 |
assert isinstance(col, Column) |
282 | 2 |
widgets, hv_col = col |
283 | 2 |
hv_obj = hv_col[1] |
284 | 2 |
wmodel, hv_model = cmodel.children[0], cmodel.children[1].children[1] |
285 | 2 |
elif loc.startswith('bottom'): |
286 | 2 |
col = layout[1] |
287 | 2 |
cmodel = model.children[1] |
288 | 2 |
assert isinstance(col, Column) |
289 | 2 |
hv_col, widgets = col |
290 | 2 |
hv_obj = hv_col[1] |
291 | 2 |
wmodel, hv_model = cmodel.children[1], cmodel.children[0].children[1] |
292 |
else: |
|
293 | 2 |
if loc.startswith('left'): |
294 | 2 |
assert len(layout) == 2 |
295 | 2 |
widgets, hv_obj = layout |
296 | 2 |
wmodel, hv_model = model.children |
297 | 2 |
elif loc.startswith('right'): |
298 | 2 |
assert len(layout) == 2 |
299 | 2 |
hv_obj, widgets = layout |
300 | 2 |
hv_model, wmodel = model.children |
301 | 2 |
elif loc.startswith('top'): |
302 | 2 |
assert len(layout) == 1 |
303 | 2 |
col = layout[0] |
304 | 2 |
cmodel = model.children[0] |
305 | 2 |
assert isinstance(col, Column) |
306 | 2 |
widgets, hv_obj = col |
307 | 2 |
wmodel, hv_model = cmodel.children |
308 | 2 |
elif loc.startswith('bottom'): |
309 | 2 |
assert len(layout) == 1 |
310 | 2 |
col = layout[0] |
311 | 2 |
cmodel = model.children[0] |
312 | 2 |
assert isinstance(col, Column) |
313 | 2 |
hv_obj, widgets = col |
314 | 2 |
hv_model, wmodel = cmodel.children |
315 | 2 |
assert hv_pane is hv_obj |
316 | 2 |
assert isinstance(hv_model, Figure) |
317 |
|
|
318 | 2 |
if loc in ('left', 'right', 'top', 'bottom', |
319 |
'top_right', 'right_bottom', 'bottom_right', |
|
320 |
'left_bottom'): |
|
321 | 2 |
box = widgets[1] |
322 | 2 |
boxmodel = wmodel.children[1] |
323 |
else: |
|
324 | 2 |
box = widgets[0] |
325 | 2 |
boxmodel = wmodel.children[0] |
326 | 2 |
assert hv_pane.widget_box is box |
327 | 2 |
assert isinstance(boxmodel, BkColumn) |
328 | 2 |
assert isinstance(boxmodel.children[0], BkColumn) |
329 | 2 |
assert isinstance(boxmodel.children[0].children[1], BkSlider) |
330 | 2 |
assert isinstance(boxmodel.children[1], BkSelect) |
331 |
|
|
332 |
|
|
333 | 2 |
@hv_available
|
334 |
def test_holoviews_widgets_from_holomap(): |
|
335 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
336 |
|
|
337 | 2 |
widgets, _ = HoloViews.widgets_from_dimensions(hmap) |
338 |
|
|
339 | 2 |
assert isinstance(widgets[0], DiscreteSlider) |
340 | 2 |
assert widgets[0].name == 'X' |
341 | 2 |
assert widgets[0].options == OrderedDict([(str(i), i) for i in range(3)]) |
342 | 2 |
assert widgets[0].value == 0 |
343 |
|
|
344 | 2 |
assert isinstance(widgets[1], Select) |
345 | 2 |
assert widgets[1].name == 'Y' |
346 | 2 |
assert widgets[1].options == ['A', 'B', 'C'] |
347 | 2 |
assert widgets[1].value == 'A' |
348 |
|
|
349 |
|
|
350 | 2 |
@hv_available
|
351 |
def test_holoviews_date_slider_widgets_from_holomap(): |
|
352 | 2 |
hmap = hv.HoloMap({dt.datetime(2016, 1, i+1): hv.Curve([i]) for i in range(3)}, kdims=['X']) |
353 |
|
|
354 | 2 |
widgets, _ = HoloViews.widgets_from_dimensions(hmap) |
355 |
|
|
356 | 2 |
assert isinstance(widgets[0], DiscreteSlider) |
357 | 2 |
assert widgets[0].name == 'X' |
358 | 2 |
assert widgets[0].options == OrderedDict([ |
359 |
('2016-01-01 00:00:00', dt.datetime(2016, 1, 1)), |
|
360 |
('2016-01-02 00:00:00', dt.datetime(2016, 1, 2)), |
|
361 |
('2016-01-03 00:00:00', dt.datetime(2016, 1, 3))]) |
|
362 | 2 |
assert widgets[0].value == dt.datetime(2016, 1, 1) |
363 |
|
|
364 |
|
|
365 | 2 |
@hv_available
|
366 |
def test_holoviews_widgets_explicit_widget_type_override(): |
|
367 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
368 |
|
|
369 | 2 |
widgets, _ = HoloViews.widgets_from_dimensions(hmap, widget_types={'X': Select}) |
370 |
|
|
371 | 2 |
assert isinstance(widgets[0], Select) |
372 | 2 |
assert widgets[0].name == 'X' |
373 | 2 |
assert widgets[0].options == OrderedDict([(str(i), i) for i in range(3)]) |
374 | 2 |
assert widgets[0].value == 0 |
375 |
|
|
376 |
|
|
377 | 2 |
@hv_available
|
378 |
def test_holoviews_widgets_invalid_widget_type_override(): |
|
379 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
380 |
|
|
381 | 2 |
with pytest.raises(ValueError): |
382 | 2 |
HoloViews.widgets_from_dimensions(hmap, widget_types={'X': 1}) |
383 |
|
|
384 |
|
|
385 | 2 |
@hv_available
|
386 |
def test_holoviews_widgets_explicit_widget_instance_override(): |
|
387 | 2 |
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y']) |
388 |
|
|
389 | 2 |
widget = Select(options=[1, 2, 3], value=3) |
390 | 2 |
widgets, _ = HoloViews.widgets_from_dimensions(hmap, widget_types={'X': widget}) |
391 |
|
|
392 | 2 |
assert widgets[0] is widget |
393 |
|
|
394 |
|
|
395 | 2 |
@hv_available
|
396 |
def test_holoviews_linked_axes(document, comm): |
|
397 | 2 |
c1 = hv.Curve([1, 2, 3]) |
398 | 2 |
c2 = hv.Curve([1, 2, 3]) |
399 |
|
|
400 | 2 |
layout = Row(HoloViews(c1, backend='bokeh'), HoloViews(c2, backend='bokeh')) |
401 |
|
|
402 | 2 |
row_model = layout.get_root(document, comm=comm) |
403 |
|
|
404 | 2 |
p1, p2 = row_model.select({'type': Figure}) |
405 |
|
|
406 | 2 |
assert p1.x_range is p2.x_range |
407 | 2 |
assert p1.y_range is p2.y_range |
408 |
|
|
409 |
|
|
410 | 2 |
@hv_available
|
411 |
def test_holoviews_linked_axes_merged_ranges(document, comm): |
|
412 | 2 |
c1 = hv.Curve([1, 2, 3]) |
413 | 2 |
c2 = hv.Curve([0, 1, 2, 3, 4]) |
414 |
|
|
415 | 2 |
layout = Row(HoloViews(c1, backend='bokeh'), HoloViews(c2, backend='bokeh')) |
416 |
|
|
417 | 2 |
row_model = layout.get_root(document, comm=comm) |
418 |
|
|
419 | 2 |
p1, p2 = row_model.select({'type': Figure}) |
420 |
|
|
421 | 2 |
assert p1.x_range is p2.x_range |
422 | 2 |
assert p1.y_range is p2.y_range |
423 | 2 |
assert p1.y_range.start == -0.4 |
424 | 2 |
assert p1.y_range.end == 4.4 |
425 |
|
|
426 |
|
|
427 | 2 |
@hv_available
|
428 |
def test_holoviews_linked_x_axis(document, comm): |
|
429 | 2 |
c1 = hv.Curve([1, 2, 3]) |
430 | 2 |
c2 = hv.Curve([1, 2, 3], vdims='y2') |
431 |
|
|
432 | 2 |
layout = Row(HoloViews(c1, backend='bokeh'), HoloViews(c2, backend='bokeh')) |
433 |
|
|
434 | 2 |
row_model = layout.get_root(document, comm=comm) |
435 |
|
|
436 | 2 |
p1, p2 = row_model.select({'type': Figure}) |
437 |
|
|
438 | 2 |
assert p1.x_range is p2.x_range |
439 | 2 |
assert p1.y_range is not p2.y_range |
440 |
|
|
441 |
|
|
442 | 2 |
@hv_available
|
443 |
def test_holoviews_axiswise_not_linked_axes(document, comm): |
|
444 | 2 |
c1 = hv.Curve([1, 2, 3]) |
445 | 2 |
c2 = hv.Curve([1, 2, 3]).opts(axiswise=True, backend='bokeh') |
446 |
|
|
447 | 2 |
layout = Row(HoloViews(c1, backend='bokeh'), HoloViews(c2, backend='bokeh')) |
448 |
|
|
449 | 2 |
row_model = layout.get_root(document, comm=comm) |
450 |
|
|
451 | 2 |
p1, p2 = row_model.select({'type': Figure}) |
452 |
|
|
453 | 2 |
assert p1.x_range is not p2.x_range |
454 | 2 |
assert p1.y_range is not p2.y_range |
455 |
|
|
456 |
|
|
457 | 2 |
@hv_available
|
458 |
def test_holoviews_shared_axes_opt_not_linked_axes(document, comm): |
|
459 | 2 |
c1 = hv.Curve([1, 2, 3]) |
460 | 2 |
c2 = hv.Curve([1, 2, 3]).opts(shared_axes=False, backend='bokeh') |
461 |
|
|
462 | 2 |
layout = Row(HoloViews(c1, backend='bokeh'), HoloViews(c2, backend='bokeh')) |
463 |
|
|
464 | 2 |
row_model = layout.get_root(document, comm=comm) |
465 |
|
|
466 | 2 |
p1, p2 = row_model.select({'type': Figure}) |
467 |
|
|
468 | 2 |
assert p1.x_range is not p2.x_range |
469 | 2 |
assert p1.y_range is not p2.y_range |
470 |
|
|
471 |
|
|
472 | 2 |
@hv_available
|
473 |
def test_holoviews_not_linked_axes(document, comm): |
|
474 | 2 |
c1 = hv.Curve([1, 2, 3]) |
475 | 2 |
c2 = hv.Curve([1, 2, 3]) |
476 |
|
|
477 | 2 |
layout = Row( |
478 |
HoloViews(c1, backend='bokeh'), |
|
479 |
HoloViews(c2, backend='bokeh', linked_axes=False) |
|
480 |
)
|
|
481 |
|
|
482 | 2 |
row_model = layout.get_root(document, comm=comm) |
483 |
|
|
484 | 2 |
p1, p2 = row_model.select({'type': Figure}) |
485 |
|
|
486 | 2 |
assert p1.x_range is not p2.x_range |
487 | 2 |
assert p1.y_range is not p2.y_range |
488 |
|
|
489 |
|
|
490 | 2 |
@hv_available
|
491 |
def test_holoviews_link_across_panes(document, comm): |
|
492 | 2 |
from bokeh.models.tools import RangeTool |
493 | 2 |
from holoviews.plotting.links import RangeToolLink |
494 |
|
|
495 | 2 |
c1 = hv.Curve([]) |
496 | 2 |
c2 = hv.Curve([]) |
497 |
|
|
498 | 2 |
RangeToolLink(c1, c2) |
499 |
|
|
500 | 2 |
layout = Row(Pane(c1, backend='bokeh'), Pane(c2, backend='bokeh')) |
501 | 2 |
row = layout.get_root(document, comm=comm) |
502 |
|
|
503 | 2 |
assert len(row.children) == 2 |
504 | 2 |
p1, p2 = row.children |
505 |
|
|
506 | 2 |
assert isinstance(p1, Figure) |
507 | 2 |
assert isinstance(p2, Figure) |
508 |
|
|
509 | 2 |
range_tool = row.select_one({'type': RangeTool}) |
510 | 2 |
assert isinstance(range_tool, RangeTool) |
511 | 2 |
assert range_tool.x_range == p2.x_range |
512 |
|
|
513 |
|
|
514 | 2 |
@hv_available
|
515 |
def test_holoviews_link_after_adding_item(document, comm): |
|
516 | 2 |
from bokeh.models.tools import RangeTool |
517 | 2 |
from holoviews.plotting.links import RangeToolLink |
518 |
|
|
519 | 2 |
c1 = hv.Curve([]) |
520 | 2 |
c2 = hv.Curve([]) |
521 |
|
|
522 | 2 |
RangeToolLink(c1, c2) |
523 |
|
|
524 | 2 |
layout = Row(Pane(c1, backend='bokeh')) |
525 | 2 |
row = layout.get_root(document, comm=comm) |
526 |
|
|
527 | 2 |
assert len(row.children) == 1 |
528 | 2 |
p1, = row.children |
529 |
|
|
530 | 2 |
assert isinstance(p1, Figure) |
531 | 2 |
range_tool = row.select_one({'type': RangeTool}) |
532 | 2 |
assert range_tool is None |
533 |
|
|
534 | 2 |
layout.append(Pane(c2, backend='bokeh')) |
535 | 2 |
_, p2 = row.children |
536 | 2 |
assert isinstance(p2, Figure) |
537 | 2 |
range_tool = row.select_one({'type': RangeTool}) |
538 | 2 |
assert isinstance(range_tool, RangeTool) |
539 | 2 |
assert range_tool.x_range == p2.x_range |
540 |
|
|
541 |
|
|
542 | 2 |
@hv_available
|
543 |
def test_holoviews_link_within_pane(document, comm): |
|
544 | 2 |
from bokeh.models.tools import RangeTool |
545 | 2 |
from holoviews.plotting.links import RangeToolLink |
546 |
|
|
547 | 2 |
c1 = hv.Curve([]) |
548 | 2 |
c2 = hv.Curve([]) |
549 |
|
|
550 | 2 |
RangeToolLink(c1, c2) |
551 |
|
|
552 | 2 |
pane = Pane(Pane(hv.Layout([c1, c2]), backend='bokeh')) |
553 | 2 |
column = pane.get_root(document, comm=comm) |
554 |
|
|
555 | 2 |
assert len(column.children) == 1 |
556 | 2 |
subcolumn = column.children[0] |
557 | 2 |
assert isinstance(subcolumn, BkColumn) |
558 | 2 |
assert len(subcolumn.children) == 2 |
559 | 2 |
toolbar, subsubcolumn = subcolumn.children |
560 | 2 |
assert isinstance(subsubcolumn, GridBox) |
561 | 2 |
assert len(subsubcolumn.children) == 2 |
562 | 2 |
(p1, _, _), (p2, _, _) = subsubcolumn.children |
563 |
|
|
564 | 2 |
assert isinstance(p1, Figure) |
565 | 2 |
assert isinstance(p2, Figure) |
566 |
|
|
567 | 2 |
range_tool = subsubcolumn.select_one({'type': RangeTool}) |
568 | 2 |
assert isinstance(range_tool, RangeTool) |
569 | 2 |
assert range_tool.x_range == p2.x_range |
570 |
|
|
571 |
|
|
572 | 2 |
@hv_available
|
573 |
def test_holoviews_property_override(document, comm): |
|
574 | 2 |
c1 = hv.Curve([]) |
575 |
|
|
576 | 2 |
pane = Pane(c1, backend='bokeh', background='red', |
577 |
css_classes=['test_class']) |
|
578 | 2 |
model = pane.get_root(document, comm=comm) |
579 |
|
|
580 | 2 |
assert model.background == 'red' |
581 | 2 |
assert model.css_classes == ['test_class'] |
Read our documentation on viewing source code .