Coverage for install/scipp/visualization/html.py: 50%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-17 01:51 +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
12def make_html(container: VariableLike) -> str:
13 """Return the HTML representation of an object.
15 See 'HTML representation' in
16 `Representations and Tables <../../user-guide/representations-and-tables.rst>`_
17 for details.
19 Parameters
20 ----------
21 container:
22 Object to render.
24 Returns
25 -------
26 :
27 HTML representation
29 See Also
30 --------
31 scipp.to_html:
32 Display the HTML representation.
33 """
34 from .formatting_datagroup_html import datagroup_repr
35 from .formatting_html import data_array_dataset_repr, variable_repr
37 if isinstance(container, Variable):
38 return variable_repr(container)
39 elif isinstance(container, DataGroup):
40 return datagroup_repr(container)
41 else:
42 return data_array_dataset_repr(container)
45def to_html(container: VariableLike) -> None:
46 """Render am object to HTML in a Jupyter notebook.
48 Parameters
49 ----------
50 container:
51 Object to render.
53 See Also
54 --------
55 scipp.make_html:
56 Create HTML representation without showing it.
57 Works outside of notebooks.
58 """
59 from IPython.display import HTML, display
61 display(HTML(make_html(container))) # type: ignore[no-untyped-call]