From 007a8bcece633ec618b3f649405e83e85a9ce0aa Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Thu, 24 Feb 2022 02:34:58 +0100 Subject: [PATCH] use bezier instead of elliptic arrows --- docs/morphisms/js/d3_visualisation.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/morphisms/js/d3_visualisation.js b/docs/morphisms/js/d3_visualisation.js index 4609b07..f1a1411 100644 --- a/docs/morphisms/js/d3_visualisation.js +++ b/docs/morphisms/js/d3_visualisation.js @@ -24,11 +24,23 @@ function drag(simulation) { } function linkArc(d) { - const r = Math.hypot(d.target.x - d.source.x, d.target.y - d.source.y); + let r = Math.hypot(d.target.x - d.source.x, d.target.y - d.source.y); + r = 40*Math.exp(r/50) + // r = 50 + 2*(r/20)**3 +// Elliptical arc: +// return ` +// M${d.source.x},${d.source.y} +// A${r},${r} 0 0,1 ${d.target.x},${d.target.y} +// `; + let xmid = (d.source.x + d.target.x) / 2 + let ymid = (d.source.y + d.target.y) / 2 + // cubic smooth Bezier return ` - M${d.source.x},${d.source.y} - A${r},${r} 0 0,1 ${d.target.x},${d.target.y} - `; + M${d.source.x} ${d.source.y} + S${xmid - 0.01*ymid} ${ymid + 0.01*xmid} + ${d.target.x},${d.target.y} + ` + ; } function highlight(node) {