0

Here's some code which is part of an application which plots a Sigma.js graph. This section deals with hiding nodes depending on their distance from the centre, or other attributes (users toggle these with buttons):

renderer.setSetting("nodeReducer", (node, data) => {
        const res = { ...data };

        // This is for hiding everything except the node being hovered over.
        if (
            _module.state.hoveredNeighbors &&
            !_module.state.hoveredNeighbors.has(node) &&
            _module.state.hoveredNode !== node
        ) {
          if (parseInt(node) !== parseInt(_module.$route.params.id)) {
            res.hidden = true;
          }
        }

        if (_module.state.selectedNode === node) {
          _module.res.highlighted = true;
        }

        // Hide by distance and registry combined
        if (res.length > 0) {
            let regName = res.registry.charAt(0).toUpperCase() + res.registry.slice(1)
            if (!_module.nodeVisibility[res.length][regName]) {
                res.hidden = true;
            }
        }

        // Hide nodes when their status is not selected
        if (!this.active[res.status] && parseInt(_module.$route.params.id) !== parseInt(node)  )
        {
          res.hidden = true;
        }

        // Hide a node if it has no active neighbours
        
        // ?????????


        return res;
      });

The difficulty is that users' selections can sometimes leave visible nodes without any apparent connections to others, because they are hidden. Hiding nodes with no visible neighbours would solve this problem, but I can't work it out.

This documentation suggests that it might be possible to find adjacent nodes and check their attributes:

https://graphology.github.io/iteration.html#neighbors-array

I can indeed do that, but the attributes I get do not include 'hidden'. Any suggestions on how to determine if a node is hidden would be welcome.

knirirr
  • 1,860
  • 4
  • 23
  • 37

0 Answers0