diff --git a/Kieker.WebGUI/.settings/org.eclipse.jdt.ui.prefs b/Kieker.WebGUI/.settings/org.eclipse.jdt.ui.prefs index a7294084e5aeedccf54d95faa3be05cdd84def8a..9961c8b4bcfdb1e33aeec990bd11d27b01e6f425 100644 --- a/Kieker.WebGUI/.settings/org.eclipse.jdt.ui.prefs +++ b/Kieker.WebGUI/.settings/org.eclipse.jdt.ui.prefs @@ -99,11 +99,11 @@ sp_cleanup.remove_trailing_whitespaces=true sp_cleanup.remove_trailing_whitespaces_all=true sp_cleanup.remove_trailing_whitespaces_ignore_empty=false sp_cleanup.remove_unnecessary_casts=true -sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unnecessary_nls_tags=true sp_cleanup.remove_unused_imports=true sp_cleanup.remove_unused_local_variables=true sp_cleanup.remove_unused_private_fields=true -sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_members=true sp_cleanup.remove_unused_private_methods=true sp_cleanup.remove_unused_private_types=true sp_cleanup.sort_members=false diff --git a/Kieker.WebGUI/lib/klay-0.2.0.LICENSE b/Kieker.WebGUI/lib/klay-0.2.0.LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..aa7cc810fa198a624c8c3de53547e33f87768c51 --- /dev/null +++ b/Kieker.WebGUI/lib/klay-0.2.0.LICENSE @@ -0,0 +1,87 @@ +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and + +b) in the case of each subsequent Contributor: + +i) changes to the Program, and + +ii) additions to the Program; + +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. + +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. + +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. + +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and + +b) its license agreement: + +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; + +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; + +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and + +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and + +b) a copy of this Agreement must be included with each copy of the Program. + +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. \ No newline at end of file diff --git a/Kieker.WebGUI/lib/klay_0.2.0.jar b/Kieker.WebGUI/lib/klay_0.2.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..8d5068cab0bf083ccd3f87d0624623de16a19899 Binary files /dev/null and b/Kieker.WebGUI/lib/klay_0.2.0.jar differ diff --git a/Kieker.WebGUI/pom.xml b/Kieker.WebGUI/pom.xml index c03afae181ac76d1b8e83faae72ff22e4fcc4f5a..0046527366d59661466f91675d36eab808463dc2 100644 --- a/Kieker.WebGUI/pom.xml +++ b/Kieker.WebGUI/pom.xml @@ -26,6 +26,7 @@ <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <kieker.jar>kieker-1.6_emf.jar</kieker.jar> + <klay.jar>klay_0.2.0.jar</klay.jar> <spring.version>3.1.2.RELEASE</spring.version> <slf4j.version>1.7.2</slf4j.version> <primefaces.themes.version>1.0.8</primefaces.themes.version> @@ -305,6 +306,13 @@ <scope>system</scope> <systemPath>${project.basedir}/lib/${kieker.jar}</systemPath> </dependency> + <dependency> + <groupId>kieler</groupId> + <artifactId>kieler</artifactId> + <version>0.2.0</version> + <scope>system</scope> + <systemPath>${project.basedir}/lib/${klay.jar}</systemPath> + </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> @@ -415,6 +423,8 @@ <tasks> <copy file="${project.basedir}/lib/${kieker.jar}" todir="${project.build.directory}/Kieker.WebGUI-${project.version}/WEB-INF/lib" /> + <copy file="${project.basedir}/lib/${klay.jar}" + todir="${project.build.directory}/Kieker.WebGUI-${project.version}/WEB-INF/lib" /> </tasks> </configuration> </execution> diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/exception/InvalidInputSizeException.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/exception/InvalidInputSizeException.java new file mode 100644 index 0000000000000000000000000000000000000000..265c5b162a65abab0ce29723cd579ae1b18a0ce7 --- /dev/null +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/exception/InvalidInputSizeException.java @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.common.exception; + + +/** + * An Exception that is thrown when an Array of invalid size is loaded by the GraphFlowLayouter. + * + * Arrays loaded by the addEdges() method must be divisible by 4. + * Arrays loaded by the addNodes() method must be of length: 1 + nodeCount * 8 + * + * @author row, Nils Christian Ehmke + */ +public class InvalidInputSizeException extends AbstractKiekerWebGUIException { + + private static final long serialVersionUID = 1L; + + public InvalidInputSizeException() { + super("Input Array has an invalid length!"); + } +} diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/exception/UninitializedGraphException.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/exception/UninitializedGraphException.java new file mode 100644 index 0000000000000000000000000000000000000000..88b38a0ec289a4b6335439a0d78156af2a44b8f0 --- /dev/null +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/exception/UninitializedGraphException.java @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.common.exception; + + +/** + * An Exception that is thrown when trying to connect Edges if a graph has not been + * loaded by the GraphFlowLayouter. + * + * @author row, Nils Christian Ehmke + */ +public class UninitializedGraphException extends AbstractKiekerWebGUIException { + + private static final long serialVersionUID = 1L; + + public UninitializedGraphException() { + super("Cannot apply Edges! Graph has not been loaded!"); + } +} diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/layout/GraphFlowLayouter.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/layout/GraphFlowLayouter.java new file mode 100644 index 0000000000000000000000000000000000000000..780fca4b6d4dc4931bbff16bef5e51a005a094e6 --- /dev/null +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/layout/GraphFlowLayouter.java @@ -0,0 +1,321 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.common.layout; + +import java.util.ArrayList; +import java.util.List; + +import kieker.webgui.common.exception.InvalidInputSizeException; +import kieker.webgui.common.exception.UninitializedGraphException; + + +import de.cau.cs.kieler.core.alg.BasicProgressMonitor; +import de.cau.cs.kieler.core.alg.IKielerProgressMonitor; +import de.cau.cs.kieler.core.kgraph.KEdge; +import de.cau.cs.kieler.core.kgraph.KNode; +import de.cau.cs.kieler.core.kgraph.KPort; +import de.cau.cs.kieler.kiml.AbstractLayoutProvider; +import de.cau.cs.kieler.kiml.klayoutdata.KEdgeLayout; +import de.cau.cs.kieler.kiml.klayoutdata.KPoint; +import de.cau.cs.kieler.kiml.klayoutdata.KShapeLayout; +import de.cau.cs.kieler.kiml.options.EdgeRouting; +import de.cau.cs.kieler.kiml.options.LayoutOptions; +import de.cau.cs.kieler.kiml.options.PortConstraints; +import de.cau.cs.kieler.kiml.util.KimlUtil; +import de.cau.cs.kieler.klay.layered.LayeredLayoutProvider; + +import org.eclipse.emf.common.util.EList; + +/** + * This class provides a single method, that is used for GraphFlow layouting. The JavaScript GraphFlow throws an "autoLayout"-Event upon using the function + * autoLayout(). This event provides two Strings which may be used by this class' layoutGraph(nodes, edges) method. The return value can then be used as an argument + * for the GraphFlow's loadPositionsFromLayout(positions) function. + * + * @author row, Nils Christian Ehmke + */ +public final class GraphFlowLayouter { + + /** + * An array containing the child node and the ports from left to right. + */ + private static List<Object>[] children; + /** + * An array containing edges. This way we can return edge information in the same order. + */ + private static KEdge[] edges; + + /** + * Private constructor as this is a utility class. + */ + private GraphFlowLayouter() { + // No code necessary + } + + /** + * Parses a String array, building a graph with nodes and fixed ports. + * + * @param input + * The parsed String array + * @return The constructed Graph + * @throws InvalidInputSizeException + */ + private static KNode addNodes(final String input) throws InvalidInputSizeException { + final String[] positions = input.split(" "); + + // set up root + final KNode graph = KimlUtil.createInitializedNode(); + graph.getData(KShapeLayout.class).setProperty(LayoutOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL); + + // prepare array of lists + List<Object> child; + GraphFlowLayouter.children = new ArrayList[positions.length / 2]; + + final int dimHalf = Integer.parseInt(positions[0]); + final int dim = dimHalf * 2; + + // check input Array for correct length + if (((positions.length - 1) % 8) != 0) { + throw new InvalidInputSizeException(); + } + + // loop variables + KNode node; + KPort port; + KShapeLayout layout; + int width; + int height; + int portCount; + int portX; + int portY; + int c = 1; + int i = 0; + + // iterate input node positions + while (c < positions.length) { + // get size and increment array pointer + width = Integer.parseInt(positions[c++]); + height = Integer.parseInt(positions[c++]); + + // create Node + node = KimlUtil.createInitializedNode(); + node.setParent(graph); + + child = new ArrayList<Object>(); + GraphFlowLayouter.children[i] = child; + child.add(node); + + // set node dimensions + layout = node.getData(KShapeLayout.class); + layout.setWidth(width); + layout.setHeight(height); + layout.setProperty(LayoutOptions.FIXED_SIZE, Boolean.TRUE); + layout.setProperty(LayoutOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS); + portX = -dimHalf; + + // add Ports + for (int portType = 0; portType < 3; portType++) { + // determine port x-position + if (portType == 1) { + portX = width - dimHalf; + } + + portCount = Integer.parseInt(positions[c++]); + portY = Integer.parseInt(positions[c++]); + + final int lp = portCount; + for (int n = 0; n < lp; n++) { + + // create port + port = KimlUtil.createInitializedPort(); + port.setNode(node); + child.add(port); + + // set layout for Port + layout = port.getData(KShapeLayout.class); + + // set position and dimension + layout.setWidth(dim); + layout.setHeight(dimHalf); + layout.setYpos(portY); + layout.setXpos(portX); + + portY += dim; + } + } + i++; + } + + return graph; + } + + /** + * Parses an array which must contain quadruples of numbers.<br/> + * The first number must be the index of the children-array, where + * the source node is located.<br/> + * The second number must be the index of the children-array, where + * the target node is located.<br/> + * The third number must be the index of the source node ArrayList, where + * the source port is located.<br/> + * The fourth number must be the index of the target node ArrayList, where + * the target port is located. + * + * @param input + * The parsed String array + * @throws UninitializedGraphException + * If the graph has not yet been initialized. + * @throws InvalidInputSizeException + * If the input size is invalid. + */ + private static void addEdges(final String input) throws UninitializedGraphException, InvalidInputSizeException { + final String[] edgeInfo = input.split(" "); + + // cannot add edges if no graph was constructed + if (GraphFlowLayouter.children == null) { + throw new UninitializedGraphException(); + } + if ((edgeInfo.length % 4) != 0) { + throw new InvalidInputSizeException(); + } + + // init edge Array + GraphFlowLayouter.edges = new KEdge[edgeInfo.length / 4]; + + // set up loop variables + KEdge edge; + int sourceID; + int targetID; + KPort sourcePort; + KPort targetPort; + int e = 0; + final int l = edgeInfo.length; + int ea = 0; + + while (e < l) { + // read from String + sourceID = Integer.parseInt(edgeInfo[e++]); + targetID = Integer.parseInt(edgeInfo[e++]); + sourcePort = (KPort) GraphFlowLayouter.children[sourceID].get(1 + Integer.parseInt(edgeInfo[e++])); + targetPort = (KPort) GraphFlowLayouter.children[targetID].get(1 + Integer.parseInt(edgeInfo[e++])); + + // add edge to graph + edge = KimlUtil.createInitializedEdge(); + edge.setSource((KNode) GraphFlowLayouter.children[sourceID].get(0)); + edge.setTarget((KNode) GraphFlowLayouter.children[targetID].get(0)); + + // set ports of edge + edge.setSourcePort(sourcePort); + sourcePort.getEdges().add(edge); + edge.setTargetPort(targetPort); + targetPort.getEdges().add(edge); + + GraphFlowLayouter.edges[ea++] = edge; + } + + } + + /** + * This method takes two Strings, describing some basic graph information, and constructs a KGraph, which is then layouted by a Kieler algorithm. + * + * @param nodes + * A String containing node dimensions. + * @param edges + * A String containing connection information of edges. + * @return A String of space separated node positions. + */ + public static String layoutGraph(final String nodes, final String edges) { + KNode graph; + try { + graph = GraphFlowLayouter.addNodes(nodes); + GraphFlowLayouter.addEdges(edges); + } catch (final InvalidInputSizeException ie) { + System.err.println(ie.getMessage()); + return null; + } catch (final UninitializedGraphException ue) { + System.err.println(ue.getMessage()); + return null; + } + + // create a progress monitor + final IKielerProgressMonitor progressMonitor = new BasicProgressMonitor(); + + // create the layout provider + final AbstractLayoutProvider layoutProvider = new LayeredLayoutProvider(); + + // perform layout on the created graph + layoutProvider.doLayout(graph, progressMonitor); + + // output layout information + // GraphFlowLayouter.printLayoutInfo(graph); + + // convert layouted graph positions to String + final String layoutedGraph = GraphFlowLayouter.getPositions(graph); + final String bendPoints = GraphFlowLayouter.getBendPoints(); + return layoutedGraph + "#" + bendPoints; + } + + /** + * Reads the (layouted) positions of a constructed KGraph and writes them as integers to a string, seperating each number with a space. + * + * @param graph + * The graph with at least one child + * @return The constructed string + */ + private static String getPositions(final KNode graph) { + final StringBuilder sb = new StringBuilder(); + KShapeLayout layout; + + for (final KNode node : graph.getChildren()) { + layout = node.getData(KShapeLayout.class); + final int x = Math.round(layout.getXpos() + (layout.getWidth() / 2)); + final int y = Math.round(layout.getYpos() + (layout.getHeight() / 2)); + sb.append(x); + sb.append(" "); + sb.append(y); + sb.append(" "); + } + + return sb.toString(); + } + + /** + * Iterates all edges and creates a semicolon separated String which contains bend points of all edges. + * + * @return The bend point String + */ + private static String getBendPoints() { + final StringBuilder sb = new StringBuilder(); + + // iterate edges + for (final KEdge edge : GraphFlowLayouter.edges) { + final KEdgeLayout layout = edge.getData(KEdgeLayout.class); + final EList<KPoint> bendPoints = layout.getBendPoints(); + + // iterate bend points + final int bl = bendPoints.size(); + for (int b = 0; b < bl; b++) { + final KPoint point = bendPoints.get(b); + sb.append(Math.round(point.getX())); + sb.append(" "); + sb.append(Math.round(point.getY())); + sb.append(" "); + } + sb.append("; "); + } + + return sb.toString(); + } +} diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java index 000422a8216e23fe43bc298bf10a3101df6138d3..1dfaffb0f483b0c1bc78f94d1eb215172028223c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java @@ -34,6 +34,7 @@ import kieker.analysis.model.analysisMetaModel.MIRepositoryConnector; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; import kieker.monitoring.core.registry.Registry; +import kieker.webgui.common.layout.GraphFlowLayouter; import org.primefaces.context.RequestContext; @@ -79,6 +80,10 @@ public final class CurrentAnalysisEditorGraphBean { * This is the javasscript code to add the remove edge listener to the graph. */ private static final String JS_CMD_ADD_REMOVE_EDGE_LISTENER = "graph.addListener('onRemoveEdge', edgeRemoveListener);"; + + private static final String JS_CMD_ADD_ERROR_LISTENER = "graph.addListener('onError', function(e){Log.write(e);});"; + + private static final String JS_CMD_ADD_AUTO_LAYOUT_LISTENER = "graph.addListener('autoLayout', autoLayoutListener);"; /** * This is the javascript code for a node object. */ @@ -111,6 +116,8 @@ public final class CurrentAnalysisEditorGraphBean { * This is the javascript code to redraw the command. */ private static final String JS_CMD_REFRESH_GRAPH = "graph.refresh();"; + private static final String JS_CMD_START_AUTO_LAYOUT = "graph.autoLayout();"; + private static final String JS_CMD_LOAD_FROM_LAYOUT = "graph.loadPositionsFromLayout('%s');"; /** * This is the javascript code to rename a node within the graph. */ @@ -180,12 +187,38 @@ public final class CurrentAnalysisEditorGraphBean { */ public synchronized void initListeners() { RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_CLICK_LISTENER); - RequestContext.getCurrentInstance().execute("graph.addListener('onError', function(e){Log.write(e);});"); + RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_ERROR_LISTENER); + RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_AUTO_LAYOUT_LISTENER); RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_REMOVE_NODE_LISTENER); RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_CREATE_EDGE_LISTENER); RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_REMOVE_EDGE_LISTENER); } + /** + * This method initializes the auto layout of the graph, resulting ing a javascript event, delivering the necessary information about the graph. + */ + public synchronized void startAutoLayout() { + RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_START_AUTO_LAYOUT); + } + + /** + * This method uses the given parameters (via request parameter map) to calculate a new layout for the graph and use this layout. + */ + public synchronized void autoLayout() { + // Get the parameters + final Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); + + final String nodes = paramMap.get("nodes"); + final String edges = paramMap.get("edges"); + + // Calculate the layout + final String newLayout = GraphFlowLayouter.layoutGraph(nodes, edges); + + // Now use it + RequestContext.getCurrentInstance().execute(String.format(CurrentAnalysisEditorGraphBean.JS_CMD_LOAD_FROM_LAYOUT, newLayout)); + RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_REFRESH_GRAPH); + } + /** * Adds the edge constraints to the graph. */ diff --git a/Kieker.WebGUI/src/main/webapp/js/flowEditor.js b/Kieker.WebGUI/src/main/webapp/js/flowEditor.js index 74707d94d45558054cf2f6f6e3005a43e4f298da..e1a3a557533670b8e8912ffd2c1a1799c9e1a308 100644 --- a/Kieker.WebGUI/src/main/webapp/js/flowEditor.js +++ b/Kieker.WebGUI/src/main/webapp/js/flowEditor.js @@ -140,9 +140,7 @@ function GraphFlow(){ This information is needed to correctly draw the Grid and may come in handy in future functions. */ - var navi = { 'width' : document.getElementById(visContainer).clientWidth, - 'height': document.getElementById(visContainer).clientHeight, - 'centerX' : 0, + var navi = { 'centerX' : 0, 'centerY' : 0, 'dragX' : null, 'dragY' : null, @@ -170,6 +168,7 @@ function GraphFlow(){ return positions; } + /** Reads nodefamily positions out of a string, which was created with the saveNodePositions() function and moves all nodes to the respective @@ -210,155 +209,182 @@ function GraphFlow(){ } /** - Returns a XML-String, representing the graph as KGraph - This function is work in progress and will be tuned - for efficiency in the future! + Extracts certain node and edge information and fuses it to a single + String, which will be argument of a listener event and can be used + by an autolayouting algorithm. */ - this.convertToKGraph = function(){ - // define helper strings - var ie = '<children incomingEdges="'; - var pt = '<ports edges="'; - var oe = [ '<outgoingEdges target="//@children.', - '" sourcePort="//@children.', - '/@ports.', - '" targetPort="//@children.', - '">\n<data xsi:type="klayoutdata:KEdgeLayout"/>\n</outgoingEdges>\n' - ]; + this.autoLayout = function(){ // this array will contain XMI-Strings - var children = [], - indexMap = []; // KGraphs use indices instead of IDs + var indexMap = []; // KGraphs use indices instead of IDs + var n, l; - // this loop prepares the children array - var child; - for(var n = 0, l = jsonCapacity.occupied; n < l; n++){ - // reserve space for edges - child = { - incomingEdges : ie, - ports : [], - outgoingEdges : "" - }; - // reserve space for port strings - for(var p = 0, pl = json[n].data.$portCount-1; p < pl; p++){ // TODO: adjust for ReadOnly - child.ports.push({"text":pt, "isEast":false}); - } - children.push(child); - - // add node id to index map + // determine node indices + for(n = 0, l = jsonCapacity.occupied; n < l; n++){ indexMap[json[n].id] = n; } // determine port indices - var node, - indexCounter = 0; - for(var n = jsonCapacity.max, l = json.length; n < l; n++){ + var node, indexCounter = 0; + for(n = jsonCapacity.max, l = json.length; n < l; n++){ node = json[n]; if(node.data.$type == "crossBox"){ indexCounter = 0; } else{ - indexMap[json[n].id] = indexCounter; + indexMap[node.id] = indexCounter; indexCounter++; } } - // now prepare all strings needed - indexCounter = -1; - var edgeCounter = 0, portCounter = 0; - var adja, edge, edgeString, targetChild, targetPort, relativeY; - for(var n = jsonCapacity.max+1, l = json.length; n < l; n++){ - node = json[n]; - if(node.data.$type == "crossBox"){ // TODO: do not rely on crossBox, make more generic - indexCounter++; - edgeCounter = 0; - portCounter = 0; - } - else{ - // is the port the first of its type within the node (e.g. the first inputPort) - relativeY = node.data.$relativeY; - if(relativeY){ - children[indexCounter].ports[portCounter].yPos = relativeY; - } - - // is the port positioned on the east side of the node? - children[indexCounter].ports[portCounter].isEast = node.data.$type == "inputPort"; - - adja = node.adjacencies; - for(var e = 0, el = adja.length; e < el; e++){ - edge = adja[e]; - edgeString = "//@children." - + indexCounter - +"/@outgoingEdges." - + edgeCounter + " "; - targetChild = indexMap[edge.data.$targetFamily]; - targetPort = indexMap[edge.nodeTo]; - - // add edge info to outgoing family - children[indexCounter].outgoingEdges += - oe[0] + targetChild + oe[1] + indexCounter + oe[2] + portCounter - + oe[3] + targetChild + oe[2] + targetPort + oe[4]; - children[indexCounter].ports[portCounter].text += edgeString; - - // add edge info to target family - children[targetChild].ports[targetPort].text += edgeString; - children[targetChild].incomingEdges += edgeString; - - edgeCounter++; - } - - portCounter++; - } - } - // redefine helper strings - ie = '">\n<data xsi:type="klayoutdata:KShapeLayout" xpos="0.0" ypos="0.0" width="'; - pt = '">\n<data xsi:type="klayoutdata:KShapeLayout" xpos="'; - var ie2 = '">\n<persistentEntries key="de.cau.cs.kieler.sizeConstraint" value="FIXED"/>\n' - + '<persistentEntries key="de.cau.cs.kieler.portConstraints" value="FIXED_POS"/>\n<insets/>\n</data>\n', - pt2 = '" width="'+(vertexLabelSize*2)+'" height="'+vertexLabelSize+'">\n</data>\n</ports>\n'; - - // assemble XMI-String - var xmi = '<?xml version="1.0" encoding="UTF-8"?>\n' - + '<kgraph:KNode xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" ' - + 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:kgraph="http://kieler.cs.cau.de/KGraph" ' - + 'xmlns:klayoutdata="http://kieler.cs.cau.de/KLayoutData">\n<data xsi:type="klayoutdata:KShapeLayout" ' - + 'width="348.0" height="112.0">\n<persistentEntries key="de.cau.cs.kieler.sizeConstraint" value="FIXED"/>\n' - + '<insets/>\n</data>\n\n'; - var ports, xPos, yPos, width, height; - for(var c = 0, l = children.length; c < l; c++){ - child = children[c]; - width = json[c].data.$width; - height = json[c].data.$height; - xmi += child.incomingEdges + ie + width + '" height="'+ height + ie2; - - ports = child.ports; - for(var p = 0, pl = ports.length; p < pl; p++){ + // prepare lots of loop variables + var nodes = ""+ vertexLabelSize, + edges = ""; + + var data, p, pl, a, al, height; + var repoCount, inputCount, outputCount; + var repoY = 0, inputY = 0, outputY = 0; + + // now convert the json array to two simple integer arrays + for(n = 0, l = jsonCapacity.occupied; n < l; n++){ + data = json[n].data; + nodes += " " + data.$width; + height = data.$height; + nodes += " " + height; + height /= 2; - // determine the y-Position of the port - relativeY = ports[p].yPos; - if(relativeY){ - yPos = relativeY + height/2; - } - else{ - yPos += 2*vertexLabelSize; + // count ports + inputCount = 0; + repoCount = 0; + outputCount = 0; + for(p = jsonCapacity.max + data.$portIndex+1, pl = p + data.$portCount -1; p < pl; p++){ + data = json[p].data; + switch(data.$type){ + case "repositoryPort" : + repoCount ++; + if(data.$relativeY){ + repoY = data.$relativeY + height; + } + break; + case "inputPort" : + inputCount ++; + if(data.$relativeY){ + inputY = data.$relativeY + height; + } + break; + case "outputPort" : + outputCount ++; + if(data.$relativeY){ + outputY = data.$relativeY + height; + } + break; } - // determine the x-Position of the port - if(ports[p].isEast){ - xPos = -vertexLabelSize; - } - else { - xPos = width - vertexLabelSize; + // check outgoing edges + adja = json[p].adjacencies; + if(adja){ + for( a = 0, al = adja.length; a < al; a++){ + node = adja[a]; + edges += n + " " + + indexMap[node.data.$targetFamily] + " " + + indexMap[node.nodeFrom] + " " + + indexMap[node.nodeTo] + " "; + } } - xmi += ports[p].text + pt + xPos + '" ypos="'+ yPos +pt2; } + nodes += " " +inputCount + " " + + inputY + " " + + repoCount + " " + + repoY + " " + + outputCount + " " + + outputY; + } + + callListener("autoLayout", [nodes, edges]); + } + + /** + Assumes that the graph has not been altered since the last call of autolayout(). + Reads a string containing new x,y positions, which are separated by spaces and + moves nodefamilies to the specified positions. + + @param positions - the position string + + */ + this.loadPositionsFromLayout = function(input){ + // split string by spaces + var bendPoints, positions; + { + var inputSplit = input.split("#"); + positions = inputSplit[0].split(" "); + if(inputSplit[1]){ + bendPoints = inputSplit[1].split(" "); + } + + } + // prepare loop variables + var node, data, adja, x, y, p = 0; + + var xOffset = -grid.data.$width/2, + yOffset = -grid.data.$height/2; + + //// + // Node Positions + + // iterate nodefamiles + for(var n = 0, l = jsonCapacity.occupied; n < l; n++){ + // extract positions from string array + x = parseFloat(positions[p++]) + xOffset; + y = parseFloat(positions[p++]) + yOffset; - xmi += child.outgoingEdges + '</children>\n'; - - delete children[c]; + // find node in graph and move it + // we do it in this complicated way to + // make smooth node positioning possible + node = fd.graph.getNode(json[n].id); + prepareNodeMove(node); + moveNode(x,y); + saveNodeMove(); + data = json[n].data; } - xmi += '</kgraph:KNode>'; - return xmi; + //// + // BendPoints + if(bendPoints){ + + var adja, a, al + e = 0, + bendList = []; + make_bendPoints:{ + // look for ports with edges + for(var po = jsonCapacity.max+1, l = json.length; po < l; po++){ + adja = json[po].adjacencies; + if(adja){ + // iterate through outgoing edges + for(a = 0, al = adja.length; a < al; a++){ + if(e == bendPoints.length){ + break make_bendPoints; + } + + // read from bend point string + while(bendPoints[e] != ";" && bendPoints[e] != ""){ + x = parseFloat(bendPoints[e++]) + xOffset; + y = parseFloat(bendPoints[e++]) + yOffset; + bendList.push({'x':x, 'y':y}); + } + if(bendList.length > 0){ + setBendPoints(adja[a].nodeFrom, adja[a].nodeTo, bendList); + // prepare a new set of bend points + bendList = []; + } + // increment if we have a separating semicolon + e++; + } + } + } + } + } + // may be animated in the future + fd.plot(); } /** @@ -517,8 +543,8 @@ function GraphFlow(){ // scaling values var oldScale = fd.canvas.scaleOffsetX, - scaleX = navi.width / (rightMost - leftMost + 4*vertexLabelSize), - scaleY = navi.height / (bottomMost - topMost +4*vertexLabelSize) + scaleX = grid.data.$width / (rightMost - leftMost + 4*vertexLabelSize), + scaleY = grid.data.$height / (bottomMost - topMost +4*vertexLabelSize) scale = Math.min(scaleX, scaleY) / oldScale; // translation values @@ -552,11 +578,17 @@ function GraphFlow(){ if(!validArg('setNodeIcon()', path, 'string')){ return; } - var icon = Image(); + var icon; + icon = new Image(); icon.src = path; + // this may happen on IE, when linking to images via web + if(!icon.complete){ + callListener("onError", ["Error in function setNodeIcon(): Timeout while loading '"+ path +"'. Please try again!"]); + return; + } // if the image was loaded successfully, its width must be greater 0 - if(icon.width > 0){ + if(icon.width != 0){ // if nodes were already created, we need to // adjust their width and iconPath if(nodeIcons[nodeType] == undefined){ @@ -690,6 +722,13 @@ function GraphFlow(){ for(var l=0; l < lArr.length; l++){ lArr[l](arguments[0], arguments[1], arguments[2]); } + } + + // auto layout listener + else if(arguments.length == 2){ + for(var l=0; l < lArr.length; l++){ + lArr[l](arguments[0], arguments[1]); + } // node listener functions with 1 argument (node) }else if(arguments.length == 1){ @@ -723,7 +762,6 @@ function GraphFlow(){ this.addEdgeConstraints = function(){ addListener("onCreateEdge", function(sourceFamily, targetFamily, sourcePort, targetPort){ - // remove Edge if it does not lead to an inputPort if(targetPort.data.$type != "inputPort"){ return false; @@ -1146,7 +1184,7 @@ function GraphFlow(){ for(var n = familyIndex; n < occ; n++){ json[n] = json[n+1]; data = json[n].data; - data.$jsonIndex-- + data.$jsonIndex--; data.$portIndex-= deletionSum; } @@ -1307,6 +1345,46 @@ function GraphFlow(){ navi.draggedNodes = null; } + /** + + */ + this.addBendPoints = function(sourceID, targetID, bendPoints){ + // check for valid arguments + if(!validArg("addBendPoints()", sourceID, "string")){ + return; + } + if(!validArg("addBendPoints()", targetID, "string")){ + return; + } + + // look up the source node and the nodeFamilys of both nodes + var adja, loopNode; + var sourceFamilyID = sourceID.substring(0, sourceID.indexOf(".")); + + // look for nodefamilies + for(var n = 0, l = jsonCapacity.occupied; n < l; n++){ + + loopNode = json[n]; + if(loopNode.id == sourceFamilyID){ + adja = loopNode.adjacencies; + } + } + + // nothing to delete? + if(source == undefined){ + return; + } + var adja = source.adjacencies; + + for(var a=0; a< adja.length; a++){ + if(adja[a].nodeTo == targetID){ + delete adja[a]; + adja.splice(a,1); + break; + } + } + + } /** * Adds a directed edge between two nodes to the graph. @@ -1360,8 +1438,20 @@ function GraphFlow(){ target = loopNode; } } + // call listener if the edge is not connected to the dummy node and check for permission if(!forced && sourceID != mouseNode.id && targetID != mouseNode.id){ + + // check if ports and families were found + if(!(sourceFamily && source)){ + callListener("onError", ["Error in function addEdge(): The source port '" + sourceID + "' does not exist."]); + return false; + } + if(!(targetFamily && target)){ + callListener("onError", ["Error in function addEdge(): The target port '" + targetID + "' does not exist."]); + return false; + } + if (!callListener("onCreateEdge", [sourceFamily, targetFamily, source, target])){ return false; } @@ -1369,13 +1459,13 @@ function GraphFlow(){ // if edge is connected to mouse, there is no targetFamily... var targetFamilyID = null; - if(targetFamily != undefined){ + if(targetFamily){ targetFamilyID = targetFamily.id; } var adja = source.adjacencies; // source node does not exist? - if(adja == undefined){ + if(!adja){ return false; } @@ -1384,7 +1474,7 @@ function GraphFlow(){ "nodeFrom": sourceID, "data": {"$direction" : [ sourceID, targetID ], "$targetFamily" : targetFamilyID, - "$color" : edgeColor}, + "$color" : edgeColor} }; if(edgeLabel){ @@ -1400,9 +1490,38 @@ function GraphFlow(){ return true; } + + /** + Sets or removes BendPoints of an Edge. + @param sourceID - the ID of the connected outputPort + @param targetID - the ID of the connected inputPort + @param bendPoints - an array of {"x":..., "y":...} objects + */ + this.setBendPoints = function(sourceID, targetID, bendPoints){ + // check for valid arguments + if(!validArg("addEdge()", sourceID, "string")){ + return false; + } + if(!validArg("addEdge()", targetID, "string")){ + return false; + } + + var adja = getNode(sourceID).adjacencies; + // look for the specific edge + for(var a = 0, l = adja.length; a < l; a++){ + if(adja[a].nodeTo == targetID){ + adja[a].data.$bendPoints = bendPoints; + + // update displayed graph (no need for refresh then) + fd.graph.getAdjacence(sourceID, targetID).data.$bendPoints = bendPoints; + break; + } + } + } + /** Removes the edge between two nodes. - @param sourceID - the if of the source Node + @param sourceID - the id of the source Node @param targetID - the id of the target Node @param forced - if true, removes the edge unconditionally and does not trigger a listener event @@ -1631,7 +1750,7 @@ function GraphFlow(){ "$type": "none", "&xPos": 0, "&typeSelected" : null, - "&yPos": 0, + "&yPos": 0 }, "id": "#DUMMY_MOUSE_NODE", "name": "", @@ -1938,8 +2057,7 @@ function GraphFlow(){ //Number of iterations for the FD algorithm iterations: 0, //Edge length - levelDistance: 0, - + levelDistance: 0 }); diff --git a/Kieker.WebGUI/src/main/webapp/js/jit.js b/Kieker.WebGUI/src/main/webapp/js/jit.js index 5ae2778749232f17a3a975324ac36e78a6db7374..bffdc8ba3ee35cf9f873affaace68b2531bd0553 100644 --- a/Kieker.WebGUI/src/main/webapp/js/jit.js +++ b/Kieker.WebGUI/src/main/webapp/js/jit.js @@ -6234,31 +6234,32 @@ var NodeHelper = { (end code) */ 'render': function(type, pos, width, height, roundness, canvas){ - width/=2; - height/=2; - var ctx = canvas.getCtx(), - rWidth = width - roundness, - rHeight = height - roundness; + var hWidth = width/2; + hHeight= height/2; + ctx = canvas.getCtx(), + rWidth = hWidth - roundness, + rHeight = hHeight - roundness; x = pos.x - rWidth, y = pos.y - rHeight; ctx.save(); - var pif = Math.PI/2; + var pif = Math.PI/2, + pit = 3 * pif; ctx.beginPath(); // upper left - ctx.arc(x , y , roundness, Math.PI, 3*pif, false); + ctx.arc(x , y , roundness, Math.PI, pit, false); x = pos.x + rWidth, - ctx.lineTo(x, pos.y - height); + ctx.lineTo(x, pos.y - hHeight); // upper right - ctx.arc(x , y , roundness, 3*pif, 0, false); + ctx.arc(x , y , roundness, pit, 0, false); y = pos.y + rHeight, - ctx.lineTo(pos.x + width, y); - + ctx.lineTo(pos.x + hWidth, y); + // lower right ctx.arc(x , y , roundness,0, pif, false); x = pos.x - rWidth, - ctx.lineTo(x, pos.y + height); + ctx.lineTo(x, pos.y + hHeight); // lower left ctx.arc(x , y , roundness, pif, Math.PI, false); @@ -6267,8 +6268,6 @@ var NodeHelper = { ctx[type](); ctx.restore(); - width*=2; - height*=2; }, /* Method: contains @@ -17863,18 +17862,20 @@ $jit.FlowGraph.$extend = true; posY = pos.y; var ctx = canvas.getCtx(); + // draw Stroke ( in the color, specified in node properties) + this.nodeHelper.roundRect.render('fill', {x: posX, y: posY}, width+4, height+4, rounded, canvas); + // fill box ctx.fillStyle = fillColor; - this.nodeHelper.roundRect.render('fill', {x: posX, y: posY}, width, height, rounded, canvas); - //this.nodeHelper.rectangle.render('fill', {x: posX, y: posY}, width, height, canvas); + this.nodeHelper.roundRect.render('fill', {x: posX, y: posY}, width, height, rounded, canvas); + //this.nodeHelper.roundRect.render('fill', {x: posX, y: posY+rounded*2}, width, height-4*rounded, rounded, canvas); - // draw Stroke ( in the color, specified in node properties) - this.nodeHelper.roundRect.render('stroke', {x: posX, y: posY}, width, height, rounded, canvas); - //this.nodeHelper.rectangle.render('stroke', {x: posX, y: posY}, width, height, canvas); var tX = posX; var img = node.data.$icon; - if(img){ + var imgLoaded = (img && img.width != undefined); // we need this for the crazy Internet Explorer + + if(imgLoaded){ tX += dim; } @@ -17912,12 +17913,10 @@ $jit.FlowGraph.$extend = true; } // draw icon - - if(img){ + if(imgLoaded){ var ix = posX - textWidth - dim*1.3, iy = posY - dim ; - ctx.drawImage(img, ix, iy, dim*2, dim*2); } diff --git a/Kieker.WebGUI/src/main/webapp/pages/AnalysisEditorPage.xhtml b/Kieker.WebGUI/src/main/webapp/pages/AnalysisEditorPage.xhtml index b9ad20d1d7c842a3a67fc56d8eac8341b79082b5..b7425888d8ecf41bd7a500631703bda11e00d2ef 100644 --- a/Kieker.WebGUI/src/main/webapp/pages/AnalysisEditorPage.xhtml +++ b/Kieker.WebGUI/src/main/webapp/pages/AnalysisEditorPage.xhtml @@ -56,6 +56,10 @@ edgeRemoveListener = function(sourceNode, targetNode, sourcePort, targetPort) { edgeRemoveCommand([{name : 'sourcePortID', value : sourcePort.id},{name : 'targetPortID', value : targetPort.id}]); } + + autoLayoutListener = function(nodes, edges) { + autoLayoutCommand([{name : 'nodes', value : nodes}, {name : 'edges', value : edges}]); + } </script> </ui:define> @@ -68,6 +72,7 @@ <p:remoteCommand name="nodeRemoveCommand" action="#{currentAnalysisEditorGraphBean.nodeRemoved()}" update=":propertiesForm"/> <p:remoteCommand name="edgeCreateCommand" action="#{currentAnalysisEditorGraphBean.edgeCreated()}"/> <p:remoteCommand name="edgeRemoveCommand" action="#{currentAnalysisEditorGraphBean.edgeRemoved()}"/> + <p:remoteCommand name="autoLayoutCommand" action="#{currentAnalysisEditorGraphBean.autoLayout()}"/> </h:form> </ui:define> @@ -102,7 +107,7 @@ <p:menuitem id="btnScaleToFit" styleClass="element-with-whitespace" icon="ui-icon-scaleToFit" ajax="true" action="#{currentAnalysisEditorGraphBean.scaleToFit()}"/> <p:menuitem id="btnGrid" styleClass="element-with-whitespace" icon="#{currentAnalysisEditorGraphBean.gridEnabled ? 'ui-icon-gridEnabled' : 'ui-icon-gridDisabled'}" ajax="true" action="#{currentAnalysisEditorGraphBean.switchGrid()}" update=":menuForm"/> <p:menuitem id="btnSnap" styleClass="element-with-whitespace" icon="#{currentAnalysisEditorGraphBean.snapEnabled ? 'ui-icon-snapEnabled' : 'ui-icon-snapDisabled'}" ajax="true" action="#{currentAnalysisEditorGraphBean.switchSnap()}" update=":menuForm"/> - <p:menuitem id="btnAutoLayout" styleClass="element-with-whitespace" icon="ui-icon-autoLayout" ajax="true" /> + <p:menuitem id="btnAutoLayout" styleClass="element-with-whitespace" icon="ui-icon-autoLayout" ajax="true" action="#{currentAnalysisEditorGraphBean.startAutoLayout()}" /> </p:menubar> <p:tooltip for="btnScaleToFit" value="#{localizedAnalysisEditorPageMessages.analysisEditorScaleToFit}"/> <p:tooltip for="btnGrid" value="#{localizedAnalysisEditorPageMessages.grid}"/>