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

1# SPDX-License-Identifier: BSD-3-Clause 

2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 

3# @file 

4# @author Dimitar Tasev 

5 

6from __future__ import annotations 

7 

8from ..core import DataGroup, Variable 

9from ..typing import VariableLike 

10 

11 

12def make_html(container: VariableLike) -> str: 

13 """Return the HTML representation of an object. 

14 

15 See 'HTML representation' in 

16 `Representations and Tables <../../user-guide/representations-and-tables.rst>`_ 

17 for details. 

18 

19 Parameters 

20 ---------- 

21 container: 

22 Object to render. 

23 

24 Returns 

25 ------- 

26 : 

27 HTML representation 

28 

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 

36 

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) 

43 

44 

45def to_html(container: VariableLike) -> None: 

46 """Render am object to HTML in a Jupyter notebook. 

47 

48 Parameters 

49 ---------- 

50 container: 

51 Object to render. 

52 

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 

60 

61 display(HTML(make_html(container))) # type: ignore[no-untyped-call]