robvandenbogaard / elm-knowledge-graph / Knowledge.Graph

This module provides everything to easily insert a navigatable knowledge graph diagram as html.

example =
    """
this knowledge graph
  is a graph
a graph
  has nodes
  has edges
edges
  have labels
"""

init =
    ( { graph = Knowledge.Graph.init example }, Cmd.none )

type Msg
    = GraphMsg Knowledge.Graph.Msg

update msg model =
    case msg of
        GraphMsg m ->
            ( { model
                | graph = Knowledge.Graph.update m model.graph
              }
            , Cmd.none
            )

view { graph } =
    Html.div []
        [ lazy Knowledge.Graph.view graph
            |> Html.map GraphMsg
        ]


type alias Model =
{ selection : Focus
, graph : Graph String ()
, labels : Dict ( Basics.Int
, Basics.Int ) String 
}

Graph model, including a selection focus, the graph nodes and structure itself and labels to be shown on edges.


type Msg

Message type facilitating the selection of nodes and edges.

init : String -> Model

Init function for the knowledge graph diagram.

update : Msg -> Model -> Model

Update function for the knowledge graph diagram.

view : Model -> Html Msg

View function for the knowledge graph diagram.

select : String -> Model -> Model

Function for selecting a node of the knowledge graph diagram. This doesn't support selecting multiple nodes yet, though the selection data type does allow for it (as it is a list).