TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to draw S-curved arrows between boxes

664 pointsby alex_stoddardover 3 years ago

17 comments

emmanueloga_over 3 years ago
GUI algorithms like these are not well documented anywhere (except, of course, all over the web and in source code! :-) ...<p>Would be nice to have a site, maybe a wiki, dedicated to this kind of thing.<p>Other interesting problems in this area:<p>* Layout algorithms<p>* Automatic assignment of keys for navigation (for nav w&#x2F;o using a mouse)<p>* Popup menu prediction [1]<p>* Text breaking &#x2F; paragraph layout [2]<p>* Etc, etc, etc ...<p>1: <a href="https:&#x2F;&#x2F;bjk5.com&#x2F;post&#x2F;44698559168&#x2F;breaking-down-amazons-mega-dropdown" rel="nofollow">https:&#x2F;&#x2F;bjk5.com&#x2F;post&#x2F;44698559168&#x2F;breaking-down-amazons-mega...</a><p>2: <a href="https:&#x2F;&#x2F;xxyxyz.org&#x2F;line-breaking&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xxyxyz.org&#x2F;line-breaking&#x2F;</a>
评论 #29656215 未加载
评论 #29656626 未加载
评论 #29656309 未加载
评论 #29656469 未加载
kazinatorover 3 years ago
In cases when the boxes overlap, there are ways to choose an arrow which will not cross the boxes. But this is prevented by the constraint that the starting and ending points must be on the midpoint of a box edge. If the midpoint of the a given edge is occluded by a box, or occludes a box, then that edge is not considered, even though it is partially visible and has a viable point for the arrow.<p>E.g. if we could start an arrow in the middle of the small protruding &quot;ledge&quot; of the bottom box, we could do this:<p><pre><code> ,-------. : : : v : +----------------+ : | | +----------------+ | | |--+ | | +----------------+ </code></pre> It&#x27;s not written in stone that box-and-arrow diagrams must be connected by edge midpoints. That can&#x27;t even work well any time you have multiple arrows emanating or terminating on the same edge.<p>Very good first iteration round, though.
评论 #29673473 未加载
nescioquidover 3 years ago
I enjoyed reading this because it reminded me of a moment of hubris as junior developer. I was working with a complicated data structure I wanted to visualize, so I decided to write some quick code to basically read the data structure and output a graph as rectangles and lines connecting them.<p>I was chastened by the complexity of just drawing the lines between boxes so that they didn&#x27;t overlap (as much as possible) and were drawn on facing sides (one of the later problems discussed in the article). I don&#x27;t recall how I did it, but I do remember a sudden refresher on matrix multiplication.<p>It drove home how simple things can be more complicated than you might expect.<p>EDIT: also, I appreciated the way the article was written. No cruft.
评论 #29655477 未加载
评论 #29656312 未加载
评论 #29653953 未加载
alejohausnerover 3 years ago
The graphviz system [1], originally from at&amp;t labs, has a program called &quot;dot&quot; that does this kind of thing very well, including routing the arrows around other boxes that may be in the way. It&#x27;s been open sourced. It&#x27;s also been ported to the web [2]<p>1: <a href="https:&#x2F;&#x2F;graphviz.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;graphviz.org&#x2F;</a><p>2: <a href="http:&#x2F;&#x2F;www.webgraphviz.com&#x2F;?tab=map" rel="nofollow">http:&#x2F;&#x2F;www.webgraphviz.com&#x2F;?tab=map</a>
评论 #29657490 未加载
评论 #29659741 未加载
jedbergover 3 years ago
We recently redid our landscaping, which included making the edge of the driveway and S curve. I thought my landscaper was pretty clever.<p>He took a flimsy pvc pipe, nailed it down at the beginning and end of the curve, and it bent into a perfect S curve that he then spray painted down to follow.<p>It’s amazing how physics and nature can solve these problems for you!
评论 #29656837 未加载
评论 #29656893 未加载
klyrsover 3 years ago
Such an innocent-sounding problem, but I&#x27;ve drawn tons of figures in inkscape, tikz and matplotlib and I swear, I&#x27;d never stop fidgeting with curved arrows if time was immaterial.<p>But of course, I have Opinions that would keep me from using this in practice. For example, my favorite style is similar to a half curly-bracket (or, taste depending, an integral symbol) -- two small semicircles connected by an axis-aligned line.<p>Edit: oh, and question from the peanut gallery... what if one box is fully within the other, and <i>centered</i>?
评论 #29655848 未加载
Minor49erover 3 years ago
This reminds me of a project I worked on that had an interface with draggable boxes just like this. The library that we used rendered the boxes as divs while the arrows were drawn as SVGs. Apparently there was a bug on Internet Explorer 11 where CSS transforms being applied to SVGs would cause the browser to slow to a crawl, or crash entirely if too many were happening at once.<p>To get around it, I switched the line drawing function for IE11 so that it would draw two divs that would extend from the middle of each box and touch corners in the middle (basically figure 4 in the article), then style them with a curved border on the appropriate side. While not as elegant as what&#x27;s shown here, it was convincing enough that nobody noticed any visual difference between it and the regular version.
gunshowmoover 3 years ago
Fantastic article. This kind of insight into how people break down complicated problems into more manageable pieces is extremely valuable.
resoniousover 3 years ago
This is a really great writeup. Whenever I try to draw diagrams using software tools, I always run into stuff like this and am disappointed with the tool&#x27;s ability to help me out.<p>I&#x27;ve actually taken up hand-drawing diagrams lately and it&#x27;s worked well. I get a lot of comments at work - &quot;haha wow nice art!&quot; (sarcasm) followed by &quot;actually this is really easy to follow&quot;. I feel like it&#x27;s both faster to draw and a more accurate representation of my mental model when I draw by hand.<p>But hey, if the diagramming tools were smart like in this post, maybe I&#x27;d go back to the tools for awhile ;)
cyber_kinetistover 3 years ago
The blog post is not bad, but as a graphics programmer I don&#x27;t get why this one algorithm is made as a full NPM package. (Getting some left-pad vibes again...) The actual source code is about 200 lines (which can probably be shortened down to 50 if you try enough), why don&#x27;t you just include it as a code snippet in that blog post for others to copy in their codebase? The code itself is pretty straightforward to understand, and you&#x27;re probably going to make some little modifications to suit your needs.
zestypingover 3 years ago
The algorithm selects the arrow option with the shortest curve length, but I think the results would look better if it selected for the option with the least bends and inflection points.<p>Here&#x27;s a specific example: <a href="https:&#x2F;&#x2F;imgur.com&#x2F;a&#x2F;1n2JiB3" rel="nofollow">https:&#x2F;&#x2F;imgur.com&#x2F;a&#x2F;1n2JiB3</a>
sriram_malharover 3 years ago
I don&#x27;t see why arrows must start at the middle of an edge. Sometimes multiple arrows from an edge look better if the end points are spaced apart (to emphasise the connectivity visually, for example). There are times when an arrow is positioned just on the inside of a corner, depending on what it is connected to and the angle of the arrow with respect to the edge.<p>In the final analysis, one should strive to get a visually balanced look, which takes into account placement, thickness of lines, density of information etc. There is no one-size fits all.
ameliusover 3 years ago
This looks like a nice result that can be useful in some cases, but it is limited to a single arrow. When you have more than one arrow, you get constraints like &quot;minimize the number of crossings&quot; and then &quot;minimize total arrow line length&quot;. At this point, it becomes way more complicated.
bullenover 3 years ago
Or you just draw stright lines and save yourself some trouble.<p>Because they are eaiser to stack without getting garbled!<p><a href="http:&#x2F;&#x2F;move.rupy.se&#x2F;file&#x2F;logic.html" rel="nofollow">http:&#x2F;&#x2F;move.rupy.se&#x2F;file&#x2F;logic.html</a>
Waterluvianover 3 years ago
I think this post finally made something click for me: runtime generated SVG is incredibly powerful and I really need to add it to my toolbox.
thewisenerdover 3 years ago
slightly(?) related: <a href="https:&#x2F;&#x2F;www.zindlerb.com&#x2F;improving-flowchart-editing-tools&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.zindlerb.com&#x2F;improving-flowchart-editing-tools&#x2F;</a><p>didn&#x27;t gather a lot of discussion though...
anonymous532over 3 years ago
It&#x27;s cute and definitely a great way to &quot;draw S-curved arrow between boxes&quot;, but, under the assumption of being built to be used within a real project with dozens or hundreds of overlapping connections, this, like many other node systems, fails to be usable unless you push the complexity somewhere else.
评论 #29656117 未加载
评论 #29654283 未加载
评论 #29654949 未加载
评论 #29657165 未加载
评论 #29659735 未加载
评论 #29657408 未加载