Skip to content

Commit 2adc181

Browse files
committed
Updating the index.d.ts and adding a test
1 parent 26cc748 commit 2adc181

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

index.d.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ declare module '@dagrejs/dagre' {
109109
labeloffest?: number | undefined;
110110
}
111111

112-
export function layout(graph: graphlib.Graph, layout?: GraphLabel & NodeConfig & EdgeConfig): void;
112+
export interface LayoutConfig {
113+
customOrder?: (graph: graphlib.Graph, order: (graph: graphlib.Graph, opts: configUnion) => void) => void;
114+
disableOptimalOrderHeuristic?: boolean;
115+
}
116+
117+
type configUnion = GraphLabel & NodeConfig & EdgeConfig & LayoutConfig;
118+
119+
export function layout(graph: graphlib.Graph, layout?: configUnion): void;
113120

114121
export interface Edge {
115122
v: string;

lib/order/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ module.exports = order;
2626
* algorithm.
2727
*/
2828
function order(g, opts) {
29-
if (opts && opts.customOrder) {
30-
opts.customOrder(order, g);
29+
if (opts && typeof opts.customOrder === 'function') {
30+
opts.customOrder(g, order);
3131
return;
3232
}
3333

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/order/order-test.js

+16
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,20 @@ describe("order", function() {
4343
var layering = util.buildLayerMatrix(g);
4444
expect(crossCount(g, layering)).to.be.lte(1);
4545
});
46+
47+
it('can skip the optimal ordering', () => {
48+
g.setNode("a", { rank: 1 });
49+
["b", "d"].forEach(v => g.setNode(v, { rank: 2 }));
50+
["c", "e"].forEach(v => g.setNode(v, { rank: 3 }));
51+
g.setPath(["a", "b", "c"]);
52+
g.setPath(["a", "d"]);
53+
g.setEdge("b", "e");
54+
g.setEdge("d", "c");
55+
56+
const opts = { disableOptimalOrderHeuristic: true };
57+
58+
order(g, opts);
59+
var layering = util.buildLayerMatrix(g);
60+
expect(crossCount(g, layering)).to.equal(1);
61+
});
4662
});

0 commit comments

Comments
 (0)