Path:
strictdoc/features/tree_map/helpers.py
Lines:
35
Non-empty lines:
28
Non-empty lines covered with requirements:
28 / 28 (100.0%)
Functions:
1
Functions covered by requirements:
1 / 1 (100.0%)
1
"""2
@relation(SDOC-SRS-157, scope=file)3
"""4
5
6
def get_color(ratio: float) -> str:
7
"""
8
Returns a hex color string representing the coverage level.9
- 0% coverage → light red (#ffaaaa)10
- 50% coverage → yellow (#ffffaa)11
- 100% coverage → light green (#aaffaa)12
"""13
14
assert isinstance(ratio, float) and 0 <= ratio <= 1
15
16
lightness = 0xAA
17
18
red = (0xFF, lightness, lightness)
19
yellow = (0xFF, 0xFF, lightness)
20
green = (lightness, 0xFF, lightness)
21
22
if ratio < 0.5:
23
# Interpolate between red and yellow.24
t = ratio / 0.5
25
r = int(red[0] + (yellow[0] - red[0]) * t)
26
g = int(red[1] + (yellow[1] - red[1]) * t)
27
b = int(red[2] + (yellow[2] - red[2]) * t)
28
else:
29
# Interpolate between yellow and green.30
t = (ratio - 0.5) / 0.5
31
r = int(yellow[0] + (green[0] - yellow[0]) * t)
32
g = int(yellow[1] + (green[1] - yellow[1]) * t)
33
b = int(yellow[2] + (green[2] - yellow[2]) * t)
34
35
return f"#{r:02x}{g:02x}{b:02x}"