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.
Maybe Basics.Int
Represents the distance between two nodes. A value of Just number
indicates the number of edges in a shortest path connecting the nodes. A value
of Nothing
means 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 Distance
can represent both forward and
backward connections.
basicPaint : (AcyclicDigraph.Node -> String) -> AcyclicDigraph -> AcyclicDigraph.Node -> ArcDiagram.Paint
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)
graph
See the Selectable Node example for more detail.
{ viewLabel : AcyclicDigraph.Node -> Distance -> Svg AcyclicDigraph.Node
, colorNode : AcyclicDigraph.Node -> Distance -> String
, colorEdge : AcyclicDigraph.Edge -> Distance -> String
}
Similar to Paint
, but each function also takes a Distance
argument.
defaultDistancePaint : DistancePaint
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.
paint : DistancePaint -> AcyclicDigraph -> AcyclicDigraph.Node -> ArcDiagram.Paint
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