ngx-vis-network-etsisi
Version:
## Description Final Degree project - Implementation of Angular library using Vis Network. The main goal of this project is get easier the use of Vis Network including an abstraction layer to different edition methods in an Angular project.
1,289 lines (1,288 loc) • 133 kB
JavaScript
/**
* @fileoverview added by tsickle
* Generated from: lib/ngx-vis-network-etsisi.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/*
* Copyright 2020 Jonathan Rodríguez Vaca
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { EventEmitter, Injectable } from '@angular/core';
import { Network } from 'vis-network/standalone';
import * as i0 from "@angular/core";
/**
* \@description This service allow CRUD operations for graph networks.
* Also, it exposes all available events from Vis Network
* @export NgxVisNetworkEtsisiService
*/
export class NgxVisNetworkEtsisiService {
constructor() {
/**
* \@description Fired when the user clicks the mouse or taps on a touchscreen device.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.click = new EventEmitter();
/**
* \@description Fired when the user double clicks the mouse or double taps on a touchscreen device.
* Since a double click is in fact 2 clicks, 2 click events are fired, followed by a double click event.
* If you do not want to use the click events if a double click event is fired,
* just check the time between click events before processing them.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.doubleClick = new EventEmitter();
/**
* \@description Fired when the user click on the canvas with the right mouse button.
* The right mouse button does not select by default.
* You can use the method getNodeAt to select the node if you want.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.oncontext = new EventEmitter();
/**
* \@description Fired when the user clicks and holds the mouse or taps and holds on a touchscreen device.
* A click event is also fired in this case.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.hold = new EventEmitter();
/**
* \@description Fired after drawing on the canvas has been completed.
* Can be used to draw on top of the network.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.release = new EventEmitter();
/**
* \@description Fired when the selection has changed by user action.
* This means a node or edge has been selected, added to the selection or deselected.
* All select events are only triggered on click and hold.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.select = new EventEmitter();
/**
* \@description Fired when a node has been selected by the user.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.selectNode = new EventEmitter();
/**
* Fired when an edge has been selected by the user.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.selectEdge = new EventEmitter();
/**
* \@description Fired when a node (or nodes) has (or have) been deselected by the user.
* The previous selection is the list of nodes and edges that were selected before the last user event.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.deselectNode = new EventEmitter();
/**
* \@description Fired when an edge (or edges) has (or have) been deselected by the user.
* The previous selection is the list of nodes and edges that were selected before the last user event.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.deselectEdge = new EventEmitter();
/**
* \@description Fired when starting a drag.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.dragStart = new EventEmitter();
/**
* \@description Fired when dragging node(s) or the view.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.dragging = new EventEmitter();
/**
* \@description Fired when the drag has finished.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.dragEnd = new EventEmitter();
/**
* \@description Fired if the option interaction:{hover:true} is enabled and the mouse hovers over a node.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.hoverNode = new EventEmitter();
/**
* \@description Fired if the option interaction:{hover:true} is enabled and the mouse moved away from a node it was hovering over before.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.blurNode = new EventEmitter();
/**
* \@description Fired if the option interaction:{hover:true} is enabled and the mouse hovers over an edge.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.hoverEdge = new EventEmitter();
/**
* \@description Fired if the option interaction:{hover:true} is enabled and the mouse moved away from an edge it was hovering over before.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.blurEdge = new EventEmitter();
/**
* \@description Fired when the popup (tooltip) is shown.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.showPopup = new EventEmitter();
/**
* \@description Fired when the popup (tooltip) is hidden.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.hidePopup = new EventEmitter();
/**
* \@description Fired when stabilization starts.
* This is also the case when you drag a node and the physics simulation restarts to stabilize again.
* Stabilization does not necessarily imply 'without showing'.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.startStabilizing = new EventEmitter();
/**
* \@description Fired when a multiple of the updateInterval number of iterations is reached.
* This only occurs in the 'hidden' stabilization.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.stabilizationProgress = new EventEmitter();
/**
* \@description Fired when the 'hidden' stabilization finishes.
* This does not necessarily mean the network is stabilized;
* it could also mean that the amount of iterations defined in the options has been reached.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.stabilizationIterationsDone = new EventEmitter();
/**
* \@description Fired when the network has stabilized or when the stopSimulation() has been called.
* The amount of iterations it took could be used to tweak the maximum amount of iterations needed to stabilize the network.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.stabilized = new EventEmitter();
/**
* \@description Fired when the user zooms in or out.
* The properties tell you which direction the zoom is in.
* The scale is a number greater than 0, which is the same that you get with network.getScale().
* When fired by clicking the zoom in or zoom out navigation buttons, the pointer property of the object passed will be null.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.zoom = new EventEmitter();
/**
* \@description Fired when the size of the canvas has been resized, either by a redraw call when the container div has changed in size,
* a setSize() call with new values or a setOptions() with new width and/or height values.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.resize = new EventEmitter();
/**
* \@description Fired before the redrawing begins. The simulation step has completed at this point.
* Can be used to move custom elements before starting drawing the new frame.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.initRedraw = new EventEmitter();
/**
* \@description Fired when an animation is finished.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.animationFinished = new EventEmitter();
/**
* \@description Fired when a user changes any option in the configurator.
* The options object can be used with the setOptions method or stringified using JSON.stringify().
* You do not have to manually put the options into the network: this is done automatically.
* You can use the event to store user options in the database.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.configChange = new EventEmitter();
/**
* \@description Fired after the Canvas has been cleared, scaled and translated to
* the viewing position but before all edges and nodes are drawn.
* Can be used to draw behind the network.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.beforeDrawing = new EventEmitter();
/**
* \@description Fired after drawing on the canvas has been completed.
* Can be used to draw on top of the network.
* \@memberOf NgxVisNetworkEtsisiService
*/
this.afterDrawing = new EventEmitter();
this.auxGraphs = {};
this.seedGraphs = {};
}
/**
* \@description It creates a new graph network.
* @throws Thrown when the graph network has already been rendered.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} container is the html element where the graph will be added.
* @param {?} id is the graph network id.
* @param {?} nodes to generate the graph network.
* @param {?} edges to generate the graph network.
* @param {?=} options to generate the graph network.
* @return {?}
*/
create(container, id, nodes, edges, options) {
if (this.auxGraphs[id]) {
throw new Error(`Graph ${id} exists`);
}
this.auxGraphs[id] = {
network: new Network(container, { nodes: nodes, edges: edges }, options),
nodes: nodes,
edges: edges,
options: options
};
this.seedGraphs[id] = { nodes: nodes.getDataSet().get(), edges: edges.getDataSet().get(), options: options };
}
/**
* \@description It gets the number of nodes for a graph with a concrete id.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
getNodesCount(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].nodes.length;
}
return 0;
}
/**
* \@description It gets the number of edges for a graph with a concrete id.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
getEdgesCount(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].edges.length;
}
return 0;
}
/**
* \@description It gets the nodes for a graph with a concrete id.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
getNodes(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].nodes;
}
return null;
}
/**
* \@description It gets the edges for a graph with a concrete id.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
getEdges(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].edges;
}
return null;
}
/**
* \@description It returns if a graph with a concrete id exists.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
isAnExistingGraphNetwork(id) {
return !!this.auxGraphs[id];
}
/**
* \@description Adds a node in a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id
* @param {?} data is the node info.
* @return {?}
*/
addNode(id, data) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].nodes.add(data);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Updates a node in a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} data is the node info.
* @return {?}
*/
updateNode(id, data) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].nodes.update(data);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Removes a concrete node in a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeId is the node id.
* @return {?}
*/
removeNode(id, nodeId) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].nodes.remove(nodeId);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Adds a concrete edge in a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} data is the edge info.
* @return {?}
*/
addEdge(id, data) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].edges.add(data);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Removes an edge in a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} edgeId is the edge id.
* @return {?}
*/
removeEdge(id, edgeId) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].edges.remove(edgeId);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Updates a background node in a graph network for only one node.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeId is the node id that we want to change
* @param {?} backgroundColor is the background color to edit the node
* @return {?}
*/
setBackgroundNode(id, nodeId, backgroundColor) {
/** @type {?} */
const selectedNode = this.getNodes(id).get(nodeId);
this.updateNode(id, Object.assign({}, selectedNode, { color: { background: backgroundColor } }));
}
/**
* \@description Gets the node positions using an array of nodes id for a graph node.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeIds is the array of nodes id.
* @return {?}
*/
getNodePositions(id, nodeIds) {
return this.auxGraphs[id].network.getPositions(nodeIds);
}
/**
* \@description It comes back to the initial state for a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
resetGraph(id) {
if (this.auxGraphs[id]) {
this.setOptions(id, this.seedGraphs[id].options);
this.updateNode(id, this.seedGraphs[id].nodes);
this.updateEdge(id, this.seedGraphs[id].edges);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description If you like the layout of your network and would like it to start in the same way next time,
* ask for the seed using this method
* and put it in the layout.randomSeed option.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?} id of the previous seed
*/
getSeed(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getSeed();
}
return -1;
}
/**
* \@description Zooms out so all nodes fit on the canvas.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?=} options to fit the graph network.
* @return {?}
*/
fit(id, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.fit(options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Redraw a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
redraw(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.redraw();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Returns the current scale of the network. 1.0 is comparable to 100%, 0 is zoomed out infinitely.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
getScale(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getScale();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description This function converts canvas coordinates to coordinates on the DOM.
* Input and output are in the form of {x:Number,y:Number}.
* The DOM values are relative to the network container.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} position is the Canvas coordinates.
* @return {?}
*/
canvasToDom(id, position) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.canvasToDOM(position);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description This function converts DOM coordinates to coordinates on the canvas.
* Input and output are in the form of {x:Number,y:Number}.
* The DOM values are relative to the network container.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} position is the Canvas coordinates.
* @return {?}
*/
domToCanvas(id, position) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.DOMtoCanvas(position);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Sets an event listener. Depending on the type of event you get different parameters for the callback function.
* Look at the event section of the documentation for more information.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} eventName is the event name that we want to listen.
* @param {?=} preventDefault is to stop the default behaviour of the event.
* @return {?}
*/
on(id, eventName, preventDefault) {
if (this.auxGraphs[id]) {
/** @type {?} */
const that = this;
this.auxGraphs[id].network.on(eventName, (/**
* @param {?} params
* @return {?}
*/
params => {
/** @type {?} */
const emitter = (/** @type {?} */ (that[eventName]));
if (emitter) {
emitter.emit(params ? [id].concat(params) : id);
}
if (preventDefault && params.event) {
params.event.preventDefault();
}
}));
return true;
}
return false;
}
/**
* \@description Removes an event listener. The function you supply has to be the exact same as the one you used in the on function.
* If no function is supplied, all listeners will be removed.
* Look at the event section of the documentation for more information.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} eventName is the event name that we want to listen.
* @return {?}
*/
off(id, eventName) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.off(eventName);
}
}
/**
* \@description Sets an event listener only once. After it has taken place, the event listener will be removed.
* Depending on the type of event you get different parameters for the callback function.
* Look at the event section of the documentation for more information.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} eventName is the event name that we want to listen.
* @return {?}
*/
once(id, eventName) {
if (this.auxGraphs[id]) {
/** @type {?} */
const that = this;
this.auxGraphs[id].network.on(eventName, (/**
* @param {?} params
* @return {?}
*/
params => {
/** @type {?} */
const emitter = (/** @type {?} */ (that[eventName]));
if (emitter) {
emitter.emit(params ? [id].concat(params) : id);
this.off(id, eventName);
}
}));
return true;
}
return false;
}
/**
* \@description Removes the network from the DOM and remove all Hammer bindings and references.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
destroy(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.destroy();
delete this.auxGraphs[id];
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Updates an edge in a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} data is the edge info.
* @return {?}
*/
updateEdge(id, data) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].edges.update(data);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Sets the options in a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} options is the configuration to modify a graph network.
* @return {?}
*/
setOptions(id, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.setOptions(options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Sets the data in a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} data is the data to modify a graph network.
* @return {?}
*/
setData(id, data) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.setData(data);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Selects the nodes of the parameter nodeIds in a graph network
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeIds is an array of node ids.
* @param {?=} highlightEdges is a flag to indicate if it highlights the edges.
* @return {?}
*/
selectNodes(id, nodeIds, highlightEdges) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.selectNodes(nodeIds, highlightEdges);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Starts the physic simulation for a graph network
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
startSimulation(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.startSimulation();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Stops the physic simulation for a graph network
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
stopSimulation(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.stopSimulation();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Moves a graph network using the moveToOptions
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} moveToOptions is the options to move the graph.
* @return {?}
*/
moveTo(id, moveToOptions) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.moveTo(moveToOptions);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Gets the connected edges using a node id for a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeId is the id of the node to obtain its connected edges.
* @return {?}
*/
getConnectedEdges(id, nodeId) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.getConnectedEdges(nodeId);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Gets the connected nodes using a node/edge id for a graph network.
* @throws {Error} Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeOrEdgeId is the id of the node/edge to obtain its connected nodes.
* @return {?}
*/
getConnectedNodes(id, nodeOrEdgeId) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.getConnectedNodes(nodeOrEdgeId);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Gets the selected nodes for a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
getSelectedNodes(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getSelectedNodes();
}
return [];
}
/**
* \@description Gets the selected edges for a graph network.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
getSelectedEdges(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getSelectedEdges();
}
return [];
}
/**
* \@description Gets a node id for a concrete position in a graph network
* @throws {Error} Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} position is the position for obtain a node id in a graph network.
* @return {?}
*/
getNodeAt(id, position) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getNodeAt(position);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Gets an edge id for a concrete position in a graph network
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} position is the position for obtain a edge id in a graph network.
* @return {?}
*/
getEdgeAt(id, position) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getEdgeAt(position);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Selects different elements for a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} selection is a set of nodes and/or edges.
* @param {?=} options is the configuration for the selection.
* @return {?}
*/
setSelection(id, selection, options = {}) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.setSelection(selection, options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Gets selected elements for a graph network.
* @param {?} id is the graph network id.
* @return {?}
*/
getSelection(id) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getSelection();
}
return undefined;
}
/**
* \@description Unselects all the selected elements for a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
unselectAll(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.unselectAll();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Deletes the selected elements.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
deleteSelected(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.deleteSelected();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Gets a bounding box for the node with nodeId including label.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeId is the node id.
* @return {?}
*/
getBoundingBox(id, nodeId) {
return this.auxGraphs[id].network.getBoundingBox(nodeId);
}
/**
* \@description Stores positions for a graph node.
* When using the vis.DataSet to load your nodes into the network,
* this method will put the X and Y positions of all nodes into that dataset.
* If you're loading your nodes from a database and have this dynamically coupled with the DataSet,
* you can use this to stabilize your network once, then save the positions in that database
* through the DataSet so the next time you load the nodes, stabilization will be near instantaneous.
* If the nodes are still moving and you're using dynamic smooth edges (which is on by default),
* you can use the option stabilization.onlyDynamicEdges in the physics module to improve initialization time.
* This method does not support clustering.
* At the moment it is not possible to cache positions when using clusters since
* they cannot be correctly initialized from just the positions.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
storePositions(id) {
this.auxGraphs[id].network.storePositions();
}
/**
* \@description Go into addNode mode. Having edit mode or manipulation enabled is not required.
* To get out of this mode, call disableEditMode().
* The callback functions defined in handlerFunctions still apply.
* To use these methods without having the manipulation GUI, make sure you set enabled to false.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
addNodeMode(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.addNodeMode();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Programmatically enable the edit mode. Similar effect to pressing the edit button.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
enableEditMode(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.enableEditMode();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Go into addEdge mode. The explanation from addNodeMode applies here as well.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
addEdgeMode(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.addEdgeMode();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Programmatically disable the edit mode.
* Similar effect to pressing the close icon (small cross in the corner of the toolbar).
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @return {?}
*/
disableEditMode(id) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.disableEditMode();
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* Updates a clustered node.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} clusteredNodeId is a clustered node id.
* @param {?=} options to update the cluster node.
* @return {?}
*/
updateClusteredNode(id, clusteredNodeId, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.updateClusteredNode(clusteredNodeId, options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Returns an array of all nodeIds of the nodes that would be released if you open the cluster.
* @throws {Error} Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} clusterNodeId is a cluster node id.
* @return {?}
*/
getNodesInCluster(id, clusterNodeId) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getNodesInCluster(clusterNodeId);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Opens the cluster, releases the contained nodes and edges, removing the cluster node and cluster edges.
* The options object is optional and currently supports one option,
* releaseFunction, which is a function that can be used to manually position the nodes after the cluster is opened.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeId is a node id.
* @param {?=} options is the open cluster options.
* @return {?}
*/
openCluster(id, nodeId, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.openCluster(nodeId, options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Returns true if the node whose ID has been supplied is a cluster.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeId is a node id.
* @return {?}
*/
isCluster(id, nodeId) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.isCluster(nodeId);
}
return false;
}
/**
* \@description Gets clustered edges.
* Similar to findNode in that it returns all the edge ids that were created from the provided edge during clustering.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} baseEdgeId is the initial edge.
* @return {?}
*/
getClusteredEdges(id, baseEdgeId) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getClusteredEdges(baseEdgeId);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Makes a cluster for a graph network.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?=} options is the cluster options.
* @return {?}
*/
cluster(id, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.cluster(options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description This method looks at the provided node and makes a cluster of it and all it's connected nodes.
* The behaviour can be customized by proving the options object.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeId is the node id.
* @param {?=} options is the cluster options.
* @return {?}
*/
clusterByConnection(id, nodeId, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.clusterByConnection((/** @type {?} */ (nodeId)), options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description This method checks all nodes in the network and those with a equal or higher amount of edges than
* specified with the hubsize qualify.
* If a hubsize is not defined, the hubsize will be determined as the average value plus two standard deviations.
* For all qualifying nodes, clusterByConnection is performed on each of them.
* The options object is described for clusterByConnection and does the same here.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?=} hubsize is the size of a hub.
* @param {?=} options is the cluster options.
* @return {?}
*/
clusterByHubSize(id, hubsize, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.clusterByHubsize(hubsize, options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description This method will cluster all nodes with 1 edge with their respective connected node.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?=} options is the cluster options.
* @return {?}
*/
clusterOutliers(id, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.clusterOutliers(options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description When a clusteredEdgeId is available, this method will return the original
* baseEdgeId provided in data.edges ie.
* After clustering the 'SelectEdge' event is fired but provides only the clustered edge.
* This method can then be used to return the baseEdgeId.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} clusteredEdgeId is the id of a clustered edge in a graph network.
* @return {?}
*/
getBaseEdge(id, clusteredEdgeId) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.getBaseEdge(clusteredEdgeId);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Visible edges between clustered nodes are not the same edge as the ones provided in data.edges passed on network creation
* With each layer of clustering, copies of the edges between clusters are created and the previous edges are hidden, until the cluster
* is opened.
* This method takes an edgeId (ie. a base edgeId from data.edges) and applies the options to it and any edges that were created from
* it while clustering.
* Example: network.clustering.updateEdge(originalEdge.id, {color : '#aa0000'});
* This would turn the base edge and any subsequent edges red, so when opening clusters the edges will all be the same color.
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} startEdgeId is the initial edge.
* @param {?=} options is the configuration for update the edges that are clustered.
* @return {?}
*/
updateClusteredEdges(id, startEdgeId, options) {
if (this.auxGraphs[id]) {
this.auxGraphs[id].network.updateEdge(startEdgeId, options);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
/**
* \@description Nodes can be in clusters.
* Clusters can also be in clusters.
* This function returns an array of nodeIds showing where the node is.
* Example:
* cluster 'A' contains cluster 'B', cluster 'B' contains cluster 'C',
* cluster 'C' contains node 'fred'.
* network.clustering.findNode('fred') will return ['A','B','C','fred'].
* @throws Thrown when the graph network doesn't exist.
* \@memberOf NgxVisNetworkEtsisiService
* @param {?} id is the graph network id.
* @param {?} nodeId is the node id.
* @return {?}
*/
findNode(id, nodeId) {
if (this.auxGraphs[id]) {
return this.auxGraphs[id].network.findNode(nodeId);
}
else {
throw new Error(`Graph ${id} doesn't exist.`);
}
}
}
NgxVisNetworkEtsisiService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
NgxVisNetworkEtsisiService.ctorParameters = () => [];
/** @nocollapse */ NgxVisNetworkEtsisiService.ngInjectableDef = i0.ɵɵdefineInjectable({ factory: function NgxVisNetworkEtsisiService_Factory() { return new NgxVisNetworkEtsisiService(); }, token: NgxVisNetworkEtsisiService, providedIn: "root" });
if (false) {
/**
* \@description Fired when the user clicks the mouse or taps on a touchscreen device.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.click;
/**
* \@description Fired when the user double clicks the mouse or double taps on a touchscreen device.
* Since a double click is in fact 2 clicks, 2 click events are fired, followed by a double click event.
* If you do not want to use the click events if a double click event is fired,
* just check the time between click events before processing them.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.doubleClick;
/**
* \@description Fired when the user click on the canvas with the right mouse button.
* The right mouse button does not select by default.
* You can use the method getNodeAt to select the node if you want.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.oncontext;
/**
* \@description Fired when the user clicks and holds the mouse or taps and holds on a touchscreen device.
* A click event is also fired in this case.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.hold;
/**
* \@description Fired after drawing on the canvas has been completed.
* Can be used to draw on top of the network.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.release;
/**
* \@description Fired when the selection has changed by user action.
* This means a node or edge has been selected, added to the selection or deselected.
* All select events are only triggered on click and hold.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.select;
/**
* \@description Fired when a node has been selected by the user.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.selectNode;
/**
* Fired when an edge has been selected by the user.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.selectEdge;
/**
* \@description Fired when a node (or nodes) has (or have) been deselected by the user.
* The previous selection is the list of nodes and edges that were selected before the last user event.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.deselectNode;
/**
* \@description Fired when an edge (or edges) has (or have) been deselected by the user.
* The previous selection is the list of nodes and edges that were selected before the last user event.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.deselectEdge;
/**
* \@description Fired when starting a drag.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.dragStart;
/**
* \@description Fired when dragging node(s) or the view.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.dragging;
/**
* \@description Fired when the drag has finished.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.dragEnd;
/**
* \@description Fired if the option interaction:{hover:true} is enabled and the mouse hovers over a node.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.hoverNode;
/**
* \@description Fired if the option interaction:{hover:true} is enabled and the mouse moved away from a node it was hovering over before.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.blurNode;
/**
* \@description Fired if the option interaction:{hover:true} is enabled and the mouse hovers over an edge.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.hoverEdge;
/**
* \@description Fired if the option interaction:{hover:true} is enabled and the mouse moved away from an edge it was hovering over before.
* \@memberOf NgxVisNetworkEtsisiService
* @type {?}
*/
NgxVisNetworkEtsisiService.prototype.blurEdge;
/**
* \@description Fired when the popup (tooltip) is shown.
* \@memberOf NgxVisNetworkEtsisiService