[SOLVED] Adding extra variables to NodeData, can it be done?

Visual manipulations and refinements
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
Mountaineer
Posts:5
Joined:08 Jul 2010 21:08
[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] Adding extra variables to NodeData, can it be done?

Post by Mountaineer » 07 Nov 2010 05:21

Hello!

I am trying to add a extra variable to the NodeData class, along with appropriate get/set functions. However Gephi crashes the moment such a function is called. Netbeans does not indicate any errors with recognizing the method, and the following code snippet inside DHNSEventBridge compiles fine.

Code: Select all

    public void simulate() // called when selected from the right click menu
    {
        this.graph = graphController.getModel().getHierarchicalGraphVisible();
        ModelImpl[] selectedNodeModels = engine.getSelectedObjects(AbstractEngine.CLASS_NODE);
        for (ModelImpl metaModelImpl : selectedNodeModels)
        {
            NodeData nodeData = (NodeData) metaModelImpl.getObj();
            nodeData.setColor(0, 1, 0);
            nodeData.setDiseased(true);  // Causes Gephi to crash
        }
   }
What would cause Gephi to crash from this? Does it have something to do with the nature of metaModelImpl?

Thank you

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: Adding extra variables to NodeData, can it be done?

Post by mbastian » 07 Nov 2010 10:46

This code can't compile fine in Java, as the 'setDiseased' method is not defined. Check your Netbeans install, as this shouldn't compile.

You can easily add data to nodes by using attributes:

Code: Select all

nodedata.getAttributes.setValue("diseased", true )
Don't forget to first define the new column:

Code: Select all

AttributeModel attModel = Lookup.getDefault().lookup(AttributeController.class).getModel();
attModel.getNodeTable().addColumn("diseased", AttributeType.BOOLEAN);

Mountaineer
Posts:5
Joined:08 Jul 2010 21:08
[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: Adding extra variables to NodeData, can it be done?

Post by Mountaineer » 07 Nov 2010 16:26

Thank you so much! You devs are great!

Now where would be the best place to put these addColumns in? If they get called more than once then Gephi throws an error.

Code: Select all

AttributeModel attModel = Lookup.getDefault().lookup(AttributeController.class).getModel();
attModel.getNodeTable().addColumn("diseased", AttributeType.BOOLEAN);
My last question is this, say I created my own attribute, like what's happening here, only with doubles. Would it appear on the "Choose a rank parameter" dropdown menu? Or are the list of available rankings set in stone during import?

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: Adding extra variables to NodeData, can it be done?

Post by mbastian » 08 Nov 2010 16:20

Now where would be the best place to put these addColumns in
You have to call this once only, you can also use hasColumn() method and for instanc eonly add the column if it doesn't exist already.
My last question is this, say I created my own attribute, like what's happening here, only with doubles. Would it appear on the "Choose a rank parameter" dropdown menu? Or are the list of available rankings set in stone during import?
All numerical attributes (float, double, integer, ...) are automatically available through ranking, you don't have to do anything. Once added as a column, Ranking can use it.

galwarion
Posts:15
Joined:19 Mar 2011 16:16
[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: Adding extra variables to NodeData, can it be done?

Post by galwarion » 22 Mar 2011 20:39

Is it possible to do ranking dynammicaly? I have already tried it... But for me its working only when I run ranking I some time pieces edged in the time line... But maybe I'm doing something bad?

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: Adding extra variables to NodeData, can it be done?

Post by mbastian » 23 Mar 2011 16:18

Ranking doesn't refresh dynamically yet when you manipulate the timelime. However, it will use the proper time range to extract current values in the range when you click on 'Apply'

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