Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radial layout: center on root option #941

Merged
merged 5 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,18 @@ algorithm radial(RadialLayoutProvider) {
supports radius
supports sorter
supports wedgeCriteria
supports centerOnRoot
}

/////////////////////////////////Options///////////////////////////////
option centerOnRoot: boolean {
label "Center On Root"
description
"Centers the layout on the root of the tree i.e. so that the central node is also the center node of the
final layout. This introduces additional whitespace."
default = false
targets parents
}
option orderId: int {
label "Order ID "
description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*******************************************************************************/
package org.eclipse.elk.alg.radial.intermediate;

import org.eclipse.elk.alg.radial.InternalProperties;
import org.eclipse.elk.alg.radial.options.RadialOptions;
import org.eclipse.elk.core.alg.ILayoutProcessor;
import org.eclipse.elk.core.math.ElkMargin;
import org.eclipse.elk.core.math.ElkPadding;
Expand Down Expand Up @@ -48,6 +50,45 @@ public void process(final ElkNode graph, final IElkProgressMonitor progressMonit

ElkPadding padding = graph.getProperty(CoreOptions.PADDING);
KVector offset = new KVector(minXPos - padding.getLeft(), minYPos - padding.getTop());


double width = maxXPos - minXPos + padding.getHorizontal();
double height = maxYPos - minYPos + padding.getVertical();

if (graph.getProperty(RadialOptions.CENTER_ON_ROOT)) {
ElkNode root = graph.getProperty(InternalProperties.ROOT_NODE);
ElkMargin rootMargins = root.getProperty(CoreOptions.MARGINS);
// calculate the current midpoint of the root, taking into account the defined margins and the already
// calculated offset necessary to shift the graph into the positive quadrant of the coordinate system
double rootX = root.getX() + root.getWidth()/2 + (rootMargins.left + rootMargins.right)/2 - offset.x;
Eddykasp marked this conversation as resolved.
Show resolved Hide resolved
double rootY = root.getY() + root.getHeight()/2 + (rootMargins.top + rootMargins.bottom)/2 - offset.y;

double dx = width - rootX;
double dy = height - rootY;

if (dx < width / 2) {
// need to add additional space on the left
double additionalX = dx - rootX;
width += additionalX;
offset.x -= additionalX;
} else {
// add addtional space on the right
double additionalX = rootX - dx;
width += additionalX;
}

if (dy < height / 2) {
//need to add additional space on the top
double additionalY = dy - rootY;
height += additionalY;
offset.y -= additionalY;
} else {
// add addtional space on the bottom
double additionalY = rootY - dy;
height += additionalY;
}

}

// process the nodes
for (ElkNode node : graph.getChildren()) {
Expand All @@ -57,12 +98,12 @@ public void process(final ElkNode graph, final IElkProgressMonitor progressMonit
}

// set up the graph
double width = maxXPos - minXPos + padding.getHorizontal();
double height = maxYPos - minYPos + padding.getVertical();
if (!graph.getProperty(CoreOptions.NODE_SIZE_FIXED_GRAPH_SIZE)) {
graph.setWidth(width);
graph.setHeight(height);
}

// store child area info
graph.setProperty(CoreOptions.CHILD_AREA_WIDTH, width - padding.getHorizontal());
graph.setProperty(CoreOptions.CHILD_AREA_HEIGHT, height - padding.getVertical());
progressMonitor.logGraph(graph, "After");
Expand Down
11 changes: 11 additions & 0 deletions test/org.eclipse.elk.alg.radial.test/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
40 changes: 40 additions & 0 deletions test/org.eclipse.elk.alg.radial.test/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.elk.alg.disco.test</name>
soerendomroes marked this conversation as resolved.
Show resolved Hide resolved
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>
Loading