This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.rei
476 lines (379 loc) · 12.4 KB
/
Graph.rei
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/**
Opaque type to represent the graph object in JS land
*/
type t;
module Attrs: {
type t = {
rankdir: Rank.Dir.t,
align: Rank.Align.t,
nodesep: int,
edgesep: int,
ranksep: int,
marginx: int,
marginy: int,
acyclicer: Acyclicer.t,
ranker: Rank.Strategy.t,
};
/**
See https://github.com/dagrejs/dagre/wiki#configuring-the-layout
Note that [align] defaults to [UpLeft] instead of [undefined].
*/
let make:
(
~rankdir: Rank.Dir.t=?,
~align: Rank.Align.t=?,
~nodesep: int=?,
~edgesep: int=?,
~ranksep: int=?,
~marginx: int=?,
~marginy: int=?,
~acyclicer: Acyclicer.t=?,
~ranker: Rank.Strategy.t=?,
unit
) =>
t;
let toDict:
t =>
{
.
"acyclicer": option(string),
"align": string,
"edgesep": int,
"marginx": int,
"marginy": int,
"nodesep": int,
"rankdir": string,
"ranker": string,
"ranksep": int,
};
};
[@bs.deriving abstract]
type config = {
directed: bool,
compound: bool,
multigraph: bool,
};
/**
Creates a graph with the given config. It's recommended that you use the
[Graph.make] function instead.
*/
[@bs.new] [@bs.module "dagre"] [@bs.scope "graphlib"]
external makeWith: config => t = "Graph";
/**
Sets the graph attributes to the given graph. Use [Graph.setAttrs]
instead.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#setGraph
*/
[@bs.send]
external setGraph: (t, Js.t('a)) => unit = "setGraph";
/**
Returns the graph attributes from the given graph. Use [Graph.attrs]
instead.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#graph
*/
[@bs.send]
external graph: t => Js.t('a) = "graph";
/**
Adds a node with its layout attributes to the graph.
Note that the JavaScript version makes the attributes (i.e. [label] in dagre
parlance) optional. This interface uses two functions: [setNode] and
[setNodeWith]. If you use the former, make sure the graph has a default set
of attributes for new nodes with [setDefaultNodeAttrs].
{[
let g = Graph.make();
Graph.setNodeWith(
g,
"furelise",
Node.attrs(~label="Für Elise", ~width=100, ~height=80, ())
);
]}
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#setNode
*/
[@bs.send]
external setNodeWith: (t, Node.t, Node.attrs) => unit = "setNode";
[@bs.send] external setNode: (t, Node.t) => unit = "setNode";
/**
Returns the attributes for the given node. Returns [None] when the node
does not exist.
{[
let g = Graph.make();
let nodeAttrs = Node.attrs(~label="Für Elise", ~width=100, ~height=80, ());
Graph.setNodeWith(g, "furelise", nodeAttrs);
Graph.node(g, "furelise") == Some(nodeAttrs);
]}
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#node
*/
[@bs.send] [@bs.return nullable]
external node: (t, Node.t) => option(Node.attrs) = "node";
/**
Checks if the graph is directed.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#isDirected
*/
[@bs.send]
external isDirected: t => bool = "isDirected";
/**
Checks if the graph allows edges to be labelled.
Note that dagre uses "label" to refer to data associated with graph, nodes
and edges and "name" for an edge label.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#isMultigraph
*/
[@bs.send]
external isMultigraph: t => bool = "isMultigraph";
[@bs.send] external isLabelled: t => bool = "isMultigraph";
/**
Checks if the graph allows for subgraphs.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#isCompound
*/
[@bs.send]
external isCompound: t => bool = "isCompound";
/**
Returns the number of nodes in the graph.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#nodeCount
*/
[@bs.send]
external nodeCount: t => int = "nodeCount";
/**
Returns the number of edges in the graph.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#edgeCount
*/
[@bs.send]
external edgeCount: t => int = "edgeCount";
/**
Sets the default attributes for new nodes.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#setDefaultNodeLabel
*/
[@bs.send]
external setDefaultNodeLabel: (t, unit => Js.t('a)) => unit =
"setDefaultNodeLabel";
[@bs.send]
external setDefaultNodeAttrs: (t, unit => Js.t('a)) => unit =
"setDefaultNodeLabel";
/**
Sets the default attributes for new nodes.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#setDefaultNodeLabel
*/
[@bs.send]
external setDefaultEdgeLabel: (t, unit => Js.t('a)) => unit =
"setDefaultEdgeLabel";
[@bs.send]
external setDefaultEdgeAttrs: (t, unit => Js.t('a)) => unit =
"setDefaultEdgeLabel";
/**
Returns the nodes in the graph. Use [Graph.node] to get the node
attributes.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#nodes
*/
[@bs.send]
external nodes: t => array(Node.t) = "nodes";
/**
Returns the edges in the graph. Use [Graph.edge] to get the edge
attributes.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#edges
*/
[@bs.send]
external edges: t => array(Edge.t) = "edges";
/**
Returns the source nodes in the graph (i.e. nodes with no incoming edges).
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#sources
*/
[@bs.send]
external sources: t => array(Node.t) = "sources";
/**
Returns the sink nodes in the graph (i.e. nodes with no outgoing edges).
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#sinks
*/
[@bs.send]
external sinks: t => array(Node.t) = "sinks";
/**
Checks if the node exists in the graph.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#hasNode
*/
[@bs.send]
external hasNode: (t, Node.t) => bool = "hasNode";
/**
Removes the given node, its attributes, and incident edges. Does nothing
if the nodes does not exist.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#removeNode
*/
[@bs.send]
external removeNode: (t, Node.t) => unit = "removeNode";
/**
Returns the predecessor nodes for the given node. Returns [None] if the
node does not exist.
Note that undirected graphs have undefined behaviour. Use [Graph.neighbors]
instead.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#predecessors
*/
[@bs.send] [@bs.return nullable]
external predecessors: (t, Node.t) => option(array(Node.t)) = "predecessors";
/**
Returns the successor nodes for the given node. Returns [None] if the
node does not exist.
Note that undirected graphs have undefined behaviour. Use [Graph.neighbors]
instead.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#successors
*/
[@bs.send] [@bs.return nullable]
external successors: (t, Node.t) => option(array(Node.t)) = "successors";
/**
Returns the nodes connected to the given node. Returns [None] if the
node does not exist.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#successors
*/
[@bs.send] [@bs.return nullable]
external neighbors: (t, Node.t) => option(array(Node.t)) = "neighbors";
/**
Returns the incoming edges for the given node. When [filter] is provided,
it returns the subset of incoming edges matching the filter node. Returns
[None] if the node does not exist.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#inEdges
*/
[@bs.send] [@bs.return nullable]
external inEdges:
(t, Node.t, ~filter: Node.t=?, unit) => option(array(Edge.t)) =
"inEdges";
/**
Returns the outgoing edges for the given node. When [filter] is provided,
it returns the subset of outgoing edges matching the filter node. Returns
[None] if the node does not exist.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#outEdges
*/
[@bs.send] [@bs.return nullable]
external outEdges:
(t, Node.t, ~filter: Node.t=?, unit) => option(array(Edge.t)) =
"outEdges";
/**
Returns the edges for the given node. When [filter] is provided, it
returns the subset of edges matching the filter node. Returns [None] if
the node does not exist.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#nodeEdges
*/
[@bs.send] [@bs.return nullable]
external nodeEdges:
(t, Node.t, ~filter: Node.t=?, unit) => option(array(Edge.t)) =
"nodeEdges";
/**
Returns the parent node for the given node. Returns [None] if the node
does not exist or if it has no parent.
Note that this function is for compound graphs, otherwise no node will
have a parent.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#parent
*/
[@bs.send] [@bs.return nullable]
external parent: (t, Node.t) => option(Node.t) = "parent";
/**
Sets the parent for the given node.
Note that it throws an exception if the graph is not compound.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#setParent
*/
[@bs.send]
external setParent: (t, Node.t, Node.t) => unit = "setParent";
/**
Removes the parent for the given node.
Note that this is equivalent to use the [g.setParent] method with a single
argument in JavaScript.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#setParent
*/
[@bs.send]
external removeParent: (t, Node.t) => unit = "setParent";
/**
Returns the children nodes for the given node. Returns [None] if the node
does not exist.
Note that this function is for compound graphs, otherwise no node will
have children.
Prefer [Graph.children] to get [None] instead of an empty array when the
graph is not compound.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#children
*/
[@bs.send] [@bs.return nullable]
external childrenRaw: (t, Node.t) => option(array(Node.t)) = "children";
/**
Returns the children for the given node. When the graph is not compound,
returns [None]. This is aligns with the [Graph.parent] behaviour.
Use [Graph.childrenRaw] if you need the original behaviour.
*/
let children: (t, Node.t) => option(array(Node.t));
/**
Checks if the given edge exists.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#hasEdge
*/
[@bs.send]
external hasEdge: (t, Edge.t) => bool = "hasEdge";
/**
Adds an edge with its layout attributes to the graph.
Note that the JavaScript version makes the attributes (i.e. [label] in dagre
parlance) optional. This interface uses two functions: [setEdge] and
[setEdgeWith]. If you use the former, make sure the graph has a default set
of attributes for new nodes with [setDefaultNodeAttrs].
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#setEdge
*/
[@bs.send]
external setEdgeWith: (t, Edge.t, Edge.attrs) => unit = "setEdge";
[@bs.send] external setEdge: (t, Edge.t) => unit = "setEdge";
/**
Returns the layout attributes for the given edge. Returns [None] if the
edge does not exist.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#edge
*/
[@bs.send] [@bs.return nullable]
external edge: (t, Edge.t) => option(Edge.attrs) = "edge";
/**
Removes the given edge from the graph.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#removeEdge
*/
[@bs.send]
external removeEdge: (t, Edge.t) => unit = "removeEdge";
/**
Returns a filtered copy of the graph. The filter is based on the node
layout attributes.
See: https://github.com/dagrejs/graphlib/issues/107
*/
[@bs.send]
external filterNodes: (t, Js.t('a) => bool) => t = "filterNodes";
/**
Serializes the given graph to a dictionary-like data structure.
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#json-write
*/
[@bs.val] [@bs.module "dagre"] [@bs.scope ("graphlib", "json")]
external serialize: t => Js.t('a) = "write";
/**
Deserializes the given dictionary-like data structure into a [Graph.t].
See: https://github.com/dagrejs/graphlib/wiki/API-Reference#json-read
*/
[@bs.val] [@bs.module "dagre"] [@bs.scope ("graphlib", "json")]
external deserialize: Js.t('a) => t = "read";
/**
Returns the graph attributes. This is a less confusing name than the
original [Graph.graph].
*/
let attrs: t => Attrs.t;
/**
Sets the graph layout attributes. This is a less confusing name than the
original [Graph.setGraph].
*/
let setAttrs: (t, Attrs.t) => unit;
/**
Creates a new graph with the given attributes. It defaults to a directed
non-compound non-labelled graph.
{[
let attrs = Graph.Attrs.make(~rankdir=Rank.Dir.LeftRight, ());
let graph = Graph.make(~attrs, ());
Graph.isDirected(graph) == true;
Graph.isCompound(graph) == false;
Graph.isLabelled(graph) == false;
Graph.attrs(graph) == attrs;
]}
*/
let make:
(
~directed: bool=?,
~compound: bool=?,
~multigraph: bool=?,
~attrs: Attrs.t=?,
unit
) =>
t;
/**
Makes a deep copy of the given graph.
*/
let copy: t => t;