You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2014/12/15 10:45:00 UTC

[5/6] stratos git commit: cartridges and group position algo binded

cartridges and group position algo binded


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/059da8e0
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/059da8e0
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/059da8e0

Branch: refs/heads/4.1.0-test
Commit: 059da8e00a4af235e32d9a5b21f58d4fbdc34df7
Parents: abd5f0e
Author: Dakshika Jayathilaka <si...@gmail.com>
Authored: Mon Dec 15 14:40:34 2014 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Mon Dec 15 15:17:04 2014 +0530

----------------------------------------------------------------------
 .../theme0/js/custom/applications-editor.js     | 42 ++++++++++++++++++--
 1 file changed, 39 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/059da8e0/components/org.apache.stratos.manager.console/console/themes/theme0/js/custom/applications-editor.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/console/themes/theme0/js/custom/applications-editor.js b/components/org.apache.stratos.manager.console/console/themes/theme0/js/custom/applications-editor.js
index 69d93fa..68697fa 100644
--- a/components/org.apache.stratos.manager.console/console/themes/theme0/js/custom/applications-editor.js
+++ b/components/org.apache.stratos.manager.console/console/themes/theme0/js/custom/applications-editor.js
@@ -35,7 +35,7 @@ var bottomConnectorOptions = {
     isSource:true,
     connectorStyle : { strokeStyle:"#666" },
     isTarget:false,
-    maxConnections:5
+    maxConnections:20
 };
 
 var endpointOptions = {
@@ -636,6 +636,36 @@ function generateGroups(data){
     //append cartridge into html content
     $('#group-list').append(groupListHtml);
 }
+
+//node positioning algo with dagre js
+function dagrePosition(){
+    // construct dagre graph from JsPlumb graph
+    var g = new dagre.graphlib.Graph();
+    g.setGraph({ranksep:'80'});
+    g.setDefaultEdgeLabel(function() { return {}; });
+    var nodes = $(".stepnode");
+
+    for (var i = 0; i < nodes.length; i++) {
+        var n = nodes[i];
+        g.setNode(n.id, {width: 52, height: 52});
+    }
+    var edges = jsPlumb.getAllConnections();
+    for (var i = 0; i < edges.length; i++) {
+        var c = edges[i];
+        g.setEdge(c.source.id,c.target.id );
+    }
+    // calculate the layout (i.e. node positions)
+    dagre.layout(g);
+
+    // Applying the calculated layout
+    g.nodes().forEach(function(v) {
+        console.log(g.nodes(v).x)
+        $("#" + v).css("left", g.node(v).x + "px");
+        $("#" + v).css("top", g.node(v).y + "px");
+    });
+    jsPlumb.repaintEverything();
+}
+
 // Document ready events
 $(document).ready(function(){
 
@@ -756,6 +786,8 @@ $(document).ready(function(){
     //handle double click for cartridge
     $('#cartridge-list').on('dblclick', ".block-cartridge", function(){
         addJsplumbCartridge($(this).attr('id'),cartridgeCounter);
+        //reposition after cartridge add
+        dagrePosition();
         //increase global count for instances
         cartridgeCounter++;
     });
@@ -772,11 +804,15 @@ $(document).ready(function(){
     $('#group-list').on('dblclick', ".block-group", function(){
         var groupJSON = JSON.parse(decodeURIComponent($(this).attr('data-info')));
         addJsplumbGroup(groupJSON,cartridgeCounter);
+        //reposition after group add
+        dagrePosition();
         //increase global count for instances
         cartridgeCounter++;
     });
 
+    //reposition on click event on editor
+    $('.reposition').on('click', function(){
+        dagrePosition();
+    });
 
 });
-
-