Function Repository Resource:

LayeredLayoutGraph

Source Notebook

Render a graph with vertices arranged in the specified layers

Contributed by: Nikolay Murzin

ResourceFunction["LayeredLayoutGraph"][g, layers]

return graph g with top-down embedding corresponding to a specified list of layers.

Examples

Basic Examples (1) 

Layer the graph with specified top-to-bottom layers of vertices:

In[1]:=
ResourceFunction["LayeredLayoutGraph"][\!\(\*
GraphicsBox[
NamespaceBox["NetworkGraphics",
DynamicModuleBox[{Typeset`graph = HoldComplete[
Graph[{1, 2, 3, 4, 5, 6, 7, 8}, {{{1, 2}, {1, 3}, {2, 4}, {3, 4}, {2, 5}, {3, 6}, {4, 7}, {5, 7}, {4, 8}}, Null}, {FormatType -> TraditionalForm, GraphLayout -> {"Dimension" -> 2}, VertexLabels -> {Automatic}}]]}, 
TagBox[GraphicsGroupBox[{
{Hue[0.6, 0.7, 0.5], Opacity[0.7], Arrowheads[Medium], ArrowBox[{{0., 3.}, {0., 2.}}, 0.030239520958083826`], ArrowBox[{{0., 3.}, {1., 2.}}, 0.030239520958083826`], ArrowBox[{{0., 2.}, {0., 1.}}, 0.030239520958083826`], ArrowBox[{{0., 2.}, {-1., 1.}}, 0.030239520958083826`], ArrowBox[{{1., 2.}, {0., 1.}}, 0.030239520958083826`], ArrowBox[{{1., 2.}, {1., 1.}}, 0.030239520958083826`], ArrowBox[{{0., 1.}, {-1., 0.}}, 0.030239520958083826`], ArrowBox[{{0., 1.}, {0., 0.}}, 0.030239520958083826`], ArrowBox[{{-1., 1.}, {-1., 0.}}, 0.030239520958083826`]}, 
{Hue[0.6, 0.2, 0.8], EdgeForm[{GrayLevel[0], Opacity[
          0.7]}], {DiskBox[{0., 3.}, 0.030239520958083826], InsetBox["1", Offset[{2, 2}, {0.030239520958083826, 3.0302395209580837}], ImageScaled[{0, 0}],
BaseStyle->"Graphics"]}, {DiskBox[{0., 2.}, 0.030239520958083826], InsetBox["2", Offset[{2, 2}, {0.030239520958083826, 2.0302395209580837}], ImageScaled[{0, 0}],
BaseStyle->"Graphics"]}, {DiskBox[{1., 2.}, 0.030239520958083826], InsetBox["3", Offset[{2, 2}, {1.030239520958084, 2.0302395209580837}], ImageScaled[{0, 0}],
BaseStyle->"Graphics"]}, {DiskBox[{0., 1.}, 0.030239520958083826], InsetBox["4", Offset[{2, 2}, {0.030239520958083826, 1.030239520958084}],
             ImageScaled[{0, 0}],
BaseStyle->"Graphics"]}, {DiskBox[{-1., 1.}, 0.030239520958083826], InsetBox["5", Offset[{2, 2}, {-0.9697604790419162, 1.030239520958084}], ImageScaled[{0, 0}],
BaseStyle->"Graphics"]}, {DiskBox[{1., 1.}, 0.030239520958083826], InsetBox["6", Offset[{2, 2}, {1.030239520958084, 1.030239520958084}], ImageScaled[{0, 0}],
BaseStyle->"Graphics"]}, {DiskBox[{-1., 0.}, 0.030239520958083826], InsetBox["7", Offset[{2, 2}, {-0.9697604790419162, 0.030239520958083826}], ImageScaled[{0, 0}],
BaseStyle->"Graphics"]}, {DiskBox[{0., 0.}, 0.030239520958083826], InsetBox["8", Offset[{2, 2}, {0.030239520958083826, 0.030239520958083826}], ImageScaled[{0, 0}],
BaseStyle->"Graphics"]}}}],
MouseAppearanceTag["NetworkGraphics"]],
AllowKernelInitialization->False]],
DefaultBaseStyle->{"NetworkGraphics", FrontEnd`GraphicsHighlightColor -> Hue[0.8, 1., 0.6]},
FormatType->TraditionalForm,
FrameTicks->None]\), {{1}, {2, 3}, {4, 5, 6}, {7, 8}}]
Out[1]=

Version History

  • 1.0.0 – 01 November 2021

Related Resources

License Information