Skip to content

Commit

Permalink
create first DAG creation function
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Oct 22, 2021
1 parent a9eddd6 commit eb985e3
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions src/ISADotNet.Viz/DAG.fs
Original file line number Diff line number Diff line change
@@ -1,13 +1,61 @@
namespace ISADotNet.Viz

open ISADotNet
open ISADotNet.API
open Cyjs.NET

module DAG =
type DAG =

let show (dag : CyGraph.CyGraph) = CyGraph.show dag
static member show (dag : CyGraph.CyGraph) = CyGraph.show dag

let toEmbeddedHTML (dag : CyGraph.CyGraph) = HTML.toEmbeddedHTML dag
static member toEmbeddedHTML (dag : CyGraph.CyGraph) = HTML.toEmbeddedHTML dag

let toHTML (dag : CyGraph.CyGraph) = HTML.toCytoHTML dag
static member toHTML (dag : CyGraph.CyGraph) = HTML.toCytoHTML dag

static member fromProcessSequence (ps : Process list, ?Schema : Schema) =

let schema = Option.defaultValue ISADotNet.Viz.Schema.DefaultGrey Schema

let edges =
ps
|> List.collect (fun p ->
p.Outputs.Value
|> List.zip p.Inputs.Value
|> List.map (fun (i,o) -> ProcessInput.getName i |> Option.get,ProcessOutput.getName o |> Option.get,p.Name.Value)
)

let cyNodes =
edges
|> List.collect (fun (i,o,e) -> [i;o])
|> List.distinct
|> List.map (fun n -> node n [CyParam.label n])

let cyEgdes =
edges
|> List.mapi (fun index (i,o,e) -> edge (string index) i o [CyParam.label e])

CyGraph.initEmpty ()
|> CyGraph.withElements cyNodes
|> CyGraph.withElements cyEgdes
|> CyGraph.withStyle "node"
[
CyParam.content =. CyParam.label
CyParam.color schema.VertexLabelColor
CyParam.Background.color schema.VertexColor
]
|> CyGraph.withStyle "edge"
[
CyParam.content =. CyParam.label
CyParam.Curve.style "bezier"
CyParam.opacity 0.666
CyParam.width 7
CyParam.Target.Arrow.shape "triangle"
CyParam.Source.Arrow.shape "circle"

CyParam.color schema.EdgeLabelColor
CyParam.Line.color schema.EdgeColor
CyParam.Target.Arrow.color schema.EdgeColor
CyParam.Source.Arrow.color schema.EdgeColor
]
|> CyGraph.withLayout (Layout.initBreadthfirst id)
|> CyGraph.withSize(800, 400)

0 comments on commit eb985e3

Please sign in to comment.