Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make classes work in Cytoscape.js

Tags:

cytoscape.js

I am trying to add a class to the node, to have all my css in a stylesheet file, not inside javascrpt declaration.

  var values = {
    nodes: [
      { data: { id: 'explore'}, 
        classes: 'ClassName1'
      },
      { data: { id: 'discover' } }
    ],
    edges: [
      { data: { source: 'explore', target: 'discover' } }
    ]
};

As you can see I am adding classes and the class name, but nothing happens.

like image 299
maxim fedotov Avatar asked Dec 03 '14 20:12

maxim fedotov


1 Answers

You should use selectors, Here is the solution:

        var cy = cytoscape({
            container: this.div[0],
            style: cytoscape.stylesheet()
            .selector(".ClassName1")
                .css({
                    'background-color': 'red',
                })        ,
            elements: values ,
            layout: 'MyLayout'
        });
        cy.layout();
like image 192
DaNeSh Avatar answered Nov 16 '22 09:11

DaNeSh