39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import plotly.graph_objects as go
|
|
|
|
from ui_common import (
|
|
PALETTE,
|
|
THRESHOLD_LINES,
|
|
add_threshold_lines,
|
|
build_tir_stacked_bar_figure,
|
|
hex_to_rgba,
|
|
)
|
|
|
|
|
|
def test_hex_to_rgba_converts_correctly():
|
|
assert hex_to_rgba("#2a78d6", 0.3) == "rgba(42,120,214,0.3)"
|
|
|
|
|
|
def test_hex_to_rgba_handles_hash_optional():
|
|
assert hex_to_rgba("2a78d6", 0.3) == "rgba(42,120,214,0.3)"
|
|
|
|
|
|
def test_add_threshold_lines_adds_one_line_per_clinical_threshold():
|
|
fig = go.Figure()
|
|
add_threshold_lines(fig, PALETTE["light"])
|
|
assert len(fig.layout.shapes) == len(THRESHOLD_LINES)
|
|
|
|
|
|
def test_add_threshold_lines_targets_subplot_row_when_given():
|
|
fig = go.Figure()
|
|
fig.add_trace(go.Scatter(x=[0], y=[0]))
|
|
add_threshold_lines(fig, PALETTE["light"], row=1)
|
|
assert len(fig.layout.shapes) == len(THRESHOLD_LINES)
|
|
|
|
|
|
def test_build_tir_stacked_bar_figure_has_one_bar_trace_per_band():
|
|
tir = {"very_low": 1.0, "low": 3.0, "in_range": 80.0, "high": 12.0, "very_high": 4.0}
|
|
fig = build_tir_stacked_bar_figure(tir, PALETTE["light"])
|
|
assert len(fig.data) == 5
|
|
assert [trace.y[0] for trace in fig.data] == [1.0, 3.0, 80.0, 12.0, 4.0]
|
|
assert fig.layout.barmode == "stack"
|