Increase width of selected edges only (cytoscape.js)

 ̄綄美尐妖づ 提交于 2019-12-07 19:44:13

问题


How can I predefine when I select a few nodes that are connected or simply edges, to make the width of the selected edges be bigger, without affecting the rest of edges of the entire network or the node's width?

I predefined this when the nodes or edges are selected:

$('#cy').cytoscape({
  style: cytoscape.stylesheet()
    .selector(':selected')
      .css({
        'background-color': 'black',
        'line-color': 'red',
        'target-arrow-color': 'black',
        'source-arrow-color': 'black',
        'opacity': 1
      })...

but there is no 'line-width', so if I put 'width': 5 it will appy it to all the edges and nodes.

So how could I modify the edge width just when selected and leaving the same the rest of the graph?

Thanks in advance!


回答1:


Cytoscape.js → Selectors

...A selector functions similar to a CSS selector on DOM elements, but selectors in Cytoscape.js instead work on collections of graph element... The selectors can be combined together to make powerful queries... Selectors can be joined together (effectively creating a logical OR) with commas... node, edge, or * (group selector) Matches elements based on group (node for nodes, edge for edges, * for all)...

In order to apply style only to selected edges use selector for selected edges.

$('#cy').cytoscape({
  style: cytoscape.stylesheet()
    .selector(':selected')
      .css({
        'background-color': 'black',
        'line-color': 'red',
        'target-arrow-color': 'black',
        'source-arrow-color': 'black'
      })
      .selector('edge:selected')  // ← ← ← ← ←
        .css({
          'width': 5
      })...

jsFiddle demo: http://jsfiddle.net/xmojmr/rbuj3o9c/2/



来源:https://stackoverflow.com/questions/27928151/increase-width-of-selected-edges-only-cytoscape-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!