简体   繁体   English

Cytoscape.js - 自定义节点

[英]Cytoscape.js - custom nodes

I understood that it's possible to create custom node styles as SVG images and then set it as the nodes' background image, but for some reason it doesn't work for me. 我知道可以创建自定义节点样式作为SVG图像,然后将其设置为节点的背景图像,但由于某种原因它不适合我。 Here's my code: 这是我的代码:

var cytoscapeStyle = [ // the stylesheet for the graph     
  {
    selector: 'node',
    style: {
      'background-color': 'white',
      'border-width': '6px',
      'label': 'data(id)',
      'background-image': 'node.svg', //doesn't work for some reason. Works when I use a png (e.g. node.png)
      'shape': 'roundrectangle',
      'width': '200px',
      'height': '90px'
    }
  },

  {
    "selector": "node:selected",
    "style": {
      "border-width": "6px",
      "border-color": "#AAD8FF",
      "border-opacity": "0.5",
      "background-color": "#77828C",
      "text-outline-color": "#77828C"
    }
  },

  {
    selector: 'edge',
    style: {
      'width': 3,
      'line-color': '#ccc',
      'target-arrow-color': '#ccc',
      'target-arrow-shape': 'triangle',
      'label': 'data(id)'
    }
  }
];

Thanks in advance :) 提前致谢 :)

put the svg (Data uri) in your data{..} and set background-image to data(svg) 将svg(Data uri)放入数据{..}并将background-image设置为data(svg)

stylestuff stylestuff

{
selector: 'node',
style: {
  'background-image': 'data(svg)'
}

nodestuff nodestuff

cy.add([
  {
    group: "nodes",
    data: { id: "somenode",
            svg: <image> //eg. "data:image/svg+xml;base64,<data>" 
                         //     or http://some.image.xyz

    }])

如果您的SVG未加载,则SVG图像无效或未指定尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM