diff --git a/plugins/value_rank/main.py b/plugins/value_rank/main.py index 3c7fd69..2b507b5 100644 --- a/plugins/value_rank/main.py +++ b/plugins/value_rank/main.py @@ -1334,7 +1334,7 @@ class ValueRankPlugin(MessagePluginInterface): # 1. 每条边中点标注“a->b / b->a”; # 2. 使用白底半透明标签提升可读性,避免与连线重叠难辨识。 edge_label_parts: List[str] = [] - for a, b, mention_count, score, a_to_b_count, b_to_a_count in selected_edges: + for edge_idx, (a, b, mention_count, score, a_to_b_count, b_to_a_count) in enumerate(selected_edges, start=1): ax, ay = pos_map[a] bx, by = pos_map[b] normalized = max(0.12, min(score / max_edge_score, 1.0)) @@ -1346,7 +1346,18 @@ class ValueRankPlugin(MessagePluginInterface): ) # 通过字典序固定方向,确保同一条边每次渲染文案方向一致。 # 标签文案改为“昵称 + 双向次数 + 恶搞关系标签”,不再展示 wxid。 + # 为避免标签压在线条上,这里把标签放到“线段法线方向”的偏移位置。 mx, my = (ax + bx) / 2.0, (ay + by) / 2.0 + dx, dy = (bx - ax), (by - ay) + edge_len = max(math.hypot(dx, dy), 1.0) + # 线段法线单位向量(逆时针旋转90度)。 + nx, ny = (-dy / edge_len), (dx / edge_len) + # 交错方向,减少多条边标签都挤在同一侧导致重叠。 + side_sign = 1.0 if (edge_idx % 2 == 0) else -1.0 + # 偏移距离与线宽相关,至少 22 像素,保证不贴线。 + offset = max(22.0, 14.0 + stroke_width * 2.4) + label_x = mx + nx * offset * side_sign + label_y = my + ny * offset * side_sign nick_a = cm.get_group_name(group_id, a) or a nick_b = cm.get_group_name(group_id, b) or b @@ -1366,7 +1377,7 @@ class ValueRankPlugin(MessagePluginInterface): label_text = f"{nick_a}→{nick_b} {a_to_b_count}/{b_to_a_count} | {relation_tag}" safe_label = html.escape(label_text) edge_label_parts.append( - f'' + f'' f'' f'{safe_label}' f''