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
* @param {Object} globalOptions
*/
setOptions(options, allOptions, globalOptions) {
if (allOptions !== undefined) {
@ -541,9 +544,10 @@ class ManipulationSystem {
/**
* generate a new target node. Used for creating new edges and editing edges
* @param x
* @param y
* @returns {*}
*
* @param {Number} x
* @param {Number} y
* @returns {vis.Node}
* @private
*/
_getNewTargetNode(x,y) {
@ -660,7 +664,7 @@ class ManipulationSystem {
/**
* create a seperator line. the index is to differentiate in the manipulation dom
* @param index
* @param {Number} [index=1]
* @private
*/
_createSeperator(index = 1) {
@ -734,8 +738,8 @@ class ManipulationSystem {
/**
* this binds an event until cleanup by the clean functions.
* @param event
* @param newFunction
* @param {Event} event The event
* @param {function} newFunction
* @private
*/
_temporaryBindEvent(event, newFunction) {
@ -745,8 +749,8 @@ class ManipulationSystem {
/**
* this overrides an UI function until cleanup by the clean function
* @param UIfunctionName
* @param newFunction
* @param {String} UIfunctionName
* @param {function} newFunction
* @private
*/
_temporaryBindUI(UIfunctionName, newFunction) {
@ -789,8 +793,9 @@ class ManipulationSystem {
/**
* Bind an hammer instance to a DOM element.
* @param domElement
* @param funct
*
* @param {Element} domElement
* @param {function} boundFunction
*/
_bindHammerToDiv(domElement, boundFunction) {
let hammer = new Hammer(domElement, {});
@ -826,7 +831,7 @@ class ManipulationSystem {
/**
* the touch is used to get the position of the initial click
* @param event
* @param {Event} event The event
* @private
*/
_controlNodeTouch(event) {
@ -838,7 +843,7 @@ class ManipulationSystem {
/**
* the drag start is used to mark one of the control nodes as selected.
* @param event
* @param {Event} event The event
* @private
*/
_controlNodeDragStart(event) { // eslint-disable-line no-unused-vars
@ -871,7 +876,7 @@ class ManipulationSystem {
/**
* dragging the control nodes or the canvas
* @param event
* @param {Event} event The event
* @private
*/
_controlNodeDrag(event) {
@ -894,7 +899,7 @@ class ManipulationSystem {
/**
* connecting or restoring the control nodes.
* @param event
* @param {Event} event The event
* @private
*/
_controlNodeDragEnd(event) {
@ -948,6 +953,7 @@ class ManipulationSystem {
* the function bound to the selection event. It checks if you want to connect a cluster and changes the description
* to walk the user through the process.
*
* @param {Event} event
* @private
*/
_handleConnect(event) {
@ -1011,7 +1017,7 @@ class ManipulationSystem {
/**
* Connect the new edge to the target if one exists, otherwise remove temp line
* @param event
* @param {Event} event The event
* @private
*/
_finishConnect(event) {
@ -1068,6 +1074,9 @@ class ManipulationSystem {
/**
* Adds a node on the specified location
*
* @param {Object} clickData
* @private
*/
_performAddNode(clickData) {
let defaultData = {
@ -1101,6 +1110,8 @@ class ManipulationSystem {
/**
* connect two nodes with a new edge.
*
* @param {vis.Node.id} sourceNodeId
* @param {vis.Node.id} targetNodeId
* @private
*/
_performAddEdge(sourceNodeId, targetNodeId) {
@ -1129,6 +1140,8 @@ class ManipulationSystem {
/**
* connect two nodes with a new edge.
*
* @param {vis.Node.id} sourceNodeId
* @param {vis.Node.id} targetNodeId
* @private
*/
_performEditEdge(sourceNodeId, targetNodeId) {

+ 15
- 11
lib/network/modules/NodesHandler.js View File

@ -201,6 +201,7 @@ class NodesHandler {
/**
* Set a data set with nodes for the network
* @param {Array | DataSet | DataView} nodes The data containing the nodes.
* @param {Boolean} [doNotEmit=false]
* @private
*/
setData(nodes, doNotEmit = false) {
@ -251,6 +252,7 @@ class NodesHandler {
/**
* Add nodes
* @param {Number[] | String[]} ids
* @param {Boolean} [doNotEmit=false]
* @private
*/
add(ids, doNotEmit = false) {
@ -336,8 +338,9 @@ class NodesHandler {
/**
* create a node
* @param properties
* @param constructorClass
* @param {Object} properties
* @param {class} [constructorClass=Node.default]
* @returns {*}
*/
create(properties, constructorClass = Node) {
return new constructorClass(properties, this.body, this.images, this.groups, this.options, this.defaultOptions, this.nodeOptions)
@ -364,7 +367,7 @@ class NodesHandler {
/**
* Returns the positions of the nodes.
* @param ids --> optional, can be array of nodeIds, can be string
* @param {Array<vis.Node.id>|String} [ids] --> optional, can be array of nodeIds, can be string
* @returns {{}}
*/
getPositions(ids) {
@ -416,7 +419,7 @@ class NodesHandler {
/**
* get the bounding box of a node.
* @param nodeId
* @param {vis.Node.id} nodeId
* @returns {j|*}
*/
getBoundingBox(nodeId) {
@ -428,9 +431,9 @@ class NodesHandler {
/**
* Get the Ids of nodes connected to this node.
* @param nodeId
* @param direction {String|undefined} values 'from' and 'to' select respectively parent and child nodes only.
* Any other value returns both parent and child nodes.
* @param {vis.Node.id} nodeId
* @param {'to'|'from'|undefined} direction values 'from' and 'to' select respectively parent and child nodes only.
* Any other value returns both parent and child nodes.
* @returns {Array}
*/
getConnectedNodes(nodeId, direction) {
@ -459,7 +462,7 @@ class NodesHandler {
/**
* Get the ids of the edges connected to this node.
* @param nodeId
* @param {vis.Node.id} nodeId
* @returns {*}
*/
getConnectedEdges(nodeId) {
@ -479,9 +482,10 @@ class NodesHandler {
/**
* Move a node.
* @param String nodeId
* @param Number x
* @param Number y
*
* @param {vis.Node.id} nodeId
* @param {Number} x
* @param {Number} y
*/
moveNode(nodeId, x, y) {
if (this.body.nodes[nodeId] !== undefined) {

+ 12
- 5
lib/network/modules/PhysicsEngine.js View File

@ -125,7 +125,7 @@ class PhysicsEngine {
/**
* set the physics options
* @param options
* @param {Object} options
*/
setOptions(options) {
if (options !== undefined) {
@ -242,6 +242,7 @@ class PhysicsEngine {
/**
* Stop the simulation, force stabilization.
* @param {boolean} [emit=true]
*/
stopSimulation(emit = true) {
this.stabilized = true;
@ -284,6 +285,8 @@ class PhysicsEngine {
/**
* trigger the stabilized event.
*
* @param {Number} [amountOfIterations=this.stabilizationIterations]
* @private
*/
_emitStabilized(amountOfIterations = this.stabilizationIterations) {
@ -455,6 +458,9 @@ class PhysicsEngine {
/**
* This compares the reference state to the current state
*
* @returns {boolean}
* @private
*/
_evaluateStepQuality() {
let dx, dy, dpos;
@ -479,7 +485,6 @@ class PhysicsEngine {
/**
* move the nodes one timestep and check if they are stabilized
* @returns {boolean}
*/
moveNodes() {
var nodeIndices = this.physicsBody.physicsNodeIndices;
@ -507,12 +512,12 @@ class PhysicsEngine {
/**
* Perform the actual step
*
* @param nodeId
* @param maxVelocity
* @param {vis.Node.id} nodeId
* @param {number} maxVelocity
* @returns {number}
* @private
*/
_performStep(nodeId,maxVelocity) {
_performStep(nodeId, maxVelocity) {
let node = this.body.nodes[nodeId];
let timestep = this.timestep;
let forces = this.physicsBody.forces;
@ -600,6 +605,8 @@ class PhysicsEngine {
/**
* Find a stable position for all nodes
*
* @param {Number} [iterations=this.options.stabilization.iterations]
*/
stabilize(iterations = this.options.stabilization.iterations) {
if (typeof iterations !== 'number') {

+ 22
- 18
lib/network/modules/SelectionHandler.js View File

@ -36,8 +36,8 @@ class SelectionHandler {
/**
* handles the selection part of the tap;
*
* @param {Object} pointer
* @private
* @param {{x: number, y: number}} pointer
* @returns {boolean}
*/
selectOnPoint(pointer) {
let selected = false;
@ -79,8 +79,9 @@ class SelectionHandler {
/**
* Create an object containing the standard fields for an event.
*
* @param {Event} event
* @param {Object} pointer | object with the x and y screen coordinates of the mouse
* @param {Event} event
* @param {{x: number, y: number}} pointer Object with the x and y screen coordinates of the mouse
* @returns {{}}
* @private
*/
_initBaseEvent(event, pointer) {
@ -102,11 +103,11 @@ class SelectionHandler {
* This adds some extra data to the event with respect to cursor position and
* selected nodes and edges.
*
* @param {String} eventType | Name of event to send
* @param {String} eventType Name of event to send
* @param {Event} event
* @param {Object} pointer | object with the x and y screen coordinates of the mouse
* @param {Object|undefined} object | If present, selection state before event occured
* @param {boolean|undefined} | Indicate if selection data should be passed
* @param {{x: number, y: number}} pointer Object with the x and y screen coordinates of the mouse
* @param {Object|undefined} oldSelection If present, selection state before event occured
* @param {boolean|undefined} [emptySelection=false] Indicate if selection data should be passed
*/
_generateClickEvent(eventType, event, pointer, oldSelection, emptySelection = false) {
let properties = this._initBaseEvent(event, pointer);
@ -172,7 +173,7 @@ class SelectionHandler {
/**
* Return a position object in canvasspace from a single point in screenspace
*
* @param pointer
* @param {{x: number, y: number}} pointer
* @returns {{left: number, top: number, right: number, bottom: number}}
* @private
*/
@ -191,6 +192,7 @@ class SelectionHandler {
* Get the top node at the passed point (like a click)
*
* @param {{x: Number, y: Number}} pointer
* @param {boolean} [returnNode=true]
* @return {Node | undefined} node
*/
getNodeAt(pointer, returnNode = true) {
@ -216,7 +218,7 @@ class SelectionHandler {
/**
* retrieve all edges overlapping with given object, selector is around center
* @param {Object} object An object with parameters left, top, right, bottom
* @return {Number[]} An array with id's of the overlapping nodes
* @param {Number[]} overlappingEdges An array with id's of the overlapping nodes
* @private
*/
_getEdgesOverlappingWith(object, overlappingEdges) {
@ -247,6 +249,7 @@ class SelectionHandler {
* Get the edges nearest to the passed point (like a click)
*
* @param {{x: Number, y: Number}} pointer
* @param {boolean} [returnEdge=true]
* @return {Edge | undefined} node
*/
getEdgeAt(pointer, returnEdge = true) {
@ -287,7 +290,7 @@ class SelectionHandler {
/**
* Add object to the selection array.
*
* @param obj
* @param {Object} obj
* @private
*/
_addToSelection(obj) {
@ -302,7 +305,7 @@ class SelectionHandler {
/**
* Add object to the selection array.
*
* @param obj
* @param {Object} obj
* @private
*/
_addToHover(obj) {
@ -521,8 +524,8 @@ class SelectionHandler {
* Remove the highlight from a node or edge, in response to mouse movement
*
* @param {Event} event
* @param {Object} pointer | object with the x and y screen coordinates of the mouse
* @param {Node || Edge} object
* @param {{x: number, y: number}} pointer object with the x and y screen coordinates of the mouse
* @param {vis.Node|vis.Edge} object
* @private
*/
emitBlurEvent(event, pointer, object) {
@ -546,8 +549,9 @@ class SelectionHandler {
* Create the highlight for a node or edge, in response to mouse movement
*
* @param {Event} event
* @param {Object} pointer | object with the x and y screen coordinates of the mouse
* @param {Node || Edge} object
* @param {{x: number, y: number}} pointer object with the x and y screen coordinates of the mouse
* @param {vis.Node|vis.Edge} object
* @returns {boolean} hoverChanged
* @private
*/
emitHoverEvent(event, pointer, object) {
@ -576,7 +580,7 @@ class SelectionHandler {
* Perform actions in response to a mouse movement.
*
* @param {Event} event
* @param {Object} pointer | object with the x and y screen coordinates of the mouse
* @param {{x: number, y: number}} pointer | object with the x and y screen coordinates of the mouse
*/
hoverObject(event, pointer) {
let object = this.getNodeAt(pointer);
@ -679,7 +683,7 @@ class SelectionHandler {
/**
* Updates the current selection
* @param {{nodes: Array.<String>, edges: Array.<String>}} Selection
* @param {{nodes: Array.<String>, edges: Array.<String>}} selection
* @param {Object} options Options
*/
setSelection(selection, options = {}) {

+ 3
- 4
lib/network/modules/View.js View File

@ -33,8 +33,8 @@ class View {
/**
* This function zooms out to fit all data on screen based on amount of nodes
* @param {Object} Options
* @param {Boolean} [initialZoom] | zoom based on fitted formula or range, true = fitted, default = false;
* @param {Object} [options={{nodes=Array}}]
* @param {Boolean} [initialZoom=false] | zoom based on fitted formula or range, true = fitted, default = false;
*/
fit(options = {nodes:[]}, initialZoom = false) {
let range;
@ -239,8 +239,7 @@ class View {
}
/**
*
* @param easingTime
* @param {boolean} [finished=false]
* @private
*/
_transitionRedraw(finished = false) {

+ 7
- 5
lib/network/modules/components/Edge.js View File

@ -7,8 +7,6 @@ var BezierEdgeStatic = require('./edges/BezierEdgeStatic').default;
var StraightEdge = require('./edges/StraightEdge').default;
/**
* @class Edge
*
* A edge connects two nodes
* @param {Object} properties Object with options. Must contain
* At least options from and to.
@ -20,6 +18,7 @@ var StraightEdge = require('./edges/StraightEdge').default;
* nodes.
* @param {Object} constants An object with default values for
* example for the color
* @class Edge
*/
class Edge {
constructor(options, body, globalOptions, defaultOptions, edgeOptions) {
@ -58,7 +57,7 @@ class Edge {
/**
* Set or overwrite options for the edge
* @param {Object} options an object with options
* @param doNotEmit
* @returns {null|boolean} null if no options, boolean if date changed
*/
setOptions(options) {
if (!options) {
@ -297,6 +296,8 @@ class Edge {
/**
* update the options in the label module
*
* @param {Object} options
*/
updateLabelModule(options) {
this.labelModule.setOptions(this.options, true);
@ -431,7 +432,7 @@ class Edge {
* based on its value.
* @param {Number} min
* @param {Number} max
* @param total
* @param {Number} total
*/
setValueRange(min, max, total) {
if (this.options.value !== undefined) {
@ -618,7 +619,7 @@ class Edge {
* @param {Number} x
* @param {Number} y
* @param {Number} radius
* @param {Number} percentage. Value between 0 (line start) and 1 (line end)
* @param {Number} percentage Value between 0 (line start) and 1 (line end)
* @return {Object} point
* @private
*/
@ -662,6 +663,7 @@ class Edge {
/**
* Check if both connecting nodes exist
* @returns {boolean}
*/
endPointsValid() {
return this.body.nodes[this.fromId] !== undefined

+ 16
- 12
lib/network/modules/components/Node.js View File

@ -20,7 +20,6 @@ var { printStyle } = require("../../../shared/Validator");
/**
* @class Node
* A node. A node can be connected to other nodes via one or multiple edges.
* @param {object} options An object containing options for the node. All
* options are optional, except for the id.
@ -42,7 +41,7 @@ var { printStyle } = require("../../../shared/Validator");
* retrieving group options
* @param {Object} constants An object with default values for
* example for the color
*
* @class Node
*/
class Node {
constructor(options, body, imagelist, grouplist, globalOptions, defaultOptions, nodeOptions) {
@ -86,6 +85,7 @@ class Node {
/**
* Detach a edge from the node
*
* @param {Edge} edge
*/
detachEdge(edge) {
@ -98,8 +98,9 @@ class Node {
/**
* Set or overwrite options for the node
*
* @param {Object} options an object with options
* @param {Object} constants and object with default, global options
* @returns {null|boolean}
*/
setOptions(options) {
let currentShape = this.options.shape;
@ -147,10 +148,7 @@ class Node {
this.updateShape(currentShape);
this.labelModule.propagateFonts(this.nodeOptions, options, this.defaultOptions);
if (options.hidden !== undefined || options.physics !== undefined) {
return true;
}
return false;
return (options.hidden !== undefined || options.physics !== undefined);
}
@ -197,10 +195,11 @@ class Node {
/**
* This process all possible shorthands in the new options and makes sure that the parentOptions are fully defined.
* Static so it can also be used by the handler.
* @param parentOptions
* @param newOptions
* @param allowDeletion
* @param globalOptions
*
* @param {Object} parentOptions
* @param {Object} newOptions
* @param {boolean} [allowDeletion=false]
* @param {Object} [globalOptions={}]
*/
static parseOptions(parentOptions, newOptions, allowDeletion = false, globalOptions = {}) {
var fields = [
@ -465,6 +464,7 @@ class Node {
* based on its value.
* @param {Number} min
* @param {Number} max
* @param {Number} total
*/
setValueRange(min, max, total) {
if (this.options.value !== undefined) {
@ -498,6 +498,7 @@ class Node {
/**
* Update the bounding box of the shape
* @param {CanvasRenderingContext2D} ctx
*/
updateBoundingBox(ctx) {
this.shape.updateBoundingBox(this.x,this.y,ctx);
@ -543,10 +544,13 @@ class Node {
}
/**
/**
* Check valid values for mass
*
* The mass may not be negative or zero. If it is, reset to 1
*
* @param {object} options
* @param {vis.Node.id} id
*/
static checkMass(options, id) {
if (options.mass !== undefined && options.mass <= 0) {

+ 23
- 2
lib/network/modules/components/edges/BezierEdgeDynamic.js View File

@ -100,6 +100,8 @@ class BezierEdgeDynamic extends BezierEdgeBase {
/**
* Draw a line between two nodes
* @param {CanvasRenderingContext2D} ctx
* @param {Array<Object>} values
* @param {vis.Node} viaNode
* @private
*/
_line(ctx, values, viaNode) {
@ -113,8 +115,9 @@ class BezierEdgeDynamic extends BezierEdgeBase {
/**
* Combined function of pointOnLine and pointOnBezier. This gives the coordinates of a point on the line at a certain percentage of the way
* @param percentage
* @param viaNode
*
* @param {number} percentage
* @param {vis.Node} viaNode
* @returns {{x: number, y: number}}
* @private
*/
@ -134,10 +137,28 @@ class BezierEdgeDynamic extends BezierEdgeBase {
return {x: x, y: y};
}
/**
*
* @param {vis.Node} nearNode
* @param {CanvasRenderingContext2D} ctx
* @returns {*}
* @private
*/
_findBorderPosition(nearNode, ctx) {
return this._findBorderPositionBezier(nearNode, ctx, this.via);
}
/**
*
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @param {number} x3
* @param {number} y3
* @returns {number}
* @private
*/
_getDistanceToEdge(x1, y1, x2, y2, x3, y3) { // x3,y3 is the point
return this._getDistanceToBezierEdge(x1, y1, x2, y2, x3, y3, this.via);
}

+ 24
- 2
lib/network/modules/components/edges/BezierEdgeStatic.js View File

@ -8,6 +8,8 @@ class BezierEdgeStatic extends BezierEdgeBase {
/**
* Draw a line between two nodes
* @param {CanvasRenderingContext2D} ctx
* @param {Array<Object>} values
* @param {vis.Node} viaNode
* @private
*/
_line(ctx, values, viaNode) {
@ -142,18 +144,38 @@ class BezierEdgeStatic extends BezierEdgeBase {
return {x: xVia, y: yVia};
}
/**
*
* @param {vis.Node} nearNode
* @param {CanvasRenderingContext2D} ctx
* @param {Object} options
* @returns {*}
* @private
*/
_findBorderPosition(nearNode, ctx, options = {}) {
return this._findBorderPositionBezier(nearNode, ctx, options.via);
}
/**
*
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @param {number} x3
* @param {number} y3
* @param {vis.Node} viaNode
* @returns {number}
* @private
*/
_getDistanceToEdge(x1, y1, x2, y2, x3, y3, viaNode = this._getViaCoordinates()) { // x3,y3 is the point
return this._getDistanceToBezierEdge(x1, y1, x2, y2, x3, y3, viaNode);
}
/**
* Combined function of pointOnLine and pointOnBezier. This gives the coordinates of a point on the line at a certain percentage of the way
* @param percentage
* @param viaNode
* @param {number} percentage
* @param {vis.Node} viaNode
* @returns {{x: number, y: number}}
* @private
*/

+ 5
- 2
lib/network/modules/components/edges/CubicBezierEdge.js View File

@ -8,6 +8,8 @@ class CubicBezierEdge extends CubicBezierEdgeBase {
/**
* Draw a line between two nodes
* @param {CanvasRenderingContext2D} ctx
* @param {Array<Object>} values
* @param {Array<vis.Node>} viaNodes
* @private
*/
_line(ctx, values, viaNodes) {
@ -55,8 +57,9 @@ class CubicBezierEdge extends CubicBezierEdgeBase {
/**
* Combined function of pointOnLine and pointOnBezier. This gives the coordinates of a point on the line at a certain percentage of the way
* @param percentage
* @param via
* @param {number} percentage
* @param {{x: number, y: number}} [via1=this._getViaCoordinates()[0]]
* @param {{x: number, y: number}} [via2=this._getViaCoordinates()[1]]
* @returns {{x: number, y: number}}
* @private
*/

+ 3
- 2
lib/network/modules/components/edges/StraightEdge.js View File

@ -8,6 +8,7 @@ class StraightEdge extends EdgeBase {
/**
* Draw a line between two nodes
* @param {CanvasRenderingContext2D} ctx
* @param {Array<Object>} values
* @private
*/
_line(ctx, values) {
@ -27,8 +28,8 @@ class StraightEdge extends EdgeBase {
/**
* Combined function of pointOnLine and pointOnBezier. This gives the coordinates of a point on the line at a certain percentage of the way
* @param percentage
* @param via
*
* @param {number} percentage
* @returns {{x: number, y: number}}
* @private
*/

+ 7
- 9
lib/network/modules/components/edges/util/BezierEdgeBase.js View File

@ -8,15 +8,11 @@ class BezierEdgeBase extends EdgeBase {
/**
* This function uses binary search to look for the point where the bezier curve crosses the border of the node.
*
* @param nearNode
* @param ctx
* @param viaNode
* @param nearNode
* @param ctx
* @param viaNode
* @param nearNode
* @param ctx
* @param viaNode
* @param {vis.Node} nearNode
* @param {CanvasRenderingContext2D} ctx
* @param {vis.Node} viaNode
* @returns {*}
* @private
*/
_findBorderPositionBezier(nearNode, ctx, viaNode = this._getViaCoordinates()) {
var maxIterations = 10;
@ -79,6 +75,8 @@ class BezierEdgeBase extends EdgeBase {
* @param {number} y2 to y
* @param {number} x3 point to check x
* @param {number} y3 point to check y
* @param {vis.Node} via
* @returns {number}
* @private
*/
_getDistanceToBezierEdge(x1, y1, x2, y2, x3, y3, via) { // x3,y3 is the point

+ 3
- 0
lib/network/modules/components/edges/util/CubicBezierEdgeBase.js View File

@ -16,6 +16,9 @@ class CubicBezierEdgeBase extends BezierEdgeBase {
* @param {number} y2 to y
* @param {number} x3 point to check x
* @param {number} y3 point to check y
* @param {vis.Node} via1
* @param {vis.Node} via2
* @returns {number}
* @private
*/
_getDistanceToBezierEdge(x1, y1, x2, y2, x3, y3, via1, via2) { // x3,y3 is the point

+ 28
- 13
lib/network/modules/components/edges/util/EdgeBase.js View File

@ -34,7 +34,12 @@ class EdgeBase {
* Redraw a edge as a line
* Draw this edge in the given canvas
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
*
* @param {CanvasRenderingContext2D} ctx
* @param {Array} values
* @param {boolean} selected
* @param {boolean} hover
* @param {vis.Node} viaNode
* @private
*/
drawLine(ctx, values, selected, hover, viaNode) {
@ -165,7 +170,7 @@ class EdgeBase {
* @param {Number} x
* @param {Number} y
* @param {Number} radius
* @param {Number} percentage. Value between 0 (line start) and 1 (line end)
* @param {Number} percentage - Value between 0 (line start) and 1 (line end)
* @return {Object} point
* @private
*/
@ -179,9 +184,9 @@ class EdgeBase {
/**
* This function uses binary search to look for the point where the circle crosses the border of the node.
* @param node
* @param ctx
* @param options
* @param {vis.Node} node
* @param {CanvasRenderingContext2D} ctx
* @param {Object} options
* @returns {*}
* @private
*/
@ -237,6 +242,8 @@ class EdgeBase {
/**
* Get the line width of the edge. Depends on width and whether one of the
* connected nodes is selected.
* @param {boolean} selected
* @param {boolean} hover
* @return {Number} width
* @private
*/
@ -293,7 +300,9 @@ class EdgeBase {
/**
* Draw a line from a node to itself, a circle
*
* @param {CanvasRenderingContext2D} ctx
* @param {Array} values
* @param {Number} x
* @param {Number} y
* @param {Number} radius
@ -324,7 +333,9 @@ class EdgeBase {
* @param {number} y2
* @param {number} x3
* @param {number} y3
* @param via
* @param {vis.Node} via
* @param {Array} values
* @returns {number}
* @private
*/
getDistanceToEdge(x1, y1, x2, y2, x3, y3, via, values) { // eslint-disable-line no-unused-vars
@ -379,10 +390,13 @@ class EdgeBase {
/**
*
* @param ctx
* @param position
* @param viaNode
* @param {CanvasRenderingContext2D} ctx
* @param {string} position
* @param {vis.Node} viaNode
* @param {boolean} selected
* @param {boolean} hover
* @param {Array} values
* @returns {{point: *, core: {x: number, y: number}, angle: *, length: number, type: *}}
*/
getArrowData(ctx, position, viaNode, selected, hover, values) {
// set lets
@ -459,10 +473,11 @@ class EdgeBase {
/**
*
* @param ctx
* @param selected
* @param hover
* @param arrowData
* @param {CanvasRenderingContext2D} ctx
* @param {Array<Object>} values
* @param {boolean} selected
* @param {boolean} hover
* @param {Object} arrowData
*/
drawArrowHead(ctx, values, selected, hover, arrowData) {
// set style

+ 1
- 1
lib/network/modules/components/nodes/util/CircleImageBase.js View File

@ -39,7 +39,7 @@ class CircleImageBase extends NodeBase {
* field 'nodes.brokenImage' in the options.
*
* @param {Image} imageObj required; main image to show for this node
* @param {Image|undefined} optional; image to show when node is selected
* @param {Image|undefined} imageObjAlt optional; image to show when node is selected
*/
setImages(imageObj, imageObjAlt) {
if (imageObjAlt && this.selected) {

+ 16
- 1
lib/network/modules/components/nodes/util/NodeBase.js View File

@ -95,6 +95,9 @@ class NodeBase {
/**
* Determine if the shape of a node needs to be recalculated.
*
* @param {boolean} selected
* @param {boolean} hover
* @returns {boolean}
* @protected
*/
needsRefresh(selected, hover) {
@ -160,6 +163,13 @@ class NodeBase {
*
* Doing it like this makes it easier to override
* in the child classes.
*
* @param {number} x width
* @param {number} y height
* @param {CanvasRenderingContext2D} ctx
* @param {boolean} selected
* @param {boolean} hover
* @private
*/
_updateBoundingBox(x, y, ctx, selected, hover) {
if (ctx !== undefined) {
@ -178,8 +188,13 @@ class NodeBase {
/**
* Default implementation of this method call.
*
* This acts as a stub which can be overridden.
*
* @param {number} x width
* @param {number} y height
* @param {CanvasRenderingContext2D} ctx
* @param {boolean} selected
* @param {boolean} hover
*/
updateBoundingBox(x, y, ctx, selected, hover) {
this._updateBoundingBox(x, y, ctx, selected, hover);

+ 26
- 27
lib/network/modules/components/physics/BarnesHutSolver.js View File

@ -1,4 +1,3 @@
class BarnesHutSolver {
constructor(body, physicsBody, options) {
this.body = body;
@ -61,8 +60,8 @@ class BarnesHutSolver {
* This function traverses the barnesHutTree. It checks when it can approximate distant nodes with their center of mass.
* If a region contains a single node, we check if it is not itself, then we apply the force.
*
* @param parentBranch
* @param node
* @param {Object} parentBranch
* @param {vis.Node} node
* @private
*/
_getForceContribution(parentBranch, node) {
@ -102,11 +101,11 @@ class BarnesHutSolver {
/**
* Calculate the forces based on the distance.
*
* @param distance
* @param dx
* @param dy
* @param node
* @param parentBranch
* @param {number} distance
* @param {number} dx
* @param {number} dy
* @param {vis.Node} node
* @param {Object} parentBranch
* @private
*/
_calculateForces(distance, dx, dy, node, parentBranch) {
@ -133,8 +132,9 @@ class BarnesHutSolver {
/**
* This function constructs the barnesHut tree recursively. It creates the root, splits it and starts placing the nodes.
*
* @param nodes
* @param nodeIndices
* @param {Array<vis.Node>} nodes
* @param {Array<number>} nodeIndices
* @returns {{root: {centerOfMass: {x: number, y: number}, mass: number, range: {minX: number, maxX: number, minY: number, maxY: number}, size: number, calcSize: number, children: {data: null}, maxWidth: number, level: number, childrenCount: number}}} BarnesHutTree
* @private
*/
_formBarnesHutTree(nodes, nodeIndices) {
@ -217,8 +217,8 @@ class BarnesHutSolver {
/**
* this updates the mass of a branch. this is increased by adding a node.
*
* @param parentBranch
* @param node
* @param {Object} parentBranch
* @param {vis.Node} node
* @private
*/
_updateBranchMass(parentBranch, node) {
@ -241,9 +241,9 @@ class BarnesHutSolver {
/**
* determine in which branch the node will be placed.
*
* @param parentBranch
* @param node
* @param skipMassUpdate
* @param {Object} parentBranch
* @param {vis.Node} node
* @param {boolean} skipMassUpdate
* @private
*/
_placeInTree(parentBranch, node, skipMassUpdate) {
@ -274,9 +274,9 @@ class BarnesHutSolver {
/**
* actually place the node in a region (or branch)
*
* @param parentBranch
* @param node
* @param region
* @param {Object} parentBranch
* @param {vis.Node} node
* @param {'NW'| 'NE' | 'SW' | 'SE'} region
* @private
*/
_placeInRegion(parentBranch, node, region) {
@ -310,7 +310,7 @@ class BarnesHutSolver {
* this function splits a branch into 4 sub branches. If the branch contained a node, we place it in the subbranch
* after the split is complete.
*
* @param parentBranch
* @param {Object} parentBranch
* @private
*/
_splitBranch(parentBranch) {
@ -340,9 +340,8 @@ class BarnesHutSolver {
* Specifically, this inserts a single new segment.
* It fills the children section of the parentBranch
*
* @param parentBranch
* @param region
* @param parentRange
* @param {Object} parentBranch
* @param {'NW'| 'NE' | 'SW' | 'SE'} region
* @private
*/
_insertRegion(parentBranch, region) {
@ -398,8 +397,8 @@ class BarnesHutSolver {
/**
* This function is for debugging purposed, it draws the tree.
*
* @param ctx
* @param color
* @param {CanvasRenderingContext2D} ctx
* @param {string} color
* @private
*/
_debug(ctx, color) {
@ -415,9 +414,9 @@ class BarnesHutSolver {
/**
* This function is for debugging purposes. It draws the branches recursively.
*
* @param branch
* @param ctx
* @param color
* @param {Object} branch
* @param {CanvasRenderingContext2D} ctx
* @param {string} color
* @private
*/
_drawBranch(branch, ctx, color) {

+ 5
- 0
lib/network/modules/components/physics/CentralGravitySolver.js View File

@ -28,6 +28,11 @@ class CentralGravitySolver {
/**
* Calculate the forces based on the distance.
* @param {number} distance
* @param {number} dx
* @param {number} dy
* @param {Object<vis.Node.id, vis.Node>} forces
* @param {vis.Node} node
* @private
*/
_calculateForces(distance, dx, dy, forces, node) {

+ 6
- 0
lib/network/modules/components/physics/FA2BasedCentralGravitySolver.js View File

@ -8,6 +8,12 @@ class ForceAtlas2BasedCentralGravitySolver extends CentralGravitySolver {
/**
* Calculate the forces based on the distance.
*
* @param {number} distance
* @param {number} dx
* @param {number} dy
* @param {Object<vis.Node.id, vis.Node>} forces
* @param {vis.Node} node
* @private
*/
_calculateForces(distance, dx, dy, forces, node) {

+ 5
- 5
lib/network/modules/components/physics/FA2BasedRepulsionSolver.js View File

@ -8,11 +8,11 @@ class ForceAtlas2BasedRepulsionSolver extends BarnesHutSolver {
/**
* Calculate the forces based on the distance.
*
* @param distance
* @param dx
* @param dy
* @param node
* @param parentBranch
* @param {number} distance
* @param {number} dx
* @param {number} dy
* @param {vis.Node} node
* @param {Object} parentBranch
* @private
*/
_calculateForces(distance, dx, dy, node, parentBranch) {

+ 1
- 0
lib/network/modules/components/physics/RepulsionSolver.js View File

@ -8,6 +8,7 @@ class RepulsionSolver {
setOptions(options) {
this.options = options;
}
/**
* Calculate the forces the nodes apply on each other based on a repulsion field.
* This field is linearly approximated.

+ 3
- 3
lib/network/modules/components/physics/SpringSolver.js View File

@ -50,9 +50,9 @@ class SpringSolver {
/**
* This is the code actually performing the calculation for the function above.
*
* @param node1
* @param node2
* @param edgeLength
* @param {vis.Node} node1
* @param {vis.Node} node2
* @param {number} edgeLength
* @private
*/
_calculateSpringForce(node1, node2, edgeLength) {

+ 85
- 49
lib/network/modules/components/shared/Label.js View File

@ -23,7 +23,7 @@ class LabelAccumulator {
*
* @param {number} l index of line to add to
* @param {string} text string to append to line
* @param {boolean} mod id of multi-font to use, default 'normal'
* @param {'bold'|'ital'|'boldital'|'mono'|'normal'} [mod='normal']
* @private
*/
_add(l, text, mod = 'normal') {
@ -54,6 +54,8 @@ class LabelAccumulator {
/**
* Returns the width in pixels of the current line.
*
* @returns {number}
*/
curWidth() {
let line = this.lines[this.current];
@ -65,6 +67,9 @@ class LabelAccumulator {
/**
* Add text in block to current line
*
* @param {string} text
* @param {'bold'|'ital'|'boldital'|'mono'|'normal'} [mod='normal']
*/
append(text, mod = 'normal') {
this._add(this.current, text, mod);
@ -73,8 +78,11 @@ class LabelAccumulator {
/**
* Add text in block to current line and start a new line
*
* @param {string} text
* @param {'bold'|'ital'|'boldital'|'mono'|'normal'} [mod='normal']
*/
newLine(text, mod = 'normal') {
newLine(text, mod = 'normal') {
this._add(this.current, text, mod);
this.current++;
}
@ -82,6 +90,8 @@ class LabelAccumulator {
/**
* Set the sizes for all lines and the whole thing.
*
* @returns {{width: (number|*), height: (number|*), lines: Array}}
*/
finalize() {
// console.log(JSON.stringify(this.lines, null, 2));
@ -180,10 +190,9 @@ class Label {
* - No number conversion (size)
* - Not all font options are set (vadjust, mod)
*
* @param inOptions {Object} font options to parse
* @param outOptions {Object} out-parameter, object in which to store the parse results (if any)
*
* @return true if font parsed as string, false otherwise
* @param {Object} outOptions out-parameter, object in which to store the parse results (if any)
* @param {Object} inOptions font options to parse
* @return {boolean} true if font parsed as string, false otherwise
*/
static parseFontString(outOptions, inOptions) {
if (!inOptions || typeof inOptions !== 'string') return false;
@ -283,6 +292,10 @@ class Label {
*
* NOTE: naming of 'groupOptions' is a misnomer; the actual value passed
* is the new values to set from setOptions().
*
* @param {Object} options
* @param {Object} groupOptions
* @param {Object} defaultOptions
*/
propagateFonts(options, groupOptions, defaultOptions) {
if (!this.fontOptions.multi) return;
@ -292,10 +305,9 @@ class Label {
* If valid, return a reference to the object in question.
* Otherwise, just return null.
*
* param 'mod' is optional.
*
* options {Object} base object to determine path from
* mod {string|undefined} if present, sub path for the mod-font
* @param {Object} options base object to determine path from
* @param {'bold'|'ital'|'boldital'|'mono'|'normal'} [mod=undefined] if present, sub path for the mod-font
* @returns {Object|null}
*/
var pathP = function(options, mod) {
if (!options || !options.font) return null;
@ -315,7 +327,10 @@ class Label {
* Get property value from options.font[mod][property] if present.
* If mod not passed, use property value from options.font[property].
*
* @return value if found, null otherwise.
* @param {vis.Label.options} options
* @param {'bold'|'ital'|'boldital'|'mono'|'normal'} mod
* @param {string} property
* @return {*|null} value if found, null otherwise.
*/
var getP = function(options, mod, property) {
let opt = pathP(options, mod);
@ -413,11 +428,12 @@ class Label {
/**
* Main function. This is called from anything that wants to draw a label.
* @param ctx
* @param x
* @param y
* @param selected
* @param baseline
* @param {CanvasRenderingContext2D} ctx
* @param {number} x
* @param {number} y
* @param {boolean} selected
* @param {boolean} hover
* @param {string} [baseline='middle']
*/
draw(ctx, x, y, selected, hover, baseline = 'middle') {
// if no label, return
@ -473,9 +489,12 @@ class Label {
/**
*
* @param ctx
* @param x
* @param baseline
* @param {CanvasRenderingContext2D} ctx
* @param {boolean} selected
* @param {boolean} hover
* @param {number} x
* @param {number} y
* @param {string} [baseline='middle']
* @private
*/
_drawText(ctx, selected, hover, x, y, baseline = 'middle') {
@ -483,13 +502,14 @@ class Label {
let viewFontSize = fontSize * this.body.view.scale;
// this ensures that there will not be HUGE letters on screen by setting an upper limit on the visible text size (regardless of zoomLevel)
if (viewFontSize >= this.elementOptions.scaling.label.maxVisible) {
// TODO: Does this actually do anything?
fontSize = Number(this.elementOptions.scaling.label.maxVisible) / this.body.view.scale;
}
let yLine = this.size.yLine;
[x, yLine] = this._setAlignment(ctx, x, yLine, baseline);
ctx.textAlign = 'left'
ctx.textAlign = 'left';
x = x - this.size.width / 2; // Shift label 1/2-distance to the left
if ((this.fontOptions.valign) && (this.size.height > this.size.labelHeight)) {
if (this.fontOptions.valign === 'top') {
@ -531,6 +551,15 @@ class Label {
}
}
/**
*
* @param {CanvasRenderingContext2D} ctx
* @param {Number} x
* @param {Number} yLine
* @param {String} baseline
* @returns {Array<Number>}
* @private
*/
_setAlignment(ctx, x, yLine, baseline) {
// check for label alignment (for edges)
// TODO: make alignment for nodes
@ -561,8 +590,10 @@ class Label {
* fade in when relative scale is between threshold and threshold - 1.
* If the relative scale would be smaller than threshold -1 the draw function would have returned before coming here.
*
* @param viewFontSize
* @returns {*[]}
* @param {string} color The font color to use
* @param {number} viewFontSize
* @param {string} initialStrokeColor
* @returns {Array<string>} An array containing the font color and stroke color
* @private
*/
_getColor(color, viewFontSize, initialStrokeColor) {
@ -576,11 +607,11 @@ class Label {
return [fontColor, strokeColor];
}
/**
*
* @param ctx
* @param selected
* @param {CanvasRenderingContext2D} ctx
* @param {boolean} selected
* @param {boolean} hover
* @returns {{width: number, height: number}}
*/
getTextSize(ctx, selected = false, hover = false) {
@ -595,11 +626,12 @@ class Label {
/**
*
* @param ctx
* @param selected
* @param x
* @param y
* @param baseline
* @param {CanvasRenderingContext2D} ctx
* @param {boolean} selected
* @param {boolean} hover
* @param {number} [x=0]
* @param {number} [y=0]
* @param {'middle'|'hanging'} [baseline='middle']
*/
calculateLabelSize(ctx, selected, hover, x = 0, y = 0, baseline = 'middle') {
if (this.labelDirty === true) {
@ -618,6 +650,9 @@ class Label {
/**
* normalize the markup system
*
* @param {boolean|'md'|'markdown'|'html'} markupSystem
* @returns {string}
*/
decodeMarkupSystem(markupSystem) {
let system = 'none';
@ -631,9 +666,9 @@ class Label {
/**
* Explodes a piece of text into single-font blocks using a given markup
* @param text
* @param markupSystem
* @returns [{ text, mod }]
* @param {string} text
* @param {boolean|'md'|'markdown'|'html'} markupSystem
* @returns {Array<{text: string, mod: string}>}
*/
splitBlocks(text, markupSystem) {
let system = this.decodeMarkupSystem(markupSystem);
@ -926,10 +961,11 @@ class Label {
/**
* This explodes the passed text into lines and determines the width, height and number of lines.
*
* @param ctx
* @param selected
* @param hover
* @param {CanvasRenderingContext2D} ctx
* @param {boolean} selected
* @param {boolean} hover
* @param {String} text the text to explode
* @returns {{width, height, lines}|*}
* @private
*/
_processLabelText(ctx, selected, hover, text) {
@ -972,7 +1008,7 @@ class Label {
let overMaxWidth = function(text) {
let width = ctx.measureText(text).width;
return (lines.curWidth() + width > self.fontOptions.maxWdt);
}
};
/**
@ -980,7 +1016,7 @@ class Label {
* current max width.
*
* @param {Array} words Array of strings signifying a text lines
* @return index of first item in string making string go over max
* @return {number} index of first item in string making string go over max
*/
let getLongestFit = function(words) {
let text = '';
@ -996,25 +1032,25 @@ class Label {
}
return w;
}
};
/**
* Determine the longest part of th string which still fits in the
* Determine the longest part of the string which still fits in the
* current max width.
*
* @param {Array} words Array of strings signifying a text lines
* @return index of first item in string making string go over max
* @return {number} index of first item in string making string go over max
*/
let getLongestFitWord = function(word) {
let getLongestFitWord = function(words) {
let w = 0;
while (w < word.length) {
if (overMaxWidth(word.slice(0,w))) break;
while (w < words.length) {
if (overMaxWidth(words.slice(0,w))) break;
w++;
}
return w;
}
};
let splitStringIntoLines = function(str, mod = 'normal', appendLast = false) {
@ -1046,7 +1082,7 @@ class Label {
words = words.slice(w);
}
}
}
};
let nlLines = String(text).split('\n');
@ -1104,9 +1140,9 @@ class Label {
/**
* This explodes the label string into lines and sets the width, height and number of lines.
* @param ctx
* @param selected
* @param hover
* @param {CanvasRenderingContext2D} ctx
* @param {boolean} selected
* @param {boolean} hover
* @private
*/
_processLabel(ctx, selected, hover) {

+ 36
- 0
lib/network/shapes.js View File

@ -5,6 +5,10 @@ if (typeof CanvasRenderingContext2D !== 'undefined') {
/**
* Draw a circle shape
*
* @param {Number} x
* @param {Number} y
* @param {Number} r
*/
CanvasRenderingContext2D.prototype.circle = function (x, y, r) {
this.beginPath();
@ -125,6 +129,12 @@ if (typeof CanvasRenderingContext2D !== 'undefined') {
/**
* http://stackoverflow.com/questions/1255512/how-to-draw-a-rounded-rectangle-on-html-canvas
*
* @param {Number} x
* @param {Number} y
* @param {Number} w
* @param {Number} h
* @param {Number} r
*/
CanvasRenderingContext2D.prototype.roundRect = function (x, y, w, h, r) {
var r2d = Math.PI / 180;
@ -151,6 +161,11 @@ if (typeof CanvasRenderingContext2D !== 'undefined') {
* http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
*
* Postfix '_vis' added to discern it from standard method ellipse().
*
* @param {Number} x
* @param {Number} y
* @param {Number} w
* @param {Number} h
*/
CanvasRenderingContext2D.prototype.ellipse_vis = function (x, y, w, h) {
var kappa = .5522848,
@ -173,6 +188,11 @@ if (typeof CanvasRenderingContext2D !== 'undefined') {
/**
* http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
*
* @param {Number} x
* @param {Number} y
* @param {Number} w
* @param {Number} h
*/
CanvasRenderingContext2D.prototype.database = function (x, y, w, h) {
var f = 1 / 3;
@ -209,6 +229,11 @@ if (typeof CanvasRenderingContext2D !== 'undefined') {
/**
* Draw an arrow at the end of a line with the given angle.
*
* @param {Number} x
* @param {Number} y
* @param {Number} angle
* @param {Number} length
*/
CanvasRenderingContext2D.prototype.arrowEndpoint = function (x, y, angle, length) {
// tail
@ -237,6 +262,11 @@ if (typeof CanvasRenderingContext2D !== 'undefined') {
/**
* Draw an circle an the end of an line with the given angle.
*
* @param {Number} x
* @param {Number} y
* @param {Number} angle
* @param {Number} length
*/
CanvasRenderingContext2D.prototype.circleEndpoint = function (x, y, angle, length) {
var radius = length * 0.4;
@ -250,6 +280,12 @@ if (typeof CanvasRenderingContext2D !== 'undefined') {
* Original code came from http://stackoverflow.com/questions/4576724/dotted-stroke-in-canvas
* @author David Jordan
* @date 2012-08-08
*
* @param {Number} x
* @param {Number} y
* @param {Number} x2
* @param {Number} y2
* @param {String} pattern
*/
CanvasRenderingContext2D.prototype.dashedLine = function (x, y, x2, y2, pattern) {
this.beginPath();

+ 1
- 1
lib/shared/Activator.js View File

@ -125,7 +125,7 @@ Activator.prototype.deactivate = function () {
/**
* Handle a tap event: activate the container
* @param event
* @param {Event} event The event
* @private
*/
Activator.prototype._onTapOverlay = function (event) {

+ 12
- 12
lib/shared/ColorPicker.js View File

@ -25,7 +25,7 @@ class ColorPicker {
/**
* this inserts the colorPicker into a div from the DOM
* @param container
* @param {Element} container
*/
insertTo(container) {
if (this.hammer !== undefined) {
@ -41,7 +41,7 @@ class ColorPicker {
/**
* the callback is executed on apply and save. Bind it to the application
* @param callback
* @param {function} callback
*/
setUpdateCallback(callback) {
if (typeof callback === 'function') {
@ -54,7 +54,7 @@ class ColorPicker {
/**
* the callback is executed on apply and save. Bind it to the application
* @param callback
* @param {function} callback
*/
setCloseCallback(callback) {
if (typeof callback === 'function') {
@ -82,8 +82,8 @@ class ColorPicker {
* 'rgba(255,255,255,1.0)' --> rgba string
* {r:255,g:255,b:255} --> rgb object
* {r:255,g:255,b:255,a:1.0} --> rgba object
* @param color
* @param setInitial
* @param {String|Object} color
* @param {boolean} [setInitial=true]
*/
setColor(color, setInitial = true) {
if (color === 'none') {
@ -152,7 +152,7 @@ class ColorPicker {
/**
* Hide the picker. Is called by the cancel button.
* Optional boolean to store the previous color for easy access later on.
* @param storePrevious
* @param {boolean} [storePrevious=true]
* @private
*/
_hide(storePrevious = true) {
@ -216,8 +216,8 @@ class ColorPicker {
/**
* set the color, place the picker
* @param rgba
* @param setInitial
* @param {Object} rgba
* @param {boolean} [setInitial=true]
* @private
*/
_setColor(rgba, setInitial = true) {
@ -243,7 +243,7 @@ class ColorPicker {
/**
* bound to opacity control
* @param value
* @param {number} value
* @private
*/
_setOpacity(value) {
@ -254,7 +254,7 @@ class ColorPicker {
/**
* bound to brightness control
* @param value
* @param {number} value
* @private
*/
_setBrightness(value) {
@ -269,7 +269,7 @@ class ColorPicker {
/**
* update the color picker. A black circle overlays the hue circle to mimic the brightness decreasing.
* @param rgba
* @param {Object} rgba
* @private
*/
_updatePicker(rgba = this.color) {
@ -515,7 +515,7 @@ class ColorPicker {
/**
* move the selector. This is called by hammer functions.
*
* @param event
* @param {Event} event The event
* @private
*/
_moveSelector(event) {

+ 41
- 40
lib/shared/Configurator.js View File

@ -11,10 +11,10 @@ var ColorPicker = require('./ColorPicker').default;
*
* The options are matched with their counterparts in each of the modules and the values used in the configuration are
*
* @param parentModule | the location where parentModule.setOptions() can be called
* @param defaultContainer | the default container of the module
* @param configureOptions | the fully configured and predefined options set found in allOptions.js
* @param pixelRatio | canvas pixel ratio
* @param {Object} parentModule | the location where parentModule.setOptions() can be called
* @param {Object} defaultContainer | the default container of the module
* @param {Object} configureOptions | the fully configured and predefined options set found in allOptions.js
* @param {Number} pixelRatio | canvas pixel ratio
*/
class Configurator {
constructor(parentModule, defaultContainer, configureOptions, pixelRatio = 1) {
@ -49,7 +49,7 @@ class Configurator {
* refresh all options.
* Because all modules parse their options by themselves, we just use their options. We copy them here.
*
* @param options
* @param {Object} options
*/
setOptions(options) {
if (options !== undefined) {
@ -225,8 +225,9 @@ class Configurator {
/**
* all option elements are wrapped in an item
* @param path
* @param domElements
* @param {Array} path | where to look for the actual option
* @param {Array<Element>} domElements
* @returns {Number}
* @private
*/
_makeItem(path, ...domElements) {
@ -245,7 +246,7 @@ class Configurator {
/**
* header for major subjects
* @param name
* @param {string} name
* @private
*/
_makeHeader(name) {
@ -258,9 +259,9 @@ class Configurator {
/**
* make a label, if it is an object label, it gets different styling.
* @param name
* @param path
* @param objectLabel
* @param {string} name
* @param {array} path | where to look for the actual option
* @param {string} objectLabel
* @returns {HTMLElement}
* @private
*/
@ -279,9 +280,9 @@ class Configurator {
/**
* make a dropdown list for multiple possible string optoins
* @param arr
* @param value
* @param path
* @param {Array<number>} arr
* @param {number} value
* @param {array} path | where to look for the actual option
* @private
*/
_makeDropdown(arr, value, path) {
@ -314,9 +315,9 @@ class Configurator {
/**
* make a range object for numeric options
* @param arr
* @param value
* @param path
* @param {Array<number>} arr
* @param {number} value
* @param {array} path | where to look for the actual option
* @private
*/
_makeRange(arr, value, path) {
@ -384,8 +385,8 @@ class Configurator {
/**
* prepare the popup
* @param string
* @param index
* @param {string} string
* @param {Number} index
* @private
*/
_setupPopup(string, index) {
@ -437,9 +438,9 @@ class Configurator {
/**
* make a checkbox for boolean options.
* @param defaultValue
* @param value
* @param path
* @param {number} defaultValue
* @param {number} value
* @param {array} path | where to look for the actual option
* @private
*/
_makeCheckbox(defaultValue, value, path) {
@ -470,9 +471,9 @@ class Configurator {
/**
* make a text input field for string options.
* @param defaultValue
* @param value
* @param path
* @param {number} defaultValue
* @param {number} value
* @param {array} path | where to look for the actual option
* @private
*/
_makeTextInput(defaultValue, value, path) {
@ -494,9 +495,9 @@ class Configurator {
/**
* make a color field with a color picker for color fields
* @param arr
* @param value
* @param path
* @param {Array<number>} arr
* @param {number} value
* @param {array} path | where to look for the actual option
* @private
*/
_makeColorField(arr, value, path) {
@ -524,10 +525,9 @@ class Configurator {
/**
* used by the color buttons to call the color picker.
* @param event
* @param value
* @param div
* @param path
* @param {number} value
* @param {HTMLElement} div
* @param {array} path | where to look for the actual option
* @private
*/
_showColorPicker(value, div, path) {
@ -555,8 +555,10 @@ class Configurator {
/**
* parse an object and draw the correct items
* @param obj
* @param path
* @param {Object} obj
* @param {array} [path=[]] | where to look for the actual option
* @param {boolean} [checkOnly=false]
* @returns {boolean}
* @private
*/
_handleObject(obj, path = [], checkOnly = false) {
@ -636,10 +638,9 @@ class Configurator {
/**
* handle the array type of option
* @param optionName
* @param arr
* @param value
* @param path
* @param {Array<number>} arr
* @param {number} value
* @param {array} path | where to look for the actual option
* @private
*/
_handleArray(arr, value, path) {
@ -661,8 +662,8 @@ class Configurator {
/**
* called to update the network with the new settings.
* @param value
* @param path
* @param {number} value
* @param {array} path | where to look for the actual option
* @private
*/
_update(value, path) {

+ 15
- 14
lib/shared/Validator.js View File

@ -12,8 +12,9 @@ class Validator {
/**
* Main function to be called
* @param options
* @param subObject
* @param {Object} options
* @param {Object} referenceOptions
* @param {Object} subObject
* @returns {boolean}
*/
static validate(options, referenceOptions, subObject) {
@ -30,9 +31,9 @@ class Validator {
/**
* Will traverse an object recursively and check every value
* @param options
* @param referenceOptions
* @param path
* @param {Object} options
* @param {Object} referenceOptions
* @param {array} path | where to look for the actual option
*/
static parse(options, referenceOptions, path) {
for (let option in options) {
@ -45,10 +46,10 @@ class Validator {
/**
* Check every value. If the value is an object, call the parse function on that object.
* @param option
* @param options
* @param referenceOptions
* @param path
* @param {String} option
* @param {Object} options
* @param {Object} referenceOptions
* @param {array} path | where to look for the actual option
*/
static check(option, options, referenceOptions, path) {
if (referenceOptions[option] === undefined && referenceOptions.__any__ === undefined) {
@ -91,7 +92,7 @@ class Validator {
* @param {Object} options | The supplied options object
* @param {Object} referenceOptions | The reference options containing all options and their allowed formats
* @param {String} referenceOption | Usually this is the same as option, except when handling an __any__ tag.
* @param {String} refOptionType | This is the type object from the reference options
* @param {String} refOptionObj | This is the type object from the reference options
* @param {Array} path | where in the object is the option
*/
static checkFields(option, options, referenceOptions, referenceOption, refOptionObj, path) {
@ -202,10 +203,10 @@ class Validator {
/**
* traverse the options in search for a match.
* @param option
* @param options
* @param path
* @param recursive
* @param {String} option
* @param {Object} options
* @param {Array} path | where to look for the actual option
* @param {Boolean} [recursive=false]
* @returns {{closestMatch: string, path: Array, distance: number}}
*/
static findInOptions(option, options, path, recursive = false) {

+ 1
- 1
lib/timeline/component/Group.js View File

@ -2,10 +2,10 @@ var util = require('../../util');
var stack = require('../Stack');
/**
* @constructor Group
* @param {Number | String} groupId
* @param {Object} data
* @param {ItemSet} itemSet
* @constructor Group
*/
function Group (groupId, data, itemSet) {
this.groupId = groupId;

+ 50
- 45
lib/util.js View File

@ -19,7 +19,7 @@ exports.isNumber = function (object) {
/**
* Remove everything in the DOM object
* @param DOMobject
* @param {Element} DOMobject
*/
exports.recursiveDOMDelete = function (DOMobject) {
if (DOMobject) {
@ -33,10 +33,10 @@ exports.recursiveDOMDelete = function (DOMobject) {
/**
* this function gives you a range between 0 and 1 based on the min and max values in the set, the total sum of all values and the current value.
*
* @param min
* @param max
* @param total
* @param value
* @param {number} min
* @param {number} max
* @param {number} total
* @param {number} value
* @returns {number}
*/
exports.giveRange = function (min, max, total, value) {
@ -47,7 +47,7 @@ exports.giveRange = function (min, max, total, value) {
var scale = 1 / (max - min);
return Math.max(0, (value - min) * scale);
}
}
};
/**
* Test whether given object is a string
@ -92,8 +92,8 @@ exports.randomUUID = function () {
/**
* assign all keys of an object that are not nested objects to a certain value (used for color objects).
* @param obj
* @param value
* @param {object} obj
* @param {number} value
*/
exports.assignAllKeys = function (obj, value) {
for (var prop in obj) {
@ -103,14 +103,15 @@ exports.assignAllKeys = function (obj, value) {
}
}
}
}
};
/**
* Fill an object with a possibly partially defined other object. Only copies values if the a object has an object requiring values.
* That means an object is not created on a property if only the b object has it.
* @param obj
* @param value
* @param {object} a
* @param {object} b
* @param {boolean} [allowDeletion=false]
*/
exports.fillIfDefined = function (a, b, allowDeletion = false) {
for (var prop in a) {
@ -130,7 +131,7 @@ exports.fillIfDefined = function (a, b, allowDeletion = false) {
}
}
}
}
};
@ -202,6 +203,7 @@ exports.selectiveExtend = function (props, a, b) { // eslint-disable-line no-un
* @param {Array.<String>} props
* @param {Object} a
* @param {Object} b
* @param {Boolean} [allowDeletion=false]
* @return {Object} a
*/
exports.selectiveDeepExtend = function (props, a, b, allowDeletion = false) {
@ -252,6 +254,7 @@ exports.selectiveDeepExtend = function (props, a, b, allowDeletion = false) {
* @param {Array.<String>} props
* @param {Object} a
* @param {Object} b
* @param {Boolean} [allowDeletion=false]
* @return {Object} a
*/
exports.selectiveNotDeepExtend = function (props, a, b, allowDeletion = false) {
@ -300,9 +303,9 @@ exports.selectiveNotDeepExtend = function (props, a, b, allowDeletion = false) {
* Deep extend an object a with the properties of object b
* @param {Object} a
* @param {Object} b
* @param [Boolean] protoExtend --> optional parameter. If true, the prototype values will also be extended.
* (ie. the options objects that inherit from others will also get the inherited options)
* @param [Boolean] global --> optional parameter. If true, the values of fields that are null will not deleted
* @param {Boolean} [protoExtend] --> optional parameter. If true, the prototype values will also be extended.
* (ie. the options objects that inherit from others will also get the inherited options)
* @param {Boolean} [allowDeletion] --> optional parameter. If true, the values of fields that are null will not deleted
* @returns {Object}
*/
exports.deepExtend = function (a, b, protoExtend, allowDeletion) {
@ -564,8 +567,8 @@ exports.getType = function (object) {
/**
* Used to extend an array and copy it. This is used to propagate paths recursively.
*
* @param arr
* @param newValue
* @param {Array} arr
* @param {*} newValue
* @returns {Array}
*/
exports.copyAndExtendArray = function (arr, newValue) {
@ -575,13 +578,12 @@ exports.copyAndExtendArray = function (arr, newValue) {
}
newArr.push(newValue);
return newArr;
}
};
/**
* Used to extend an array and copy it. This is used to propagate paths recursively.
*
* @param arr
* @param newValue
* @param {Array} arr
* @returns {Array}
*/
exports.copyArray = function (arr) {
@ -590,7 +592,7 @@ exports.copyArray = function (arr) {
newArr.push(arr[i]);
}
return newArr;
}
};
/**
* Retrieve the absolute left value of a DOM element
@ -619,7 +621,7 @@ exports.getAbsoluteTop = function (elem) {
/**
* add a className to the given elements style
* @param {Element} elem
* @param {String} className
* @param {String} classNames
*/
exports.addClassName = function (elem, classNames) {
var classes = elem.className.split(' ');
@ -633,7 +635,7 @@ exports.addClassName = function (elem, classNames) {
/**
* add a className to the given elements style
* @param {Element} elem
* @param {String} className
* @param {String} classNames
*/
exports.removeClassName = function (elem, classNames) {
var classes = elem.className.split(' ');
@ -676,7 +678,7 @@ exports.forEach = function (object, callback) {
* Convert an object into an array: all objects properties are put into the
* array. The resulting array is unordered.
* @param {Object} object
* @param {Array} array
* @returns {Array} array
*/
exports.toArray = function (object) {
var array = [];
@ -773,6 +775,7 @@ exports.removeEventListener = function (element, action, listener, useCapture) {
/**
* Cancels the event if it is cancelable, without stopping further propagation of the event.
* @param {Event} event
*/
exports.preventDefault = function (event) {
if (!event)
@ -818,6 +821,7 @@ exports.getTarget = function (event) {
* Check if given element contains given parent somewhere in the DOM tree
* @param {Element} element
* @param {Element} parent
* @returns {boolean}
*/
exports.hasParent = function (element, parent) {
var e = element;
@ -946,9 +950,9 @@ exports.hexToRGB = function (hex) {
/**
* This function takes color in hex format or rgb() or rgba() format and overrides the opacity. Returns rgba() string.
* @param color
* @param opacity
* @returns {*}
* @param {String} color
* @param {Number} opacity
* @returns {String}
*/
exports.overrideOpacity = function (color, opacity) {
var rgb;
@ -972,10 +976,10 @@ exports.overrideOpacity = function (color, opacity) {
/**
*
* @param red 0 -- 255
* @param green 0 -- 255
* @param blue 0 -- 255
* @returns {string}
* @param {Number} red 0 -- 255
* @param {Number} green 0 -- 255
* @param {Number} blue 0 -- 255
* @returns {String}
* @constructor
*/
exports.RGBToHex = function (red, green, blue) {
@ -1067,10 +1071,10 @@ exports.parseColor = function (color) {
/**
* http://www.javascripter.net/faq/rgb2hsv.htm
*
* @param red
* @param green
* @param blue
* @returns {*}
* @param {Number} red
* @param {Number} green
* @param {Number} blue
* @returns {{h: Number, s: Number, v: Number}}
* @constructor
*/
exports.RGBToHSV = function (red, green, blue) {
@ -1152,9 +1156,9 @@ exports.removeCssText = function (element, cssText) {
/**
* https://gist.github.com/mjijackson/5311256
* @param h
* @param s
* @param v
* @param {Number} h
* @param {Number} s
* @param {Number} v
* @returns {{r: number, g: number, b: number}}
* @constructor
*/
@ -1198,18 +1202,19 @@ exports.isValidRGB = function (rgb) {
rgb = rgb.replace(" ", "");
var isOk = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/i.test(rgb);
return isOk;
}
};
exports.isValidRGBA = function (rgba) {
rgba = rgba.replace(" ", "");
var isOk = /rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),(.{1,3})\)/i.test(rgba);
return isOk;
}
};
/**
* This recursively redirects the prototype of JSON objects to the referenceObject
* This is used for default options.
*
* @param referenceObject
* @param {Array<String>} fields
* @param {Object} referenceObject
* @returns {*}
*/
exports.selectiveBridgeObject = function (fields, referenceObject) {
@ -1233,7 +1238,7 @@ exports.selectiveBridgeObject = function (fields, referenceObject) {
* This recursively redirects the prototype of JSON objects to the referenceObject
* This is used for default options.
*
* @param referenceObject
* @param {Object} referenceObject
* @returns {*}
*/
exports.bridgeObject = function (referenceObject) {
@ -1262,9 +1267,9 @@ exports.bridgeObject = function (referenceObject) {
/**
* This method provides a stable sort implementation, very fast for presorted data
*
* @param a the array
* @param a order comparator
* @returns {the array}
* @param {Array} a the array
* @param {function} compare an order comparator
* @returns {Array}
*/
exports.insertSort = function (a,compare) {
for (var i = 0; i < a.length; i++) {

Loading…
Cancel
Save