Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes in the information pane are not in the correct order #47

Open
moqri opened this issue Aug 11, 2014 · 8 comments
Open

Attributes in the information pane are not in the correct order #47

moqri opened this issue Aug 11, 2014 · 8 comments

Comments

@moqri
Copy link

moqri commented Aug 11, 2014

The attributes in the information pane (appearing after choosing a node) is not in the same order as my data table in Gephi. I was wondering how I can change the order of them in the information pane.

Thanks,
Mahdi

@moqri moqri changed the title Change the order of attributes in the information pane Attributes in the information pane are not in the correct order Aug 11, 2014
@novastra
Copy link

novastra commented Sep 9, 2014

Hello,

I am also interested in this issue. As stated in the JSon doc, the order of attribute is random. My guess is that in the incoming functionnality 'Attributes' it will be possible to order the attributes and select/unselect.

For now maybe we can change the data order in right panel around this line of main.js but I don't know how to do it.

What is the best solution to reorder data.json attributes that are shown in the right panel?

Thanks,

@moqri
Copy link
Author

moqri commented Sep 10, 2014

@Princen, I have posted a solution here: http://blogs.oii.ox.ac.uk/vis/?p=191#comments

"Mahdi on September 8, 2014 at 1:45 am said:
Thanks Scott,
Another way I found around it is to change the attribute orders in nodeActive() in your main.js. The attributes are staked in an array named “e”. For example adding these lines will change the order of attribute 0 and 1:
var b = e[0];
e[0] = e[1];
e[1] = b;
"

@novastra
Copy link

Thank you,
I found a way to do it, in my case I could order my data with this :

e.reverse();
e.push(h);
e.reverse();

I think it is the only thing to do with the JSon attribute issue. Order it whith array modifications.

@computermacgyver
Copy link
Member

Thanks, @Mahdimo for reporting this and providing the temporary work around. I swear reordering attributes in Gephi's data table used to change the way the attributes were given to the plugin when I request them and write the data.json file.

Regardless, a better solution anyway is to allow de/selection and reordering in the plugin dialogue. I will try to incorporate this in a future plugin release.

In the meantime, this work around is fine. Another option is to rewrite the data.json file to order the attributes as desired in that file. This would be done with e.g., a simple python script one time such as

import json
from collections import OrderedDict

#Read the original data file (from a file called orig.json)
with open("orig.json","r") as fhIn:
    data=json.load(fhIn)

#Update the following line with the attributes in your data file and the order you want them in
desired=["Youtube","Album","Duration"]

for node in data["nodes"]:
    attributes=node["attributes"]

    node["attributes"]=OrderedDict()
    for att in desired:
        if att in attributes:
            node["attributes"][att]=attributes[att]

#New file to write out ordered json -- rename this output to data.json and put with in the directory created by the plugin
with open("new.json","w") as fhOut:
    json.dump(data,fhOut)

@a10martin
Copy link

I’ve run into a different variation of this same problem, which I think means that the two solutions noted above won’t work for me.

My nodes have many attributes in Gephi, and when there’s a null value, SigmaJS isn’t actually exporting those attributes for a given node. If the column is blank, the data.json file just doesn’t contain that attribute. This works great because then the info pane only includes the headers & info that are applicable to a given node. But, it means that the data.json file not only has “scrambled” columns, it also doesn’t have the same attributes/columns in each node. So I don’t know how I could re-order the attributes using either of the solutions in this thread.

Any ideas on how I could handle that?

Here’s an example of what my nodes might look like in data.json:

{
    "nodes": [
        {
            "label": “Internal Project #1",
            "x": 1617.029296875,
            "y": -861.1317138671875,
            "id": "59",
            "attributes": {
                "Category of Node": “Internal Project",
                “US State”: “New Hampshire”,
                "Area of Study": “Purple Monkeys",
            },
            "color": "rgb(189,215,255)",
            "size": 30.454545974731445
        },
        {
            "label": “External Partner #2",
            "x": -1929.1329345703125,
            "y": 329.1484069824219,
            "id": "124",
            "attributes": {
                "Category of Node": “External Partner",
                “US State": “Georgia",
                “Funding Level": “Top Tier",
                "Institution Category": "Scientific Facility",
            },
            "color": "rgb(167,167,167)",
            "size": 11.363636016845703
        }
    ]
}

@computermacgyver
Copy link
Member

@a10martin , the python code given in this comment will work even if not all the attributes appear in every node. You will just have to update the desired=["Youtube","Album","Duration"] line to include the names of your attributes. Let me know if you encounter any issues.

@novastra
Copy link

novastra commented Feb 9, 2015

@a10martin If I understand correctly, you want to manage to have common attributes in the same order but in your example "Category of Node" and “US State" are ordered. If you want to reorder them, the python script is the best solution.
I used both solutions : ordering the elements of an array and changing them with the py script.
One more thing if you want the attribute to be exported from Gephi when it is void, you can insert an ASCII 255 space. This allows the attribute to be latter manipulated but I don't know if it is what you want..

@a10martin
Copy link

Thanks, @Princen and @computermacgyver. I do want to be able to re-order the attributes, both the common ones (in all nodes) and the non-common ones (that only appear in some nodes), since they are coming out of Gephi "scrambled." For instance, "Area of Study" is a much more important parameter than "US State," which I would prefer be displayed last in the info pane.

I actually like the fact that the null attributes don't come out of Gephi, as it gives a much cleaner result in the SigmaJS information pane.

I'll give the Python approach a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants