Search code examples
javascriptmeteorcytoscape.jscytoscape-web

cytoscape.js & meteor simple example doesnt work


  1. i added to meteor cytoscape : infinitedg:cytoscape
  2. i have very basic meteor app:

hello.js http://pastebin.com/2frsHc9g hello.html http://pastebin.com/10EYyJ74

but i am not able to make it work

here is error i can see in console of web browser:

on rendered zavolana hello.js:9 ss [object Object] debug.js:41 Exception from Tracker afterFlush function: debug.js:41 TypeError: Cannot read property 'addEventListener' of undefined at CanvasRenderer.registerBinding (infinitedg_cytoscape.js:17127) at CanvasRenderer.load (infinitedg_cytoscape.js:17283) at new CanvasRenderer (infinitedg_cytoscape.js:13419) at $$.fn.core.initRenderer (infinitedg_cytoscape.js:7527) at new $$.Core (infinitedg_cytoscape.js:6592) at Function.$$.init (infinitedg_cytoscape.js:75) at cytoscape (infinitedg_cytoscape.js:58) at HTMLDivElement. (infinitedg_cytoscape.js:2808) at Function.jQuery.extend.each (jquery.js:384) at jQuery.fn.jQuery.each (jquery.js:136)

do you have please some "hello world" of combination of cytoscape and meteor ?


Solution

  • problem was with wrong library installed via meteor

    after i installed correct cytoscape library, it is working

    correct is cytoscape:cytoscape

    here is minimal and working example:

    JS

    sit = "" //hlavni objekt
    
    if (Meteor.isClient) {
    
    
    
    
        Template.graf.rendered = function() {
    
            // Meteor.defer(function() {
            //setTimeout(function(){
    
            console.log("on rendered called");
            //var divcy = $('#cy');
            // console.log("ss " + divcy);
            sit = cytoscape({
                container: document.getElementById('cy'),
    
    
                ready: function() {
                    console.log("network ready");
                    updateNetworkData(sit); // load data when cy is ready
                },
    
                style: cytoscape.stylesheet()
                    .selector('node')
                    .style({
                        'content': function(e) {
                            return e.data("name")
                        },
    
                        'font-size': 12,
                        'text-valign': 'center',
                        'color': 'white',
                        'text-outline-width': 2,
                        'text-outline-color': function(e) {
                            return e.locked() ? "red" : "#888"
                        },
                        'min-zoomed-font-size': 8
                            // 'width': 'mapData(score, 0, 1, 20, 50)',
                            // 'height': 'mapData(score, 0, 1, 20, 50)'
                    })
                    .selector('edge')
                    .style({
                        'content': function(e) {
                            return e.data("name") ? e.data("name") : "";
                        },
                        'target-arrow-shape': 'triangle',
                    })
    
    
            });
    
            //})
        }
    
    
    
    
    }
    
    if (Meteor.isServer) {
        Meteor.startup(function() {
            // code to run on server at startup
        });
    }
    
    
    
    function updateNetworkData(net) {
    
        // init Data
    
        var nodes = [{ // node a
                group: 'nodes',
                data: {
                    id: 'a',
                    name:'a'
                }
            }, { // node b
                group: 'nodes',
                data: {
                    id: 'b',
                  name:'b'
                }
            }
    
        ]
        var edges = [{ // edge ab
                group: 'edges',
                data: {
                    id: 'ab',
                  name:'ab',
                    source: 'a',
                    target: 'b'
                }
            }
    
        ]
    
        net.elements().remove(); // make sure evything is clean
    
        net.add(nodes);
        net.add(edges);
    
        net.reset() // render layout
    }
    

    CSS

    #cy {
      width : 70vw;
      height: 50vw;
      position: absolute;
    }
    

    HTML

    <head>
      <title>hello</title>
    </head>
    
    <body>
      <h1>Welcome to Meteor!b</h1>
      {{>graf}}
    </body>
    
    <template name="graf">
      <div id="cy"></div>
    </template>