Skip to content

Commit

Permalink
Handled automatic collation of DynamicMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 4, 2017
1 parent e1926ae commit d8b402e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
14 changes: 5 additions & 9 deletions holoviews/plotting/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .. import DynamicMap
from . import Plot
from .comms import JupyterComm
from .util import displayable, collate
from .util import displayable, collate, initialize_dynamic

from param.parameterized import bothmethod

Expand Down Expand Up @@ -159,16 +159,12 @@ def get_plot(self_or_cls, obj, renderer=None):
"""
Given a HoloViews Viewable return a corresponding plot instance.
"""
# Initialize DynamicMaps with first data item
initialize_dynamic(obj)

if not isinstance(obj, Plot) and not displayable(obj):
obj = collate(obj)

# Initialize DynamicMaps with first data item
dmaps = obj.traverse(lambda x: x, specs=[DynamicMap])
for dmap in dmaps:
if dmap.sampled:
# Skip initialization until plotting code
continue
dmap[dmap._initial_key()]
initialize_dynamic(obj)

if not renderer: renderer = self_or_cls.instance()
if not isinstance(obj, Plot):
Expand Down
19 changes: 16 additions & 3 deletions holoviews/plotting/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def collate(obj):
"(http://git.io/vtIQh)" % nested_type)
return obj.collate()
if isinstance(obj, HoloMap):
display_warning.warning("Nesting %ss within a HoloMap makes it difficult "
display_warning.warning("Nesting {0}s within a {1} makes it difficult "
"to access your data or control how it appears; "
"we recommend calling .collate() on the HoloMap "
"we recommend calling .collate() on the {1} "
"in order to follow the recommended nesting "
"structure shown in the Composing Data tutorial"
"(http://git.io/vtIQh)" % obj.type.__name__)
"(http://git.io/vtIQh)".format(obj.type.__name__, type(obj).__name__))
return obj.collate()
elif isinstance(obj, (Layout, NdLayout)):
try:
Expand All @@ -70,6 +70,19 @@ def collate(obj):
raise Exception(undisplayable_info(obj))


def initialize_dynamic(obj):
"""
Initializes all DynamicMap objects contained by the object
"""
dmaps = obj.traverse(lambda x: x, specs=[DynamicMap])
for dmap in dmaps:
if dmap.sampled:
# Skip initialization until plotting code
continue
if not len(dmap):
dmap[dmap._initial_key()]


def undisplayable_info(obj, html=False):
"Generate helpful message regarding an undisplayable object"

Expand Down

0 comments on commit d8b402e

Please sign in to comment.