Skip to content

Neighbors

  • Plugin name: "neighbors"
  • Plugin namespace: "neighbors"

Loading the plugin

import { loadModule } from "@3ddv/dvm";

var input_options = {
    container: "container-id",
    plugins: ["neighbors"]
};

loadModule("map_viewer", input_options)
    .then(function(viewer) {
        start(viewer);
    })
    .catch(function(err) {
        console.error(err);
    });

function start(viewer) {
    // ...
}

Warning

This plugin requires special metadata to compute the neighbors, so it will not work with all maps, only those with that additional information.

If this plugin is loaded, the module will have the following additional features:

Methods

getAdjacentNeighbors()

Static Badge

Asynchronous method that returns a group of quantity adjacent nodes that achieve the following requirements:

  • The introduced node has to be available or selected.
  • There must be enough contiguous nodes that are available or selected.

If also filter_single_nodes flag is set to true, the following conditions need also to be achieved:

  • the returned node set cannot leave a node with state available or selected without at least one adjacent node with state available or selected.

  • In case of achieving the above conditions, an array with the same quantity of nodes requested will be given (including the introduced node).

  • In case of not achieving the above conditions, the returning array will be empty.

The difference with the original getNeighbors method is that this one allows circular rows, and it's not dependant of the row parameter, and that it's asynchronous.

Warning

This method is asynchronous.

Input:

  • node (string | MapViewerNode): base node from which adjacent nodes will be searched.
  • quantity (number): Quantity of nodes to be obtained.
  • options (Object) [optional]: Object with additional options:
    • filter_single_nodes (boolean) [optional]: If true, returned groups will apply the stranded single nodes filtering logic. Default es false.
    • subset ((string | MapViewerNode)[]) [optional]: Optional subset of nodes to do the computations, instead of the full map.

Output:

  • node_array (MapViewerNode[]): MapViewerNode array with the nodes that meet the requirements.

Example:

const nodes = await viewer.neighbors.getAdjacentNeighbors("S_123-A-4", 3, { filter_single_nodes: true });

getNeighbors()

Asynchronous method that returns a group of quantity nearby nodes that achieve the following requirements:

  • The introduced node has to be available or selected.
  • There must be enough nearby nodes that are available or selected.

If also filter_single_nodes flag is set to true, the following conditions need also to be achieved:

  • the returned node set cannot leave a node with state available or selected without at least one adjacent node with state available or selected.

  • In case of achieving the above conditions, an array with the same quantity of nodes requested will be given (including the introduced node).

  • In case of not achieving the above conditions, the returning array will be empty, unless the flag return_always, in which case it will return the maximum group achieved.

The difference with the original getNeighbors method is that this one allows circular rows, it's not dependant of the row parameter, and it allows to give groups with other rows.

Warning

This method is asynchronous.

Input:

  • node (string | MapViewerNode): base node from which adjacent nodes will be searched.
  • quantity (number): Quantity of nodes to be obtained.
  • options (Object) [optional]: Object with additional options:
    • filter_single_nodes (boolean) [optional]: If true, returned groups will apply the stranded single nodes filtering logic. Default es false.
    • subset ((string | MapViewerNode)[]) [optional]: Optional subset of nodes to do the computations, instead of the full map.
    • return_always (boolean) [optional]: Returns the maximum achievable group if not enough nodes are found. Default is false.

Output:

  • node_array (MapViewerNode[]): MapViewerNode array with the nodes that meet the requirements.

Example:

const nodes = await viewer.neighbors.getNeighbors("S_123-A-4", 3, { filter_single_nodes: true });

validateNeighbors()

Static Badge

Asynchronous method that checks if the input can be considered a group of neighbors, meaning that, starting from an arbitrary node in the list and following the neighbors graph, you can reach all the other nodes in the list.

Warning

This method is asynchronous.

Input:

  • nodes ((string | MapViewerNode)[]): List of nodes to check if they are neighbors of each other.

Output:

  • result (boolean): true if the all nodes of the input are considered neighbors of each other, false otherwise.

Example:

const current_selection = viewer.getNodesByState("seat", "selected");
const is_valid = await viewer.neighbors.validateNeighbors(current);