首页 > 解决方案 > 如何将预先存在的 css 类附加到 Cytoscape JS for Angular 中的节点标签

问题描述

尽管节点的 CSS 不符合要求,但我在整个项目中都有一个统一的 CSS 主题。我需要根据日间模式和夜间模式更改 css 标签颜色,我是如何实现的?

this.cy = cytoscape({
    container: document.getElementById(this.pageId),
    boxSelectionEnabled: false,
    autounselectify: true,
    zoomingEnabled: true,
    panningEnabled: true,
    autoungrabify: false,
    elements: this.nodes,    
    style: [{
      selector: 'node',
      style: {
        'width':'data(cpu)',
        'height': 'data(cpu)',
        //'shape': 'circle',
        'background-image': 'data(HealthImage)',
        'background-fit': 'contain contain',
        'background-color': '#f5f7fa',
        'label': 'data(' + this.nodeName + ')',
        'cssClass': 'form-group', //tried this didn't work
        "text-valign": "bottom",
        "text-halign": "center",
        "font-size": "12px",
        "text-margin-y": "8px"
      }
    }]
});

标签: cssangulartypescriptclasscytoscape.js

解决方案


您可以使用 javascript 代码设置 cytoscape js 样式。也许您可以设置一个计时器来更改样式或始终检查时间并根据时间设置样式。

http://js.cytoscape.org/#cy.style


推荐阅读