({{, (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) 
is an option and property for (RefLink[Graph, paclet:ref/Graph]) and related functions that specifies a function to use to generate primitives for rendering each vertex. }})

OpenersNotesSection(Spacer1)Details

The following option settings can be used:

The wrapper (RefLink[Property, paclet:ref/Property])[v,VertexShapeFunction->f] can be used when creating graphs in functions such as (RefLink[Graph, paclet:ref/Graph]) etc.

Use GraphElementData["VertexShapeFunction"] to get a list of all named vertex functions.

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction])->func specifies that each vertex should be rendered with the primitives provided by func[{x,y},v,{w,h}], where {x,y} is the center, v the vertex name, and {w,h} the width and the height.

The vertex function func should render the vertex primitives in the bounding box {{x-w,x+w},{y-h,y+h}} automatically computed by layout algorithms.

OpenersPrimaryExamplesSection(Spacer1)Examples  (18)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Draw vertices using a predefined vertex function:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->"Square",VertexSize->0.2]

Specify a vertex function for an individual vertex:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->{ 1->"Square"},VertexSize->0.2]

Use a (RefLink[Property, paclet:ref/Property]) wrapper to specify individual vertex functions:

Graph[{Property[1,VertexShapeFunction->"Square"],2,3},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2]

Draw vertices by running a program:

vf[{xc_,yc_},name_,{w_,h_}]:=
Block[{xmin=xc-w,xmax=xc+w,ymin=yc-h,ymax=yc+h},
Polygon[{{xmin,ymin},{xmax,ymax},{xmin,ymax},{xmax,ymin}}]
];

CompleteGraph[4,VertexShapeFunction->vf,VertexSize->0.2]

OpenersExampleSection1(Spacer1)Scope  (13)

OpenersExampleSubsection0(Spacer1)VertexShapeFunction Specification  (9)

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be used for general graphs:

{Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->"Square",VertexSize->0.2],PathGraph[Range[25],VertexShapeFunction->"Square",VertexSize->0.2]}

Matrix graphs:

AdjacencyGraph[{{0,1,1},{1,0,1},{1,1,0}},VertexShapeFunction->"Square",VertexSize->0.2]

Special graphs:

{PetersenGraph[5,2,VertexShapeFunction->"Square",VertexSize->0.2],GridGraph[{4,4},VertexShapeFunction->"Square",VertexSize->0.2]}

Random graphs:

RandomGraph[UniformGraphDistribution[10,20],VertexShapeFunction->"Square",VertexSize->0.2]

Use (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in a (RefLink[Property, paclet:ref/Property]) wrapper:

Graph[{Property[1,VertexShapeFunction->"Square"],2,3},{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2]

HighlightGraph[GridGraph[{3,3},VertexSize->0.2],Property[5,VertexShapeFunction->"Square"]]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) works with patterns:

CompleteGraph[5,VertexShapeFunction->{_?EvenQ->"Star"},VertexSize->0.2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf1[{xc_,yc_},name_,{w_,h_}]:=Rectangle[{xc-w,yc-h},{xc+w,yc+h}]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf1]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf2[{xc_,yc_},name_,{w_,h_}]:={Red,Rectangle[{xc-w,yc-h},{xc+w,yc+h}]}

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexSize, paclet:ref/VertexSize]):

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->"Star",VertexSize->{1->Small,Medium}]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexShape, paclet:ref/VertexShape]):

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexSize->0.2,VertexShapeFunction->"Star",VertexShape->]

OpenersExampleSubsection1(Spacer1)VertexShapeFunction Gallery  (4)

Get a list of built-in collections for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

GraphElementData["Vertex"]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Basic" collection:

GraphElementData["Vertex","Basic"]

Simple basic shapes:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"Triangle","Square","Rectangle","Pentagon","Hexagon","Octagon"}}]

Common basic shapes:

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"DownTrapezoid","UpTrapezoid","Parallelogram","FiveDown","Circle","Diamond","Star","Capsule"}}]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Rounded" collection:

GraphElementData["Vertex","Rounded"]

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->Style[vf,9]],{vf,GraphElementData["Vertex","Rounded"]}]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Concave" collection:

GraphElementData["Vertex","Concave"]

Table[Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->Style[vf,9]],{vf,GraphElementData["Vertex","Concave"]}]

OpenersExampleSection3(Spacer1)Applications  (1)

Draw vertices using a predefined graphic using (RefLink[Inset, paclet:ref/Inset]):

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},VertexShapeFunction->(Inset[,#]&)]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Graph, paclet:ref/Graph])  ▪  (RefLink[GraphStyle, paclet:ref/GraphStyle])  ▪  (RefLink[VertexStyle, paclet:ref/VertexStyle])  ▪  (RefLink[VertexLabels, paclet:ref/VertexLabels])  ▪  (RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Visualization, paclet:guide/GraphVisualization])}, {▪(RefLinkPlain[Graph Properties, paclet:guide/GraphProperties])}, {▪(RefLinkPlain[Graph Styling, Labeling, and Layout, paclet:guide/GraphStylingAndLabeling])}, {▪(RefLinkPlain[Properties, paclet:guide/Properties])}})}})