Editing the graph on the fly

Extensions and customization
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
dcombe
Posts:4
Joined:10 Dec 2010 17:51
Contact:
Editing the graph on the fly

Post by dcombe » 20 Dec 2010 16:20

Hello.
I want to create a plugin which is able to modify the graph while it is executed.
I started using the statistics plugin template. Here is what it looks like :

Code: Select all

public void execute(GraphModel graphModel, AttributeModel attributeModel) {
        Graph graph = graphModel.getGraphVisible();
        graph.readLock();
        
        try {
            Progress.start(progressTicket, graph.getNodeCount());

            // For edges that will be removed
           Vector<Edge> edges=new Vector<Edge>();
            int i=0;
            
            for (Node m : graph.getNodes()) {
                    int m_inf_n=1;
                    for (Node n : graph.getNodes()) {
                        if(m_inf_n==1){// in order to test only one time each couple of nodes
                            if(!m.equals(n))
                                m_inf_n=0;
                            continue;
                        }
                        if(TEST){
                                Edge e=graphModel.factory().new Edge(m, n);
                                edges.add(e);
                        }
                    }
                Progress.progress(progressTicket);
                if (cancel) {
                    break;
                }
            }
            graph.readUnlockAll();
            graph.writeLock();

            //Writing the new edges
            for( Edge e : edges){
                    graph.addEdge(e);
            }
            
            graph.readUnlockAll();
        } catch (Exception e) {
            // print stack trace as report
            StringWriter sw=new StringWriter();
            PrintWriter pw=new PrintWriter(sw, true);
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
            res+= sw.toString();
        } finally {
            //Unlock graph
            graph.readUnlockAll();
        }
    }
The application appear unstable after the execution of the function.
Am I editing the graph in a good manner ? Should I use an EdgeDraft instead ? Do I need to refresh some display ?

David

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Editing the graph on the fly

Post by mbastian » 21 Dec 2010 08:24

Hi David, it seems you are not closing the write lock you opened. That is critical and will eventually crash the application.

Code: Select all

            graph.writeLock();

            //Writing the new edges
            for( Edge e : edges){
                    graph.addEdge(e);
            }
           
            graph.writeUnlock();

wicky10
Posts:1
Joined:26 Nov 2014 07:14
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Editing the graph on the fly

Post by wicky10 » 26 Nov 2014 07:19

Should I use an EdgeDraft instead ? http://pass4-sure.ws/Do I need to refresh some display ?

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable