From f32822f6ba6c04ba19a2fb4db3a73f5c5e7c900d Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 30 Dec 2024 22:47:45 +0200 Subject: [PATCH] Don't consider curved edges in offset heuristic --- src/ui.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ui.mjs b/src/ui.mjs index bfc7c1b..74cef32 100644 --- a/src/ui.mjs +++ b/src/ui.mjs @@ -310,6 +310,9 @@ UIMode.Connect = class extends UIMode { const align = new Map(); const offset = new Map(); const curve = new Map(); + // In our offset heuristic below, where we attempt to avoid overlap, we only + // wish to consider offset for edges that are not curved. + const offset_only = new Map(); // We only want to pick `centre` when the source and target are equally constraining // (otherwise we end up picking `centre` far too often). So we check that they're both // being considered equally. This means `centre` is chosen only rarely, but often in @@ -351,6 +354,12 @@ UIMode.Connect = class extends UIMode { } offset.set(options.offset, offset.get(options.offset) + 1); } + if (options.offset !== null && (options.curve === null || options.curve === 0)) { + if (!offset_only.has(options.offset)) { + offset_only.set(options.offset, 0); + } + offset_only.set(options.offset, offset_only.get(options.offset) + 1); + } if (options.curve !== null) { if (!curve.has(options.curve)) { curve.set(options.curve, 0); @@ -408,7 +417,7 @@ UIMode.Connect = class extends UIMode { const attempt = offset_attempts.shift(); // We need to negate because the offsets in `offset` are negated, because they // record offset candidates, rather than offsets that are present. - if (!offset.has(-attempt)) { + if (!offset_only.has(-attempt)) { options.offset = attempt; break; }