Using mapData() after adding several edges by cy.add() in cytoscape.js
00:25 10 Jun 2018

I am using cytoscape.js for converting a raw txt data to cytoscape.js graph. For that, first I make the graph with : var cy = cytoscape({...}) without any elements. Then after reading nodes and edges from a text file, I add them with this for nodes :

        cy.add({
            data: {id: keys[i]}
        }
    );

and this for edges:

        cy.add({
        data: {
            id: 'edge' + i,
            source: edges[i].source,
            target: edges[i].target,
            label: edges[i].weight
        }

    });

Then I want to apply 'width': 'mapData(weight, 0, 100, 1, 6)'. How can I do that? I tried these:

  1. using mapData() in edge selector when making cy variable. (It doesn't works for added edges and nodes)

  2. using mapData() for each edge after making each of them: cy.$('#edge' + i).style('width','mapData(weight, 0, 100, 1, 6)');

  3. using mapData() after making all nodes and edges : cy.elements('edge').style('line-color','mapData(weight,1,6,blue,green)');

None of them work!

javascript html css cytoscape.js