Home Wiki Blog Forum GEXF.net

Gephi forums

Community support

Wait until filter finishes?

Visual manipulations and refinements

Wait until filter finishes?

Postby Apple Cider » 20 Aug 2013 19:52

Hello,

I've got a function which filters the graph and auto-lays it out. The trouble is, the filtering doesn't complete before it starts the layout. This is probably very basic, but what would be a good way to wait for filtering to complete before proceeding with the autolayout? It seems with FilterController's filterVisible(Query) method it spins off a new Thread, but I'm not sure how to deal with it. Here's what I've got going:

Code: Select all
public void filter() {
            Partition<Node> categoryPartition = partitionController.buildPartition(nodeCategory, graph);
           
            String[] categories = new String[]{"SOURCE", "SCORED", "BRIDGE"};
            Query categoryQuery = FilterUtils.createNodeQuery(categoryPartition, categories);
            Query distQuery = FilterUtils.createNeighborhoodQuery(source, 1);
           
            Query query = FilterUtils.unionQueries(new Query[]{categoryQuery, distQuery});
           
            filterController.filterVisible(query);
        }

public void layout() {
            AutoLayout layout = new AutoLayout(1, TimeUnit.SECONDS);
            layout.setGraphModel(graphModel);
           
            ForceAtlasLayout forceDirectedLayout = new ForceAtlasLayout(null);
            AutoLayout.DynamicProperty repulsionProperty =
                AutoLayout.createDynamicProperty("forceAtlas.repulsionStrength.name",
                                                 5000D, 0f);
            layout.addLayout(forceDirectedLayout, 1f,
                             new AutoLayout.DynamicProperty[]{repulsionProperty});
       
            layout.execute();
}


And it's executed as a LongTask in this function:

Code: Select all
public void execute() {
        Progress.setDisplayName(progressTicket, "Analytic running...");
        Progress.start(progressTicket);
       
        Progress.progress(progressTicket, "Loading graph into Gephi...");
        performImport();
       
        Progress.progress(progressTicket, "Filtering graph...");
        filter();
       
        Progress.progress(progressTicket, "Laying out graph...");
        layout();
        //and so forth...
}


I'm not sure if this is more of a Toolkit question, so apologies if it belongs there! Thanks for the help!
Apple Cider
 
Posts: 4
Joined: 17 May 2013 21:54

Re: Wait until filter finishes?

Postby seinecle » 24 Aug 2013 09:43

I'm not a pro Java dev so this answer might be plain wrong, but at least it will take you 2 seconds to test:
=> put a return variable to your filter method:

Code: Select all
public [b]String[/b] filter() {
            Partition<Node> categoryPartition = partitionController.buildPartition(nodeCategory, graph);
           
            String[] categories = new String[]{"SOURCE", "SCORED", "BRIDGE"};
            Query categoryQuery = FilterUtils.createNodeQuery(categoryPartition, categories);
            Query distQuery = FilterUtils.createNeighborhoodQuery(source, 1);
           
            Query query = FilterUtils.unionQueries(new Query[]{categoryQuery, distQuery});
           
            filterController.filterVisible(query);

            [b]return "filtered!";[/b]
       }


Then in your execute method:

Code: Select all
          String result = filter();


This should definitely make the layout() function wait for the filter() function to return a result before getting initiated. Still I am a bit surprised because I thought Java was synchronous all the way - but it would seem that void methods are run asynchronously?
http://www.clementlevallois.net
Gephi tutorials and personalized trainings: http://www.clementlevallois.net/training.html
Join the Gephi Facebook group for help and support: https://www.facebook.com/groups/gephi/
User avatar
seinecle
Gephi Community Support
 
Posts: 527
Joined: 08 Feb 2010 17:55
Location: Lyon, France


Return to Filtering, Ranking & Interacting with the graph

Who is online

Users browsing this forum: No registered users and 0 guests