From 574ff46482fddb0c522ae111b44ab03209eea0b5 Mon Sep 17 00:00:00 2001 From: Klemek Date: Mon, 15 Jul 2019 09:26:31 +0200 Subject: [PATCH] fixed links size --- src/rendering.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rendering.js b/src/rendering.js index 4ee5e31..c0e342e 100644 --- a/src/rendering.js +++ b/src/rendering.js @@ -37,6 +37,7 @@ const DEFAULT_OPTIONS = { }; const DEFAULT_SCALE = 0.4; +const LINK_MARGIN = (1 - DEFAULT_SCALE) / 2; module.exports = (options = DEFAULT_OPTIONS) => { const self = { @@ -162,9 +163,20 @@ module.exports = (options = DEFAULT_OPTIONS) => { const angle = Math.atan2(dst.y - src.y, (dst.x - src.x) * options['h-spacing']) * 180 / Math.PI; - const size = Math.sqrt(Math.pow((dst.x - src.x) * options['h-spacing'], 2) + Math.pow(dst.y - src.y, 2)); + let size = link['size'] || options['links']['size']; - const path = self.getLinkPath(link.type, link['size'] || options['links']['size'] || size); + if (!size) { + let dx = Math.abs(dst.x - src.x) * options['h-spacing']; + if (dx > 0) + dx -= LINK_MARGIN * 2; + let dy = Math.abs(dst.y - src.y); + if (dy > 0) + dy -= LINK_MARGIN * 2; + + size = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)) / DEFAULT_SCALE; + } + + const path = self.getLinkPath(link.type, size); if (!path) return;