Coverage for install/scipp/visualization/html.py: 47%
15 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-04-28 01:28 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-04-28 01:28 +0000
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3# @file
4# @author Dimitar Tasev
6from __future__ import annotations
8from ..core import DataGroup, Variable
9from ..typing import VariableLike
10from .table import table # noqa: F401
13def make_html(container: VariableLike) -> str:
14 """Return the HTML representation of an object.
16 See 'HTML representation' in
17 `Representations and Tables <../../user-guide/representations-and-tables.rst>`_
18 for details.
20 Parameters
21 ----------
22 container:
23 Object to render.
25 Returns
26 -------
27 :
28 HTML representation
30 See Also
31 --------
32 scipp.to_html:
33 Display the HTML representation.
34 """
35 from .formatting_datagroup_html import datagroup_repr
36 from .formatting_html import dataset_repr, variable_repr
38 if isinstance(container, Variable):
39 return variable_repr(container)
40 elif isinstance(container, DataGroup):
41 return datagroup_repr(container)
42 else:
43 return dataset_repr(container)
46def to_html(container: VariableLike):
47 """Render am object to HTML in a Jupyter notebook.
49 Parameters
50 ----------
51 container:
52 Object to render.
54 See Also
55 --------
56 scipp.make_html:
57 Create HTML representation without showing it.
58 Works outside of notebooks.
59 """
60 from IPython.display import HTML, display
62 display(HTML(make_html(container)))