CytoscapeJS背景色灰色

时间:2019-12-19 09:20:49

标签: jquery cytoscape.js cytoscape

我有一个Cytoscape JS网站的小例子,它的背景色经过了调整。但是,要使背景可见,必须首先单击其中一个节点。这是为什么 ?如何立即查看背景颜色?

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://pagecdn.io/lib/cytoscape/3.10.2/cytoscape.min.js"></script>



<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <style media="screen">
      #cy {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="cy"></div>


  </body>
</html>

<script type="text/javascript">
    $(document).ready(function(){
      var cy = cytoscape({
      container: document.getElementById('cy'),
      elements: {
        nodes: [
          { data: { id: 'n1'}, style: {  'pie-size': '80%',
                                'pie-1-background-color': '#E8747C',
                                'pie-1-background-size': '75%',
                                'pie-2-background-color': '#74CBE8',
                                'pie-2-background-size': '25%'}  },
          { data: { id: 'n2'}, style: {'background-color': '#E8747C'}  }
        ],
        edges: [
          { data: { source: 'n1', target: 'n2' } }
        ]
      }
    });
    })
</script>

1 个答案:

答案 0 :(得分:0)

通常,您可以在cytoscape.js样式表(文档中的see this section)中指定以下样式:

$(document).ready(function() {
  var cy = cytoscape({
    container: document.getElementById('cy'),
    style: [{
        selector: '.quarter',
        css: {
          'pie-size': '80%',
          'pie-1-background-color': '#E8747C',
          'pie-1-background-size': '75%',
          'pie-2-background-color': '#74CBE8',
          'pie-2-background-size': '25%'
        }
      },
      {
        selector: '.uniform',
        css: {
          'background-color': '#E8747C'
        }
      }
    ],
    elements: {
      nodes: [{
          data: {
            id: 'n1'
          },
          classes: ['quarter']
        },
        {
          data: {
            id: 'n2'
          },
          classes: ['uniform']
        }
      ],
      edges: [{
        data: {
          source: 'n1',
          target: 'n2'
        }
      }]
    }
  });
})
body {
  font: 14px helvetica neue, helvetica, arial, sans-serif;
}

#cy {
  height: 100%;
  width: 100%;
  left: 0;
  top: 0;
  float: left;
  position: absolute;
}
<html>

<head>
  <meta charset=utf-8 />
  <meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
  <script src="https://unpkg.com/cytoscape@3.3.0/dist/cytoscape.min.js">
  </script>
  <script src="https://unpkg.com/jquery@3.3.1/dist/jquery.js"></script>
</head>

<body>
  <div id="cy"></div>
</body>

</html>