use of org.kie.workbench.common.stunner.core.graph.content.HasBounds in project kie-wb-common by kiegroup.
the class SugiyamaLayoutServiceTest method testGetHeight.
@Test
public void testGetHeight() {
final Node n = mock(Node.class);
final HasBounds hasBounds = mock(HasBounds.class);
final Bounds bounds = mock(Bounds.class);
final double height = 15;
final int expected = (int) height;
when(bounds.getHeight()).thenReturn(height);
when(hasBounds.getBounds()).thenReturn(bounds);
when(n.getContent()).thenReturn(hasBounds);
int actual = layoutService.getHeight(n);
assertEquals(expected, actual);
}
use of org.kie.workbench.common.stunner.core.graph.content.HasBounds in project kie-wb-common by kiegroup.
the class AbstractLayoutService method hasLayoutInformation.
/**
* Checks if the specified graph has layout information.
* A graph with at 25% of its nodes or less at position (0,0) is considered a graph with no layout information.
* @param graph The graph.
* @return True if the graph has layout information, false otherwise.
*/
@Override
public boolean hasLayoutInformation(final Graph<?, ?> graph) {
final double threshold = getLayoutInformationThreshold(graph);
int nodesWithLayout = 0;
for (final Node n : graph.nodes()) {
final Object content = n.getContent();
if (content instanceof HasBounds) {
if (!isNullOrCloseToZero(((HasBounds) content).getBounds())) {
nodesWithLayout++;
}
}
if (nodesWithLayout >= threshold) {
return true;
}
}
return false;
}
use of org.kie.workbench.common.stunner.core.graph.content.HasBounds in project kie-wb-common by kiegroup.
the class LayoutHelper method applyLayout.
public void applyLayout(final Diagram diagram, final LayoutExecutor layoutExecutor, final boolean overrideCurrentLayout) {
final Graph<?, Node> graph = diagram.getGraph();
if (graph != null && (overrideCurrentLayout || !this.layoutService.hasLayoutInformation(graph))) {
final Layout layout = this.layoutService.createLayout(graph);
layoutExecutor.applyLayout(layout, graph);
for (final Node node : graph.nodes()) {
if (CanvasLayoutUtils.isCanvasRoot(diagram, node)) {
if (node.getContent() instanceof HasBounds) {
((HasBounds) node.getContent()).setBounds(Bounds.create(0, 0, 0, 0));
}
}
}
}
}
use of org.kie.workbench.common.stunner.core.graph.content.HasBounds in project kie-wb-common by kiegroup.
the class OpenDiagramLayoutExecutor method applyLayout.
@Override
public void applyLayout(final Layout layout, final Graph graph) {
if (layout.getNodePositions().size() == 0) {
return;
}
final HashMap<String, Node> indexByUuid = new HashMap<>();
for (final Object n : graph.nodes()) {
if (n instanceof Node) {
final Node node = (Node) n;
indexByUuid.put(node.getUUID(), node);
}
}
for (final VertexPosition position : layout.getNodePositions()) {
final Node indexed = indexByUuid.get(position.getId());
if (indexed.getContent() instanceof HasBounds) {
((HasBounds) indexed.getContent()).setBounds(Bounds.create(position.getUpperLeft().getX(), position.getUpperLeft().getY(), position.getBottomRight().getX(), position.getBottomRight().getY()));
}
}
notifyUser();
}
use of org.kie.workbench.common.stunner.core.graph.content.HasBounds in project kie-wb-common by kiegroup.
the class SugiyamaLayoutServiceTest method testGetWidth.
@Test
public void testGetWidth() {
final Node n = mock(Node.class);
final HasBounds hasBounds = mock(HasBounds.class);
final Bounds bounds = mock(Bounds.class);
final double width = 17;
final int expected = (int) width;
when(bounds.getWidth()).thenReturn(width);
when(hasBounds.getBounds()).thenReturn(bounds);
when(n.getContent()).thenReturn(hasBounds);
int actual = layoutService.getWidth(n);
assertEquals(expected, actual);
}
Aggregations