FSharpGephiStreamer


Streaming a graph to gephi

Gephi enables the visualization and exploration of all kinds of graphs and networks. The library FSharpGephiStreamer provides functions suitable for use from F# scripting to stream graph data to gephi.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
#r "FSharpGephiStreamer.dll"
open FSharpGephiStreamer

/// Record type that represents a custum node 
type MyNode = {
    Id    : int
    Label : string
    Size  : float
    Data  : string
    }

/// Create a custum node
let createMyNode id label size data =
    {Id=id; Label=label; Size=size; Data=data};    


type MyEdge = {
    Id :     int
    Source : int
    Target : int
    Weight : float    
    }

let createMyEdge id sourceId targetId weight =
    {Id=id; Source=sourceId; Target=targetId; Weight=weight;};    



let rnd = System.Random(42)

/// Returns orange or blue otherwise
let rndColor () = 
    match rnd.NextDouble() with
    | x when x <= 0.3 -> Colors.Table.Office.orange
    | _ -> Colors.Table.Office.blue



let addMyNode (node:MyNode) =

    let nodeConverter (node:MyNode) =
        [
            Grammar.Attribute.Label node.Label; 
            Grammar.Attribute.Size  node.Size; 
            Grammar.Attribute.Color (rndColor ()); 
            Grammar.Attribute.UserDef ("UserData",node.Data); 
        ]

    Streamer.addNode nodeConverter node.Id node



let addMyEdge (edge:MyEdge) =

    let edgeConverter (edge:MyEdge) =
        [
            Grammar.Attribute.Size  edge.Weight; 
            Grammar.Attribute.EdgeType  Grammar.EdgeDirection.Undirected;             
            Grammar.Attribute.Color Colors.Table.Office.grey ;      
        ]
    
    Streamer.addEdge edgeConverter edge.Id edge.Source edge.Target edge



let nodes =
    [|0..10|] 
    |> Array.map (fun id -> 
                    createMyNode id (string id) (float ((2+id)*10)) "userdef.data")



nodes
|> Array.map addMyNode
        

for i=0 to 10 do
    for ii=i+1 to 10 do        
        let tmpedge = 
            createMyEdge (i*i+ii) nodes.[i].Id nodes.[ii].Id 5.
        if rnd.NextDouble() <= 0.3 then
            addMyEdge tmpedge |> ignore

Demo

1: 
Streamer.updateNode id 7 ([Grammar.Color Colors.Table.Office.red])
namespace FSharpGephiStreamer
type MyNode =
  {Id: int;
   Label: string;
   Size: float;
   Data: string;}

Full name: Tutorial.MyNode


 Record type that represents a custum node
MyNode.Id: int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
MyNode.Label: string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
MyNode.Size: float
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
Multiple items
MyNode.Data: string

--------------------
namespace Microsoft.FSharp.Data
val createMyNode : id:int -> label:string -> size:float -> data:string -> MyNode

Full name: Tutorial.createMyNode


 Create a custum node
val id : int
val label : string
val size : float
val data : string
namespace Microsoft.FSharp.Data
type MyEdge =
  {Id: int;
   Source: int;
   Target: int;
   Weight: float;}

Full name: Tutorial.MyEdge
MyEdge.Id: int
MyEdge.Source: int
MyEdge.Target: int
MyEdge.Weight: float
val createMyEdge : id:int -> sourceId:int -> targetId:int -> weight:float -> MyEdge

Full name: Tutorial.createMyEdge
val sourceId : int
val targetId : int
val weight : float
val rnd : System.Random

Full name: Tutorial.rnd
namespace System
Multiple items
type Random =
  new : unit -> Random + 1 overload
  member Next : unit -> int + 2 overloads
  member NextBytes : buffer:byte[] -> unit
  member NextDouble : unit -> float

Full name: System.Random

--------------------
System.Random() : unit
System.Random(Seed: int) : unit
val rndColor : unit -> Colors.Color

Full name: Tutorial.rndColor


 Returns orange or blue otherwise
System.Random.NextDouble() : float
val x : float
module Colors

from FSharpGephiStreamer
module Table

from FSharpGephiStreamer.Colors
module Office

from FSharpGephiStreamer.Colors.Table
val orange : Colors.Color

Full name: FSharpGephiStreamer.Colors.Table.Office.orange
val blue : Colors.Color

Full name: FSharpGephiStreamer.Colors.Table.Office.blue
val addMyNode : node:MyNode -> Either<string,RestfulAux.Error>

Full name: Tutorial.addMyNode
val node : MyNode
val nodeConverter : (MyNode -> Grammar.Attribute list)
module Grammar

from FSharpGephiStreamer
type Attribute =
  | Size of float
  | Color of Color
  | EdgeType of EdgeDirection
  | PositionX of float
  | PositionY of float
  | PositionZ of float
  | Label of string
  | UserDef of string * obj

Full name: FSharpGephiStreamer.Grammar.Attribute
union case Grammar.Attribute.Label: string -> Grammar.Attribute
union case Grammar.Attribute.Size: float -> Grammar.Attribute
union case Grammar.Attribute.Color: Colors.Color -> Grammar.Attribute
union case Grammar.Attribute.UserDef: string * obj -> Grammar.Attribute
MyNode.Data: string
module Streamer

from FSharpGephiStreamer
val addNode : nodeConverter:Streamer.NodeConverter<'node> -> nodeId:obj -> ('node -> Either<string,RestfulAux.Error>)

Full name: FSharpGephiStreamer.Streamer.addNode
val addMyEdge : edge:MyEdge -> Either<string,RestfulAux.Error>

Full name: Tutorial.addMyEdge
val edge : MyEdge
val edgeConverter : (MyEdge -> Grammar.Attribute list)
union case Grammar.Attribute.EdgeType: Grammar.EdgeDirection -> Grammar.Attribute
type EdgeDirection =
  | Directed
  | Undirected
  static member convert : (EdgeDirection -> bool)

Full name: FSharpGephiStreamer.Grammar.EdgeDirection
union case Grammar.EdgeDirection.Undirected: Grammar.EdgeDirection
val grey : Colors.Color

Full name: FSharpGephiStreamer.Colors.Table.Office.grey
val addEdge : edgeConverter:Streamer.EdgeConverter<'edge> -> edgeId:obj -> sourceId:obj -> targetId:obj -> ('edge -> Either<string,RestfulAux.Error>)

Full name: FSharpGephiStreamer.Streamer.addEdge
val nodes : MyNode []

Full name: Tutorial.nodes
module Array

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
val i : int
val ii : int
val tmpedge : MyEdge
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
val updateNode : nodeConverter:Streamer.NodeConverter<'node> -> nodeId:obj -> ('node -> Either<string,RestfulAux.Error>)

Full name: FSharpGephiStreamer.Streamer.updateNode
val id : x:'T -> 'T

Full name: Microsoft.FSharp.Core.Operators.id
val red : Colors.Color

Full name: FSharpGephiStreamer.Colors.Table.Office.red
Fork me on GitHub