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

"Cannot create graph without links and nodes" #17

Closed
Robrechtc opened this issue Mar 10, 2015 · 1 comment
Closed

"Cannot create graph without links and nodes" #17

Robrechtc opened this issue Mar 10, 2015 · 1 comment

Comments

@Robrechtc
Copy link

Hey again! I've been playing with ngraph a bit and I'm currently trying out the fromJSON package. This is the JSON data I'm retrieving:

{
    "nodes": [
        {
            "id": "BBA1"
       },
        {
            "id": "Bank and stock"
        },
        {
            "id": "Economic history"
        },
        {
            "id": "Principles of law"
        },
        {
            "id": "Statistics I"
        },
        {
            "id": "Managerial economics B"
        },
        { 
            "id": "Mathematics I-B"
        },
        {
            "id": "Accounting B"
        }
   ],
    "links": [
        {
            "toId": "Bank and stock",
           "fromId": "BBA1"
        },
        {
            "toId": "Economic history",
            "fromId": "BBA1"
        },
        {
            "toId": "Principles of law",
            "fromId": "BBA1"
        },
        {
            "toId": "Statistics I",
            "fromId": "BBA1"
        },
        {
            "toId": "Managerial economics B",
            "fromId": "BBA1"
        },
       {
            "toId": "Mathematics I-B",
            "fromId": "BBA1"
        },
        {
            "toId": "Accounting B",
            "fromId": "BBA1"
        }
    ]
}

My test.html file is this:

<script src="/static/jquery-1.11.0.min.js"></script>
<script src="/static/node_modules/ngraph.fabric/node_modules/fabric/dist/fabric.js"></script>
<script src="/static/bundle.js" type="application/x-javascript"></script>
<title>Ngraph testing</title>
<style>
    body { height: 100%; width: 100%; position: absolute; overflow: hidden; margin: 0; padding: 0;}
</style>

</head>
<body onload="ngraph.main()">

</body>
</html>

And this is my index.js:

module.exports.main = function () {
    var jsonString = $.ajax({
            'url': '/coursedata',
            'datatype': 'json',
            'type': 'GET',
            'data': {
                'path': '-BBA1-Semester 2',
            }
        })

    var fromJSON = require('ngraph.fromjson')
    var graph = fromJSON(jsonString)
    var createFabric = require('ngraph.fabric')
    var fabricGraphics = createFabric(graph);

    fabricGraphics.run();

}

As I am passing my nodes and links, I have no clue what's causing this error :p many thanks in advance for reading and replying!

@anvaka
Copy link
Owner

anvaka commented Mar 11, 2015

This doesn't look correct:

   var jsonString = $.ajax({
            'url': '/coursedata',
            'datatype': 'json',
            'type': 'GET',
            'data': {
                'path': '-BBA1-Semester 2',
            }
        });

I think you are using jquery to perform ajax request. If so, refer to the documentation to see how to handle ajax response. Should probably be something like

$.ajax({
     'url': '/coursedata',
     'datatype': 'json',
     'type': 'GET',
     'data': {
         'path': '-BBA1-Semester 2',
     }
}).done(function(jsonString) {
 // ...
});

@anvaka anvaka closed this as completed Mar 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants