Skip to content

Commit 8a9fbd4

Browse files
committed
revert on commit 98daafa
but multiple styles are collected and output at once
1 parent df389ee commit 8a9fbd4

File tree

4 files changed

+80
-54
lines changed

4 files changed

+80
-54
lines changed

dgraph/dGraphTreeLayout.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ struct
239239
| `Peripheries p -> vattrs.peripheries <- set_if_none vattrs.peripheries p
240240
| `Regular r -> vattrs.regular <- set_if_none vattrs.regular r
241241
| `Shape shape -> vattrs.shape <- set_if_none vattrs.shape shape
242-
| `Style s -> vattrs.style <- s @ vattrs.style
242+
| `Style s -> vattrs.style <- s :: vattrs.style
243243
| `Width w -> vattrs.width <- set_if_none vattrs.width w
244244
| `Fillcolor c ->
245245
vattrs.fillcolor <- set_if_none vattrs.fillcolor
@@ -605,7 +605,7 @@ struct
605605
eattrs.labelfontsize <- set_if_none eattrs.labelfontsize s;
606606
attributes_list_to_eattributes eattrs q
607607
| `Style s :: q ->
608-
eattrs.style <- s @ eattrs.style;
608+
eattrs.style <- s :: eattrs.style;
609609
attributes_list_to_eattributes eattrs q
610610
| (`Arrowhead _ | `Arrowsize _ | `Arrowtail _ | `Comment _ | `Constraint _
611611
| `Headlabel _ | `Headport _ | `Headurl _ | `Labelangle _
@@ -631,7 +631,7 @@ struct
631631
let dgraph_layout_default =
632632
[ `Color 0xFF0000; `Decorate false; `Dir `Forward; `Fontcolor 0x00000;
633633
`Fontname "Sans"; `Fontsize 12; `Label ""; `Labelfontcolor 0x000000;
634-
`Labelfontname "Sans"; `Labelfontsize 12; `Style [`Solid] ]
634+
`Labelfontname "Sans"; `Labelfontsize 12; `Style `Solid ]
635635
in
636636
attributes_list_to_eattributes eattrs
637637
(Tree.default_edge_attributes tree

dgraph/dGraphTreeModel.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ module SubTreeMake(G: Graphviz.GraphWithDotAttrs) = struct
175175

176176
let vertex_attributes v =
177177
let t = tree () in
178-
if TM.is_ghost_node v t then [ `Style [`Invis] ]
178+
if TM.is_ghost_node v t then [ `Style `Invis ]
179179
else G.vertex_attributes (TM.get_graph_vertex v t)
180180

181181
let edge_attributes e =
182182
let t = tree () in
183183
if TM.is_ghost_node (T.E.src e) t || TM.is_ghost_node (T.E.dst e) t then
184-
[ `Style [`Dashed]; `Dir `None ]
184+
[ `Style `Dashed; `Dir `None ]
185185
else
186186
G.edge_attributes
187187
(G.find_edge

src/graphviz.ml

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ let fprint_dir ppf = function
8080
`TopToBottom -> fprintf ppf "TB"
8181
| `LeftToRight -> fprintf ppf "LR"
8282

83+
8384
(** The [ATTRIBUTES] module type defines the interface for the engines. *)
8485
module type ATTRIBUTES = sig
8586

@@ -167,7 +168,8 @@ module CommonAttributes = struct
167168
(** Sets the shape of the node. Default value is [`Ellipse].
168169
[`Polygon (i, f)] draws a polygon with [n] sides and a skewing
169170
of [f]. *)
170-
| `Style of [ `Rounded | `Filled | `Solid | `Dashed | `Dotted | `Bold | `Invis ] list
171+
| `Style of
172+
[ `Rounded | `Filled | `Solid | `Dashed | `Dotted | `Bold | `Invis ]
171173
(** Sets the layout style of the node. Several styles may be combined
172174
simultaneously. *)
173175
| `Width of float
@@ -208,7 +210,7 @@ module CommonAttributes = struct
208210
| `Penwidth of float
209211
(** Width of the pen (in points) used to draw the edge. Default value
210212
is [1.0]. *)
211-
| `Style of [ `Solid | `Dashed | `Dotted | `Bold | `Invis ] list
213+
| `Style of [ `Solid | `Dashed | `Dotted | `Bold | `Invis ]
212214
(** Sets the layout style of the edge. Several styles may be combined
213215
simultaneously. *)
214216
]
@@ -242,19 +244,22 @@ module CommonAttributes = struct
242244
| `Polygon (i, f) -> fprintf ppf "polygon, sides=%i, skew=%f" i f
243245

244246
let rec fprint_string_list ppf = function
245-
[] -> ()
247+
| [] -> ()
246248
| [hd] -> fprintf ppf "%s" hd
247249
| hd :: tl -> fprintf ppf "%s,%a" hd fprint_string_list tl
248250

249251
let node_style_str = function
250-
`Rounded -> "rounded"
252+
| `Rounded -> "rounded"
251253
| `Filled -> "filled"
252254
| `Solid -> "solid"
253255
| `Dashed -> "dashed"
254256
| `Dotted -> "dotted"
255257
| `Bold -> "bold"
256258
| `Invis -> "invis"
257259

260+
let fprint_style_list ppf a =
261+
fprintf ppf "style=\"%a\"" fprint_string_list (List.map node_style_str a)
262+
258263
let fprint_vertex ppf = function
259264
| `Color a -> fprintf ppf "color=%a" fprint_color a
260265
| `ColorWithTransparency a ->
@@ -269,7 +274,7 @@ module CommonAttributes = struct
269274
| `Peripheries i -> fprintf ppf "peripheries=%i" i
270275
| `Regular b -> fprintf ppf "regular=%b" b
271276
| `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
273278
| `Width f -> fprintf ppf "width=%f" f
274279

275280
let edge_style_str =
@@ -296,7 +301,40 @@ module CommonAttributes = struct
296301
(* (String.escaped s) *)
297302
| `Labelfontsize i -> fprintf ppf "labelfontsize=%i" i
298303
| `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
300338

301339
end
302340

@@ -310,8 +348,8 @@ module type ENGINE = sig
310348
module Attributes : sig
311349
include ATTRIBUTES
312350
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
315353
end
316354

317355
(** The litteral name of the engine. *)
@@ -375,34 +413,6 @@ struct
375413
fprintf ppf "%a;@ " EN.Attributes.fprint_graph att
376414
) list
377415

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-
406416
(** [fprint_graph ppf graph] pretty prints the graph [graph] in
407417
the CGL language on the formatter [ppf]. *)
408418
let fprint_graph ppf graph =
@@ -414,8 +424,8 @@ struct
414424
let print_nodes ppf =
415425
let default_node_attributes = X.default_vertex_attributes graph in
416426
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
419429
default_node_attributes;
420430

421431
X.iter_vertex
@@ -433,7 +443,7 @@ struct
433443
end;
434444
fprintf ppf "%s%a;@ "
435445
(X.vertex_name node)
436-
fprint_node_attributes
446+
EN.Attributes.fprint_vertex_list
437447
(X.vertex_attributes node)
438448
)
439449
graph
@@ -448,16 +458,14 @@ struct
448458
let sg, nodes = SG.find name !subgraphs in
449459
let children = SG.filter (fun n (sg, nodes) -> sg.EN.Attributes.sg_parent = Some name) !subgraphs in
450460
fprintf ppf "@[<v 2>subgraph cluster_%s { %t%t@ %t };@]@\n"
451-
461+
452462
name
453-
463+
454464
(fun ppf ->
455-
(List.iter
456-
(fun n -> fprintf ppf "%a;@\n" EN.Attributes.fprint_vertex n)
465+
EN.Attributes.fprint_vertex_list ppf
457466
sg.EN.Attributes.sg_attributes
458-
)
459467
)
460-
468+
461469
(fun ppf ->
462470
(List.iter (fun n -> fprintf ppf "%s;" (X.vertex_name n)) nodes)
463471
)
@@ -481,14 +489,15 @@ struct
481489
let default_edge_attributes = X.default_edge_attributes graph in
482490
if default_edge_attributes <> [] then
483491
fprintf ppf "edge%a;@ "
484-
fprint_edge_attributes default_edge_attributes;
492+
EN.Attributes.fprint_edge_list default_edge_attributes;
485493

486494
X.iter_edges_e (function edge ->
487495
fprintf ppf "%s %s %s%a;@ "
488496
(X.vertex_name (X.E.src edge))
489497
EN.edge_arrow
490498
(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)
492501
) graph
493502

494503
in
@@ -736,6 +745,14 @@ module DotAttributes = struct
736745
| `Tailurl s -> fprintf ppf "tailURL=%a" fprint_string s
737746
| `Weight i -> fprintf ppf "weight=%i" i
738747

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+
739756
end
740757

741758
(** Graph modules with dot attributes *)
@@ -844,6 +861,14 @@ module NeatoAttributes = struct
844861
| `Len f -> fprintf ppf "len=%f" f
845862
| `Weight f -> fprintf ppf "weight=%f" f
846863

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+
847872
end
848873

849874
module Neato =

src/graphviz.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ module CommonAttributes : sig
142142
(** Sets the shape of the vertex. Default value is [`Ellipse].
143143
[`Polygon (i, f)] draws a polygon with [n] sides and a skewing
144144
of [f]. *)
145-
| `Style of [ `Rounded | `Filled | `Solid | `Dashed | `Dotted | `Bold | `Invis ] list
145+
| `Style of
146+
[ `Rounded | `Filled | `Solid | `Dashed | `Dotted | `Bold | `Invis ]
146147
(** Sets the layout style of the vertex.
147148
Several styles may be combined simultaneously. *)
148149
| `Width of float
@@ -183,7 +184,7 @@ module CommonAttributes : sig
183184
| `Penwidth of float
184185
(** Width of the pen (in points) used to draw the edge. Default value
185186
is [1.0]. *)
186-
| `Style of [ `Solid | `Dashed | `Dotted | `Bold | `Invis ] list
187+
| `Style of [ `Solid | `Dashed | `Dotted | `Bold | `Invis ]
187188
(** Sets the layout style of the edge. Several styles may be combined
188189
simultaneously. *)
189190
]

0 commit comments

Comments
 (0)