| author | wenzelm | 
| Fri, 24 Jul 2015 22:19:36 +0200 | |
| changeset 60775 | 4592a9118d0b | 
| parent 60089 | 8bd5999133d4 | 
| child 74232 | 1091880266e5 | 
| permissions | -rw-r--r-- | 
| 49561 | 1  | 
(* Title: Pure/General/graph_display.ML  | 
2  | 
Author: Makarius  | 
|
3  | 
||
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
4  | 
Support for graph display.  | 
| 49561 | 5  | 
*)  | 
6  | 
||
7  | 
signature GRAPH_DISPLAY =  | 
|
8  | 
sig  | 
|
| 
59208
 
2486d625878b
for graph display, prefer graph data structure over list with dependencies;
 
wenzelm 
parents: 
59207 
diff
changeset
 | 
9  | 
type node  | 
| 
 
2486d625878b
for graph display, prefer graph data structure over list with dependencies;
 
wenzelm 
parents: 
59207 
diff
changeset
 | 
10  | 
val content_node: string -> Pretty.T list -> node  | 
| 
 
2486d625878b
for graph display, prefer graph data structure over list with dependencies;
 
wenzelm 
parents: 
59207 
diff
changeset
 | 
11  | 
  val session_node: {name: string, unfold: bool, directory: string, path: string} -> node
 | 
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
12  | 
type entry = (string * node) * string list  | 
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
13  | 
val display_graph: entry list -> unit  | 
| 
60089
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
14  | 
val display_graph_old: entry list -> unit  | 
| 49561 | 15  | 
end;  | 
16  | 
||
17  | 
structure Graph_Display: GRAPH_DISPLAY =  | 
|
18  | 
struct  | 
|
19  | 
||
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
20  | 
(* graph entries *)  | 
| 
59208
 
2486d625878b
for graph display, prefer graph data structure over list with dependencies;
 
wenzelm 
parents: 
59207 
diff
changeset
 | 
21  | 
|
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
22  | 
datatype node =  | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
23  | 
  Node of {name: string, content: Pretty.T list, unfold: bool, directory: string, path: string};
 | 
| 49561 | 24  | 
|
| 
59208
 
2486d625878b
for graph display, prefer graph data structure over list with dependencies;
 
wenzelm 
parents: 
59207 
diff
changeset
 | 
25  | 
fun content_node name content =  | 
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
26  | 
  Node {name = name, content = content, unfold = true, directory = "", path = ""};
 | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
27  | 
|
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
28  | 
fun session_node {name, unfold, directory, path} =
 | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
29  | 
  Node {name = name, content = [], unfold = unfold, directory = directory, path = path};
 | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
30  | 
|
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
31  | 
type entry = (string * node) * string list;  | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
32  | 
|
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
33  | 
|
| 
60089
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
34  | 
(* display graph *)  | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
35  | 
|
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
36  | 
local  | 
| 59449 | 37  | 
|
38  | 
fun encode_node (Node {name, content, ...}) =
 | 
|
39  | 
(name, content) |>  | 
|
40  | 
let open XML.Encode  | 
|
41  | 
in pair string (YXML.parse_body o Pretty.symbolic_string_of o Pretty.chunks) end;  | 
|
42  | 
||
43  | 
val encode_graph =  | 
|
44  | 
let open XML.Encode in list (pair (pair string encode_node) (list string)) end;  | 
|
45  | 
||
| 
60089
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
46  | 
in  | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
47  | 
|
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
48  | 
fun display_graph entries =  | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
49  | 
let  | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
50  | 
val ((bg1, bg2), en) =  | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
51  | 
YXML.output_markup_elem  | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
52  | 
        (Active.make_markup Markup.graphviewN {implicit = false, properties = []});
 | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
53  | 
  in writeln ("See " ^ bg1 ^ YXML.string_of_body (encode_graph entries) ^ bg2 ^ "graph" ^ en) end;
 | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
54  | 
|
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
55  | 
end;  | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
56  | 
|
| 59449 | 57  | 
|
58  | 
(* support for old browser *)  | 
|
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
59  | 
|
| 
60089
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
60  | 
local  | 
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
61  | 
|
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
62  | 
structure Graph =  | 
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
63  | 
Graph(type key = string * string val ord = prod_ord string_ord string_ord);  | 
| 
59208
 
2486d625878b
for graph display, prefer graph data structure over list with dependencies;
 
wenzelm 
parents: 
59207 
diff
changeset
 | 
64  | 
|
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
65  | 
fun build_graph entries =  | 
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
66  | 
let  | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
67  | 
val ident_names =  | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
68  | 
      fold (fn ((ident, Node {name, ...}), _) => Symtab.update_new (ident, (name, ident)))
 | 
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
69  | 
entries Symtab.empty;  | 
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
70  | 
val the_key = the o Symtab.lookup ident_names;  | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
71  | 
in  | 
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
72  | 
Graph.empty  | 
| 
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
73  | 
|> fold (fn ((ident, node), _) => Graph.new_node (the_key ident, node)) entries  | 
| 
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
74  | 
|> fold (fn ((ident, _), parents) =>  | 
| 
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
75  | 
fold (fn parent => Graph.add_edge (the_key parent, the_key ident)) parents) entries  | 
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
76  | 
end;  | 
| 49561 | 77  | 
|
| 
59244
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
78  | 
val sort_graph = build_graph #> (fn graph =>  | 
| 
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
79  | 
Graph.topological_order graph |> map (fn key =>  | 
| 
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
80  | 
let val (_, (node, (preds, _))) = Graph.get_entry graph key  | 
| 
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
81  | 
in ((#2 key, node), map #2 (Graph.Keys.dest preds)) end));  | 
| 
 
19b5fc4b2b38
more uniform support for graph display in ML/Scala;
 
wenzelm 
parents: 
59211 
diff
changeset
 | 
82  | 
|
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
83  | 
val encode_browser =  | 
| 59449 | 84  | 
sort_graph  | 
85  | 
  #> map (fn ((key, Node {name, unfold, content = _, directory, path}), parents) =>
 | 
|
| 
59208
 
2486d625878b
for graph display, prefer graph data structure over list with dependencies;
 
wenzelm 
parents: 
59207 
diff
changeset
 | 
86  | 
"\"" ^ name ^ "\" \"" ^ key ^ "\" \"" ^ directory ^ (if unfold then "\" + \"" else "\" \"") ^  | 
| 
59210
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
87  | 
path ^ "\" > " ^ space_implode " " (map quote parents) ^ " ;")  | 
| 
 
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
 
wenzelm 
parents: 
59208 
diff
changeset
 | 
88  | 
#> cat_lines;  | 
| 
50715
 
8cfd585b9162
prefer old graph browser in Isabelle/jEdit, which still produces better layout;
 
wenzelm 
parents: 
50450 
diff
changeset
 | 
89  | 
|
| 
60089
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
90  | 
in  | 
| 
49565
 
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
 
wenzelm 
parents: 
49561 
diff
changeset
 | 
91  | 
|
| 
60089
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
92  | 
fun display_graph_old entries =  | 
| 59449 | 93  | 
let  | 
94  | 
val ((bg1, bg2), en) =  | 
|
95  | 
YXML.output_markup_elem  | 
|
96  | 
        (Active.make_markup Markup.browserN {implicit = false, properties = []});
 | 
|
| 
60089
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
97  | 
  in writeln ("See " ^ bg1 ^ encode_browser entries ^ bg2 ^ "graph" ^ en) end;
 | 
| 49561 | 98  | 
|
99  | 
end;  | 
|
| 
60089
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
100  | 
|
| 
 
8bd5999133d4
let the system choose Graph_Display.display_graph_old: thm_deps needs tree hierarchy, code_deps needs cycles (!?);
 
wenzelm 
parents: 
59449 
diff
changeset
 | 
101  | 
end;  |