如何显示单击的节点Sigma.JS的标签

时间:2019-07-30 13:37:35

标签: javascript sigma.js

在单击此节点后,我想使节点及其邻居的标签可见。 到目前为止,我单击它后实现了“突出显示”节点,所以我处理了该事件。

我找不到有关节点设置的任何文档-全局标签阈值不是我想要的。

function(s) {
        sigma.plugins.relativeSize(s, 2);
        s.graph.nodes().forEach(function(n) {
        n.originalColor = n.color;
        });
        s.graph.edges().forEach(function(e) {
        e.originalColor = e.color;
        });
        s.bind('clickNode', function(e) {
            var nodeId = e.data.node.id,
                toKeep = s.graph.neighbors(nodeId);
            toKeep[nodeId] = e.data.node;

            s.graph.nodes().forEach(function(n) {
              if (toKeep[n.id]) {
                n.color = n.originalColor;
                n.settings('labelThreshold', 80); }
              else {
                n.color = '#eee';
                n.settings('labelThreshold', 1);}
            });

            s.graph.edges().forEach(function(e) {
              if (toKeep[e.source] && toKeep[e.target]) {
                e.color = e.originalColor;
                n.settings('labelThreshold', 80); }
              else {
                e.color = '#eee';
                n.settings('labelThreshold', 1); }
            });

            s.refresh();
        });

        s.bind('clickStage', function(e) {
            s.graph.nodes().forEach(function(n) {
              n.color = n.originalColor;
              n.settings('labelThreshold', 80);
            });

            s.graph.edges().forEach(function(e) {
              e.color = e.originalColor;
            });

            // Same as in the previous event:
            s.refresh(); 
        });

现在,在更改阈值之后,所有标签都显示出来,但是我有成千上万个节点,这非常难以理解。我只想显示这些节点的标签,这些标签仍保留原始颜色。

0 个答案:

没有答案