According to the documentation, it should be possible to do a TreePlot[g] with some general Graph-object g. But this is not true. To make things worse, a Graph-object cannot be created from data suitable for TreePlot.
I have to create a graph g from some Depth-First-Search algorithm searching paths from some start-vertex to some end-vertex, draw it as a TreePlot, and then find and list paths from start to end by FindPath[g,start,end]. The algorithm records labeled edges of the graph, one after the other. (The graph is not really a tree, since in the last step all leaves end up in the same end-state, but this is not a problem for TreePlot).
Unfortunately such edges have to be recorded as
graphData={Labeled[vi->vj,label],...} for Graph, but as
graphData={{vi->vj,label},...} for TreePlot
and those two different notations are incompatible, i.e: the notation for Graph is not understood by TreePlot and the notation for TreePlot is not understood by Graph.
In the end I can either not draw a TreePlot or not create a Graph and FindPath from the same recorded data graphData.
Of course I could maintain both graphData-notations or convert one into the other. But why? For me the problem is, that TreePlot[g] does not accept general Graph-objects g. And this is a bug in Wolfram Language.
See the following code for tests. Actually I have the same problem with vertex labels, which is not elaborated here.
If[True, (* Test Graph (from Graph-Data) & TreePlot & FindPath *)
Block[{a, b1, b2, c, graphData, graph},
(* Define graphData as a labeled list of edges in a form suitable \
for Graph *)
Print[Style["1 Defining a graph by graphData suitable for Graph",
Red, Bold]];
graphData = {Labeled[a -> b1, "a,b1"], Labeled[a -> b2, "a,b2"],
b1 -> c, b2 -> c};
Echo[graphData, "1 graphData: "];
(* Make a Graph-object from graphData *)
graph = Graph[graphData];
Echo[Row[{Head[graph], " ", graph}],
"1 make graph from graphData: "];
(* TreePlot and FindPath from graphData *)
Print[TreePlot[graphData, Left, a,
PlotLabel -> Style["1.1 TreePlot from graphData", Blue, Bold],
DirectedEdges -> True, VertexLabeling -> True,
EdgeLabeling -> True]];
Print[Style[
Row[{"1.1 FindPath from graphData: All paths from a to c: ",
FindPath[graphData, a, c, Infinity, All]}], Blue, Bold]];
(* TreePlot and FindPath from graph *)
Print[TreePlot[graph, Left, a,
PlotLabel -> Style["1.2 TreePlot from graph", Blue, Bold],
DirectedEdges -> True, VertexLabeling -> True,
EdgeLabeling -> True]];
Print[Style[
Row[{"1.2 FindPath from graph: All paths from a to c: ",
FindPath[graph, a, c, Infinity, All]}], Blue, Bold]];
(* Define graphData as a labeled list of edges in a Form suitable \
for TreePlot *)
Print[Style["2 Defining a graph by graphData suitable for TreePlot",
Red, Bold]];
graphData = {{a -> b1, "a,b1"}, {a -> b2, "a,b2"}, b1 -> c, b2 -> c};
Echo[graphData, "2 graphData: "];
(* Make a Graph-object from graphData *)
graph = Graph[graphData];
Echo[Row[{Head[graph], " ", graph}],
"2 make graph from graphData: "];
(* TreePlot and FindPath from graphData *)
Print[TreePlot[graphData, Left, a,
PlotLabel -> Style["2.1 TreePlot from graphData", Blue, Bold],
DirectedEdges -> True, VertexLabeling -> True,
EdgeLabeling -> True]];
Print[Style[
Row[{"2.1 FindPath from graphData: All paths from a to c: ",
FindPath[graphData, a, c, Infinity, All]}], Blue, Bold]];
(* TreePlot and FindPath from graph *)
Print[TreePlot[graph, Left, a,
PlotLabel -> Style["2.2 TreePlot from graph", Blue, Bold],
DirectedEdges -> True, VertexLabeling -> True,
EdgeLabeling -> True]];
Print[Style[
Row[{"2.2 FindPath from graph: All paths from a to c: ",
FindPath[graph, a, c, Infinity, All]}], Blue, Bold]];
]
]
1 Defining a graph by graphData suitable for Graph
1 graphData: {a->b1
a,b1
,a->b2
a,b2
,b1->c,b2->c}
1 make graph from graphData: Graph
TreePlot::grph: {a->b1
a,b1
,a->b2
a,b2
,b1->c,b2->c} is not a valid graph.
TreePlot::grph: {a->b1
a,b1
,a->b2
a,b2
,b1->c,b2->c} is not a valid graph.
TreePlot::grph: {a->b1
a,b1
,a->b2
a,b2
,b1->c,b2->c} is not a valid graph.
General::stop: Further output of TreePlot::grph will be suppressed during this calculation.
TreePlot[{a->b1
a,b1
,a->b2
a,b2
,b1->c,b2->c},Left,a,PlotLabel->1.1 TreePlot from graphData,DirectedEdges->True,VertexLabeling->True,EdgeLabeling->True]
1.1 FindPath from graphData: All paths from a to c: {{a,b2,c},{a,b1,c}}
TreePlot[SparseArray[Specified elements: 4
Dimensions: {4,4}
],Left,a,PlotLabel->1.2 TreePlot from graph,DirectedEdges->True,VertexLabeling->True,EdgeLabeling->True,DirectedEdges->True]
1.2 FindPath from graph: All paths from a to c: {{a,b2,c},{a,b1,c}}
2 Defining a graph by graphData suitable for TreePlot
2 graphData: {{a->b1,a,b1},{a->b2,a,b2},b1->c,b2->c}
2 make graph from graphData: Graph Graph[{{a->b1,a,b1},{a->b2,a,b2},b1->c,b2->c}]
FindPath::graph: A graph object is expected at position 1 in FindPath[{{a->b1,a,b1},{a->b2,a,b2},b1->c,b2->c},a,c,\[Infinity],All].
2.1 FindPath from graphData: All paths from a to c: FindPath[{{a->b1,a,b1},{a->b2,a,b2},b1->c,b2->c},a,c,\[Infinity],All]
TreePlot[Graph[{{a->b1,a,b1},{a->b2,a,b2},b1->c,b2->c}],Left,a,PlotLabel->2.2 TreePlot from graph,DirectedEdges->True,VertexLabeling->True,EdgeLabeling->True]
FindPath::graph: A graph object is expected at position 1 in FindPath[Graph[{{a->b1,a,b1},{a->b2,a,b2},b1->c,b2->c}],a,c,\[Infinity],All].
2.2 FindPath from graph: All paths from a to c: FindPath[Graph[{{a->b1,a,b1},{a->b2,a,b2},b1->c,b2->c}],a,c,\[Infinity],All]