def add_marker_value_annotations(
ax,
timestamps: np.ndarray,
samples: np.ndarray,
signal_label: str,
color: str,
markers: List[Dict[str, Any]],
numeric_for_plot: bool,
signal_index: int = 0,
) -> None:
"""
각 marker 시점에서 해당 신호의 값을 주석으로 표시
겹침을 줄이기 위해 signal_index별로 y 오프셋을 다르게 준다.
"""
# 신호별 주석 오프셋 패턴
offset_cycle = [18, 6, -6, -18, 30, -30, 42, -42]
for marker_idx, marker in enumerate(markers):
target_time = marker["time"]
actual_time, actual_value = get_value_at_time(timestamps, samples, target_time)
if numeric_for_plot:
y_value = actual_value
else:
encoded, _ = encode_non_numeric(samples)
idx = int(np.argmin(np.abs(timestamps - actual_time)))
y_value = encoded[idx]
text = f"{signal_label}={format_value(actual_value)}"
# marker마다 x 오프셋도 약간 다르게 줘서 완전 중첩 방지
x_offset = 6 + (marker_idx % 3) * 8
y_offset = offset_cycle[signal_index % len(offset_cycle)]
ax.annotate(
text,
xy=(actual_time, y_value),
xytext=(x_offset, y_offset),
textcoords="offset points",
fontsize=7,
color=color,
bbox=dict(boxstyle="round,pad=0.2", fc="white", ec=color, alpha=0.7),
arrowprops=dict(
arrowstyle="-",
color=color,
lw=0.8,
alpha=0.7,
shrinkA=0,
shrinkB=0,
),
)
add_marker_value_annotations(
ax=ax,
timestamps=timestamps,
samples=samples,
signal_label=signal_cfg.get("label") or raw_name,
color=color if color else "black",
markers=markers,
numeric_for_plot=numeric_for_plot,
signal_index=plotted_count,
)