【问题标题】:applying specific css to added edges in cytoscape edgehandles将特定的 css 应用于 cytoscape 边缘句柄中的添加边缘
【发布时间】:2015-01-12 11:51:50
【问题描述】:

我想将特定的 CSS(例如特定的线条颜色)添加到使用 cytoscape.js-edgehandles.js 添加的某些但所有边缘。

我曾经使用 cy.edges(selector) 命令将特定的线条颜色(红色)应用于带有源('I')的边缘。但这仅适用于已经存在的边缘,而不适用于添加的边缘。

$('#cy').cytoscape({

准备好了:函数(){

window.cy = this;

cy.edges("[source='I']").addClass('red');

},

elements: {
                    nodes: [
                        { data: { id: 'I', name: 'Irlande' } },
                        { data: { id: 'H', name: 'Pays-Bas' } },
                        { data: { id: 'F', name: 'France' } },
                        { data: { id: 'L', name: 'Luxembourg' } }
                    ],
                    edges: [

                        { data: { source: 'I', target: 'F' } },

                        { data: { source: 'I', target: 'H' } }
                        { data: { source: 'I', target: 'L' } },
                        { data: { source: 'H', target: 'I' } },
                        { data: { source: 'H', target: 'F' } },
                        { data: { source: 'F', target: 'I' } },
                        { data: { source: 'F', target: 'H' } },
                        { data: { source: 'F', target: 'L' } },
                        { data: { source: 'L', target: 'I' } }

                    ]

                },

});

这让我想到了几个相关的问题:

添加的边缘是否与现有边缘合并? 如果答案是“否”,我怎样才能让它们与边 [] 合并?

cytoscape.js-edgehandles.js 中的相关代码是:

var edge = cy.add($.extend(true, { 组:'边缘', 数据: { 来源:source.id(), 目标:target.id() } }, options().edgeParams(source, target, 0))).addClass(classes);

          added = added.add( edge );

          break;

        default:
          target.removeClass('edgehandles-target');
          break; // don't add anything
        }
      }

谢谢,

悬垂

【问题讨论】:

    标签: cytoscape.js edges


    【解决方案1】:

    您可以在样式表中为此目的使用classes。无论何时创建,它们都将采用样式表中指定的样式——类似于 HTML 中的 CSS 样式表。

    【讨论】:

    • 嗨,Max,感谢您的回答。我将尝试按照您的建议使用课程。但乍一看,它们指的是节点而不是边。我错了吗?正如我在消息中所写,我尝试将样式应用于特定边缘(具有特定来源),但它只更改了现有边缘,并没有添加。
    • 还有我的另一个问题:添加的边缘数据是否存储在某处?在 elements.edges 数组中?我怎样才能访问它,以便在创建类和触发事件时添加它们?
    • 我找到了我的问题的部分答案:来自特定来源的添加边可以使用特定选择器在样式部分中设置样式:{selector: 'edge[source = "I"]', css :{'线条颜色':'红色',}}。这使我得出结论,添加的边缘确实与现有边缘合并。
    猜你喜欢
    • 2018-07-20
    • 2015-06-10
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多