Skip to content

Commit 7ef82dd

Browse files
committed
Docs imporvment
1 parent 1534521 commit 7ef82dd

File tree

1 file changed

+67
-64
lines changed

1 file changed

+67
-64
lines changed

Diff for: src/components/graph/graph.coords.js

+67-64
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { logWarning } from "../../utils";
33

44
/**
55
* Computes the normalized vector from a vector.
6-
* @param {Object} vector a 2D vector with x and y components
7-
* @param {number} vector.x x coordinate
8-
* @param {number} vector.y y coordinate
9-
* @returns {Object} normalized vector
6+
*
7+
* @param {Object} vector - A 2D vector with x and y components.
8+
* @param {number} vector.x - The X coordinate.
9+
* @param {number} vector.y - The Y coordinate.
10+
* @returns {Object} Normalized vector.
1011
* @memberof Graph/helper
1112
*/
1213
function normalize(vector) {
@@ -15,13 +16,12 @@ function normalize(vector) {
1516
}
1617

1718
/**
18-
* Calculate the length of a vector, from the center of a rectangle,
19-
* to one of it's edges.
19+
* Calculates the vector length from the center of a rectangle to the closest edge following a direction.
2020
* This calculation is taken from https://stackoverflow.com/a/3197924.
2121
*
22-
* @param {Object.<string, number>} RectangleCoords, The coords of the left-top vertex, and the right-bottom vertex.
23-
* @param {Object.<string, number>} VectorOriginCoords The center of the rectangle coords.
24-
* @param {Object.<string, number>} directionVector a 2D vector with x and y components.
22+
* @param {Object.<string, number>} RectangleCoords - The coords of the left-top vertex, and the right-bottom vertex.
23+
* @param {Object.<string, number>} VectorOriginCoords - The center of the rectangle coords.
24+
* @param {Object.<string, number>} directionVector - A 2D vector with x and y components.
2525
* @returns {number} The length of the vector from the center of the symbol to it's closet edge, considering the given direction vector.
2626
*/
2727
function calcRectangleVectorLengthFromCoords({ x1, y1, x2, y2 }, { px, py }, directionVector) {
@@ -46,10 +46,10 @@ function calcRectangleVectorLengthFromCoords({ x1, y1, x2, y2 }, { px, py }, dir
4646
}
4747

4848
/**
49-
* Calculate a the vector length from the center of a circle to it's perimeter.
49+
* Calculates the radius of the node.
5050
*
51-
* @param {number} nodeSize The size of the circle, when no viewGenerator is specified, else the size of an edge of the viewGenerator square.
52-
* @param {boolean} isCustomNode is viewGenerator specified.
51+
* @param {number} nodeSize - The size of the circle, when no viewGenerator is specified, else the size of an edge of the viewGenerator square.
52+
* @param {boolean} isCustomNode - Is viewGenerator specified.
5353
* @returns {number} The length of the vector from the center of the symbol to it's closet edge, considering the given direction vector.
5454
*/
5555
function calcCircleVectorLength(nodeSize, isCustomNode) {
@@ -58,20 +58,20 @@ function calcCircleVectorLength(nodeSize, isCustomNode) {
5858
// nodeSize equals the Diameter in the case of custome-node.
5959
radiusLength = nodeSize / 10 / 2;
6060
} else {
61-
// because this is a circle and A = pi * r^2
62-
// we multiply by 0.95, because if we don't the link is not melting properly
61+
// because this is a circle and A = pi * r^2.
6362
radiusLength = Math.sqrt(nodeSize / Math.PI);
6463
}
65-
return radiusLength;
64+
// We multiply by 0.95, so that our link will melt properly to its destination component.
65+
return radiusLength * 0.95;
6666
}
6767

6868
/**
69-
* Calculate a the vector length from the center of a square to it's perimeter.
69+
* Calculates the vector length from the center of a square to the closest edge following a direction.
7070
*
71-
* @param {number} nodeSize The size of the square, when no viewGenerator is specified, else the size of an edge of the viewGenerator square.
72-
* @param {Object.<string, number>} nodeCoords The coords of a the square node.
73-
* @param {Object.<string, number>} directionVector a 2D vector with x and y components
74-
* @param {boolean} isCustomNode is viewGenerator specified.
71+
* @param {number} nodeSize - The size of the square, when no viewGenerator is specified, else the size of an edge of the viewGenerator square.
72+
* @param {Object.<string, number>} nodeCoords - The coords of a the square node.
73+
* @param {Object.<string, number>} directionVector - A 2D vector with x and y components.
74+
* @param {boolean} isCustomNode - Is viewGenerator specified.
7575
* @returns {number} The length of the vector from the center of the symbol to it's closet edge, considering the given direction vector.
7676
*/
7777
function calcSquareVectorLength(nodeSize, { x, y }, directionVector, isCustomNode) {
@@ -80,11 +80,11 @@ function calcSquareVectorLength(nodeSize, { x, y }, directionVector, isCustomNod
8080
// nodeSize equals the edgeSize in the case of custome-node.
8181
edgeSize = nodeSize / 10;
8282
} else {
83-
// All the edges of a square are equal, inorder to calc it's size we multplie two edges.
83+
// All the edges of a square are equal, inorder to calc its size we multplie two edges.
8484
edgeSize = Math.sqrt(nodeSize);
8585
}
8686

87-
// The x and y coords in this library, represent the top center of the component.
87+
// The x and y coords represent the top center of the component
8888
const leftSquareX = x - edgeSize / 2;
8989
const topSquareY = y - edgeSize / 2;
9090

@@ -96,11 +96,11 @@ function calcSquareVectorLength(nodeSize, { x, y }, directionVector, isCustomNod
9696
}
9797

9898
/**
99-
* Calculate a the vector length from the center of a rectangle to it's perimeter.
99+
* Calculates the vector length from the center of a rectangle to the closest edge following a direction.
100100
*
101-
* @param {number} nodeSize The size of the square, when no viewGenerator is specified, else the size of an edge of the viewGenerator square.
102-
* @param {Object.<string, number>} nodeCoords The coords of a the square node.
103-
* @param {Object.<string, number>} directionVector a 2D vector with x and y components.
101+
* @param {number} nodeSize - The size of the square, when no viewGenerator is specified, else the size of an edge of the viewGenerator square.
102+
* @param {Object.<string, number>} nodeCoords - The coords of a the square node.
103+
* @param {Object.<string, number>} directionVector - A 2D vector with x and y components.
104104
* @returns {number} The length of the vector from the center of the symbol to it's closet edge, considering the given direction vector.
105105
*/
106106
function calcRectangleVectorLength(nodeSize, { x, y }, directionVector) {
@@ -122,11 +122,11 @@ function calcRectangleVectorLength(nodeSize, { x, y }, directionVector) {
122122
/**
123123
* Calculate a the vector length of symbol that included in symbols with optimized positioning.
124124
*
125-
* @param {string} symbolType the string that specifies the symbol type (should be one of {@link #node-symbol-type|node.symbolType})
126-
* @param {(number | Object.<string, number>)} nodeSize The size of the square, when no viewGenerator is specified, else the size of an edge of the viewGenerator square.
127-
* @param {Object.<string, number>} nodeCoords The coords of a the square node.
128-
* @param {Object.<string, number>} directionVector a 2D vector with x and y components.
129-
* @param {boolean} isCustomNode is viewGenerator specified.
125+
* @param {string} symbolType - The string that specifies the symbol type (should be one of {@link #node-symbol-type|node.symbolType}).
126+
* @param {(number | Object.<string, number>)} nodeSize - The size of the square, when no viewGenerator is specified, else the size of an edge of the viewGenerator square.
127+
* @param {Object.<string, number>} nodeCoords - The coords of a the square node.
128+
* @param {Object.<string, number>} directionVector - A 2D vector with x and y components.
129+
* @param {boolean} isCustomNode - Is viewGenerator specified.
130130
* @returns {number} The length of the vector from the center of the symbol to it's closet edge, considering the given direction vector.
131131
*/
132132
function calcVectorLength(symbolType, nodeSize, { x, y }, directionVector, isCustomNode) {
@@ -155,12 +155,12 @@ function calcVectorLength(symbolType, nodeSize, { x, y }, directionVector, isCus
155155

156156
/**
157157
* When directed graph is specified, we add arrow head to the link.
158-
* In order to add the arrow head we subtract it's size from the last point of the link.
158+
* In order to add the arrow head we subtract its size from the last point of the link.
159159
*
160-
* @param {number} p1 x or y, of the link last point.
161-
* @param {number} p2 x or y, of the link ending point.
162-
* @param {number} pDirectionVector The link direction vector in the x or y axis.
163-
* @param {number} arrowSize The size of the arrow head.
160+
* @param {number} p1 - x or y coordinate, of the link last point.
161+
* @param {number} p2 - x or y coordinate, of the link ending point.
162+
* @param {number} pDirectionVector - The link direction vector in the x or y axis.
163+
* @param {number} arrowSize - The size of the arrow head.
164164
* @returns {number} The amount we should add to the x or y coords, in order to free up space for the arrow head.
165165
*/
166166
function directedGraphCoordsOptimization(p1, p2, pDirectionVector, arrowSize) {
@@ -180,15 +180,15 @@ function directedGraphCoordsOptimization(p1, p2, pDirectionVector, arrowSize) {
180180

181181
/**
182182
* When directed graph is specified, we add arrow head to the link.
183-
* In order to add the arrow head we subtract it's size from the last point of the link.
183+
* In order to add the arrow head we subtract its size from the last point of the link.
184184
*
185-
* @param {Object.<string, number>} optimizedTargetCoords The modified coords of the target node.
186-
* @param {Object.<string, number>} prevCoords The coords of a the last point in the link (last link.breakPoints or the sourceCoords).
187-
* @param {Object.<string, number>} directionVector a 2D vector with x and y components.
188-
* @param {number} arrowSize The size of the arrow head.
189-
* @param {Object.<string, number>} targetCoords The initial coords of the target node.
190-
* @param {(number | Object.<string, number>)} targetNodeSize The target node size.
191-
* @param {boolean} isCustomNode is viewGenerator specified.
185+
* @param {Object.<string, number>} optimizedTargetCoords - The modified coords of the target node.
186+
* @param {Object.<string, number>} prevCoords - The coords of a the last point in the link (last link.breakPoints or the sourceCoords).
187+
* @param {Object.<string, number>} directionVector - A 2D vector with x and y components.
188+
* @param {number} arrowSize - The size of the arrow head.
189+
* @param {Object.<string, number>} targetCoords - The initial coords of the target node.
190+
* @param {(number | Object.<string, number>)} targetNodeSize - The target node size.
191+
* @param {boolean} isCustomNode - Is viewGenerator specified.
192192
* @returns {Object.<string, number>} The amount we should add to the x or y coords, in order to free up space for the arrow head.
193193
*/
194194
function directedGraphOptimization(
@@ -230,15 +230,15 @@ function directedGraphOptimization(
230230
* Computes new node coordinates to make arrowheads point at nodes.
231231
* Arrow configuration is only available for circles, squares and rectangles.
232232
*
233-
* @param {Object} info - the couple of nodes we need to compute new coordinates
234-
* @param {string} info.sourceId - node source id
235-
* @param {string} info.targetId - node target id
236-
* @param {Object} info.sourceCoords - node source coordinates
237-
* @param {Object} info.targetCoords - node target coordinates
238-
* @param {Object.<string, Object>} nodes - same as {@link #graphrenderer|nodes in renderGraph}.
239-
* @param {Object} config - same as {@link #graphrenderer|config in renderGraph}.
240-
* @param {number} strokeWidth - width of the link stroke
241-
* @param {Array.<Object>} breakPoints - additional set of points that the link will cross
233+
* @param {Object} info - The couple of nodes we need to compute new coordinates.
234+
* @param {string} info.sourceId - Node source id.
235+
* @param {string} info.targetId - Node target id.
236+
* @param {Object} info.sourceCoords - Node source coordinates.
237+
* @param {Object} info.targetCoords - Node target coordinates.
238+
* @param {Object.<string, Object>} nodes - Same as {@link #graphrenderer|nodes in renderGraph}.
239+
* @param {Object} config - Same as {@link #graphrenderer|config in renderGraph}.
240+
* @param {number} strokeWidth - Width of the link stroke.
241+
* @param {Array.<Object>} breakPoints - Additional set of points that the link will cross.
242242
* @returns {Object} new nodes coordinates
243243
* @memberof Graph/helper
244244
*/
@@ -286,9 +286,13 @@ function getNormalizedNodeCoordinates(
286286
const isSourceCustomNode = sourceNode?.viewGenerator || config.node?.viewGenerator;
287287
const sourceNodeSize = sourceNode?.size || config.node?.size;
288288

289-
const sourceVectorLength =
290-
calcVectorLength(sourceSymbolType, sourceNodeSize, { x: srcX, y: srcY }, firstDirectionVector, isSourceCustomNode) *
291-
0.95;
289+
const sourceVectorLength = calcVectorLength(
290+
sourceSymbolType,
291+
sourceNodeSize,
292+
{ x: srcX, y: srcY },
293+
firstDirectionVector,
294+
isSourceCustomNode
295+
);
292296

293297
srcX += sourceVectorLength * firstDirectionVector.x;
294298
srcY += sourceVectorLength * firstDirectionVector.y;
@@ -302,14 +306,13 @@ function getNormalizedNodeCoordinates(
302306
const isTargetCustomNode = targetNode?.viewGenerator || config.node?.viewGenerator;
303307
const targetNodeSize = targetNode?.size || config.node?.size;
304308

305-
const targetVectorLength =
306-
calcVectorLength(
307-
targetSymbolType,
308-
targetNodeSize,
309-
{ x: trgX, y: trgY },
310-
secondDirectionVector,
311-
isTargetCustomNode
312-
) * 0.95;
309+
const targetVectorLength = calcVectorLength(
310+
targetSymbolType,
311+
targetNodeSize,
312+
{ x: trgX, y: trgY },
313+
secondDirectionVector,
314+
isTargetCustomNode
315+
);
313316

314317
const arrowSize = config.directed ? strokeSize : 0;
315318
trgX -= targetVectorLength * secondDirectionVector.x;

0 commit comments

Comments
 (0)