Springy Cytoscape.js Uncaught TypeError: Cannot read property 'mass' of undefined
NickName:tjustbecause Ask DateTime:2015-06-11T11:29:46

Springy Cytoscape.js Uncaught TypeError: Cannot read property 'mass' of undefined

I am attempting to use the Springy layout from cytoscape.js to build a new graph from a json file, and I am getting the error Uncaught TypeError: Cannot read property 'mass' of undefined from springy.js 343.

  1. I have 'mass' and a value for 'mass' defined in my json file which I have verified that it is being accessed correctly via console.log, and
  2. I have looked at the source code and from by beginners' understanding of javascript, it should set a default if undefined.

springy.js line 343

Layout.ForceDirected.prototype.eachNode = function(callback) {
    var t = this;
    this.graph.nodes.forEach(function(n){
        callback.call(t, n, t.point(n));
    });
};

Here is my code ...

<html>
<head>
  <title>Springy.js image node demo</title>
</head>
<body>
<script src="jquery-1.11.3.js"></script>
<script src="springy.js"></script>
<script src="springyui.js"></script>
<script src="bluebird.min.js"></script>
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>-->

<script/>  

  $.ajax({
    url: 'https://rawgit.com/theresajbecker/CompBio/master/SuperSmallNodes.json',
    type: 'GET',
    dataType: 'json'
  }).done(function(graphP) {  

    for (var i = 0; i < graphP.elements.nodes.length; i++) {  
        var node = graphP.elements.nodes[i].data.id;
        var Nmass = graphP.elements.nodes[i].data.mass;
        console.log('mass');
        console.log(graphP.elements.nodes[i].data.mass);


        console.log('node id');
        console.log(graphP.elements.nodes[i].data.id);
        console.log('station_name');
        console.log(graphP.elements.nodes[i].data.station_name);
    }

    for (i = 0; i < graphP.elements.edges.length; i++) {
        var Nnode = graphP.elements.edges[i].data.source;
        console.log('edges source');
        console.log(graphP.elements.edges[i].data.source);
        console.log('edges target');
        console.log(graphP.elements.edges[i].data.target);
        //console.log(node)
        }

    var graph = new Springy.Graph();




    for ( i = 0; i < graphP.elements.nodes.length; i++) 
                                                     {  
        var NGnode = graph.newNode({ label: 'graphP.elements.nodes[i].data.id'});
                                                     }




    for ( i = 0; i < graphP.elements.edges.length; i++) {  
        var edge = graph.newEdge({source: graphP.elements.edges[i].data.target},
                                 {target: graphP.elements.edges[i].data.target});
    }



$(document).ready(function(){
  var springy = window.springy = jQuery('#springydemo').springy({
    graph: graph,
    nodeSelected: function(node){
      console.log('Node selected: ' + JSON.stringify(node.data));
    },
    repulsion: 500
    }); 

});  


});
</script>
    <div>
<canvas id="springydemo" width="800" height="400" style="border: 1px solid black;"></canvas>
</div>


</body>
</html>

So which part am I misunderstanding?

Copyright Notice:Content Author:「tjustbecause」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30771053/springy-cytoscape-js-uncaught-typeerror-cannot-read-property-mass-of-undefine

More about “Springy Cytoscape.js Uncaught TypeError: Cannot read property 'mass' of undefined” related questions

Springy Cytoscape.js Uncaught TypeError: Cannot read property 'mass' of undefined

I am attempting to use the Springy layout from cytoscape.js to build a new graph from a json file, and I am getting the error Uncaught TypeError: Cannot read property 'mass' of undefined from sprin...

Show Detail

Uncaught TypeError: Cannot read property of null

Hello im having trouble of fixing this error Uncaught TypeError: Cannot read property '2' of null. This is what i want to do, if i click to the day without event the #myModal will show but if i cli...

Show Detail

How to use Springy.js in an Angular application?

I want to use Springy.js in an Angular application. I added the library with npm install springy --save and created this simple test: import {Springy} from 'springy'; ... calculate() { const

Show Detail

Uncaught TypeError: Cannot read property of undefined - javascript

I know this question has been asked before, but I've looked through the different versions of this question and am not seeing an answer for my particular issue. My code: var display = { differen...

Show Detail

Uncaught TypeError: Cannot read property 'DDP' of undefined

I installed meteor version 1.0 on EC2 (Amazon Web Service) Centos. Created a simple application as: meteor create myapp. When accessing my app from web browser, I got the following: Uncaught TypeE...

Show Detail

Uncaught TypeError: Cannot read property

I got this error: Uncaught TypeError: Cannot read property 'd' of undefined and it's on the var d section. function sign() { var d = document.first.d.value; var mon = document.first.mon.v...

Show Detail

jQuery Uncaught TypeError: Cannot read property 'msie' of undefined in drupal

I'm facing following error on my Drupal Website: caught TypeError: Cannot read property 'version' of undefined jquery.formalize.js?nkmwqx:13 Uncaught TypeError: Cannot read property 'msie' of unde...

Show Detail

What does the "Uncaught TypeError: Cannot read property" JS error mean?

Can someone explain to me what these errors mean? I need the answers for a school project. Error 1 "Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null" Error 2 "Uncaught Typ...

Show Detail

Uncaught TypeError: Cannot read property foo of undefined

My JavaScript: todo.completed = !todo.completed; ERROR: Uncaught TypeError: Cannot read property 'completed' of undefined at Object.toggleCompleted (script.js:34) at Object.toggleComplet...

Show Detail

dart2js Uncaught TypeError cannot read property

When I compile my dart2js I keep getting an error from the shadow_dom.debug.js Uncaught TypeError: Cannot read property 'st885323213750055768' of undefined Does anyone what this property is?

Show Detail