[Gephi-plugins] adding attributes for every node?

Mathieu Bastian mathieu.bastian at gmail.com
Wed Sep 28 17:34:23 CEST 2011


Hi Chris,

The documentation of this module could be improved indeed.

To add attributes you first need to add the columns:

AttributeTable nodeTable = am.getNodeTable();
AttributeColumn newColumn = nodeTable.addColumn("column name",
AttributeType.BOOLEAN);

Then you can set the values for each node for this column. You need to do
that directly from the node, not from the AttributesAPI:

GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel gm = gc.getModel();
Graph graph = gm.getGraph();
for(Node n : graph.getNodes()) {
   n.getNodeData().getAttributes(newColumn.getIndex(), true);
}

You can definitely add columns before adding any nodes, it's
actually recommended. Nodes contain the AttributeRow (accessible from
getNodeData().getAttributes()) and are added automatically. You don't need
to manipulate rows at all. Just use the setValue() and getValue().

Checkout also this tutorial:
http://wiki.gephi.org/index.php/Toolkit_-_Manipulate_attributes

Mathieu

On Tue, Sep 27, 2011 at 10:08 PM, Chris Esposito
<chris.esposito at gmail.com>wrote:

> Hi,
>      I'm finding the attributes API a bit hard to figure out how to put
> into use. I'd like to add 2 attributes to every node - a boolean and a list
> of integers. This seems like the right start:
>
>         1) AttributeController ac =
> Lookup.getDefault().lookup(AttributeController.class);
>         2)  AttributeModel am = ac.getModel();
>         3) AttributeTable ant = am.getNodeTable();
>
> Is it the case that for a node, attributes correspond to columns in the
> attributeTable? Is there one row per node?  If so, do I need to manually add
> / delete rows from this table as nodes come and go in the graph?
>
> Given the node attribute table, it seems to me at this point that I need to
> also add 2 columns, using an addColumn call for each. I'd have to make all
> of these calls before adding any nodes to the graph as well, I suppose.
>
> Thanks,
> Chris
>
> **
>
>
>
> _______________________________________________
> gephi-plugins mailing list
> gephi-plugins at lists.gephi.org
> http://gephi.org/mailman/listinfo/gephi-plugins
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gephi.org/pipermail/gephi-plugins/attachments/20110928/595421b1/attachment-0001.html>


More information about the gephi-plugins mailing list