Cytoscape.js move nodes to allow for pasted nodes










0















I have to provide a copy/paste functionality using the dagre layout. The idea is the user copies a node and where ever they decide to "paste" it, the hierarchy of nodes copied, will be created there. This would mean that all nodes in the way would have to move.
I first thought maybe I could call layout again but that doesn't "fit" them in.



I'm still learning cytoscape.js so if this is a simple question, please excuse me.










share|improve this question


























    0















    I have to provide a copy/paste functionality using the dagre layout. The idea is the user copies a node and where ever they decide to "paste" it, the hierarchy of nodes copied, will be created there. This would mean that all nodes in the way would have to move.
    I first thought maybe I could call layout again but that doesn't "fit" them in.



    I'm still learning cytoscape.js so if this is a simple question, please excuse me.










    share|improve this question
























      0












      0








      0








      I have to provide a copy/paste functionality using the dagre layout. The idea is the user copies a node and where ever they decide to "paste" it, the hierarchy of nodes copied, will be created there. This would mean that all nodes in the way would have to move.
      I first thought maybe I could call layout again but that doesn't "fit" them in.



      I'm still learning cytoscape.js so if this is a simple question, please excuse me.










      share|improve this question














      I have to provide a copy/paste functionality using the dagre layout. The idea is the user copies a node and where ever they decide to "paste" it, the hierarchy of nodes copied, will be created there. This would mean that all nodes in the way would have to move.
      I first thought maybe I could call layout again but that doesn't "fit" them in.



      I'm still learning cytoscape.js so if this is a simple question, please excuse me.







      cytoscape.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 14:20









      jbassking10jbassking10

      195620




      195620






















          1 Answer
          1






          active

          oldest

          votes


















          0














          This would be something quite hard to achieve, so hear me out:



          First step:



          • Cytoscape has a extension called context-menus (demo)

          • Another extension is called clipboard (demo)

          • make yourself familiar with these two

          Second step:



          • create your graph with these two extensions and a dagre graph

          • when you copy these nodes, make the copy function behave like this:

            • add the nodes with their edges in the right hierarchy


          • when you right click on a node, add a insert into hierarchy function, which adds the copied nodes into the graph

          Code examples:



          var options1 = 
          // List of initial menu items
          menuItems: [

          id: 'addToHierarchy',
          content: 'Add to hierarchy',
          tooltipText: 'Add nodes to hierarchy here',
          selector: 'node',
          onClickFunction: function ()
          // your handlerFunction
          ,
          disabled: false

          ]
          ;
          var instance = cy.contextMenus( options1 );

          var options2 =
          clipboardSize: 0,
          // The following 4 options allow the user to provide custom behavior to
          // the extension. They can be used to maintain consistency of some data
          // when elements are duplicated.
          // These 4 options are set to null by default. The function prototypes
          // are provided below for explanation purpose only.

          // Function executed on the collection of elements being copied, before
          // they are serialized in the clipboard
          beforeCopy: function(eles) ,
          // Function executed on the clipboard just after the elements are copied.
          // clipboard is of the form: nodes: json, edges: json
          afterCopy: function(clipboard) ,
          // Function executed on the clipboard right before elements are pasted,
          // when they are still in the clipboard.
          beforePaste: function(clipboard) ,
          // Function executed on the collection of pasted elements, after they
          // are pasted.
          afterPaste: function(eles)
          ;

          var clipboard = cy.clipboard(options2);





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302377%2fcytoscape-js-move-nodes-to-allow-for-pasted-nodes%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            This would be something quite hard to achieve, so hear me out:



            First step:



            • Cytoscape has a extension called context-menus (demo)

            • Another extension is called clipboard (demo)

            • make yourself familiar with these two

            Second step:



            • create your graph with these two extensions and a dagre graph

            • when you copy these nodes, make the copy function behave like this:

              • add the nodes with their edges in the right hierarchy


            • when you right click on a node, add a insert into hierarchy function, which adds the copied nodes into the graph

            Code examples:



            var options1 = 
            // List of initial menu items
            menuItems: [

            id: 'addToHierarchy',
            content: 'Add to hierarchy',
            tooltipText: 'Add nodes to hierarchy here',
            selector: 'node',
            onClickFunction: function ()
            // your handlerFunction
            ,
            disabled: false

            ]
            ;
            var instance = cy.contextMenus( options1 );

            var options2 =
            clipboardSize: 0,
            // The following 4 options allow the user to provide custom behavior to
            // the extension. They can be used to maintain consistency of some data
            // when elements are duplicated.
            // These 4 options are set to null by default. The function prototypes
            // are provided below for explanation purpose only.

            // Function executed on the collection of elements being copied, before
            // they are serialized in the clipboard
            beforeCopy: function(eles) ,
            // Function executed on the clipboard just after the elements are copied.
            // clipboard is of the form: nodes: json, edges: json
            afterCopy: function(clipboard) ,
            // Function executed on the clipboard right before elements are pasted,
            // when they are still in the clipboard.
            beforePaste: function(clipboard) ,
            // Function executed on the collection of pasted elements, after they
            // are pasted.
            afterPaste: function(eles)
            ;

            var clipboard = cy.clipboard(options2);





            share|improve this answer



























              0














              This would be something quite hard to achieve, so hear me out:



              First step:



              • Cytoscape has a extension called context-menus (demo)

              • Another extension is called clipboard (demo)

              • make yourself familiar with these two

              Second step:



              • create your graph with these two extensions and a dagre graph

              • when you copy these nodes, make the copy function behave like this:

                • add the nodes with their edges in the right hierarchy


              • when you right click on a node, add a insert into hierarchy function, which adds the copied nodes into the graph

              Code examples:



              var options1 = 
              // List of initial menu items
              menuItems: [

              id: 'addToHierarchy',
              content: 'Add to hierarchy',
              tooltipText: 'Add nodes to hierarchy here',
              selector: 'node',
              onClickFunction: function ()
              // your handlerFunction
              ,
              disabled: false

              ]
              ;
              var instance = cy.contextMenus( options1 );

              var options2 =
              clipboardSize: 0,
              // The following 4 options allow the user to provide custom behavior to
              // the extension. They can be used to maintain consistency of some data
              // when elements are duplicated.
              // These 4 options are set to null by default. The function prototypes
              // are provided below for explanation purpose only.

              // Function executed on the collection of elements being copied, before
              // they are serialized in the clipboard
              beforeCopy: function(eles) ,
              // Function executed on the clipboard just after the elements are copied.
              // clipboard is of the form: nodes: json, edges: json
              afterCopy: function(clipboard) ,
              // Function executed on the clipboard right before elements are pasted,
              // when they are still in the clipboard.
              beforePaste: function(clipboard) ,
              // Function executed on the collection of pasted elements, after they
              // are pasted.
              afterPaste: function(eles)
              ;

              var clipboard = cy.clipboard(options2);





              share|improve this answer

























                0












                0








                0







                This would be something quite hard to achieve, so hear me out:



                First step:



                • Cytoscape has a extension called context-menus (demo)

                • Another extension is called clipboard (demo)

                • make yourself familiar with these two

                Second step:



                • create your graph with these two extensions and a dagre graph

                • when you copy these nodes, make the copy function behave like this:

                  • add the nodes with their edges in the right hierarchy


                • when you right click on a node, add a insert into hierarchy function, which adds the copied nodes into the graph

                Code examples:



                var options1 = 
                // List of initial menu items
                menuItems: [

                id: 'addToHierarchy',
                content: 'Add to hierarchy',
                tooltipText: 'Add nodes to hierarchy here',
                selector: 'node',
                onClickFunction: function ()
                // your handlerFunction
                ,
                disabled: false

                ]
                ;
                var instance = cy.contextMenus( options1 );

                var options2 =
                clipboardSize: 0,
                // The following 4 options allow the user to provide custom behavior to
                // the extension. They can be used to maintain consistency of some data
                // when elements are duplicated.
                // These 4 options are set to null by default. The function prototypes
                // are provided below for explanation purpose only.

                // Function executed on the collection of elements being copied, before
                // they are serialized in the clipboard
                beforeCopy: function(eles) ,
                // Function executed on the clipboard just after the elements are copied.
                // clipboard is of the form: nodes: json, edges: json
                afterCopy: function(clipboard) ,
                // Function executed on the clipboard right before elements are pasted,
                // when they are still in the clipboard.
                beforePaste: function(clipboard) ,
                // Function executed on the collection of pasted elements, after they
                // are pasted.
                afterPaste: function(eles)
                ;

                var clipboard = cy.clipboard(options2);





                share|improve this answer













                This would be something quite hard to achieve, so hear me out:



                First step:



                • Cytoscape has a extension called context-menus (demo)

                • Another extension is called clipboard (demo)

                • make yourself familiar with these two

                Second step:



                • create your graph with these two extensions and a dagre graph

                • when you copy these nodes, make the copy function behave like this:

                  • add the nodes with their edges in the right hierarchy


                • when you right click on a node, add a insert into hierarchy function, which adds the copied nodes into the graph

                Code examples:



                var options1 = 
                // List of initial menu items
                menuItems: [

                id: 'addToHierarchy',
                content: 'Add to hierarchy',
                tooltipText: 'Add nodes to hierarchy here',
                selector: 'node',
                onClickFunction: function ()
                // your handlerFunction
                ,
                disabled: false

                ]
                ;
                var instance = cy.contextMenus( options1 );

                var options2 =
                clipboardSize: 0,
                // The following 4 options allow the user to provide custom behavior to
                // the extension. They can be used to maintain consistency of some data
                // when elements are duplicated.
                // These 4 options are set to null by default. The function prototypes
                // are provided below for explanation purpose only.

                // Function executed on the collection of elements being copied, before
                // they are serialized in the clipboard
                beforeCopy: function(eles) ,
                // Function executed on the clipboard just after the elements are copied.
                // clipboard is of the form: nodes: json, edges: json
                afterCopy: function(clipboard) ,
                // Function executed on the clipboard right before elements are pasted,
                // when they are still in the clipboard.
                beforePaste: function(clipboard) ,
                // Function executed on the collection of pasted elements, after they
                // are pasted.
                afterPaste: function(eles)
                ;

                var clipboard = cy.clipboard(options2);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 7:33









                Stephan T.Stephan T.

                1,2361821




                1,2361821





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302377%2fcytoscape-js-move-nodes-to-allow-for-pasted-nodes%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kleinkühnau

                    Makov (Slowakei)

                    Deutsches Schauspielhaus