gephi / gephi-plugins

Repository for Gephi Plugins maintained by the team. Each plugin has it's branch.
270 stars 620 forks source link

Create default empty column #196

Closed juliannej closed 6 years ago

juliannej commented 6 years ago

I am working on a plugin for node weight. I want 'weight' to become a default column once my plugin (layout) is selected that can be overwritten if the data already had a column entitled 'weight' or if the user wants to copy over a column they already have to act as node weight.

Do you think it is possible to do this for my plugin? Is this the correct place to ask? Would I be using the ToolKit (e.g. addColumn())?

The example I am following is the multi gravity plugin, but they don't create a column by default - they just read the column if present or use 0 and inform the user that they are missing attribute(s).

eduramiba commented 6 years ago

Sure, you can add the column if missing, but also make sure to validate that the column with that id might already exist and have a different type (non numeric), in which case you have to tell the user it's incorrect.

juliannej commented 6 years ago

The actual addition - would this be using the toolkit addColumn() function?

juliannej commented 6 years ago

I think this would be the case. If I want to allow weight to be a dynamic property OR a static property - what do I put in type when I am adding the column? e.g. addColumn(String id, Class type)

eduramiba commented 6 years ago

Hi, The column cannot be static and dynamic at the same time. If you want static, use any number type such as Double.class.

For dynamic, it depends on the TimeRepresentation (https://gephi.org/gephi/0.9.2/apidocs/org/gephi/graph/api/TimeRepresentation.html) of the graph. For INTERVAL, use IntervalDoubleMap.class, for TIMESTAMP, use TimestampDoubleMap.class.

juliannej commented 6 years ago

Thank you. With addColumn() do I expect that a new column should be visible in Data Observatory? So far I have not been able to do this. Do I need to alter the table after import?

eduramiba commented 6 years ago

It should not be necessary, data laboratory does it like this: https://github.com/gephi/gephi/blob/master/modules/DataLaboratoryAPI/src/main/java/org/gephi/datalab/impl/AttributeColumnsControllerImpl.java#L124

juliannej commented 6 years ago

Sorry - can you clarify:

  1. whether I would be able to call this on an instance of Table?
  2. what package I need to import to access this?

Thank you, Julianne

eduramiba commented 6 years ago

Yes, you should only need to call addColumn on the nodes table. Does it succeed? Then you should be able to see the column in the data laboratory table, it should be that simple.

Other example: https://github.com/gephi/gephi/blob/master/modules/StatisticsPlugin/src/main/java/org/gephi/statistics/plugin/Modularity.java#L641

juliannej commented 6 years ago

Thank you!!