Skip to content

Commit

Permalink
add jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
tbo47 committed Oct 5, 2024
1 parent f634472 commit dcc429f
Show file tree
Hide file tree
Showing 38 changed files with 405 additions and 126 deletions.
6 changes: 6 additions & 0 deletions src/dagre-js/create-clusters.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/**
* @import { Graph } from '../graphlib/graph.js';
*/
import * as d3 from 'd3';
import { addLabel } from './label/add-label.js';
import * as util from './util.js';

export { createClusters, setCreateClusters };

/**
* @param { Graph } g
*/
var createClusters = function (selection, g) {
var clusters = g.nodes().filter(function (v) {
return util.isSubgraph(g, v);
Expand Down
15 changes: 15 additions & 0 deletions src/dagre-js/create-edge-paths.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/**
* @import { Graph } from '../graphlib/graph.js';
*/
import * as d3 from 'd3';
import * as _ from 'lodash-es';
import { intersectNode } from './intersect/intersect-node.js';
import * as util from './util.js';

export { createEdgePaths, setCreateEdgePaths };

/**
* @param { Graph } g
*/
var createEdgePaths = function (selection, g, arrows) {
var previousPaths = selection
.selectAll('g.edgePath')
Expand Down Expand Up @@ -73,6 +79,9 @@ function makeFragmentRef(url, fragmentId) {
return baseUrl + '#' + fragmentId;
}

/**
* @param { Graph } g
*/
function calcPoints(g, e) {
var edge = g.edge(e);
var tail = g.node(e.v);
Expand Down Expand Up @@ -109,6 +118,9 @@ function getCoords(elem) {
return { x: matrix.e, y: matrix.f };
}

/**
* @param { Graph } g
*/
function enter(svgPaths, g) {
var svgPathsEnter = svgPaths.enter().append('g').attr('class', 'edgePath').style('opacity', 0);
svgPathsEnter
Expand All @@ -126,6 +138,9 @@ function enter(svgPaths, g) {
return svgPathsEnter;
}

/**
* @param { Graph } g
*/
function exit(svgPaths, g) {
var svgPathExit = svgPaths.exit();
util.applyTransition(svgPathExit, g).style('opacity', 0).remove();
Expand Down
12 changes: 8 additions & 4 deletions src/dagre-js/create-nodes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/**
* @import { Graph } from '../graphlib/graph.js';
*/
import * as d3 from 'd3';
import { pick } from 'lodash-es';
import { addLabel } from './label/add-label.js';
import * as util from './util.js';

export { createNodes, setCreateNodes };

var createNodes = function (selection, g, shapes) {
/**
* @param { Graph } g
*/
export var createNodes = function (selection, g, shapes) {
var simpleNodes = g.nodes().filter(function (v) {
return !util.isSubgraph(g, v);
});
Expand Down Expand Up @@ -87,6 +91,6 @@ var createNodes = function (selection, g, shapes) {
return svgNodes;
};

function setCreateNodes(value) {
export function setCreateNodes(value) {
createNodes = value;
}
17 changes: 12 additions & 5 deletions src/dagre-js/render.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @import { Graph } from '../graphlib/graph.js';
*/
import * as d3 from 'd3';
import { defaults } from 'lodash-es';
import { layout } from '../dagre/index.js';
Expand All @@ -9,12 +12,15 @@ import { createNodes, setCreateNodes } from './create-nodes.js';
import { positionClusters } from './position-clusters.js';
import { positionEdgeLabels } from './position-edge-labels.js';
import { positionNodes } from './position-nodes.js';
import { shapes, setShapes } from './shapes.js';
import { setShapes, shapes } from './shapes.js';

export { render };

// This design is based on http://bost.ocks.org/mike/chart/.
function render() {
/**
* @param { Graph } g
*/
var fn = function (svg, g) {
preProcessGraph(g);

Expand Down Expand Up @@ -102,11 +108,9 @@ var EDGE_DEFAULT_ATTRS = {
* @property {number} [width]
* @property {number} [_prevHeight]
* @property {number} [height]
*/

/**
*
* Pre-processes the graph by setting default labels and padding for nodes.
* @param {Object} g - The graph object.
* @param { Graph } g
*/
function preProcessGraph(g) {
g.nodes().forEach((v) => {
Expand Down Expand Up @@ -163,6 +167,9 @@ function preProcessGraph(g) {
});
}

/**
* @param { Graph } g
*/
function postProcessGraph(g) {
g.nodes().forEach((v) => {
/** @type {Node} */
Expand Down
9 changes: 8 additions & 1 deletion src/dagre-js/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/**
* @import { Graph } from '../graphlib/graph.js';
*/
import * as _ from 'lodash-es';

// Public utility functions
export { isSubgraph, edgeToId, applyStyle, applyClass, applyTransition };

/*
/**
* Returns true if the specified node in the graph is a subgraph node. A
* subgraph node is one that contains other nodes.
* @param { Graph } g
*/
function isSubgraph(g, v) {
return !!g.children(v).length;
Expand All @@ -32,6 +36,9 @@ function applyClass(dom, classFn, otherClasses) {
}
}

/**
* @param { Graph } g
*/
function applyTransition(selection, g) {
var graph = g.graph();

Expand Down
18 changes: 14 additions & 4 deletions src/dagre/acyclic.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/**
* @import { Graph } from '../graphlib/graph.js';
*/
import * as _ from 'lodash-es';
import { greedyFAS } from './greedy-fas.js';

export { run, undo };

function run(g) {
/**
* @param { Graph } g
*/
export function run(g) {
var fas = g.graph().acyclicer === 'greedy' ? greedyFAS(g, weightFn(g)) : dfsFAS(g);
_.forEach(fas, function (e) {
var label = g.edge(e);
Expand All @@ -20,6 +24,9 @@ function run(g) {
}
}

/**
* @param { Graph } g
*/
function dfsFAS(g) {
var fas = [];
var stack = {};
Expand All @@ -45,7 +52,10 @@ function dfsFAS(g) {
return fas;
}

function undo(g) {
/**
* @param { Graph } g
*/
export function undo(g) {
_.forEach(g.edges(), function (e) {
var label = g.edge(e);
if (label.reversed) {
Expand Down
13 changes: 10 additions & 3 deletions src/dagre/add-border-segments.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/**
* @import { Graph } from '../graphlib/graph.js';
*/
import * as _ from 'lodash-es';
import * as util from './util.js';

export { addBorderSegments };

function addBorderSegments(g) {
/**
* @param { Graph } g
*/
export function addBorderSegments(g) {
function dfs(v) {
var children = g.children(v);
var node = g.node(v);
Expand All @@ -24,6 +28,9 @@ function addBorderSegments(g) {
_.forEach(g.children(), dfs);
}

/**
* @param { Graph } g
*/
function addBorderNode(g, prop, prefix, sg, sgNode, rank) {
var label = { width: 0, height: 0, rank: rank, borderType: prop };
var prev = sgNode[prop][rank - 1];
Expand Down
24 changes: 20 additions & 4 deletions src/dagre/coordinate-system.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/**
* @import { Graph } from '../graphlib/graph.js';
*/
import * as _ from 'lodash-es';

export { adjust, undo };

function adjust(g) {
/**
* @param { Graph } g
*/
export function adjust(g) {
var rankDir = g.graph().rankdir.toLowerCase();
if (rankDir === 'lr' || rankDir === 'rl') {
swapWidthHeight(g);
}
}

function undo(g) {
/**
* @param { Graph } g
*/
export function undo(g) {
var rankDir = g.graph().rankdir.toLowerCase();
if (rankDir === 'bt' || rankDir === 'rl') {
reverseY(g);
Expand All @@ -21,6 +28,9 @@ function undo(g) {
}
}

/**
* @param { Graph } g
*/
function swapWidthHeight(g) {
_.forEach(g.nodes(), function (v) {
swapWidthHeightOne(g.node(v));
Expand All @@ -36,6 +46,9 @@ function swapWidthHeightOne(attrs) {
attrs.height = w;
}

/**
* @param { Graph } g
*/
function reverseY(g) {
_.forEach(g.nodes(), function (v) {
reverseYOne(g.node(v));
Expand All @@ -54,6 +67,9 @@ function reverseYOne(attrs) {
attrs.y = -attrs.y;
}

/**
* @param { Graph } g
*/
function swapXY(g) {
_.forEach(g.nodes(), function (v) {
swapXYOne(g.node(v));
Expand Down
7 changes: 2 additions & 5 deletions src/dagre/data/list.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/*
/**
* Simple doubly linked list implementation derived from Cormen, et al.,
* "Introduction to Algorithms".
*/

export { List };

class List {
export class List {
constructor() {
var sentinel = {};
sentinel._next = sentinel._prev = sentinel;
Expand Down
9 changes: 5 additions & 4 deletions src/dagre/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import * as _ from 'lodash-es';
import { Graph } from '../graphlib/index.js';
import * as util from './util.js';

export { debugOrdering };

/* istanbul ignore next */
function debugOrdering(g) {
/**
* istanbul ignore next
* @param { Graph } g
*/
export function debugOrdering(g) {
var layerMatrix = util.buildLayerMatrix(g);

var h = new Graph({ compound: true, multigraph: true }).setGraph({});
Expand Down
14 changes: 8 additions & 6 deletions src/dagre/greedy-fas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import * as _ from 'lodash-es';
import { Graph } from '../graphlib/index.js';
import { List } from './data/list.js';

/*
var DEFAULT_WEIGHT_FN = _.constant(1);

/**
* A greedy heuristic for finding a feedback arc set for a graph. A feedback
* arc set is a set of edges that can be removed to make a graph acyclic.
* The algorithm comes from: P. Eades, X. Lin, and W. F. Smyth, "A fast and
* effective heuristic for the feedback arc set problem." This implementation
* adjusts that from the paper to allow for weighted edges.
* @param { Graph } g
*/
export { greedyFAS };

var DEFAULT_WEIGHT_FN = _.constant(1);

function greedyFAS(g, weightFn) {
export function greedyFAS(g, weightFn) {
if (g.nodeCount() <= 1) {
return [];
}
Expand All @@ -28,6 +27,9 @@ function greedyFAS(g, weightFn) {
);
}

/**
* @param { Graph } g
*/
function doGreedyFAS(g, buckets, zeroIdx) {
var results = [];
var sources = buckets[buckets.length - 1];
Expand Down
5 changes: 4 additions & 1 deletion src/dagre/greedy-fas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { findCycles } from '../graphlib/alg/find-cycles.js';
import { greedyFAS } from './greedy-fas.js';

describe('greedyFAS', function () {
var g;
/**
* @param {Graph} g
*/
let g;

beforeEach(function () {
g = new Graph();
Expand Down
Loading

0 comments on commit dcc429f

Please sign in to comment.