Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement show method #6370

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions holoviews/core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
AdjointLayout allows one or two Views to be adjoined to a primary View
to act as supplementary elements.
"""
from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
import param
from panel.pane.holoviews import HoloViews

from . import traversal
from .dimension import Dimension, Dimensioned, ViewableElement, ViewableTree
from .ndmapping import NdMapping, UniformNdMapping

if TYPE_CHECKING:
from panel.io.server import Server

class Layoutable:
"""
Expand All @@ -34,6 +40,16 @@ def __add__(x, y):
def __radd__(self, other):
return self.__class__.__add__(other, self)

def show(self, pane_params: dict | None = None, **show_kwargs: dict) -> Server:
"""
Starts a Bokeh server and displays the HoloViews object in a new tab.

Args:
pane_params: Params to pass to `pn.pane.HoloViews`
**show_kwargs: Keyword arguments to pass to the `show` method.
"""
return HoloViews(self, **pane_params or {}).show(**show_kwargs)


class Composable(Layoutable):
"""
Expand Down
16 changes: 16 additions & 0 deletions holoviews/core/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
Also supplies ViewMap which is the primary multi-dimensional Map type
for indexing, slicing and animating collections of Views.
"""
from __future__ import annotations

from functools import reduce
from typing import TYPE_CHECKING

import numpy as np
import param
from panel.pane import HoloViews

from .dimension import Dimension, Dimensioned, ViewableElement, ViewableTree
from .layout import AdjointLayout, Composable, Layout, Layoutable
from .ndmapping import UniformNdMapping
from .util import dimensioned_streams, sanitize_identifier, unique_array

if TYPE_CHECKING:
from panel.io.server import Server


class Overlayable:
"""
Expand Down Expand Up @@ -52,6 +58,16 @@ def dynamic_mul(*args, **kwargs):
except NotImplementedError:
return NotImplemented

def show(self, pane_params: dict | None = None, **show_kwargs: dict) -> Server:
"""
Starts a Bokeh server and displays the HoloViews object in a new tab.

Args:
pane_params: Params to pass to `pn.pane.HoloViews`
**show_kwargs: Keyword arguments to pass to the `show` method.
"""
return HoloViews(self, **pane_params or {}).show(**show_kwargs)


class CompositeOverlay(ViewableElement, Composable):
"""
Expand Down
18 changes: 17 additions & 1 deletion holoviews/core/spaces.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import itertools
import types
from collections import defaultdict
Expand All @@ -6,9 +8,11 @@
from itertools import groupby
from numbers import Number
from types import FunctionType
from typing import TYPE_CHECKING

import numpy as np
import param
from panel.pane.holoviews import HoloViews

from ..streams import Params, Stream, streams_list_from_dict
from . import traversal, util
Expand All @@ -19,6 +23,9 @@
from .options import Store, StoreOptions
from .overlay import CompositeOverlay, NdOverlay, Overlay, Overlayable

if TYPE_CHECKING:
from panel.io.server import Server


class HoloMap(Layoutable, UniformNdMapping, Overlayable):
"""
Expand Down Expand Up @@ -424,6 +431,16 @@ def hist(self, dimension=None, num_bins=20, bin_range=None,
else:
return histmaps[0]

def show(self, pane_params: dict | None = None, **show_kwargs: dict) -> Server:
"""
Starts a Bokeh server and displays the HoloViews object in a new tab.

Args:
pane_params: Params to pass to `pn.pane.HoloViews`
**show_kwargs: Keyword arguments to pass to the `show` method.
"""
return HoloViews(self, **pane_params or {}).show(**show_kwargs)


class Callable(param.Parameterized):
"""
Expand Down Expand Up @@ -597,7 +614,6 @@ def __call__(self, *args, **kwargs):
return ret



class Generator(Callable):
"""
Generators are considered a special case of Callable that accept no
Expand Down
18 changes: 18 additions & 0 deletions holoviews/element/chart.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
import param
from panel.pane.holoviews import HoloViews

from ..core import Dataset, Dimension, Element2D, NdOverlay, Overlay, util
from ..core.dimension import process_dimensions
Expand All @@ -10,6 +15,9 @@
)
from .selection import Selection1DExpr

if TYPE_CHECKING:
from panel.io.server import Server


class Chart(Dataset, Element2D):
"""
Expand Down Expand Up @@ -56,6 +64,16 @@ def __init__(self, data, kdims=None, vdims=None, **params):
def __getitem__(self, index):
return super().__getitem__(index)

def show(self, pane_params: dict | None = None, **show_kwargs: dict) -> Server:
"""
Starts a Bokeh server and displays the HoloViews object in a new tab.

Args:
pane_params: Params to pass to `pn.pane.HoloViews`
**show_kwargs: Keyword arguments to pass to the `show` method.
"""
return HoloViews(self, **pane_params or {}).show(**show_kwargs)


class Scatter(Selection1DExpr, Chart):
"""
Expand Down
Loading