admin管理员组文章数量:1394054
A piece of code using MSAGL with the GDI viewer is able to make an acceptable rendition of a graph with subgraphs, e.g.:
open System.Windows.Controls
open System.Windows.Media
open Microsoft.Msagl.Drawing
type GraphViewer = Microsoft.Msagl.GraphViewerGdi.GViewer
let addNamespaceToGraph (graph: Graph) (ns: string) =
let rec loop (parentGraph: Subgraph) (path: string list) (names: string list) =
match names with
| [] -> ()
| name :: rest ->
let path' = name::path
let subNamespace = String.Join('.', path' |> List.rev)
let subgraph' =
match parentGraph.Subgraphs |> Seq.tryFind (fun sg -> sg.Id = subNamespace) with
| Some sg -> sg
| None ->
let newSubgraph = new Subgraph(subNamespace)
newSubgraph.LabelText <- name
parentGraph.AddSubgraph(newSubgraph)
newSubgraph
loop subgraph' path' rest
let root = graph.RootSubgraph
let path = ns.Split('.') |> List.ofArray
loop root [] path
let createGraph () : Graph =
let graph = new Graph("Namespaces")
let addNamespace = addNamespaceToGraph graph
// Add namespaces
addNamespace "Foo.Bar.Baz"
addNamespace "Foo.Bar.Qux"
addNamespace "Foo.Baz"
// Add an edge between nodes in different subgraphs
graph.AddEdge("Foo.Bar.Baz", "Foo.Baz") |> ignore
graph
let showGraph (graph: Graph) =
let viewer = new GraphViewer()
viewer.Graph <- graph // Set the graph after layout is performed
viewer
let graph = createGraph()
showGraph graph |> Dump
Becomes:
However, almost identical code, using the WPF viewer makes an unusable rendition:
open System.Windows.Controls
open System.Windows.Media
open Microsoft.Msagl.Drawing
type GraphViewer = Microsoft.Msagl.WpfGraphControl.GraphViewer
let addNamespaceToGraph (graph: Graph) (ns: string) =
let rec loop (parentGraph: Subgraph) (path: string list) (names: string list) =
match names with
| [] -> ()
| name :: rest ->
let path' = name::path
let subNamespace = String.Join('.', path' |> List.rev)
let subgraph' =
match parentGraph.Subgraphs |> Seq.tryFind (fun sg -> sg.Id = subNamespace) with
| Some sg -> sg
| None ->
let newSubgraph = new Subgraph(subNamespace)
newSubgraph.LabelText <- name
parentGraph.AddSubgraph(newSubgraph)
newSubgraph
loop subgraph' path' rest
let root = graph.RootSubgraph
let path = ns.Split('.') |> List.ofArray
loop root [] path
let createGraph () : Graph =
let graph = new Graph("Namespaces")
let addNamespace = addNamespaceToGraph graph
// Add namespaces
addNamespace "Foo.Bar.Baz"
addNamespace "Foo.Bar.Qux"
addNamespace "Foo.Baz"
// Add an edge between nodes in different subgraphs
graph.AddEdge("Foo.Bar.Baz", "Foo.Baz") |> ignore
graph
let showGraph (graph: Graph) =
let viewer = new GraphViewer()
let canvas = new Canvas()
viewer.BindToPanel(canvas)
viewer.Graph <- graph // Set the graph after layout is performed
canvas
let graph = createGraph()
showGraph graph |> Dump
Becomes:
What can I do to fix the rendering with the WPF viewer, if anything?
本文标签: How to make MSAGL subgraphs render okay with WPF viewer vs GDI viewerStack Overflow
版权声明:本文标题:How to make MSAGL subgraphs render okay with WPF viewer vs GDI viewer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744748457a2623030.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论