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

Fix dagre.js for abnormal wide edges #1246

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions source/dagre.js
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ dagre.layout = (graph, layout) => {
}
const label = g.node(v).label;
if (min !== Number.POSITIVE_INFINITY && label.borderType !== borderType) {
xs[v] = Math.max(xs[v], min);
xs[v] = Math.min(xs[v], min);
Copy link
Author

Choose a reason for hiding this comment

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

this will choose smallest width

Copy link

Choose a reason for hiding this comment

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

@seanshpark @lutzroeder

How about the following code?

                            let minOut = Number.POSITIVE_INFINITY;
                            let minIn = Number.POSITIVE_INFINITY;
                            for (const e of blockG.node(v).out) {
                                minOut = Math.min(minOut, xs[e.w] - e.label);
                            }
                            for (const e of blockG.node(v).in) {
                                minIn = Math.min(minIn, xs[e.w] - e.label);
                            }
                            const label = g.node(v).label;
                            if (minOut !== Number.POSITIVE_INFINITY && minIn !== Number.NEGATIVE_INFINITY && label.borderType !== borderType) {
                                if (Math.abs(xs[v] - minOut) < Math.abs(xs[v] - minIn)) {
                                    xs[v] = Math.max(xs[v], minOut);
                                }else {
                                    xs[v] = Math.max(xs[v], minIn);
                                }
                            }
model before after
yolov5n yolov5n onnx new_yolov5n onnx
sample.zip saved_model pbtxt new_saved_model pbtxt

Copy link
Author

Choose a reason for hiding this comment

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

How about the following code?

This looks better !

}
} else {
visited.add(v);
Expand Down Expand Up @@ -1740,7 +1740,7 @@ dagre.layout = (graph, layout) => {
for (const [v, x] of Object.entries(xs)) {
const halfWidth = g.node(v).label.width / 2;
max = Math.max(x + halfWidth, max);
min = Math.min(x - halfWidth, min);
min = Math.min(Math.max(0, x - halfWidth), min);
Copy link
Author

Choose a reason for hiding this comment

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

some x - halfWidth goes to minus, which will make below const width = max - min; larger.

}
const width = max - min;
if (width < minWidth) {
Expand Down