Hi,
I’m looking into making a very simple layout algorithm for a 2D graph with directed edges. I want to place my nodes in straight rows, snaking around the page. For example:
A - B - C - D||H - G - F - E||I - J - K - L
(Where D and E, and H and I share an edge)
I’ve looked into implementing the Layout interface, and into extending BarnesHutLayout, or SpringBox, but those options all seem much more complex than necessary for my purposes.
My graph will be embedded in a Swing GUI, and ideally the constructor to my layout class would take a reference to the Swing component containing the graph. Then my layout algorithm could place the first node in the centre of the graph, and as new nodes were added it would add them at the same y coordinate as the previous node, and at the same x coordinate as the previous node, plus some constant distance. It would keep adding nodes like this until the total width of the graph exceeded the width of the Swing component containing it, at which point it would modify the y value of the previous node, and start adding nodes on the next ‘line’.
I’m not at all sure how to achieve all of the above. I’ve put together a little code which uses a layout algorithm which extends SpringBox, but while the nodes gravitate towards more a straight line shape, they still ‘spring’ a little.
Any help would be much appreciated. Code snippets would be especially helpful.
Many thanks, Andrew
Archives gérées par MHonArc 2.6.16.