Formerly brainrape/elm-arc-diagram. Search finds this package by either name.
This module provides convenience functions for creating ArcDiagram.Paint
values that will color nodes and edges based on distance from a given node.
This is useful for highlighting the subgraph which is reachable from a
given node.
Get a Paint value that uses the defaultDistancePaint coloring and your
own label text, by providing a toLabel function, a graph, and a node.
ArcDiagram.view
ArcDiagram.defaultLayout
(ArcDiagram.Distance.basicPaint toLabel graph node)
graphSee the Selectable Node example for more detail.
Similar to Paint, but each function also takes a Distance argument.
The defaultDistancePaint will color connected nodes and edges blue or red
(for forward or backward connections), and color unconnected nodes, edges, and
labels light gray.
Get a Paint value from a DistancePaint value, a graph, and a node.
colorFromDistance : Distance -> String
colorFromDistance distance =
case distance of
Just _ ->
"black"
Nothing ->
"lightgray"
view : AcyclicDigraph -> Node -> Html Node
view graph node =
ArcDiagram.view
ArcDiagram.defaultLayout
(ArcDiagram.Distance.paint
{ viewLabel = \n d -> viewColorLabel (colorFromDistance d) (toLabel n)
, colorNode = always colorFromDistance
, colorEdge = always colorFromDistance
}
graph
node
)
graph
Represents the distance between two nodes. A value of
Just numberindicates the number of edges in a shortest path connecting the nodes. A value ofNothingmeans there is no path connecting the nodes.Unconventionally, the number may be negative, which indicates there is a path in the reverse direction. This way
Distancecan represent both forward and backward connections.