Browse Source

Enable jsdoc-require MethodDefinition (#3382)

* Enables require MethodDefinition for require-jsdoc lint rule and corrects 66% of missing Method Definitions

* Adds jsdoc for all remaining methods and corrects @class/@constructor documentation

* Define values more accurately

* Correct bugs that prevent jsdoc generation
revert-3409-performance
macleodbroad-wf 6 years ago
committed by Yotam Berkowitz
parent
commit
48c7cf93f1
63 changed files with 1509 additions and 296 deletions
  1. +1
    -1
      .eslintrc
  2. +4
    -1
      lib/DataSet.js
  3. +1
    -1
      lib/graph3d/Graph3d.js
  4. +8
    -2
      lib/network/CachedImage.js
  5. +8
    -3
      lib/network/Images.js
  6. +4
    -1
      lib/network/NetworkUtil.js
  7. +29
    -7
      lib/network/modules/Canvas.js
  8. +21
    -5
      lib/network/modules/CanvasRenderer.js
  9. +20
    -3
      lib/network/modules/Clustering.js
  10. +27
    -8
      lib/network/modules/EdgesHandler.js
  11. +7
    -1
      lib/network/modules/Groups.js
  12. +18
    -5
      lib/network/modules/InteractionHandler.js
  13. +15
    -2
      lib/network/modules/KamadaKawai.js
  14. +45
    -6
      lib/network/modules/LayoutEngine.js
  15. +66
    -0
      lib/network/modules/ManipulationSystem.js
  16. +19
    -6
      lib/network/modules/NodesHandler.js
  17. +13
    -3
      lib/network/modules/PhysicsEngine.js
  18. +25
    -4
      lib/network/modules/SelectionHandler.js
  19. +21
    -5
      lib/network/modules/View.js
  20. +53
    -15
      lib/network/modules/components/Edge.js
  21. +49
    -5
      lib/network/modules/components/NavigationHandler.js
  22. +42
    -21
      lib/network/modules/components/Node.js
  23. +12
    -1
      lib/network/modules/components/algorithms/FloydWarshall.js
  24. +22
    -5
      lib/network/modules/components/edges/BezierEdgeDynamic.js
  25. +12
    -5
      lib/network/modules/components/edges/BezierEdgeStatic.js
  26. +37
    -5
      lib/network/modules/components/edges/CubicBezierEdge.js
  27. +31
    -5
      lib/network/modules/components/edges/StraightEdge.js
  28. +11
    -5
      lib/network/modules/components/edges/util/BezierEdgeBase.js
  29. +7
    -4
      lib/network/modules/components/edges/util/CubicBezierEdgeBase.js
  30. +88
    -7
      lib/network/modules/components/edges/util/EdgeBase.js
  31. +9
    -6
      lib/network/modules/components/nodes/Cluster.js
  32. +36
    -4
      lib/network/modules/components/nodes/shapes/Box.js
  33. +34
    -5
      lib/network/modules/components/nodes/shapes/Circle.js
  34. +35
    -4
      lib/network/modules/components/nodes/shapes/CircularImage.js
  35. +29
    -6
      lib/network/modules/components/nodes/shapes/Database.js
  36. +22
    -4
      lib/network/modules/components/nodes/shapes/Diamond.js
  37. +22
    -4
      lib/network/modules/components/nodes/shapes/Dot.js
  38. +28
    -5
      lib/network/modules/components/nodes/shapes/Ellipse.js
  39. +42
    -4
      lib/network/modules/components/nodes/shapes/Icon.js
  40. +36
    -5
      lib/network/modules/components/nodes/shapes/Image.js
  41. +22
    -4
      lib/network/modules/components/nodes/shapes/Square.js
  42. +22
    -4
      lib/network/modules/components/nodes/shapes/Star.js
  43. +28
    -4
      lib/network/modules/components/nodes/shapes/Text.js
  44. +22
    -4
      lib/network/modules/components/nodes/shapes/Triangle.js
  45. +22
    -4
      lib/network/modules/components/nodes/shapes/TriangleDown.js
  46. +40
    -1
      lib/network/modules/components/nodes/util/CircleImageBase.js
  47. +63
    -8
      lib/network/modules/components/nodes/util/NodeBase.js
  48. +32
    -5
      lib/network/modules/components/nodes/util/ShapeBase.js
  49. +15
    -5
      lib/network/modules/components/physics/BarnesHutSolver.js
  50. +15
    -5
      lib/network/modules/components/physics/CentralGravitySolver.js
  51. +7
    -5
      lib/network/modules/components/physics/FA2BasedCentralGravitySolver.js
  52. +8
    -5
      lib/network/modules/components/physics/FA2BasedRepulsionSolver.js
  53. +11
    -5
      lib/network/modules/components/physics/HierarchicalRepulsionSolver.js
  54. +11
    -5
      lib/network/modules/components/physics/HierarchicalSpringSolver.js
  55. +11
    -5
      lib/network/modules/components/physics/RepulsionSolver.js
  56. +11
    -5
      lib/network/modules/components/physics/SpringSolver.js
  57. +70
    -9
      lib/network/modules/components/shared/Label.js
  58. +11
    -2
      lib/shared/ColorPicker.js
  59. +29
    -5
      lib/shared/Configurator.js
  60. +6
    -2
      lib/shared/Popup.js
  61. +39
    -11
      lib/shared/Validator.js
  62. +3
    -2
      lib/timeline/Timeline.js
  63. +2
    -2
      lib/util.js

+ 1
- 1
.eslintrc View File

@ -22,7 +22,7 @@
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": false,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": false
}

+ 4
- 1
lib/DataSet.js View File

@ -141,7 +141,10 @@ DataSet.prototype.on = function(event, callback) {
});
};
// TODO: remove this deprecated function some day (replaced with `on` since version 0.5, deprecated since v4.0)
/**
* TODO: remove this deprecated function some day (replaced with `on` since version 0.5, deprecated since v4.0)
* @throws {Error}
*/
DataSet.prototype.subscribe = function () {
throw new Error('DataSet.subscribe is deprecated. Use DataSet.on instead.');
};

+ 1
- 1
lib/graph3d/Graph3d.js View File

@ -1540,7 +1540,7 @@ Graph3d.prototype._getColorsColor = function(point) {
* Get the colors for the 'size' graph styles.
* These styles are currently: 'bar-size' and 'dot-size'
*
* @returns {{fill: *, border: (string|undefinedOptions.colorOptions.stroke|{string, undefined}|string|colorOptions.stroke|{string}|*)}}
* @returns {{fill: *, border: (string|colorOptions.stroke|{string, undefined}|string|colorOptions.stroke|{string}|*)}}
* @private
*/
Graph3d.prototype._getColorsSize = function() {

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

@ -7,10 +7,16 @@
*
* NOTE: Images can also be of type 'data:svg+xml`. This code also works
* for svg, but the mipmapping may not be necessary.
*
* @class CachedImage
*/
class CachedImage {
// eslint-disable-next-line no-unused-vars
constructor(image) {
/**
* Create a Chached Image
* @param {Image} image
* @constructor
*/
constructor(image) { // eslint-disable-line no-unused-vars
this.NUM_ITERATIONS = 4; // Number of items in the coordinates array
this.image = new Image();

+ 8
- 3
lib/network/Images.js View File

@ -3,16 +3,21 @@ import CachedImage from './CachedImage';
/**
* This class loads images and keeps them stored.
* @class Images
* class Images
*/
class Images {
constructor(callback){
/**
* Create a Images
* @callback callback
* @param {function} callback
* @constructor Images
*/
constructor(callback){
this.images = {};
this.imageBroken = {};
this.callback = callback;
}
/**
* @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

+ 4
- 1
lib/network/NetworkUtil.js View File

@ -1,9 +1,12 @@
let util = require("../util");
/**
* @constructor NetworkUtil
* @class NetworkUtil
*/
class NetworkUtil {
/**
* @constructor NetworkUtil
*/
constructor() {}
/**

+ 29
- 7
lib/network/modules/Canvas.js View File

@ -8,9 +8,14 @@ let util = require('../../util');
* This function is executed once when a Network object is created. The frame
* contains a canvas, and this canvas contains all objects like the axis and
* nodes.
* @private
*
* @class Canvas
*/
class Canvas {
/**
* @param {Object} body
* @constructor Canvas
*/
constructor(body) {
this.body = body;
this.pixelRatio = 1;
@ -31,6 +36,9 @@ class Canvas {
this.bindEventListeners();
}
/**
* Binds event listeners
*/
bindEventListeners() {
// bind the events
this.body.emitter.once("resize", (obj) => {
@ -47,10 +55,11 @@ class Canvas {
this.hammer.destroy();
this._cleanUp();
});
}
/**
* @param {Object} options
*/
setOptions(options) {
if (options !== undefined) {
let fields = ['width','height','autoResize'];
@ -71,6 +80,9 @@ class Canvas {
}
}
/**
* @private
*/
_cleanUp() {
// automatically adapt to a changing size of the browser.
if (this.resizeTimer !== undefined) {
@ -80,6 +92,9 @@ class Canvas {
this.resizeFunction = undefined;
}
/**
* @private
*/
_onResize() {
this.setSize();
this.body.emitter.emit("_redraw");
@ -144,6 +159,13 @@ class Canvas {
}
}
/**
*
* @param {number|string} value
* @returns {string}
* @private
* @static
*/
_prepareValue(value) {
if (typeof value === 'number') {
return value + 'px';
@ -335,12 +357,14 @@ class Canvas {
return emitEvent;
}
/**
*
* @returns {CanvasRenderingContext2D}
*/
getContext() {
return this.frame.canvas.getContext("2d");
}
/**
* Determine the pixel ratio for various browsers.
*
@ -360,7 +384,6 @@ class Canvas {
ctx.backingStorePixelRatio || 1);
}
/**
* Lazy determination of pixel ratio.
*
@ -370,7 +393,6 @@ class Canvas {
this.pixelRatio = this._determinePixelRatio();
}
/**
* Set the transform in the contained context, based on its pixelRatio
*/

+ 21
- 5
lib/network/modules/CanvasRenderer.js View File

@ -44,12 +44,14 @@ function _initRequestAnimationFrame() {
let util = require('../../util');
/**
*
* @param {Object} body
* @param {Canvas} canvas
* @constructor CanvasRenderer
* @class CanvasRenderer
*/
class CanvasRenderer {
/**
* @param {Object} body
* @param {Canvas} canvas
* @constructor CanvasRenderer
*/
constructor(body, canvas) {
_initRequestAnimationFrame();
this.body = body;
@ -74,6 +76,9 @@ class CanvasRenderer {
this.bindEventListeners();
}
/**
* Binds event listeners
*/
bindEventListeners() {
this.body.emitter.on("dragStart", () => { this.dragging = true; });
this.body.emitter.on("dragEnd", () => { this.dragging = false; });
@ -111,6 +116,10 @@ class CanvasRenderer {
}
/**
*
* @param {Object} options
*/
setOptions(options) {
if (options !== undefined) {
let fields = ['hideEdgesOnDrag','hideNodesOnDrag'];
@ -157,7 +166,10 @@ class CanvasRenderer {
return timer;
}
/**
*
* @private
*/
_startRendering() {
if (this.renderingActive === true) {
if (this.renderTimer === undefined) {
@ -166,6 +178,10 @@ class CanvasRenderer {
}
}
/**
*
* @private
*/
_renderStep() {
if (this.renderingActive === true) {
// reset the renderTimer so a new scheduled animation step can be set

+ 20
- 3
lib/network/modules/Clustering.js View File

@ -99,11 +99,13 @@ var Edge = require('./components/Edge').default; // Only needed for check on ty
var Node = require('./components/Node').default; // Only needed for check on type!
/**
*
* @param {Object} body
* @constructor ClusterEngine
* @class ClusterEngine
*/
class ClusterEngine {
/**
* @param {Object} body
* @constructor ClusterEngine
*/
constructor(body) {
this.body = body;
this.clusteredNodes = {}; // key: node id, value: { clusterId: <id of cluster>, node: <node instance>}
@ -580,12 +582,22 @@ class ClusterEngine {
}
}
/**
*
* @param {Edge} edge
* @private
*/
_backupEdgeOptions(edge) {
if (this.clusteredEdges[edge.id] === undefined) {
this.clusteredEdges[edge.id] = {physics: edge.options.physics};
}
}
/**
*
* @param {Edge} edge
* @private
*/
_restoreEdge(edge) {
let originalOptions = this.clusteredEdges[edge.id];
if (originalOptions !== undefined) {
@ -772,6 +784,11 @@ class ClusterEngine {
}
}
/**
*
* @param {Cluster.id} clusterId
* @returns {Array<Node.id>}
*/
getNodesInCluster(clusterId) {
let nodesArray = [];
if (this.isCluster(clusterId) === true) {

+ 27
- 8
lib/network/modules/EdgesHandler.js View File

@ -6,13 +6,15 @@ var Edge = require("./components/Edge").default;
var Label = require("./components/shared/Label").default;
/**
*
* @param {Object} body
* @param {Array<Image>} images
* @param {Array<Group>} groups
* @constructor EdgesHandler
* @class EdgesHandler
*/
class EdgesHandler {
/**
* @param {Object} body
* @param {Array<Image>} images
* @param {Array<Group>} groups
* @constructor EdgesHandler
*/
constructor(body, images, groups) {
this.body = body;
this.images = images;
@ -120,6 +122,9 @@ class EdgesHandler {
this.bindEventListeners();
}
/**
* Binds event listeners
*/
bindEventListeners() {
// this allows external modules to force all dynamic curves to turn static.
this.body.emitter.on("_forceDisableDynamicCurves", (type, emit = true) => {
@ -184,6 +189,10 @@ class EdgesHandler {
}
/**
*
* @param {Object} options
*/
setOptions(options) {
this.edgeOptions = options;
if (options !== undefined) {
@ -358,7 +367,9 @@ class EdgesHandler {
}
}
/**
* Refreshes Edge Handler
*/
refresh() {
let edges = this.body.edges;
for (let edgeId in edges) {
@ -373,6 +384,11 @@ class EdgesHandler {
}
}
/**
*
* @param {Object} properties
* @returns {Edge}
*/
create(properties) {
return new Edge(properties, this.body, this.options, this.defaultOptions, this.edgeOptions)
}
@ -402,7 +418,11 @@ class EdgesHandler {
}
}
/**
*
* @param {Edge.id} edgeId
* @returns {Array}
*/
getConnectedNodes(edgeId) {
let nodeList = [];
if (this.body.edges[edgeId] !== undefined) {
@ -413,7 +433,6 @@ class EdgesHandler {
return nodeList;
}
/**
* Scan for missing nodes and remove corresponding edges, if any.
*

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

@ -5,6 +5,9 @@ let util = require('../../util');
* @class Groups
*/
class Groups {
/**
* @constructor Groups
*/
constructor() {
this.clear();
this.defaultIndex = 0;
@ -44,7 +47,10 @@ class Groups {
util.extend(this.options, this.defaultOptions);
}
/**
*
* @param {Object} options
*/
setOptions(options) {
let optionFields = ['useDefaultGroups'];

+ 18
- 5
lib/network/modules/InteractionHandler.js View File

@ -4,13 +4,15 @@ var NavigationHandler = require('./components/NavigationHandler').default;
var Popup = require('./../../shared/Popup').default;
/**
*
* @param {Object} body
* @param {Canvas} canvas
* @param {SelectionHandler} selectionHandler
* @constructor InteractionHandler
* @class InteractionHandler
*/
class InteractionHandler {
/**
* @param {Object} body
* @param {Canvas} canvas
* @param {SelectionHandler} selectionHandler
* @constructor InteractionHandler
*/
constructor(body, canvas, selectionHandler) {
this.body = body;
this.canvas = canvas;
@ -59,6 +61,9 @@ class InteractionHandler {
this.bindEventListeners()
}
/**
* Binds event listeners
*/
bindEventListeners() {
this.body.emitter.on('destroy', () => {
clearTimeout(this.popupTimer);
@ -66,6 +71,10 @@ class InteractionHandler {
})
}
/**
*
* @param {Object} options
*/
setOptions(options) {
if (options !== undefined) {
// extend all but the values in fields
@ -174,6 +183,10 @@ class InteractionHandler {
}
}
/**
*
* @param {Event} event
*/
onContext(event) {
let pointer = this.getPointer({x:event.clientX, y:event.clientY});
this.selectionHandler._generateClickEvent('oncontext', event, pointer);

+ 15
- 2
lib/network/modules/KamadaKawai.js View File

@ -9,8 +9,16 @@ import FloydWarshall from "./components/algorithms/FloydWarshall.js"
* -- Tomihisa KAMADA and Satoru KAWAI in 1989
*
* Possible optimizations in the distance calculation can be implemented.
*
* @class KamadaKawai
*/
class KamadaKawai {
/**
* @param {Object} body
* @param {Number} edgeLength
* @param {Number} edgeStrength
* @constructor KamadaKawai
*/
constructor(body, edgeLength, edgeStrength) {
this.body = body;
this.springLength = edgeLength;
@ -121,7 +129,7 @@ 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 {vis.Node.id} m
* @param {Number} m
* @param {Number} dE_dx
* @param {Number} dE_dy
* @private
@ -242,7 +250,12 @@ class KamadaKawai {
}
}
//Update method, just doing single column (rows are auto-updated) (update all sums)
/**
* Update method, just doing single column (rows are auto-updated) (update all sums)
*
* @param {Number} m
* @private
*/
_updateE_matrix(m) {
let nodesArray = this.body.nodeIndices;
let nodes = this.body.nodes;

+ 45
- 6
lib/network/modules/LayoutEngine.js View File

@ -37,10 +37,13 @@ var NetworkUtil = require('../NetworkUtil').default;
/**
* Container for derived data on current network, relating to hierarchy.
*
* Local, private class.
* @class HierarchicalStatus
* @private
*/
class HierarchicalStatus {
/**
* @constructor HierarchicalStatus
*/
constructor() {
this.childrenReference = {}; // child id's per node id
this.parentReference = {}; // parent id's per node id
@ -54,7 +57,6 @@ class HierarchicalStatus {
this.treeIndex = -1; // Highest tree id in current network.
}
/**
* Add the relation between given nodes to the current state.
*
@ -160,6 +162,11 @@ class HierarchicalStatus {
}
/**
*
* @param {Node} nodeA
* @param {Node} nodeB
*/
levelDownstream(nodeA, nodeB) {
if (this.levels[nodeB.id] === undefined) {
// set initial level
@ -309,11 +316,13 @@ class HierarchicalStatus {
}
/**
*
* @param {Object} body
* @constructor LayoutEngine
* @class LayoutEngine
*/
class LayoutEngine {
/**
* @param {Object} body
* @constructor LayoutEngine
*/
constructor(body) {
this.body = body;
@ -342,6 +351,9 @@ class LayoutEngine {
this.bindEventListeners();
}
/**
* Binds event listeners
*/
bindEventListeners() {
this.body.emitter.on('_dataChanged', () => {
this.setupHierarchicalLayout();
@ -364,6 +376,12 @@ class LayoutEngine {
});
}
/**
*
* @param {Object} options
* @param {Object} allOptions
* @returns {Object}
*/
setOptions(options, allOptions) {
if (options !== undefined) {
let hierarchical = this.options.hierarchical;
@ -406,6 +424,11 @@ class LayoutEngine {
return allOptions;
}
/**
*
* @param {Object} allOptions
* @returns {Object}
*/
adaptAllOptionsForHierarchicalLayout(allOptions) {
if (this.options.hierarchical.enabled === true) {
let backupPhysics = this.optionsBackup.physics;
@ -482,11 +505,19 @@ class LayoutEngine {
return allOptions;
}
/**
*
* @returns {number}
*/
seededRandom() {
let x = Math.sin(this.randomSeed++) * 10000;
return x - Math.floor(x);
}
/**
*
* @param {Array<Node>} nodesArray
*/
positionInitially(nodesArray) {
if (this.options.hierarchical.enabled !== true) {
this.randomSeed = this.initialRandomSeed;
@ -614,6 +645,10 @@ class LayoutEngine {
}
}
/**
* Expands all clusters
* @private
*/
_declusterAll() {
let clustersPresent = true;
while (clustersPresent === true) {
@ -630,6 +665,10 @@ class LayoutEngine {
}
}
/**
*
* @returns {number|*}
*/
getSeed() {
return this.initialRandomSeed;
}

+ 66
- 0
lib/network/modules/ManipulationSystem.js View File

@ -6,9 +6,15 @@ let hammerUtil = require('../../hammerUtil');
/**
* clears the toolbar div element of children
*
* @class ManipulationSystem
* @private
*/
class ManipulationSystem {
/**
* @param {Object} body
* @param {Canvas} canvas
* @param {SelectionHandler} selectionHandler
*/
constructor(body, canvas, selectionHandler) {
this.body = body;
this.canvas = canvas;
@ -114,6 +120,9 @@ class ManipulationSystem {
}
/**
* Enables Edit Mode
*/
enableEditMode() {
this.editMode = true;
@ -126,6 +135,9 @@ class ManipulationSystem {
}
}
/**
* Disables Edit Mode
*/
disableEditMode() {
this.editMode = false;
@ -675,30 +687,55 @@ class ManipulationSystem {
// ---------------------- DOM functions for buttons --------------------------//
/**
*
* @param {Locale} locale
* @private
*/
_createAddNodeButton(locale) {
let button = this._createButton('addNode', 'vis-button vis-add', locale['addNode'] || this.options.locales['en']['addNode']);
this.manipulationDiv.appendChild(button);
this._bindHammerToDiv(button, this.addNodeMode.bind(this));
}
/**
*
* @param {Locale} locale
* @private
*/
_createAddEdgeButton(locale) {
let button = this._createButton('addEdge', 'vis-button vis-connect', locale['addEdge'] || this.options.locales['en']['addEdge']);
this.manipulationDiv.appendChild(button);
this._bindHammerToDiv(button, this.addEdgeMode.bind(this));
}
/**
*
* @param {Locale} locale
* @private
*/
_createEditNodeButton(locale) {
let button = this._createButton('editNode', 'vis-button vis-edit', locale['editNode'] || this.options.locales['en']['editNode']);
this.manipulationDiv.appendChild(button);
this._bindHammerToDiv(button, this.editNode.bind(this));
}
/**
*
* @param {Locale} locale
* @private
*/
_createEditEdgeButton(locale) {
let button = this._createButton('editEdge', 'vis-button vis-edit', locale['editEdge'] || this.options.locales['en']['editEdge']);
this.manipulationDiv.appendChild(button);
this._bindHammerToDiv(button, this.editEdgeMode.bind(this));
}
/**
*
* @param {Locale} locale
* @private
*/
_createDeleteButton(locale) {
var deleteBtnClass;
if (this.options.rtl) {
@ -711,12 +748,26 @@ class ManipulationSystem {
this._bindHammerToDiv(button, this.deleteSelected.bind(this));
}
/**
*
* @param {Locale} locale
* @private
*/
_createBackButton(locale) {
let button = this._createButton('back', 'vis-button vis-back', locale['back'] || this.options.locales['en']['back']);
this.manipulationDiv.appendChild(button);
this._bindHammerToDiv(button, this.showManipulatorToolbar.bind(this));
}
/**
*
* @param {number|string} id
* @param {string} className
* @param {label} label
* @param {string} labelClassName
* @returns {HTMLElement}
* @private
*/
_createButton(id, className, label, labelClassName = 'vis-label') {
this.manipulationDOM[id+'Div'] = document.createElement('div');
@ -728,6 +779,11 @@ class ManipulationSystem {
return this.manipulationDOM[id+'Div'];
}
/**
*
* @param {Label} label
* @private
*/
_createDescription(label) {
this.manipulationDiv.appendChild(
this._createButton('description', 'vis-button vis-none', label)
@ -998,6 +1054,11 @@ class ManipulationSystem {
}
}
/**
*
* @param {Event} event
* @private
*/
_dragControlNode(event) {
let pointer = this.body.functions.getPointer(event.center);
if (this.temporaryIds.nodes[0] !== undefined) {
@ -1062,6 +1123,11 @@ class ManipulationSystem {
}
/**
*
* @param {Event} event
* @private
*/
_dragStartEdge(event) {
let pointer = this.lastTouch;
this.selectionHandler._generateClickEvent('dragStart', event, pointer, undefined, true);

+ 19
- 6
lib/network/modules/NodesHandler.js View File

@ -6,14 +6,16 @@ var Node = require("./components/Node").default;
var Label = require("./components/shared/Label").default;
/**
*
* @param {Object} body
* @param {Array<Image>} images
* @param {Array<Group>} groups
* @param {LayoutEngine} layoutEngine
* @constructor NodesHandler
* @class NodesHandler
*/
class NodesHandler {
/**
* @param {Object} body
* @param {Images} images
* @param {Array<Group>} groups
* @param {LayoutEngine} layoutEngine
* @constructor NodesHandler
*/
constructor(body, images, groups, layoutEngine) {
this.body = body;
this.images = images;
@ -148,6 +150,9 @@ class NodesHandler {
this.bindEventListeners();
}
/**
* Binds event listeners
*/
bindEventListeners() {
// refresh the nodes. Used when reverting from hierarchical layout
this.body.emitter.on('refreshNodes', this.refresh.bind(this));
@ -165,6 +170,10 @@ class NodesHandler {
});
}
/**
*
* @param {Object} options
*/
setOptions(options) {
this.nodeOptions = options;
if (options !== undefined) {
@ -355,6 +364,10 @@ class NodesHandler {
}
/**
*
* @param {boolean} [clearPositions=false]
*/
refresh(clearPositions = false) {
let nodes = this.body.nodes;
for (let nodeId in nodes) {

+ 13
- 3
lib/network/modules/PhysicsEngine.js View File

@ -11,11 +11,13 @@ var util = require('../../util');
/**
*
* @param {Object} body
* @constructor PhysicsEngine
* @class PhysicsEngine
*/
class PhysicsEngine {
/**
* @param {Object} body
* @constructor PhysicsEngine
*/
constructor(body) {
this.body = body;
this.physicsBody = {physicsNodeIndices:[], physicsEdgeIndices:[], forces: {}, velocities: {}};
@ -96,6 +98,9 @@ class PhysicsEngine {
this.bindEventListeners();
}
/**
* Binds event listeners
*/
bindEventListeners() {
this.body.emitter.on('initPhysics', () => {this.initPhysics();});
this.body.emitter.on('_layoutFailed', () => {this.layoutFailed = true;});
@ -716,6 +721,11 @@ class PhysicsEngine {
}
/**
* TODO: Is this function used at all? If not, remove it!
* @param {CanvasRenderingContext2D} ctx
* @private
*/
_drawForces(ctx) {
for (var i = 0; i < this.physicsBody.physicsNodeIndices.length; i++) {
let node = this.body.nodes[this.physicsBody.physicsNodeIndices[i]];

+ 25
- 4
lib/network/modules/SelectionHandler.js View File

@ -4,12 +4,14 @@ var Edge = require('./components/Edge').default;
let util = require('../../util');
/**
*
* @param {Object} body
* @param {Canvas} canvas
* @constructor SelectionHandler
* @class SelectionHandler
*/
class SelectionHandler {
/**
* @param {Object} body
* @param {Canvas} canvas
* @constructor SelectionHandler
*/
constructor(body, canvas) {
this.body = body;
this.canvas = canvas;
@ -31,6 +33,10 @@ class SelectionHandler {
}
/**
*
* @param {Object} [options]
*/
setOptions(options) {
if (options !== undefined) {
let fields = ['multiselect','hoverConnectedEdges','selectable','selectConnectedEdges'];
@ -61,6 +67,11 @@ class SelectionHandler {
return selected;
}
/**
*
* @param {{x: Number, y: Number}} pointer
* @returns {boolean}
*/
selectAdditionalOnPoint(pointer) {
let selectionChanged = false;
if (this.options.selectable === true) {
@ -134,6 +145,12 @@ class SelectionHandler {
this.body.emitter.emit(eventType, properties);
}
/**
*
* @param {Object} obj
* @param {boolean} [highlightEdges=this.options.selectConnectedEdges]
* @returns {boolean}
*/
selectObject(obj, highlightEdges = this.options.selectConnectedEdges) {
if (obj !== undefined) {
if (obj instanceof Node) {
@ -148,6 +165,10 @@ class SelectionHandler {
return false;
}
/**
*
* @param {Object} obj
*/
deselectObject(obj) {
if (obj.isSelected() === true) {
obj.selected = false;

+ 21
- 5
lib/network/modules/View.js View File

@ -3,12 +3,14 @@ let util = require('../../util');
var NetworkUtil = require('../NetworkUtil').default;
/**
*
* @param {Object} body
* @param {Canvas} canvas
* @constructor View
* @class View
*/
class View {
/**
* @param {Object} body
* @param {Canvas} canvas
* @constructor View
*/
constructor(body, canvas) {
this.body = body;
this.canvas = canvas;
@ -31,7 +33,10 @@ class View {
this.body.emitter.on("unlockNode", this.releaseNode.bind(this));
}
/**
*
* @param {Object} [options={}]
*/
setOptions(options = {}) {
this.options = options;
}
@ -236,6 +241,9 @@ class View {
this.body.view.translation = targetTranslation;
}
/**
* Resets state of a locked on Node
*/
releaseNode() {
if (this.lockedOnNodeId !== undefined && this.viewFunction !== undefined) {
this.body.emitter.off("initRedraw", this.viewFunction);
@ -273,10 +281,18 @@ class View {
}
/**
*
* @returns {number}
*/
getScale() {
return this.body.view.scale;
}
/**
*
* @returns {{x: number, y: number}}
*/
getViewPosition() {
return this.canvas.DOMtoCanvas({x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight});
}

+ 53
- 15
lib/network/modules/components/Edge.js View File

@ -8,19 +8,25 @@ var StraightEdge = require('./edges/StraightEdge').default;
/**
* A edge connects two nodes
* @param {Object} properties Object with options. Must contain
* At least options from and to.
* Available options: from (number),
* to (number), label (string, color (string),
* width (number), style (string),
* length (number), title (string)
* @param {Network} network A Network object, used to find and edge to
* nodes.
* @param {Object} constants An object with default values for
* example for the color
* @class Edge
*/
class Edge {
/**
*
* @param {Object} options Object with options. Must contain
* At least options from and to.
* Available options: from (number),
* to (number), label (string, color (string),
* width (number), style (string),
* length (number), title (string)
* @param {Object} body A Network object, used to find and edge to
* nodes.
* @param {Object} globalOptions An object with default values for
* example for the color
* @param {Object} defaultOptions
* @param {Object} edgeOptions
* @constructor Edge
*/
constructor(options, body, globalOptions, defaultOptions, edgeOptions) {
if (body === undefined) {
throw "No body provided";
@ -103,6 +109,13 @@ class Edge {
return dataChanged;
}
/**
*
* @param {Object} parentOptions
* @param {Object} newOptions
* @param {boolean} [allowDeletion=false]
* @param {Object} [globalOptions={}]
*/
static parseOptions(parentOptions, newOptions, allowDeletion = false, globalOptions = {}) {
var fields = [
'arrowStrikethrough',
@ -205,6 +218,10 @@ class Edge {
}
}
/**
*
* @param {Object} options
*/
choosify(options) {
this.chooser = true;
@ -221,6 +238,10 @@ class Edge {
}
}
/**
*
* @returns {{toArrow: boolean, toArrowScale: (allOptions.edges.arrows.to.scaleFactor|{number}|allOptions.edges.arrows.middle.scaleFactor|allOptions.edges.arrows.from.scaleFactor|Array|number), toArrowType: *, middleArrow: boolean, middleArrowScale: (number|allOptions.edges.arrows.middle.scaleFactor|{number}|Array), middleArrowType: (allOptions.edges.arrows.middle.type|{string}|string|*), fromArrow: boolean, fromArrowScale: (allOptions.edges.arrows.to.scaleFactor|{number}|allOptions.edges.arrows.middle.scaleFactor|allOptions.edges.arrows.from.scaleFactor|Array|number), fromArrowType: *, arrowStrikethrough: (*|boolean|allOptions.edges.arrowStrikethrough|{boolean}), color: undefined, inheritsColor: (string|string|string|allOptions.edges.color.inherit|{string, boolean}|Array|*), opacity: *, hidden: *, length: *, shadow: *, shadowColor: *, shadowSize: *, shadowX: *, shadowY: *, dashes: (*|boolean|Array|allOptions.edges.dashes|{boolean, array}), width: *}}
*/
getFormattingValues() {
let toArrow = (this.options.arrows.to === true) || (this.options.arrows.to.enabled === true)
let fromArrow = (this.options.arrows.from === true) || (this.options.arrows.from.enabled === true)
@ -417,7 +438,6 @@ class Edge {
}
/**
* Retrieve the value of the edge. Can be undefined
* @return {Number} value
@ -453,6 +473,10 @@ class Edge {
this.updateLabelModule();
}
/**
*
* @private
*/
_setInteractionWidths() {
if (typeof this.options.hoverWidth === 'function') {
this.edgeType.hoverWidth = this.options.hoverWidth(this.options.width);
@ -510,7 +534,12 @@ class Edge {
this.drawLabel (ctx, viaNode);
}
/**
*
* @param {CanvasRenderingContext2D} ctx
* @param {Object} arrowData
* @param {{toArrow: boolean, toArrowScale: (allOptions.edges.arrows.to.scaleFactor|{number}|allOptions.edges.arrows.middle.scaleFactor|allOptions.edges.arrows.from.scaleFactor|Array|number), toArrowType: *, middleArrow: boolean, middleArrowScale: (number|allOptions.edges.arrows.middle.scaleFactor|{number}|Array), middleArrowType: (allOptions.edges.arrows.middle.type|{string}|string|*), fromArrow: boolean, fromArrowScale: (allOptions.edges.arrows.to.scaleFactor|{number}|allOptions.edges.arrows.middle.scaleFactor|allOptions.edges.arrows.from.scaleFactor|Array|number), fromArrowType: *, arrowStrikethrough: (*|boolean|allOptions.edges.arrowStrikethrough|{boolean}), color: undefined, inheritsColor: (string|string|string|allOptions.edges.color.inherit|{string, boolean}|Array|*), opacity: *, hidden: *, length: *, shadow: *, shadowColor: *, shadowSize: *, shadowX: *, shadowY: *, dashes: (*|boolean|Array|allOptions.edges.dashes|{boolean, array}), width: *}} values
*/
drawArrows(ctx, arrowData, values) {
if (values.fromArrow) {
this.edgeType.drawArrowHead(ctx, values, this.selected, this.hover, arrowData.from);
@ -523,7 +552,11 @@ class Edge {
}
}
/**
*
* @param {CanvasRenderingContext2D} ctx
* @param {Node} viaNode
*/
drawLabel(ctx, viaNode) {
if (this.options.label !== undefined) {
// set style
@ -622,6 +655,7 @@ class Edge {
* @param {Number} percentage Value between 0 (line start) and 1 (line end)
* @return {Object} point
* @private
* @static
*/
_pointOnCircle(x, y, radius, percentage) {
var angle = percentage * 2 * Math.PI;
@ -631,12 +665,16 @@ class Edge {
}
}
/**
* Sets selected state to true
*/
select() {
this.selected = true;
}
/**
* Sets selected state to false
*/
unselect() {
this.selected = false;
}

+ 49
- 5
lib/network/modules/components/NavigationHandler.js View File

@ -3,12 +3,14 @@ var hammerUtil = require('../../../hammerUtil');
var keycharm = require('keycharm');
/**
*
* @param {Object} body
* @param {Canvas} canvas
* @constructor NavigationHandler
* @class NavigationHandler
*/
class NavigationHandler {
/**
* @param {Object} body
* @param {Canvas} canvas
* @constructor NavigationHandler
*/
constructor(body, canvas) {
this.body = body;
this.canvas = canvas;
@ -27,6 +29,10 @@ class NavigationHandler {
this.options = {}
}
/**
*
* @param {Object} options
*/
setOptions(options) {
if (options !== undefined) {
this.options = options;
@ -34,6 +40,9 @@ class NavigationHandler {
}
}
/**
* Creates or refreshes navigation and sets key bindings
*/
create() {
if (this.options.navigationButtons === true) {
if (this.iconsCreated === false) {
@ -47,6 +56,9 @@ class NavigationHandler {
this.configureKeyboardBindings();
}
/**
* Cleans up previous navigation items
*/
cleanNavigation() {
// clean hammer bindings
if (this.navigationHammers.length != 0) {
@ -108,6 +120,10 @@ class NavigationHandler {
this.iconsCreated = true;
}
/**
*
* @param {String} action
*/
bindToRedraw(action) {
if (this.boundFunctions[action] === undefined) {
this.boundFunctions[action] = this[action].bind(this);
@ -116,6 +132,10 @@ class NavigationHandler {
}
}
/**
*
* @param {String} action
*/
unbindFromRedraw(action) {
if (this.boundFunctions[action] !== undefined) {
this.body.emitter.off("initRedraw", this.boundFunctions[action]);
@ -150,11 +170,30 @@ class NavigationHandler {
}
this.boundFunctions = {};
}
/**
*
* @private
*/
_moveUp() {this.body.view.translation.y += this.options.keyboard.speed.y;}
/**
*
* @private
*/
_moveDown() {this.body.view.translation.y -= this.options.keyboard.speed.y;}
/**
*
* @private
*/
_moveLeft() {this.body.view.translation.x += this.options.keyboard.speed.x;}
/**
*
* @private
*/
_moveRight(){this.body.view.translation.x -= this.options.keyboard.speed.x;}
/**
*
* @private
*/
_zoomIn() {
var scaleOld = this.body.view.scale;
var scale = this.body.view.scale * (1 + this.options.keyboard.speed.zoom);
@ -168,6 +207,11 @@ class NavigationHandler {
this.body.emitter.emit('zoom', { direction: '+', scale: this.body.view.scale, pointer: null });
}
/**
*
* @private
*/
_zoomOut() {
var scaleOld = this.body.view.scale;
var scale = this.body.view.scale / (1 + this.options.keyboard.speed.zoom);

+ 42
- 21
lib/network/modules/components/Node.js View File

@ -21,29 +21,34 @@ var { printStyle } = require("../../../shared/Validator");
/**
* 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.
* {number} id Id of the node. Required
* {string} label Text label for the node
* {number} x Horizontal position of the node
* {number} y Vertical position of the node
* {string} shape Node shape, available:
* "database", "circle", "ellipse",
* "box", "image", "text", "dot",
* "star", "triangle", "triangleDown",
* "square", "icon"
* {string} image An image url
* {string} title An title text, can be HTML
* {anytype} group A group name or number
* @param {Network.Images} imagelist A list with images. Only needed
* when the node has an image
* @param {Network.Groups} grouplist A list with groups. Needed for
* retrieving group options
* @param {Object} constants An object with default values for
* example for the color
* @class Node
*/
class Node {
/**
*
* @param {object} options An object containing options for the node. All
* options are optional, except for the id.