@@ -80,6 +80,7 @@ let fprint_dir ppf = function
80
80
`TopToBottom -> fprintf ppf " TB"
81
81
| `LeftToRight -> fprintf ppf " LR"
82
82
83
+
83
84
(* * The [ATTRIBUTES] module type defines the interface for the engines. *)
84
85
module type ATTRIBUTES = sig
85
86
@@ -167,7 +168,8 @@ module CommonAttributes = struct
167
168
(* * Sets the shape of the node. Default value is [`Ellipse].
168
169
[`Polygon (i, f)] draws a polygon with [n] sides and a skewing
169
170
of [f]. *)
170
- | `Style of [ `Rounded | `Filled | `Solid | `Dashed | `Dotted | `Bold | `Invis ] list
171
+ | `Style of
172
+ [ `Rounded | `Filled | `Solid | `Dashed | `Dotted | `Bold | `Invis ]
171
173
(* * Sets the layout style of the node. Several styles may be combined
172
174
simultaneously. *)
173
175
| `Width of float
@@ -208,7 +210,7 @@ module CommonAttributes = struct
208
210
| `Penwidth of float
209
211
(* * Width of the pen (in points) used to draw the edge. Default value
210
212
is [1.0]. *)
211
- | `Style of [ `Solid | `Dashed | `Dotted | `Bold | `Invis ] list
213
+ | `Style of [ `Solid | `Dashed | `Dotted | `Bold | `Invis ]
212
214
(* * Sets the layout style of the edge. Several styles may be combined
213
215
simultaneously. *)
214
216
]
@@ -242,19 +244,22 @@ module CommonAttributes = struct
242
244
| `Polygon (i , f ) -> fprintf ppf " polygon, sides=%i, skew=%f" i f
243
245
244
246
let rec fprint_string_list ppf = function
245
- [] -> ()
247
+ | [] -> ()
246
248
| [hd] -> fprintf ppf " %s" hd
247
249
| hd :: tl -> fprintf ppf " %s,%a" hd fprint_string_list tl
248
250
249
251
let node_style_str = function
250
- `Rounded -> " rounded"
252
+ | `Rounded -> " rounded"
251
253
| `Filled -> " filled"
252
254
| `Solid -> " solid"
253
255
| `Dashed -> " dashed"
254
256
| `Dotted -> " dotted"
255
257
| `Bold -> " bold"
256
258
| `Invis -> " invis"
257
259
260
+ let fprint_style_list ppf a =
261
+ fprintf ppf " style=\" %a\" " fprint_string_list (List. map node_style_str a)
262
+
258
263
let fprint_vertex ppf = function
259
264
| `Color a -> fprintf ppf " color=%a" fprint_color a
260
265
| `ColorWithTransparency a ->
@@ -269,7 +274,7 @@ module CommonAttributes = struct
269
274
| `Peripheries i -> fprintf ppf " peripheries=%i" i
270
275
| `Regular b -> fprintf ppf " regular=%b" b
271
276
| `Shape a -> fprintf ppf " shape=%a" fprint_shape a
272
- | `Style a -> fprintf ppf " style= \" %a \" " fprint_string_list ( List. map node_style_str a)
277
+ | `Style _ -> assert false
273
278
| `Width f -> fprintf ppf " width=%f" f
274
279
275
280
let edge_style_str =
@@ -296,7 +301,40 @@ module CommonAttributes = struct
296
301
(* (String.escaped s) *)
297
302
| `Labelfontsize i -> fprintf ppf " labelfontsize=%i" i
298
303
| `Penwidth f -> fprintf ppf " penwidth=%f" f
299
- | `Style a -> fprintf ppf " style=\" %a\" " fprint_string_list (List. map edge_style_str a)
304
+ | `Style _ -> assert false
305
+
306
+ let rec filter_style al sl l = match l with
307
+ | [] -> al, sl
308
+ | `Style s :: l -> filter_style al (s :: sl) l
309
+ | a :: l -> filter_style (a :: al) sl l
310
+
311
+ (* * [fprint_graph_attribute printer ppf list] pretty prints a list of
312
+ attributes on the formatter [ppf], using the printer [printer] for
313
+ each attribute. The list appears between brackets and attributes
314
+ are speparated by ",". If the list is empty, nothing is printed. *)
315
+ let fprint_attributes fprint_style_list fprint_attribute ppf list =
316
+ if list <> [] then begin
317
+ let list , styles = filter_style [] [] list in
318
+ let rec fprint_attributes_rec ppf = function
319
+ | [] -> ()
320
+ | hd :: tl ->
321
+ fprintf ppf " %a" fprint_attribute hd;
322
+ if tl <> [] then fprintf ppf " ,@ " ;
323
+ fprint_attributes_rec ppf tl
324
+ in
325
+ fprintf ppf " [@[<hov>%a" fprint_attributes_rec list ;
326
+ if styles <> [] then begin
327
+ if list <> [] then fprintf ppf " ,@ " ;
328
+ fprint_style_list ppf styles
329
+ end ;
330
+ fprintf ppf " @]]"
331
+ end
332
+
333
+ let fprint_vertex_list =
334
+ fprint_attributes fprint_style_list fprint_vertex
335
+
336
+ let fprint_edge_list =
337
+ fprint_attributes fprint_style_list fprint_edge
300
338
301
339
end
302
340
@@ -310,8 +348,8 @@ module type ENGINE = sig
310
348
module Attributes : sig
311
349
include ATTRIBUTES
312
350
val fprint_graph :formatter -> graph -> unit
313
- val fprint_vertex : formatter -> vertex -> unit
314
- val fprint_edge : formatter -> edge -> unit
351
+ val fprint_vertex_list : formatter -> vertex list -> unit
352
+ val fprint_edge_list : formatter -> edge list -> unit
315
353
end
316
354
317
355
(* * The litteral name of the engine. *)
@@ -375,34 +413,6 @@ struct
375
413
fprintf ppf " %a;@ " EN.Attributes. fprint_graph att
376
414
) list
377
415
378
- (* * [fprint_graph_attribute printer ppf list] pretty prints a list of
379
- attributes on the formatter [ppf], using the printer [printer] for
380
- each attribute. The list appears between brackets and attributes
381
- are speparated by ",". If the list is empty, nothing is printed. *)
382
- let fprint_attributes fprint_attribute ppf = function
383
- [] -> ()
384
- | hd :: tl ->
385
- let rec fprint_attributes_rec ppf = function
386
- [] -> ()
387
- | hd' :: tl' ->
388
- fprintf ppf " ,@ %a%a"
389
- fprint_attribute hd'
390
- fprint_attributes_rec tl'
391
- in
392
- fprintf ppf " [@[<hov>%a%a@]]"
393
- fprint_attribute hd
394
- fprint_attributes_rec tl
395
-
396
- (* * [fprint_graph_attributes ppf list] pretty prints a list of
397
- node attributes using the format of [fprint_attributes]. *)
398
- let fprint_node_attributes ppf list =
399
- fprint_attributes EN.Attributes. fprint_vertex ppf list
400
-
401
- (* * [fprint_graph_attributes ppf list] pretty prints a list of
402
- edge attributes using the format of [fprint_attributes]. *)
403
- let fprint_edge_attributes ppf list =
404
- fprint_attributes EN.Attributes. fprint_edge ppf list
405
-
406
416
(* * [fprint_graph ppf graph] pretty prints the graph [graph] in
407
417
the CGL language on the formatter [ppf]. *)
408
418
let fprint_graph ppf graph =
@@ -414,8 +424,8 @@ struct
414
424
let print_nodes ppf =
415
425
let default_node_attributes = X. default_vertex_attributes graph in
416
426
if default_node_attributes <> [] then
417
- fprintf ppf " node%a;@ "
418
- fprint_node_attributes
427
+ fprintf ppf " node%a;@ "
428
+ EN.Attributes. fprint_vertex_list
419
429
default_node_attributes;
420
430
421
431
X. iter_vertex
@@ -433,7 +443,7 @@ struct
433
443
end ;
434
444
fprintf ppf " %s%a;@ "
435
445
(X. vertex_name node)
436
- fprint_node_attributes
446
+ EN.Attributes. fprint_vertex_list
437
447
(X. vertex_attributes node)
438
448
)
439
449
graph
@@ -448,16 +458,14 @@ struct
448
458
let sg, nodes = SG. find name ! subgraphs in
449
459
let children = SG. filter (fun n (sg , nodes ) -> sg.EN.Attributes. sg_parent = Some name) ! subgraphs in
450
460
fprintf ppf " @[<v 2>subgraph cluster_%s { %t%t@ %t };@]@\n "
451
-
461
+
452
462
name
453
-
463
+
454
464
(fun ppf ->
455
- (List. iter
456
- (fun n -> fprintf ppf " %a;@\n " EN.Attributes. fprint_vertex n)
465
+ EN.Attributes. fprint_vertex_list ppf
457
466
sg.EN.Attributes. sg_attributes
458
- )
459
467
)
460
-
468
+
461
469
(fun ppf ->
462
470
(List. iter (fun n -> fprintf ppf " %s;" (X. vertex_name n)) nodes)
463
471
)
@@ -481,14 +489,15 @@ struct
481
489
let default_edge_attributes = X. default_edge_attributes graph in
482
490
if default_edge_attributes <> [] then
483
491
fprintf ppf " edge%a;@ "
484
- fprint_edge_attributes default_edge_attributes;
492
+ EN.Attributes. fprint_edge_list default_edge_attributes;
485
493
486
494
X. iter_edges_e (function edge ->
487
495
fprintf ppf " %s %s %s%a;@ "
488
496
(X. vertex_name (X.E. src edge))
489
497
EN. edge_arrow
490
498
(X. vertex_name (X.E. dst edge))
491
- fprint_edge_attributes (X. edge_attributes edge)
499
+ EN.Attributes. fprint_edge_list
500
+ (X. edge_attributes edge)
492
501
) graph
493
502
494
503
in
@@ -736,6 +745,14 @@ module DotAttributes = struct
736
745
| `Tailurl s -> fprintf ppf " tailURL=%a" fprint_string s
737
746
| `Weight i -> fprintf ppf " weight=%i" i
738
747
748
+ let fprint_vertex_list =
749
+ CommonAttributes. fprint_attributes
750
+ CommonAttributes. fprint_style_list fprint_vertex
751
+
752
+ let fprint_edge_list =
753
+ CommonAttributes. fprint_attributes
754
+ CommonAttributes. fprint_style_list fprint_edge
755
+
739
756
end
740
757
741
758
(* * Graph modules with dot attributes *)
@@ -844,6 +861,14 @@ module NeatoAttributes = struct
844
861
| `Len f -> fprintf ppf " len=%f" f
845
862
| `Weight f -> fprintf ppf " weight=%f" f
846
863
864
+ let fprint_vertex_list =
865
+ CommonAttributes. fprint_attributes
866
+ CommonAttributes. fprint_style_list fprint_vertex
867
+
868
+ let fprint_edge_list =
869
+ CommonAttributes. fprint_attributes
870
+ CommonAttributes. fprint_style_list fprint_edge
871
+
847
872
end
848
873
849
874
module Neato =
0 commit comments