Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defensive check #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bundle.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rm -rf dist
OUTFILE=dist/dagre-d3.7.0.11.js
OUTFILE=dist/dagre-d3-es.7.0.12.js
npx esbuild src/index.js --bundle --platform=neutral --packages=external --outfile=$OUTFILE
sed -i '' 's|from "d3";|from "https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";|' $OUTFILE
sed -i '' 's|from "lodash-es"|from "https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js"|' $OUTFILE
sed -i '' 's|from "lodash-es"|from "https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js"|' $OUTFILE
cp $OUTFILE ../tbo47.github.io/
1 change: 1 addition & 0 deletions src/dagre-js/create-edge-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function createLine(edge, points) {
}

function getCoords(elem) {
if (!elem) return { x: 0, y: 0 };
var bbox = elem.getBBox();
var matrix = elem.ownerSVGElement
.getScreenCTM()
Expand Down
1 change: 1 addition & 0 deletions src/dagre-js/intersect/intersect-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { intersectNode };

function intersectNode(node, point) {
if (!node || !node.intersect) return false;
return node.intersect(point);
}
4 changes: 2 additions & 2 deletions src/dagre/position/bk.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ function findType1Conflicts(g, layering) {
if (w || v === lastNode) {
_.forEach(layer.slice(scanPos, i + 1), function (scanNode) {
_.forEach(g.predecessors(scanNode), function (u) {
var uLabel = g.node(u),
uPos = uLabel.order;
const uLabel = g.node(u) || {};
const uPos = uLabel.order || 0;
if ((uPos < k0 || k1 < uPos) && !(uLabel.dummy && g.node(scanNode).dummy)) {
addConflict(conflicts, u, scanNode);
}
Expand Down
6 changes: 4 additions & 2 deletions src/dagre/rank/network-simplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ function updateRanks(t, g) {
edge = g.edge(parent, v);
flipped = true;
}

g.node(v).rank = g.node(parent).rank + (flipped ? edge.minlen : -edge.minlen);
if (g.node(v)) {
const parentRank = g.node(parent) ? g.node(parent).rank : 0;
g.node(v).rank = parentRank + (flipped ? edge.minlen : -edge.minlen);
}
});
}

Expand Down
5 changes: 3 additions & 2 deletions src/dagre/rank/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function longestPath(g) {
// return value of _.map([null])
rank = 0;
}

if (!label) label = {};
return (label.rank = rank);
}

Expand All @@ -59,5 +59,6 @@ function longestPath(g) {
* difference between the length of the edge and its minimum length.
*/
function slack(g, e) {
return g.node(e.w).rank - g.node(e.v).rank - g.edge(e).minlen;
const evRank = g.node(e.v) ? g.node(e.v).rank || 0 : 0;
return g.node(e.w).rank - evRank - g.edge(e).minlen;
}
3 changes: 3 additions & 0 deletions src/dagre/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function predecessorWeights(g) {
* ({x, y, width, height}) if it were pointing at the rectangle's center.
*/
function intersectRect(rect, point) {
if (!rect || !point) return { x: 0, y: 0 };
var x = rect.x;
var y = rect.y;

Expand Down Expand Up @@ -136,6 +137,7 @@ function buildLayerMatrix(g) {
});
_.forEach(g.nodes(), function (v) {
var node = g.node(v);
if (!node) node = {};
var rank = node.rank;
Comment on lines 139 to 141
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this create bugs / inconsistencies? The newly created object has no link to g or v.

Should dagre throw an error, so that the root cause can be fixed?

if (!_.isUndefined(rank)) {
layering[rank][node.order] = v;
Expand Down Expand Up @@ -207,6 +209,7 @@ function addBorderNode(g, prefix, rank, order) {
function maxRank(g) {
return _.max(
_.map(g.nodes(), function (v) {
if (!g.node(v)) return 0;
var rank = g.node(v).rank;
if (!_.isUndefined(rank)) {
return rank;
Expand Down
1 change: 1 addition & 0 deletions src/graphlib/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class Graph {
} else if (this.hasNode(v)) {
return [];
}
return [];
}
predecessors(v) {
var predsV = this._preds[v];
Expand Down
3 changes: 2 additions & 1 deletion src/graphlib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Includes only the "core" of graphlib

import { Graph } from './graph.js';
import * as graphlibJson from './json.js';

const version = '2.1.9-pre';

export { Graph, version };
export { Graph, version, graphlibJson };
Loading