l
    const removeLinks = new go.Set(); // links connected to a node data to remove
    const it = diagram.nodes;
    while (it.next()) {
      const n = it.value;
      const d = n.data;
      if (d === null) continue;
      if (!n.actualBounds.intersectsRect(viewb) && !n.isSelected) {
        // even if the node is out of the viewport, keep it if it is selected or
        // if any link connecting with the node is still in the viewport
        if (!n.linksConnected.any((l) => l.actualBounds.intersectsRect