Browse Source

Removes redundant .eslintrc from graph3d, lints the rest of the code … (#3363)

* Removes redundant .eslintrc from graph3d, lints the rest of the code base, and enables valid-jsdoc lint rule

* Corrects lint violations
revert-3409-performance
macleodbroad-wf 7 years ago
committed by Yotam Berkowitz
parent
commit
d4e4e9fa07
50 changed files with 743 additions and 486 deletions
  1. +7
    -7
      .eslintrc
  2. +27
    -22
      lib/DOMutil.js
  3. +5
    -3
      lib/DataSet.js
  4. +2
    -1
      lib/DataView.js
  5. +0
    -1
      lib/Queue.js
  6. +0
    -40
      lib/graph3d/.eslintrc
  7. +1
    -0
      lib/hammerUtil.js
  8. +2
    -0
      lib/module/hammer.js
  9. +7
    -2
      lib/network/CachedImage.js
  10. +17
    -15
      lib/network/Images.js
  11. +1
    -1
      lib/network/Network.js
  12. +10
    -2
      lib/network/NetworkUtil.js
  13. +4
    -0
      lib/network/modules/Canvas.js
  14. +9
    -3
      lib/network/modules/CanvasRenderer.js
  15. +60
    -43
      lib/network/modules/Clustering.js
  16. +3
    -1
      lib/network/modules/EdgesHandler.js
  17. +1
    -1
      lib/network/modules/Groups.js
  18. +15
    -8
      lib/network/modules/InteractionHandler.js
  19. +13
    -11
      lib/network/modules/KamadaKawai.js
  20. +58
    -25
      lib/network/modules/LayoutEngine.js
  21. +29
    -16
      lib/network/modules/ManipulationSystem.js
  22. +15
    -11
      lib/network/modules/NodesHandler.js
  23. +12
    -5
      lib/network/modules/PhysicsEngine.js
  24. +22
    -18
      lib/network/modules/SelectionHandler.js
  25. +3
    -4
      lib/network/modules/View.js
  26. +7
    -5
      lib/network/modules/components/Edge.js
  27. +16
    -12
      lib/network/modules/components/Node.js
  28. +23
    -2
      lib/network/modules/components/edges/BezierEdgeDynamic.js
  29. +24
    -2
      lib/network/modules/components/edges/BezierEdgeStatic.js
  30. +5
    -2
      lib/network/modules/components/edges/CubicBezierEdge.js
  31. +3
    -2
      lib/network/modules/components/edges/StraightEdge.js
  32. +7
    -9
      lib/network/modules/components/edges/util/BezierEdgeBase.js
  33. +3
    -0
      lib/network/modules/components/edges/util/CubicBezierEdgeBase.js
  34. +28
    -13
      lib/network/modules/components/edges/util/EdgeBase.js
  35. +1
    -1
      lib/network/modules/components/nodes/util/CircleImageBase.js
  36. +16
    -1
      lib/network/modules/components/nodes/util/NodeBase.js
  37. +26
    -27
      lib/network/modules/components/physics/BarnesHutSolver.js
  38. +5
    -0
      lib/network/modules/components/physics/CentralGravitySolver.js
  39. +6
    -0
      lib/network/modules/components/physics/FA2BasedCentralGravitySolver.js
  40. +5
    -5
      lib/network/modules/components/physics/FA2BasedRepulsionSolver.js
  41. +1
    -0
      lib/network/modules/components/physics/RepulsionSolver.js
  42. +3
    -3
      lib/network/modules/components/physics/SpringSolver.js
  43. +85
    -49
      lib/network/modules/components/shared/Label.js
  44. +36
    -0
      lib/network/shapes.js
  45. +1
    -1
      lib/shared/Activator.js
  46. +12
    -12
      lib/shared/ColorPicker.js
  47. +41
    -40
      lib/shared/Configurator.js
  48. +15
    -14
      lib/shared/Validator.js
  49. +1
    -1
      lib/timeline/component/Group.js
  50. +50
    -45
      lib/util.js

+ 7
- 7
.eslintrc View File

@ -26,13 +26,13 @@
"ClassDeclaration": false,
"ArrowFunctionExpression": false
}
}]
// "valid-jsdoc": [2, {
// "requireReturnDescription": false,
// "requireReturn": false,
// "requireParamDescription": false,
// "requireReturnType": false
// }],
}],
"valid-jsdoc": [2, {
"requireReturnDescription": false,
"requireReturn": false,
"requireParamDescription": false,
"requireReturnType": false
}],
}
// To flag presence of console.log without breaking linting:
//"no-console": ["warn", { allow: ["warn", "error"] }],

+ 27
- 22
lib/DOMutil.js View File

@ -2,7 +2,7 @@
/**
* this prepares the JSON container for allocating SVG elements
* @param JSONcontainer
* @param {Object} JSONcontainer
* @private
*/
exports.prepareElements = function(JSONcontainer) {
@ -19,7 +19,7 @@ exports.prepareElements = function(JSONcontainer) {
* this cleans up all the unused SVG elements. By asking for the parentNode, we only need to supply the JSON container from
* which to remove the redundant elements.
*
* @param JSONcontainer
* @param {Object} JSONcontainer
* @private
*/
exports.cleanupElements = function(JSONcontainer) {
@ -38,22 +38,22 @@ exports.cleanupElements = function(JSONcontainer) {
/**
* Ensures that all elements are removed first up so they can be recreated cleanly
* @param JSONcontainer
* @param {Object} JSONcontainer
*/
exports.resetElements = function(JSONcontainer) {
exports.prepareElements(JSONcontainer);
exports.cleanupElements(JSONcontainer);
exports.prepareElements(JSONcontainer);
}
};
/**
* Allocate or generate an SVG element if needed. Store a reference to it in the JSON container and draw it in the svgContainer
* the JSON container and the SVG container have to be supplied so other svg containers (like the legend) can use this.
*
* @param elementType
* @param JSONcontainer
* @param svgContainer
* @returns {*}
* @param {String} elementType
* @param {Object} JSONcontainer
* @param {Object} svgContainer
* @returns {Element}
* @private
*/
exports.getSVGElement = function (elementType, JSONcontainer, svgContainer) {
@ -86,11 +86,11 @@ exports.getSVGElement = function (elementType, JSONcontainer, svgContainer) {
* Allocate or generate an SVG element if needed. Store a reference to it in the JSON container and draw it in the svgContainer
* the JSON container and the SVG container have to be supplied so other svg containers (like the legend) can use this.
*
* @param elementType
* @param JSONcontainer
* @param DOMContainer
* @param {String} elementType
* @param {Object} JSONcontainer
* @param {Element} DOMContainer
* @param {Element} insertBefore
* @returns {*}
* @private
*/
exports.getDOMElement = function (elementType, JSONcontainer, DOMContainer, insertBefore) {
var element;
@ -135,13 +135,13 @@ exports.getDOMElement = function (elementType, JSONcontainer, DOMContainer, inse
* The reason the JSONcontainer and the target SVG svgContainer have to be supplied is so the legend can use these functions
* as well.
*
* @param x
* @param y
* @param groupTemplate: A template containing the necessary information to draw the datapoint e.g., {style: 'circle', size: 5, className: 'className' }
* @param JSONcontainer
* @param svgContainer
* @param labelObj
* @returns {*}
* @param {Number} x
* @param {Number} y
* @param {Object} groupTemplate: A template containing the necessary information to draw the datapoint e.g., {style: 'circle', size: 5, className: 'className' }
* @param {Object} JSONcontainer
* @param {Object} svgContainer
* @param {Object} labelObj
* @returns {vis.PointItem}
*/
exports.drawPoint = function(x, y, groupTemplate, JSONcontainer, svgContainer, labelObj) {
var point;
@ -192,9 +192,14 @@ exports.drawPoint = function(x, y, groupTemplate, JSONcontainer, svgContainer, l
/**
* draw a bar SVG element centered on the X coordinate
*
* @param x
* @param y
* @param className
* @param {Number} x
* @param {Number} y
* @param {Number} width
* @param {Number} height
* @param {String} className
* @param {Object} JSONcontainer
* @param {Object} svgContainer
* @param {string} style
*/
exports.drawBar = function (x, y, width, height, className, JSONcontainer, svgContainer, style) {
if (height != 0) {

+ 5
- 3
lib/DataSet.js View File

@ -3,6 +3,7 @@ var Queue = require('./Queue');
/**
* DataSet
* // TODO: add a DataSet constructor DataSet(data, options)
*
* Usage:
* var dataSet = new DataSet({
@ -42,7 +43,6 @@ var Queue = require('./Queue');
* - {number} delay Delay in ms, null by default
* - {number} max Maximum number of entries in the queue, Infinity by default
* @constructor DataSet
* // TODO: add a DataSet constructor DataSet(data, options)
*/
function DataSet (data, options) {
// correctly read optional arguments
@ -89,13 +89,12 @@ function DataSet (data, options) {
}
/**
* @param {Object} [options] Available options:
* @param {Object} options Available options:
* {Object} queue Queue changes to the DataSet,
* flush them all at once.
* Queue options:
* - {number} delay Delay in ms, null by default
* - {number} max Maximum number of entries in the queue, Infinity by default
* @param options
*/
DataSet.prototype.setOptions = function(options) {
if (options && options.queue !== undefined) {
@ -319,6 +318,8 @@ DataSet.prototype.update = function (data, senderId) {
* {String[]} [fields] field names to be returned
* {function} [filter] filter items
* {String | function} [order] Order the items by a field name or custom sort function.
* @param {Array} args
* @returns {DataSet}
* @throws Error
*/
DataSet.prototype.get = function (args) { // eslint-disable-line no-unused-vars
@ -509,6 +510,7 @@ DataSet.prototype.getIds = function (options) {
/**
* Returns the DataSet itself. Is overwritten for example by the DataView,
* which returns the DataSet it is connected to instead.
* @returns {DataSet}
*/
DataSet.prototype.getDataSet = function () {
return this;

+ 2
- 1
lib/DataView.js View File

@ -156,7 +156,8 @@ DataView.prototype.refresh = function () {
* {Array | DataTable} [data] If provided, items will be appended to this
* array or table. Required in case of Google
* DataTable.
* @param args
* @param {Array} args
* @return {DataSet|DataView}
*/
DataView.prototype.get = function (args) { // eslint-disable-line no-unused-vars
var me = this;

+ 0
- 1
lib/Queue.js View File

@ -35,7 +35,6 @@ function Queue(options) {
* - max: number When the queue exceeds the given maximum number
* of entries, the queue is flushed automatically.
* Default value of max is Infinity.
* @param options
*/
Queue.prototype.setOptions = function (options) {
if (options && typeof options.delay !== 'undefined') {

+ 0
- 40
lib/graph3d/.eslintrc View File

@ -1,40 +0,0 @@
{
"env": {
"browser": true,
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"sourceType": "module",
},
"extends": "eslint:recommended",
// For the full list of rules, see: http://eslint.org/docs/rules/
"rules": {
"complexity": [2, 55],
"max-statements": [2, 115],
"no-unreachable": 1,
"no-useless-escape": 0,
"no-console": 0,
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": true
}
}],
"valid-jsdoc": [2, {
"requireReturnDescription": false,
"requireReturn": false,
"requireParamDescription": false,
"requireReturnType": true
}],
}
// To flag presence of console.log without breaking linting:
//"no-console": ["warn", { allow: ["warn", "error"] }],
}

+ 1
- 0
lib/hammerUtil.js View File

@ -17,6 +17,7 @@ exports.onTouch = function (hammer, callback) {
* Register a release event, taking place after a gesture
* @param {Hammer} hammer A hammer instance
* @param {function} callback Callback, called as callback(event)
* @returns {*}
*/
exports.onRelease = function (hammer, callback) {
callback.inputHandler = function (event) {

+ 2
- 0
lib/module/hammer.js View File

@ -2,6 +2,8 @@
* Setup a mock hammer.js object, for unit testing.
*
* Inspiration: https://github.com/uber/deck.gl/pull/658
*
* @returns {{on: noop, off: noop, destroy: noop, emit: noop, get: get}}
*/
function hammerMock() {
const noop = () => {};

+ 7
- 2
lib/network/CachedImage.js View File

@ -102,8 +102,12 @@ class CachedImage {
*
* Credits to 'Alex de Mulder' for original implementation.
*
* ctx {Context} context on which to draw zoomed image
* factor {Float} scale factor at which to draw
* @param {CanvasRenderingContext2D} ctx context on which to draw zoomed image
* @param {Float} factor scale factor at which to draw
* @param {Number} left
* @param {Number} top
* @param {Number} width
* @param {Number} height
*/
drawImageAtPosition(ctx, factor, left, top, width, height) {
if (factor > 2 && this.initialized()) {
@ -137,6 +141,7 @@ class CachedImage {
*
* Source: http://stackoverflow.com/a/1977898/1223531
*
* @returns {boolean}
* @private
*/
_isImageOk() {

+ 17
- 15
lib/network/Images.js View File

@ -2,8 +2,8 @@ import CachedImage from './CachedImage';
/**
* @class Images
* This class loads images and keeps them stored.
* @class Images
*/
class Images {
constructor(callback){
@ -16,7 +16,7 @@ class Images {
/**
* @param {string} url The original Url that failed to load, if the broken image is successfully loaded it will be added to the cache using this Url as the key so that subsequent requests for this Url will return the broken image
* @param {string} brokenUrl Url the broken image to try and load
* @return {Image} imageToLoadBrokenUrlOn The image object
* @param {Image} imageToLoadBrokenUrlOn The image object
*/
_tryloadBrokenUrl (url, brokenUrl, imageToLoadBrokenUrlOn) {
//If these parameters aren't specified then exit the function because nothing constructive can be done
@ -36,10 +36,12 @@ class Images {
imageToLoadBrokenUrlOn.image.src = brokenUrl;
}
/**
* @return {Image} imageToRedrawWith The images that will be passed to the callback when it is invoked
*/
_redrawWithImage (imageToRedrawWith) {
/**
*
* @param {vis.Image} imageToRedrawWith
* @private
*/
_redrawWithImage (imageToRedrawWith) {
if (this.callback) {
this.callback(imageToRedrawWith);
}
@ -50,7 +52,7 @@ class Images {
* @param {string} brokenUrl Url of an image to use if the url image is not found
* @return {Image} img The image object
*/
load (url, brokenUrl, id) { // eslint-disable-line no-unused-vars
load (url, brokenUrl) {
//Try and get the image from the cache, if successful then return the cached image
var cachedImage = this.images[url];
if (cachedImage) return cachedImage;
@ -75,7 +77,7 @@ class Images {
console.error("Could not load image:", url);
//Try and load the image specified by the brokenUrl using
this._tryloadBrokenUrl(url, brokenUrl, img);
}
};
//Set the source of the image to the url, this is what actually kicks off the loading of the image
img.image.src = url;
@ -85,13 +87,13 @@ class Images {
}
/**
* IE11 fix -- thanks dponch!
*
* Local helper function
*
* @private
*/
/**
* IE11 fix -- thanks dponch!
*
* Local helper function
* @param {vis.Image} imageToCache
* @private
*/
_fixImageCoordinates(imageToCache) {
if (imageToCache.width === 0) {
document.body.appendChild(imageToCache);

+ 1
- 1
lib/network/Network.js View File

@ -29,7 +29,6 @@ var KamadaKawai = require("./modules/KamadaKawai.js").default;
/**
* @constructor Network
* Create a network visualization, displaying nodes and edges.
*
* @param {Element} container The DOM element in which the Network will
@ -38,6 +37,7 @@ var KamadaKawai = require("./modules/KamadaKawai.js").default;
* {Array} nodes
* {Array} edges
* @param {Object} options Options
* @constructor Network
*/
function Network(container, data, options) {
if (!(this instanceof Network)) {

+ 10
- 2
lib/network/NetworkUtil.js View File

@ -4,6 +4,10 @@ class NetworkUtil {
/**
* Find the center position of the network considering the bounding boxes
*
* @param {Array<vis.Node>} allNodes
* @param {Array<vis.Node>} [specificNodes=[]]
* @returns {{minX: number, maxX: number, minY: number, maxY: number}}
*/
static getRange(allNodes, specificNodes = []) {
var minY = 1e9, maxY = -1e9, minX = 1e9, maxX = -1e9, node;
@ -33,6 +37,10 @@ class NetworkUtil {
/**
* Find the center position of the network
*
* @param {Array<vis.Node>} allNodes
* @param {Array<vis.Node>} [specificNodes=[]]
* @returns {{minX: number, maxX: number, minY: number, maxY: number}}
*/
static getRangeCore(allNodes, specificNodes = []) {
var minY = 1e9, maxY = -1e9, minX = 1e9, maxX = -1e9, node;
@ -73,8 +81,8 @@ class NetworkUtil {
/**
* This returns a clone of the options or options of the edge or node to be used for construction of new edges or check functions for new nodes.
* @param item
* @param type
* @param {vis.Item} item
* @param {'node'|undefined} type
* @returns {{}}
*/
static cloneOptions(item, type) {

+ 4
- 0
lib/network/modules/Canvas.js View File

@ -87,6 +87,8 @@ class Canvas {
/**
* Get and store the cameraState
*
* @param {Number} [pixelRatio=this.pixelRatio]
* @private
*/
_getCameraState(pixelRatio = this.pixelRatio) {
@ -246,6 +248,7 @@ class Canvas {
* or '50%')
* @param {string} height Height in pixels or percentage (for example '400px'
* or '30%')
* @returns {boolean}
*/
setSize(width = this.options.width, height = this.options.height) {
width = this._prepareValue(width);
@ -341,6 +344,7 @@ class Canvas {
/**
* Determine the pixel ratio for various browsers.
*
* @returns {number}
* @private
*/
_determinePixelRatio() {

+ 9
- 3
lib/network/modules/CanvasRenderer.js View File

@ -119,7 +119,9 @@ class CanvasRenderer {
*
* Calls the callback when the next frame can or will be drawn.
*
* @param delay {number} - timeout case only, wait this number of milliseconds
* @param {function} callback
* @param {number} delay - timeout case only, wait this number of milliseconds
* @returns {function|undefined}
* @private
*/
_requestNextFrame(callback, delay) {
@ -189,8 +191,6 @@ class CanvasRenderer {
/**
* Redraw the network with the current data
* @param hidden | Used to get the first estimate of the node sizes.
* Only the nodes are drawn after which they are quickly drawn over.
* @private
*/
_requestRedraw() {
@ -200,6 +200,12 @@ class CanvasRenderer {
}
}
/**
* Redraw the network with the current data
* @param {boolean} [hidden=false] | Used to get the first estimate of the node sizes.
* Only the nodes are drawn after which they are quickly drawn over.
* @private
*/
_redraw(hidden = false) {
if (this.allowRedraw === true) {
this.body.emitter.emit("initRedraw");

+ 60
- 43
lib/network/modules/Clustering.js View File

@ -113,8 +113,8 @@ class ClusterEngine {
/**
*
* @param hubsize
* @param options
* @param {Number} hubsize
* @param {Object} options
*/
clusterByHubsize(hubsize, options) {
if (hubsize === undefined) {
@ -142,10 +142,10 @@ class ClusterEngine {
/**
* loop over all nodes, check if they adhere to the condition and cluster if needed.
* @param options
* @param refreshData
*/
* loop over all nodes, check if they adhere to the condition and cluster if needed.
* @param {Object} options
* @param {Boolean} [refreshData=true]
*/
cluster(options = {}, refreshData = true) {
if (options.joinCondition === undefined) {throw new Error("Cannot call clusterByNodeData without a joinCondition function in the options.");}
@ -180,9 +180,9 @@ class ClusterEngine {
/**
* Cluster all nodes in the network that have only X edges
* @param edgeCount
* @param options
* @param refreshData
* @param {Number} edgeCount
* @param {Object} options
* @param {Boolean} [refreshData=true]
*/
clusterByEdgeCount(edgeCount, options, refreshData = true) {
options = this._checkOptions(options);
@ -256,18 +256,18 @@ class ClusterEngine {
}
/**
* Cluster all nodes in the network that have only 1 edge
* @param options
* @param refreshData
*/
* Cluster all nodes in the network that have only 1 edge
* @param {Object} options
* @param {Boolean} [refreshData=true]
*/
clusterOutliers(options, refreshData = true) {
this.clusterByEdgeCount(1,options,refreshData);
}
/**
* Cluster all nodes in the network that have only 2 edge
* @param options
* @param refreshData
* @param {Object} options
* @param {Boolean} [refreshData=true]
*/
clusterBridges(options, refreshData = true) {
this.clusterByEdgeCount(2,options,refreshData);
@ -277,9 +277,9 @@ class ClusterEngine {
/**
* suck all connected nodes of a node into the node.
* @param nodeId
* @param options
* @param refreshData
* @param {vis.Node.id} nodeId
* @param {Object} options
* @param {Boolean} [refreshData=true]
*/
clusterByConnection(nodeId, options, refreshData = true) {
// kill conditions
@ -353,10 +353,10 @@ class ClusterEngine {
* This function creates the edges that will be attached to the cluster
* It looks for edges that are connected to the nodes from the "outside' of the cluster.
*
* @param childNodesObj
* @param childEdgesObj
* @param clusterNodeProperties
* @param clusterEdgeProperties
* @param {{vis.Node.id: vis.Node}} childNodesObj
* @param {{vis.Edge.id: vis.Edge}} childEdgesObj
* @param {Object} clusterNodeProperties
* @param {Object} clusterEdgeProperties
* @private
*/
_createClusterEdges (childNodesObj, childEdgesObj, clusterNodeProperties, clusterEdgeProperties) {
@ -414,6 +414,8 @@ class ClusterEngine {
/**
* Find a cluster edge which matches the given created edge.
* @param {vis.Edge} createdEdge
* @returns {vis.Edge}
*/
var getNewEdge = function(createdEdge) {
for (let j = 0; j < newEdges.length; j++) {
@ -462,7 +464,7 @@ class ClusterEngine {
/**
* This function checks the options that can be supplied to the different cluster functions
* for certain fields and inserts defaults if needed
* @param options
* @param {Object} options
* @returns {*}
* @private
*/
@ -590,7 +592,7 @@ class ClusterEngine {
/**
* Check if a node is a cluster.
* @param nodeId
* @param {vis.Node.id} nodeId
* @returns {*}
*/
isCluster(nodeId) {
@ -631,10 +633,11 @@ class ClusterEngine {
/**
* Open a cluster by calling this function.
* @param {String} clusterNodeId | the ID of the cluster node
* @param {Boolean} refreshData | wrap up afterwards if not true
*/
* Open a cluster by calling this function.
* @param {vis.Edge.id} clusterNodeId | the ID of the cluster node
* @param {Object} options
* @param {Boolean} refreshData | wrap up afterwards if not true
*/
openCluster(clusterNodeId, options, refreshData = true) {
// kill conditions
if (clusterNodeId === undefined) {throw new Error("No clusterNodeId supplied to openCluster.");}
@ -811,7 +814,7 @@ class ClusterEngine {
/**
* Using a clustered nodeId, update with the new options
* @param clusteredNodeId
* @param {vis.Edge.id} clusteredNodeId
* @param {object} newOptions
*/
updateClusteredNode(clusteredNodeId, newOptions) {
@ -825,7 +828,7 @@ class ClusterEngine {
/**
* Using a base edgeId, update all related clustered edges with the new options
* @param startEdgeId
* @param {vis.Edge.id} startEdgeId
* @param {object} newOptions
*/
updateEdge(startEdgeId, newOptions) {
@ -843,8 +846,8 @@ class ClusterEngine {
/**
* Get a stack of clusterEdgeId's (+base edgeid) that a base edge is the same as. cluster edge C -> cluster edge B -> cluster edge A -> base edge(edgeId)
* @param edgeId
* @returns {Array}
* @param {vis.Edge.id} edgeId
* @returns {Array<vis.Edge.id>}
*/
getClusteredEdges(edgeId) {
let stack = [];
@ -862,8 +865,8 @@ class ClusterEngine {
/**
* Get the base edge id of clusterEdgeId. cluster edge (clusteredEdgeId) -> cluster edge B -> cluster edge C -> base edge
* @param clusteredEdgeId
* @returns baseEdgeId
* @param {vis.Edge.id} clusteredEdgeId
* @returns {vis.Edge.id} baseEdgeId
*
* TODO: deprecate in 5.0.0. Method getBaseEdges() is the correct one to use.
*/
@ -876,8 +879,8 @@ class ClusterEngine {
/**
* Get all regular edges for this clustered edge id.
*
* @param {Number} clusteredEdgeId
* @returns {Array[Number} all baseEdgeId's under this clustered edge
* @param {vis.Edge.id} clusteredEdgeId
* @returns {Array<vis.Edge.id>} all baseEdgeId's under this clustered edge
*/
getBaseEdges(clusteredEdgeId) {
let IdsToHandle = [clusteredEdgeId];
@ -921,8 +924,8 @@ class ClusterEngine {
/**
* Get the Id the node is connected to
* @param edge
* @param nodeId
* @param {vis.Edge} edge
* @param {vis.Node.id} nodeId
* @returns {*}
* @private
*/
@ -942,6 +945,7 @@ class ClusterEngine {
* We determine how many connections denote an important hub.
* We take the mean + 2*std as the important hub size. (Assuming a normal distribution of data, ~2.2%)
*
* @returns {Number}
* @private
*/
_getHubSize() {
@ -979,7 +983,12 @@ class ClusterEngine {
/**
* Create an edge for the cluster representation.
*
* @return {Edge} newly created clustered edge
* @param {vis.Node.id} fromId
* @param {vis.Node.id} toId
* @param {vis.Edge} baseEdge
* @param {Object} clusterEdgeProperties
* @param {Object} extraOptions
* @returns {Edge} newly created clustered edge
* @private
*/
_createClusteredEdge(fromId, toId, baseEdge, clusterEdgeProperties, extraOptions) {
@ -1012,9 +1021,10 @@ class ClusterEngine {
/**
* Add the passed child nodes and edges to the given cluster node.
*
* @param childNodes {Object|Node} hash of nodes or single node to add in cluster
* @param childEdges {Object|Edge} hash of edges or single edge to take into account when clustering
* @param clusterNode {Node} cluster node to add nodes and edges to
* @param {Object|Node} childNodes hash of nodes or single node to add in cluster
* @param {Object|Edge} childEdges hash of edges or single edge to take into account when clustering
* @param {Node} clusterNode cluster node to add nodes and edges to
* @param {Object} [clusterEdgeProperties]
* @private
*/
_clusterEdges(childNodes, childEdges, clusterNode, clusterEdgeProperties) {
@ -1075,7 +1085,8 @@ class ClusterEngine {
*
* NOTE: If you know a cleaner way to do this, please enlighten me (wimrijnders).
*
* @return {Node|undefined} Node instance for cluster, if present
* @param {vis.Node.id} nodeId
* @returns {Node|undefined} Node instance for cluster, if present
* @private
*/
_getClusterNodeForNode(nodeId) {
@ -1095,6 +1106,10 @@ class ClusterEngine {
* Internal helper function for conditionally removing items in array
*
* Done like this because Array.filter() is not fully supported by all IE's.
*
* @param {Array} arr
* @param {function} callback
* @returns {Array}
* @private
*/
_filter(arr, callback) {
@ -1276,6 +1291,7 @@ class ClusterEngine {
/**
* Determine if node with given id is part of a cluster.
*
* @param {vis.Node.id} nodeId
* @return {boolean} true if part of a cluster.
*/
_isClusteredNode(nodeId) {
@ -1290,6 +1306,7 @@ class ClusterEngine {
* - it is directly replaced by a clustering edge
* - any of its connecting nodes is in a cluster
*
* @param {vis.Edge.id} edgeId
* @return {boolean} true if part of a cluster.
*/
_isClusteredEdge(edgeId) {

+ 3
- 1
lib/network/modules/EdgesHandler.js View File

@ -215,7 +215,7 @@ class EdgesHandler {
/**
* Load edges by reading the data table
* @param {Array | DataSet | DataView} edges The data containing the edges.
* @private
* @param {boolean} [doNotEmit=false]
* @private
*/
setData(edges, doNotEmit = false) {
@ -264,6 +264,7 @@ class EdgesHandler {
/**
* Add edges
* @param {Number[] | String[]} ids
* @param {boolean} [doNotEmit=false]
* @private
*/
add(ids, doNotEmit = false) {
@ -330,6 +331,7 @@ class EdgesHandler {
/**
* Remove existing edges. Non existing ids will be ignored
* @param {Number[] | String[]} ids
* @param {boolean} [emit=true]
* @private
*/
remove(ids, emit = true) {

+ 1
- 1
lib/network/modules/Groups.js View File

@ -1,8 +1,8 @@
let util = require('../../util');
/**
* @class Groups
* This class can store groups and options specific for groups.
* @class Groups
*/
class Groups {
constructor() {

+ 15
- 8
lib/network/modules/InteractionHandler.js View File

@ -96,7 +96,7 @@ class InteractionHandler {
/**
* On start of a touch gesture, store the pointer
* @param event
* @param {Event} event The event
* @private
*/
onTouch(event) {
@ -111,6 +111,7 @@ class InteractionHandler {
/**
* handle tap/click event: select/unselect a node
* @param {Event} event
* @private
*/
onTap(event) {
@ -125,6 +126,7 @@ class InteractionHandler {
/**
* handle doubletap event
* @param {Event} event
* @private
*/
onDoubleTap(event) {
@ -136,6 +138,7 @@ class InteractionHandler {
/**
* handle long tap event: multi select nodes
* @param {Event} event
* @private
*/
onHold(event) {
@ -152,6 +155,7 @@ class InteractionHandler {
/**
* handle the release of the screen
*
* @param {Event} event
* @private
*/
onRelease(event) {
@ -180,8 +184,9 @@ class InteractionHandler {
*
* TODO: This is all SelectionHandler calls; the method should be moved to there.
*
* @param pointer
* @param add
* @param {{x: Number, y: Number}} pointer
* @param {Event} event
* @param {boolean} [add=false]
*/
checkSelectionChanges(pointer, event, add = false) {
let previousSelection = this.selectionHandler.getSelection();
@ -228,9 +233,9 @@ class InteractionHandler {
/**
* Remove all node and edge id's from the first set that are present in the second one.
*
* @param firstSet
* @param secondSet
* @returns {{nodes: array, edges: array}}
* @param {{nodes: Array<vis.Node>, edges: Array<vis.Edge>}} firstSet
* @param {{nodes: Array<vis.Node>, edges: Array<vis.Edge>}} secondSet
* @returns {{nodes: Array<vis.Node>, edges: Array<vis.Edge>}}
* @private
*/
_determineDifference(firstSet, secondSet) {
@ -258,6 +263,7 @@ class InteractionHandler {
* This function is called by onDragStart.
* It is separated out because we can then overload it for the datamanipulation system.
*
* @param {Event} event
* @private
*/
onDragStart(event) {
@ -317,6 +323,7 @@ class InteractionHandler {
/**
* handle drag event
* @param {Event} event
* @private
*/
onDrag(event) {
@ -375,6 +382,7 @@ class InteractionHandler {
/**
* handle drag start event
* @param {Event} event
* @private
*/
onDragEnd(event) {
@ -399,7 +407,7 @@ class InteractionHandler {
/**
* Handle pinch event
* @param event
* @param {Event} event The event
* @private
*/
onPinch(event) {
@ -420,7 +428,6 @@ class InteractionHandler {
* Zoom the network in or out
* @param {Number} scale a number around 1, and between 0.01 and 10
* @param {{x: Number, y: Number}} pointer Position on screen
* @return {Number} appliedScale scale is limited within the boundaries
* @private
*/
zoom(scale, pointer) {

+ 13
- 11
lib/network/modules/KamadaKawai.js View File

@ -20,7 +20,7 @@ class KamadaKawai {
/**
* Not sure if needed but can be used to update the spring length and spring constant
* @param options
* @param {Object} options
*/
setOptions(options) {
if (options) {
@ -36,8 +36,9 @@ class KamadaKawai {
/**
* Position the system
* @param nodesArray
* @param edgesArray
* @param {Array<vis.Node>} nodesArray
* @param {Array<vis.Edge>} edgesArray
* @param {boolean} [ignoreClusters=false]
*/
solve(nodesArray, edgesArray, ignoreClusters = false) {
// get distance matrix
@ -77,7 +78,8 @@ class KamadaKawai {
/**
* get the node with the highest energy
* @returns {*[]}
* @param {boolean} ignoreClusters
* @returns {Number[]}
* @private
*/
_getHighestEnergyNode(ignoreClusters) {
@ -106,8 +108,8 @@ class KamadaKawai {
/**
* calculate the energy of a single node
* @param m
* @returns {*[]}
* @param {vis.Node.id} m
* @returns {Number[]}
* @private
*/
_getEnergy(m) {
@ -119,9 +121,9 @@ class KamadaKawai {
/**
* move the node based on it's energy
* the dx and dy are calculated from the linear system proposed by Kamada and Kawai
* @param m
* @param dE_dx
* @param dE_dy
* @param {vis.Node.id} m
* @param {Number} dE_dx
* @param {Number} dE_dy
* @private
*/
_moveNode(m, dE_dx, dE_dy) {
@ -167,7 +169,7 @@ class KamadaKawai {
/**
* Create the L matrix: edge length times shortest path
* @param D_matrix
* @param {Object} D_matrix
* @private
*/
_createL_matrix(D_matrix) {
@ -186,7 +188,7 @@ class KamadaKawai {
/**
* Create the K matrix: spring constants times shortest path
* @param D_matrix
* @param {Object} D_matrix
* @private
*/
_createK_matrix(D_matrix) {

+ 58
- 25
lib/network/modules/LayoutEngine.js View File

@ -57,6 +57,9 @@ class HierarchicalStatus {
/**
* Add the relation between given nodes to the current state.
*
* @param {vis.Node.id} parentNodeId
* @param {vis.Node.id} childNodeId
*/
addRelation(parentNodeId, childNodeId) {
if (this.childrenReference[parentNodeId] === undefined) {
@ -92,6 +95,7 @@ class HierarchicalStatus {
/**
* Return the number of separate trees in the current network.
* @returns {Number}
*/
numTrees() {
return (this.treeIndex + 1); // This assumes the indexes are assigned consecitively
@ -100,6 +104,8 @@ class HierarchicalStatus {
/**
* Assign a tree id to a node
* @param {vis.Node} node
* @param {String|Number} treeId
*/
setTreeIndex(node, treeId) {
if (this.trees[node.id] === undefined) {
@ -113,6 +119,8 @@ class HierarchicalStatus {
* Ensure level for given id is defined.
*
* Sets level to zero for given node id if not already present
*
* @param {vis.Node.id} nodeId
*/
ensureLevel(nodeId) {
if (this.levels[nodeId] === undefined) {
@ -125,6 +133,8 @@ class HierarchicalStatus {
* get the maximum level of a branch.
*
* TODO: Never entered; find a test case to test this!
* @param {vis.Node.id} nodeId
* @returns {Number}
*/
getMaxLevel(nodeId) {
let accumulator = {};
@ -164,6 +174,8 @@ class HierarchicalStatus {
/**
* Small util method to set the minimum levels of the nodes to zero.
*
* @param {Array<vis.Node>} nodes
*/
setMinLevelToZero(nodes) {
let minLevel = 1e9;
@ -189,6 +201,10 @@ class HierarchicalStatus {
/**
* Get the min and max xy-coordinates of a given tree
*
* @param {Array<vis.Node>} nodes
* @param {Number} index
* @returns {{min_x: number, max_x: number, min_y: number, max_y: number}}
*/
getTreeSize(nodes, index) {
let min_x = 1e9;
@ -220,6 +236,8 @@ class HierarchicalStatus {
/**
* Check if two nodes have the same parent(s)
*
* @param {vis.Node} node1
* @param {vis.Node} node2
* @return true if the two nodes have a same ancestor node, false otherwise
*/
hasSameParent(node1, node2) {
@ -243,6 +261,8 @@ class HierarchicalStatus {
/**
* Check if two nodes are in the same tree.
*
* @param {vis.Node} node1
* @param {vis.Node} node2
* @return true if this is so, false otherwise
*/
inSameSubNetwork(node1, node2) {
@ -252,6 +272,8 @@ class HierarchicalStatus {
/**
* Get a list of the distinct levels in the current network
*
* @returns {Array}
*/
getLevels() {
return Object.keys(this.distributionOrdering);
@ -260,6 +282,9 @@ class HierarchicalStatus {
/**
* Add a node to the ordering per level
*
* @param {vis.Node} node
* @param {Number} level
*/
addToOrdering(node, level) {
if (this.distributionOrdering[level] === undefined) {
@ -788,6 +813,10 @@ class LayoutEngine {
/**
* Condense elements. These can be nodes or branches depending on the callback.
*
* @param {function} callback
* @param {Array<Number>} levels
* @param {*} centerParents
*/
let shiftElementsCloser = (callback, levels, centerParents) => {
let hier = this.hierarchical;
@ -1063,9 +1092,9 @@ class LayoutEngine {
/**
* This gives the space around the node. IF a map is supplied, it will only check against nodes NOT in the map.
* This is used to only get the distances to nodes outside of a branch.
* @param node
* @param map
* @returns {*[]}
* @param {vis.Node} node
* @param {{vis.Node.id: vis.Node}} map
* @returns {Number[]}
* @private
*/
_getSpaceAroundNode(node, map) {
@ -1106,7 +1135,7 @@ class LayoutEngine {
/**
* We use this method to center a parent node and check if it does not cross other nodes when it does.
* @param node
* @param {vis.Node} node
* @private
*/
_centerParent(node) {
@ -1176,8 +1205,8 @@ class LayoutEngine {
* This is a recursively called function to enumerate the branches from the largest hubs and place the nodes
* on a X position that ensures there will be no overlap.
*
* @param parentId
* @param parentLevel
* @param {vis.Node.id} parentId
* @param {Number} parentLevel
* @private
*/
_placeBranchNodes(parentId, parentLevel) {
@ -1228,9 +1257,9 @@ class LayoutEngine {
/**
* This method checks for overlap and if required shifts the branch. It also keeps records of positioned nodes.
* Finally it will call _placeBranchNodes to place the branch nodes.
* @param node
* @param level
* @param pos
* @param {vis.Node} node
* @param {Number} level
* @param {Number} pos
* @private
*/
_validatePositionAndContinue(node, level, pos) {
@ -1256,7 +1285,8 @@ class LayoutEngine {
/**
* Receives an array with node indices and returns an array with the actual node references.
* Used for sorting based on node properties.
* @param idArray
* @param {Array<vis.Node.id>} idArray
* @returns {Array<vis.Node>}
*/
_indexArrayToNodes(idArray) {
let array = [];
@ -1304,7 +1334,8 @@ class LayoutEngine {
/**
* Return the active (i.e. visible) edges for this node
*
* @returns {array} Array of edge instances
* @param {vis.Node} node
* @returns {Array<vis.Edge>} Array of edge instances
* @private
*/
_getActiveEdges(node) {
@ -1417,7 +1448,6 @@ class LayoutEngine {
/**
* Allocate nodes in levels based on the direction of the edges.
*
* @param hubsize
* @private
*/
_determineLevelsDirected() {
@ -1480,8 +1510,8 @@ class LayoutEngine {
/**
* Crawl over the entire network and use a callback on each node couple that is connected to each other.
* @param callback | will receive nodeA, nodeB and the connecting edge. A and B are distinct.
* @param startingNodeId
* @param {function} [callback=function(){}] | will receive nodeA, nodeB and the connecting edge. A and B are distinct.
* @param {vis.Node.id} startingNodeId
* @private
*/
_crawlNetwork(callback = function() {}, startingNodeId) {
@ -1542,8 +1572,8 @@ class LayoutEngine {
/**
* Shift a branch a certain distance
* @param parentId
* @param diff
* @param {vis.Node.id} parentId
* @param {number} diff
* @private
*/
_shiftBlock(parentId, diff) {
@ -1573,8 +1603,8 @@ class LayoutEngine {
/**
* Find a common parent between branches.
* @param childA
* @param childB
* @param {vis.Node.id} childA
* @param {vis.Node.id} childB
* @returns {{foundParent, withChild}}
* @private
*/
@ -1613,9 +1643,10 @@ class LayoutEngine {
/**
* Abstract the getting of the position so we won't have to repeat the check for direction all the time
* @param node
* @param position
* @param level
* @param {vis.Node} node
* @param {{x: Number, y: Number}} position
* @param {Number} level
* @param {boolean} [doNotUpdate=false]
* @private
*/
_setPositionForHierarchy(node, position, level, doNotUpdate = false) {
@ -1637,7 +1668,7 @@ class LayoutEngine {
* Utility function to cut down on typing this all the time.
*
* TODO: use this in all applicable situations in this class.
*
* @returns {boolean}
* @private
*/
_isVertical() {
@ -1646,7 +1677,7 @@ class LayoutEngine {
/**
* Abstract the getting of the position of a node so we do not have to repeat the direction check all the time.
* @param node
* @param {vis.Node} node
* @returns {number|*}
* @private
*/
@ -1661,7 +1692,8 @@ class LayoutEngine {
/**
* Use the x or y value to sort the array, allowing users to specify order.
* @param nodeArray
*
* @param {Array<vis.Node>} nodeArray
* @private
*/
_sortNodeArray(nodeArray) {
@ -1686,6 +1718,7 @@ class LayoutEngine {
* The return value is the type to use to translate dynamic curves to
* another type, in the case of hierarchical layout. Dynamic curves do
* not work for that layout type.
* @returns {'horizontal'|'vertical'}
*/
getStaticType() {
// Node that 'type' is the edge type, and therefore 'orthogonal' to the layout type.
@ -1702,7 +1735,7 @@ class LayoutEngine {
* Determine the center position of a branch from the passed list of child nodes
*
* This takes into account the positions of all the child nodes.
* @param childNodes {array} Array of either child nodes or node id's
* @param {Array<vis.Node|vis.Node.id>} childNodes Array of either child nodes or node id's
* @return {number}
* @private
*/

+ 29
- 16
lib/network/modules/ManipulationSystem.js View File

@ -72,7 +72,10 @@ class ManipulationSystem {
/**
* Set the Options
* @param options
*
* @param {Object} options
* @param {Object} allOptions