From cb33c9f1089b5a62769ae06030fdc35d7a94cb0b Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Wed, 11 Sep 2024 03:19:40 -0700 Subject: [PATCH] add show method --- holoviews/core/layout.py | 16 ++++++++++++++++ holoviews/core/overlay.py | 16 ++++++++++++++++ holoviews/core/spaces.py | 18 +++++++++++++++++- holoviews/element/chart.py | 18 ++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/holoviews/core/layout.py b/holoviews/core/layout.py index 46a5137313..a014937434 100644 --- a/holoviews/core/layout.py +++ b/holoviews/core/layout.py @@ -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: """ @@ -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): """ diff --git a/holoviews/core/overlay.py b/holoviews/core/overlay.py index f7fd786e42..640ad743f5 100644 --- a/holoviews/core/overlay.py +++ b/holoviews/core/overlay.py @@ -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: """ @@ -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): """ diff --git a/holoviews/core/spaces.py b/holoviews/core/spaces.py index 2bce983830..79c8bbfdf6 100644 --- a/holoviews/core/spaces.py +++ b/holoviews/core/spaces.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import itertools import types from collections import defaultdict @@ -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 @@ -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): """ @@ -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): """ @@ -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 diff --git a/holoviews/element/chart.py b/holoviews/element/chart.py index 6b5f52b547..3b97e3fc0f 100644 --- a/holoviews/element/chart.py +++ b/holoviews/element/chart.py @@ -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 @@ -10,6 +15,9 @@ ) from .selection import Selection1DExpr +if TYPE_CHECKING: + from panel.io.server import Server + class Chart(Dataset, Element2D): """ @@ -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): """