use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.
the class LayoutConfiguratorTest method testCombineMultipleClass.
@Test
public void testCombineMultipleClass() {
Graph g = new Graph();
LayoutConfigurator lc = new LayoutConfigurator();
lc.configure(ElkNode.class).setProperty(CoreOptions.SPACING_NODE_NODE, 42d);
lc.configure(ElkGraphElement.class).setProperty(CoreOptions.SPACING_EDGE_NODE, 42d);
ElkUtil.applyVisitors(g.root, lc);
assertEquals(42d, g.n1.getProperty(CoreOptions.SPACING_NODE_NODE), EPSILON);
assertEquals(42d, g.n1.getProperty(CoreOptions.SPACING_EDGE_NODE), EPSILON);
}
use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.
the class Issue562Test method test.
@Test
public void test() {
// Create the basic graph structure
ElkNode graph = ElkGraphUtil.createGraph();
ElkNode n1 = ElkGraphUtil.createNode(graph);
ElkPort p1 = ElkGraphUtil.createPort(n1);
ElkPort p2 = ElkGraphUtil.createPort(n1);
ElkEdge e = ElkGraphUtil.createSimpleEdge(p1, p2);
// Create a layout configurator to apply options, just as it would happen in the DiagramLayoutEngine
LayoutConfigurator config = new LayoutConfigurator();
config.configure(n1).setProperty(CoreOptions.INSIDE_SELF_LOOPS_ACTIVATE, true);
config.configure(e).setProperty(CoreOptions.INSIDE_SELF_LOOPS_YO, true);
// Apply the configurator and a layout algorithm resolver, just like the DiagramLayoutEngine does
ElkUtil.applyVisitors(graph, config, new LayoutAlgorithmResolver());
// Apply layout. We don't want an UnsupportedConfigurationException to be thrown
try {
new RecursiveGraphLayoutEngine().layout(graph, new NullElkProgressMonitor());
} catch (UnsupportedConfigurationException ex) {
fail(ex.toString());
}
}
use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.
the class LayoutConfiguratorTest method testPreventOverridingExistingOptions.
@Test
public void testPreventOverridingExistingOptions() {
Graph g = new Graph();
g.root.setProperty(CoreOptions.SPACING_NODE_NODE, 13d);
LayoutConfigurator lc = new LayoutConfigurator();
lc.configure(ElkNode.class).setProperty(CoreOptions.SPACING_NODE_NODE, 42d);
lc.addFilter(LayoutConfigurator.NO_OVERWRITE);
ElkUtil.applyVisitors(g.root, lc);
assertEquals(13d, g.root.getProperty(CoreOptions.SPACING_NODE_NODE), EPSILON);
}
use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.
the class DiagramLayoutEngine method handleAncestors.
/**
* Handle the ancestors of the parent element if {@link CoreOptions#LAYOUT_ANCESTORS} is set.
* For every ancestor node of the parent element (i.e. {@link LayoutMapping#getParentElement()}),
* all containing elements that are not ancestors are excluded from layout.
*
* @param mapping
* a mapping for the layout graph
* @param params
* layout parameters
*/
protected void handleAncestors(final LayoutMapping mapping, final Parameters params) {
boolean layoutAncestors = params.getGlobalSettings().getProperty(CoreOptions.LAYOUT_ANCESTORS);
if (layoutAncestors) {
// Mark all parallel areas for exclusion from layout
ElkGraphElement graphElem = mapping.getGraphMap().inverse().get(mapping.getParentElement());
if (graphElem instanceof ElkNode && ((ElkNode) graphElem).getParent() != null) {
if (params.configurators.isEmpty()) {
params.configurators.add(new LayoutConfigurator());
}
ElkNode node = (ElkNode) graphElem;
do {
ElkNode parent = node.getParent();
for (ElkNode child : parent.getChildren()) {
if (child != node) {
for (IGraphElementVisitor c : params.configurators) {
if (c instanceof LayoutConfigurator) {
IPropertyHolder childConfig = ((LayoutConfigurator) c).configure(child);
// Do not layout the content of the child node
childConfig.setProperty(CoreOptions.NO_LAYOUT, true);
// Do not change the size of the child node
childConfig.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.fixed());
// Do not move the ports of the child node
childConfig.setProperty(CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
}
}
}
}
node = parent;
} while (node.getParent() != null);
}
}
}
use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.
the class DiagramLayoutEngine method addDiagramConfig.
/**
* Create a diagram layout configuration and add it to the setup.
*/
protected void addDiagramConfig(final Parameters params, final LayoutMapping layoutMapping) {
LayoutConfigurator diagramConfig = configManager.createConfigurator(layoutMapping);
if (params.configurators.isEmpty()) {
params.addLayoutRun(diagramConfig);
} else {
ListIterator<IGraphElementVisitor> configIter = params.configurators.listIterator();
while (configIter.hasNext()) {
boolean isFirstConfig = !configIter.hasPrevious();
IGraphElementVisitor setupConfig = configIter.next();
if (setupConfig instanceof LayoutConfigurator) {
LayoutConfigurator layoutConfigurator = (LayoutConfigurator) setupConfig;
if (params.overrideDiagramConfig) {
if (isFirstConfig || layoutConfigurator.isClearLayout()) {
LayoutConfigurator newConfig;
if (configIter.hasNext()) {
newConfig = new LayoutConfigurator().overrideWith(diagramConfig);
} else {
newConfig = diagramConfig;
}
configIter.set(newConfig.overrideWith(layoutConfigurator));
}
} else {
layoutConfigurator.overrideWith(diagramConfig);
}
}
}
}
}
Aggregations