[SOLVED] How to specify Z order of edges?

Screenshots, Vectorial Preview and printable exports
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
ayjaygi
Posts:15
Joined:01 Jul 2011 12:13
[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
[SOLVED] How to specify Z order of edges?

Post by ayjaygi » 18 Oct 2011 21:28

I'm currently scaling the thickness of my edges based on their weights and would like the thicker edges to end up on top of the thinner, more plentiful edges.

How can I accomplish this?

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: How to specify Z order of edges?

Post by mbastian » 20 Oct 2011 02:12

That should be quite easy to do. If you look at the Preview SPI you'll see an ItemBuilder interface. That is what is building the Preview objects. It returns a list of items and this list is later used for drawing, in the same order.

By sorting this list by edge weight it will do the job. You can write a plugin that will overwrite (and extend) the default EdgeBuilder class (located in the PreviewPlugin module).

It should look like this:

Code: Select all

@ServiceProvider(service = ItemBuilder.class, supersedes = "org.gephi.preview.plugin.builders.EdgeBuilder")
public class MyEdgeItemBuilder extends EdgeBuilder {

    @Override
    public Item[] getItems(Graph graph, AttributeModel attributeModel) {
        EdgeItem[] items = (EdgeItem[]) super.getItems(graph, attributeModel);
        Arrays.sort(items, new Comparator<EdgeItem>() {

            @Override
            public int compare(EdgeItem o1, EdgeItem o2) {
                Float w1 = o1.getData(EdgeItem.WEIGHT);
                Float w2 = o2.getData(EdgeItem.WEIGHT);
                return w1.compareTo(w2);
            }
        });
        return items;
    }
}


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