I am looking to modify the appearance of my graph based on JavaScript variables that are globally set. For example, if my edges contain attributes such as name
and price
, I want to customize the labels of the edges depending on a global variable called label_type
:
let label_type = 'I_want_name_labels'
switch(label_type) {
case 'I_want_name_labels':
cy.style().selector('edge').style({'label': 'data(name)'});
break;
case 'I_want_price_labels':
cy.style().selector('edge').style({'label': 'data(price)'});
break;
}
The code above is not working as expected (no labels displayed), and I'm unsure why. Here is the structure of my edges:
{
"data": {
"id": "node_node2",
"source": "node1",
"target": "node2",
"directed": true,
"name": "Baltazar",
"price": 1095.73
}
}
Note: I attempted to use
cy.filter('edge').style({'label': 'data(name)'})
instead, but it seems that accessing data
this way raises a warning:
The style property `label: data(name)` is invalid
So, how can I implement conditional styling in cytoscape.js? What am I missing here?