Coverage for install/scipp/visualization/colors.py: 64%

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# @author Neil Vaytet 

4 

5import numpy as np 

6import numpy.typing as npt 

7 

8STYLE = { 

9 'attrs': '#ff5555', 

10 'coords': '#c6e590', 

11 'data': '#f6d028', 

12 'masks': '#c8c8c8', 

13} 

14 

15 

16def hex_to_rgb(hex_color: str) -> npt.NDArray[np.int64]: 

17 rgb_hex = [hex_color[x : x + 2] for x in [1, 3, 5]] 

18 return np.array([int(hex_value, 16) for hex_value in rgb_hex]) 

19 

20 

21def rgb_to_hex(rgb: npt.NDArray[np.int64]) -> str: 

22 hex_value = [] 

23 for i in rgb: 

24 h = hex(int(i))[2:] 

25 if len(h) < 2: 

26 h = f"{h}0" 

27 hex_value.append(h) 

28 return "#" + "".join(hex_value)