Graph Maker
WMG_Random_Graph Class Reference

A class used to create random graphs. More...

Inheritance diagram for WMG_Random_Graph:
WMG_Graph_Manager WMG_Events WMG_GUI_Functions WMG_Text_Functions

Public Member Functions

List< GameObject > GenerateGraph ()
 Creates a node, and then calls GenerateGraphFromNode. More...
 
List< GameObject > GenerateGraphFromNode (WMG_Node fromNode)
 Generates the random graph. More...
 
- Public Member Functions inherited from WMG_Graph_Manager
GameObject CreateNode (Object prefabNode, GameObject parent)
 Creates a node for this graph. More...
 
GameObject CreateLink (WMG_Node fromNode, GameObject toNode, Object prefabLink, GameObject parent)
 Creates a link for this graph, and repositions the link. More...
 
GameObject CreateLinkNoRepos (WMG_Node fromNode, GameObject toNode, Object prefabLink, GameObject parent)
 Creates a link for this graph, and does not repoisition the link. More...
 
WMG_Link GetLink (WMG_Node fromNode, WMG_Node toNode)
 Given two nodes, get the link between those nodes for this graph. More...
 
GameObject ReplaceNodeWithNewPrefab (WMG_Node theNode, Object prefabNode)
 Given a node, and a prefab, re-instantiate the node using the specified prefab which has a WMG_Node script attached. More...
 
void DeleteNode (WMG_Node theNode)
 Deletes a node. More...
 
void DeleteLink (WMG_Link theLink)
 Deletes a link. More...
 
List< WMG_LinkFindShortestPathBetweenNodes (WMG_Node fromNode, WMG_Node toNode)
 Given two nodes return one or more shortest paths between the nodes based on the number of links (unweighted), using Breadth-first search algorithm. More...
 
List< WMG_LinkFindShortestPathBetweenNodesWeighted (WMG_Node fromNode, WMG_Node toNode, bool includeRadii)
 Given two nodes return one or more shortest paths between the nodes based on the link weights (weighted), and also node radii if include radii is true, using Dijkstra's algorithm. More...
 
- Public Member Functions inherited from WMG_Events
delegate void WMG_Click_H (WMG_Series aSeries, WMG_Node aNode, PointerEventData pointerEventData)
 
void addNodeClickEvent (GameObject go)
 
delegate void WMG_Link_Click_H (WMG_Series aSeries, WMG_Link aLink, PointerEventData pointerEventData)
 
void addLinkClickEvent (GameObject go)
 
delegate void WMG_Click_Leg_H (WMG_Series aSeries, WMG_Node aNode, PointerEventData pointerEventData)
 
void addNodeClickEvent_Leg (GameObject go)
 
delegate void WMG_Link_Click_Leg_H (WMG_Series aSeries, WMG_Link aLink, PointerEventData pointerEventData)
 
void addLinkClickEvent_Leg (GameObject go)
 
delegate void WMG_Pie_Slice_Click_H (WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice, PointerEventData pointerEventData)
 
void addPieSliceClickEvent (GameObject go)
 
delegate void WMG_Pie_Legend_Entry_Click_H (WMG_Pie_Graph pieGraph, WMG_Legend_Entry legendEntry, PointerEventData pointerEventData)
 
void addPieLegendEntryClickEvent (GameObject go)
 
delegate void WMG_Ring_Click_H (WMG_Ring ring, PointerEventData pointerEventData)
 
void addRingClickEvent (GameObject go)
 
delegate void WMG_MouseEnter_H (WMG_Series aSeries, WMG_Node aNode, bool state)
 
void addNodeMouseEnterEvent (GameObject go)
 
delegate void WMG_Link_MouseEnter_H (WMG_Series aSeries, WMG_Link aLink, bool state)
 
void addLinkMouseEnterEvent (GameObject go)
 
delegate void WMG_MouseEnter_Leg_H (WMG_Series aSeries, WMG_Node aNode, bool state)
 
void addNodeMouseEnterEvent_Leg (GameObject go)
 
delegate void WMG_Link_MouseEnter_Leg_H (WMG_Series aSeries, WMG_Link aLink, bool state)
 
void addLinkMouseEnterEvent_Leg (GameObject go)
 
delegate void WMG_Pie_Slice_MouseEnter_H (WMG_Pie_Graph pieGraph, WMG_Pie_Graph_Slice aSlice, bool state)
 
void addPieSliceMouseEnterEvent (GameObject go)
 
delegate void WMG_Ring_MouseEnter_H (WMG_Ring ring, bool state)
 
void addRingMouseEnterEvent (GameObject go)
 
void addNodeMouseLeaveEvent (GameObject go)
 
void addLinkMouseLeaveEvent (GameObject go)
 
void addNodeMouseLeaveEvent_Leg (GameObject go)
 
void addLinkMouseLeaveEvent_Leg (GameObject go)
 
- Public Member Functions inherited from WMG_GUI_Functions
void SetActive (GameObject obj, bool state)
 
bool activeInHierarchy (GameObject obj)
 
void SetActiveAnchoredSprite (GameObject obj, bool state)
 
void SetActiveImage (GameObject obj, bool state)
 
Texture2D getTexture (GameObject obj)
 
void setTexture (GameObject obj, Sprite sprite)
 
void changeSpriteFill (GameObject obj, float fill)
 
void changeRadialSpriteRotation (GameObject obj, Vector3 newRot)
 
void changeSpriteColor (GameObject obj, Color aColor)
 
void changeSpriteAlpha (GameObject obj, float alpha)
 
float getSpriteAlpha (GameObject obj)
 
void changeSpriteWidth (GameObject obj, int aWidth)
 
void changeSpriteHeight (GameObject obj, int aHeight)
 
void setTextureMaterial (GameObject obj, Material aMat)
 
Material getTextureMaterial (GameObject obj)
 
void changeSpriteSize (GameObject obj, int aWidth, int aHeight)
 
void changeSpriteSizeFloat (GameObject obj, float aWidth, float aHeight)
 
Vector2 getSpriteSize (GameObject obj)
 
void changeBarWidthHeight (GameObject obj, int aWidth, int aHeight)
 
float getSpriteWidth (GameObject obj)
 
float getSpriteHeight (GameObject obj)
 
float getTextWidth (GameObject obj)
 
float getTextHeight (GameObject obj)
 
void forceUpdateText (GameObject obj)
 
void setAnchor (GameObject go, Vector2 anchor, Vector2 pivot, Vector2 anchoredPosition)
 
void setAnchoredPosition (GameObject go, Vector2 anchoredPosition)
 
void stretchToParent (GameObject go)
 
bool rectIntersectRect (GameObject r1, GameObject r2)
 
void getRectDiffs (GameObject child, GameObject container, ref Vector2 xDif, ref Vector2 yDif)
 
float getSpritePositionX (GameObject obj)
 
float getSpritePositionY (GameObject obj)
 
Vector2 getSpritePositionXY (GameObject obj)
 
float getSpritePivotTopToBot (GameObject obj)
 
Vector3 getPositionRelativeTransform (GameObject obj, GameObject relative)
 
void changePositionByRelativeTransform (GameObject obj, GameObject relative, Vector2 delta)
 
void changeSpritePositionTo (GameObject obj, Vector3 newPos)
 
void changeSpritePositionToX (GameObject obj, float newPos)
 
void changeSpritePositionToY (GameObject obj, float newPos)
 
Vector2 getChangeSpritePositionTo (GameObject obj, Vector2 newPos)
 
void changeSpritePositionRelativeToObjBy (GameObject obj, GameObject relObj, Vector3 changeAmt)
 
void changeSpritePositionRelativeToObjByX (GameObject obj, GameObject relObj, float changeAmt)
 
void changeSpritePositionRelativeToObjByY (GameObject obj, GameObject relObj, float changeAmt)
 
Vector2 getSpritePivot (GameObject obj)
 
void changeSpriteParent (GameObject child, GameObject parent)
 
void getFirstCanvasOnSelfOrParent (Transform trans, ref Canvas canv)
 
void addRaycaster (GameObject obj)
 
void setAsNotInteractible (GameObject obj)
 
void bringSpriteToFront (GameObject obj)
 
void sendSpriteToBack (GameObject obj)
 
- Public Member Functions inherited from WMG_Text_Functions
void changeLabelText (GameObject obj, string aText)
 
void changeLabelFontSize (GameObject obj, int newFontSize)
 
Vector2 getTextSize (GameObject obj)
 
void changeSpritePivot (GameObject obj, WMGpivotTypes theType)
 
void changeLabelColor (GameObject obj, Color newColor)
 
void changeLabelFontStyle (GameObject obj, FontStyle newFontStyle)
 
void changeLabelFont (GameObject obj, Font newFont)
 

Public Attributes

Object nodePrefab
 The prefab used to create the nodes. More...
 
Object linkPrefab
 The prefab used to create the links. More...
 
int numNodes
 The total number of nodes that can appear in this graph. More...
 
float minAngle
 The minimum possible angle between neighbor nodes. More...
 
float minAngleRange
 This can be used to control the direction in which the graph propagates. More...
 
float maxAngleRange
 This can be used to control the direction in which the graph propagates. More...
 
int minRandomNumberNeighbors
 This controls how many neighbors there are for each node. More...
 
int maxRandomNumberNeighbors
 This controls how many neighbors there are for each node. More...
 
float minRandomLinkLength
 Determines the distance between nodes. More...
 
float maxRandomLinkLength
 Determines the distance between nodes. More...
 
bool centerPropogate
 Determines how the propagation proceeds. More...
 
bool noLinkIntersection
 This ensures that a randomly generated link does not intersect with any existing links. More...
 
bool noNodeIntersection
 This ensures that a randomly generated node will not intersect with any existing nodes. More...
 
float noNodeIntersectionRadiusPadding
 This adds onto the radii used in the circle intersection checks used for the node intersection checks. More...
 
int maxNeighborAttempts
 Sometimes highly depending on the parameters used, the graph will fail to produce any results, or fail to produce all the nodes specified. More...
 
bool noLinkNodeIntersection
 Ensures that creating a new node does not intersect an existing link, or that creating a new link does not intersect an existing node. More...
 
float noLinkNodeIntersectionRadiusPadding
 Increases the radius of the node used in the circle-line intersection checks. More...
 
bool createOnStart
 If true, then the GenerateGraph function is called in Awake(). More...
 
bool debugRandomGraph
 This can be useful to troubleshoot what is happening during the random graph generation process. More...
 

Additional Inherited Members

- Public Types inherited from WMG_Text_Functions
enum  WMGpivotTypes {
  WMGpivotTypes.Bottom, WMGpivotTypes.BottomLeft, WMGpivotTypes.BottomRight, WMGpivotTypes.Center,
  WMGpivotTypes.Left, WMGpivotTypes.Right, WMGpivotTypes.Top, WMGpivotTypes.TopLeft,
  WMGpivotTypes.TopRight
}
 
- Properties inherited from WMG_Graph_Manager
List< GameObject > NodesParent [get]
 The list of GameObjects which are WMG_Nodes for this graph. More...
 
List< GameObject > LinksParent [get]
 The list of GameObjects which are WMG_Links for this graph. More...
 
- Events inherited from WMG_Events
WMG_Click_H WMG_Click
 Occurs when a series point is clicked. More...
 
WMG_Link_Click_H WMG_Link_Click
 Occurs when a series link / line is clicked. More...
 
WMG_Click_Leg_H WMG_Click_Leg
 Occurs when a series legend node / swatch is clicked. More...
 
WMG_Link_Click_Leg_H WMG_Link_Click_Leg
 Occurs when a series legend link / line is clicked. More...
 
WMG_Pie_Slice_Click_H WMG_Pie_Slice_Click
 Occurs when a pie graph slice is clicked. More...
 
WMG_Pie_Legend_Entry_Click_H WMG_Pie_Legend_Entry_Click
 Occurs when a pie graph legend swatch is clicked. More...
 
WMG_Ring_Click_H WMG_Ring_Click
 Occurs when a ring graph ring / band is clicked. More...
 
WMG_MouseEnter_H WMG_MouseEnter
 Occurs when a series point is hovered. More...
 
WMG_Link_MouseEnter_H WMG_Link_MouseEnter
 Occurs when a series link / line is hovered. More...
 
WMG_MouseEnter_Leg_H WMG_MouseEnter_Leg
 Occurs when a series legend node / swatch is hovered. More...
 
WMG_Link_MouseEnter_Leg_H WMG_Link_MouseEnter_Leg
 Occurs when a series legend link / line is hovered. More...
 
WMG_Pie_Slice_MouseEnter_H WMG_Pie_Slice_MouseEnter
 Occurs when a pie graph slice is hovered. More...
 
WMG_Ring_MouseEnter_H WMG_Ring_MouseEnter
 Occurs when a ring graph ring / band is hovered. More...
 

Detailed Description

A class used to create random graphs.

Member Function Documentation

◆ GenerateGraph()

List<GameObject> WMG_Random_Graph.GenerateGraph ( )

Creates a node, and then calls GenerateGraphFromNode.

Returns
The graph.

◆ GenerateGraphFromNode()

List<GameObject> WMG_Random_Graph.GenerateGraphFromNode ( WMG_Node  fromNode)

Generates the random graph.

Starts from a single node, where each node is processed by attempting to create neighbors and links to neighbors from the node. This function ends when all existing nodes have been fully processed (maxNeighborAttempts reached for each node), or when numNodes has been created. A node is processed if all of its neighbors were successfully created or if not all neighbors were created, but maxNeighborAttempts was reached. maxNeighborAttempts (a failed neighbor creation attempt) can get incremented for the following reasons:

  • When a randomly generated angle falls between existing neighbors that is less than minAngle.
  • If noLinkIntersection is true, a randomly generated angle and length would create a link that would cross an existing link in this graph's links parent.
  • If noNodeIntersection is true, a randomly generated angle and length would create a node that that would circle interesect an existing node in this graph's nodes parent.
  • The same as above but noNodeIntersectionRadiusPadding > 0, performs the circle intersections check with the nodes' radii increased by the specified padding.
  • If noLinkNodeIntersection is true, a randomly generated node would intersect with an existing link or a randomly generated link would intersect with an existing node.
  • The same as above but noLinkNodeIntersectionRadiusPadding > 0, performs circle - line intersections with the node radius increased by the specified padding.
Returns
The graph from node.
Parameters
fromNodeFrom node.

Member Data Documentation

◆ centerPropogate

bool WMG_Random_Graph.centerPropogate

Determines how the propagation proceeds.

If this is false, then a node is randomly picked from the set of unprocessed nodes to process. Processing a node randomly generates neighbors for that node, marks the node processed, and moves on to another node process. If this is true, then the next node processed will be the oldest one that was created.

◆ createOnStart

bool WMG_Random_Graph.createOnStart

If true, then the GenerateGraph function is called in Awake().

If you want to change parameters at run-time and then generate the graph yourself then you would set this to false, get a reference to this script and call GenerateGraph manually.

◆ debugRandomGraph

bool WMG_Random_Graph.debugRandomGraph

This can be useful to troubleshoot what is happening during the random graph generation process.

◆ linkPrefab

Object WMG_Random_Graph.linkPrefab

The prefab used to create the links.

◆ maxAngleRange

float WMG_Random_Graph.maxAngleRange

This can be used to control the direction in which the graph propagates.

For example, to create procedural lightning looking graphs you would want to set this to a narrow range like 0 - 45.

◆ maxNeighborAttempts

int WMG_Random_Graph.maxNeighborAttempts

Sometimes highly depending on the parameters used, the graph will fail to produce any results, or fail to produce all the nodes specified.

If this happens a warning is logged to the console saying how many nodes were produced which was less than the number of nodes you specified. This generally means your parameters were too specific. To help with this, you can increase this number to try and fully complete the graph. The default is 100, meaning while processing a neighbor, up to 100 random angles and link lengths are generated. Failing any of the checks such as the min neighbor angle or intersection checks will increase the attempt number and generate a new possibility.

◆ maxRandomLinkLength

float WMG_Random_Graph.maxRandomLinkLength

Determines the distance between nodes.

Setting a high range will create more sporadic looking graphs, while setting the values equal will generate grid like graphs.

◆ maxRandomNumberNeighbors

int WMG_Random_Graph.maxRandomNumberNeighbors

This controls how many neighbors there are for each node.

◆ minAngle

float WMG_Random_Graph.minAngle

The minimum possible angle between neighbor nodes.

So if this is 15, then there should not exist any 2 neighbors that are less than 15 degrees apart from one another.

◆ minAngleRange

float WMG_Random_Graph.minAngleRange

This can be used to control the direction in which the graph propagates.

For example, to create procedural lightning looking graphs you would want to set this to a narrow range like 0 - 45.

◆ minRandomLinkLength

float WMG_Random_Graph.minRandomLinkLength

Determines the distance between nodes.

Setting a high range will create more sporadic looking graphs, while setting the values equal will generate grid like graphs.

◆ minRandomNumberNeighbors

int WMG_Random_Graph.minRandomNumberNeighbors

This controls how many neighbors there are for each node.

◆ nodePrefab

Object WMG_Random_Graph.nodePrefab

The prefab used to create the nodes.

◆ noLinkIntersection

bool WMG_Random_Graph.noLinkIntersection

This ensures that a randomly generated link does not intersect with any existing links.

This should generally always be set to true unless you want to create some strange overlapping graph.

◆ noLinkNodeIntersection

bool WMG_Random_Graph.noLinkNodeIntersection

Ensures that creating a new node does not intersect an existing link, or that creating a new link does not intersect an existing node.

This performs circle-line intersection checks with the creating link / node with all existing nodes / links.

◆ noLinkNodeIntersectionRadiusPadding

float WMG_Random_Graph.noLinkNodeIntersectionRadiusPadding

Increases the radius of the node used in the circle-line intersection checks.

A higher value will ensure a graph that has links and nodes that are more spaced apart from each other.

◆ noNodeIntersection

bool WMG_Random_Graph.noNodeIntersection

This ensures that a randomly generated node will not intersect with any existing nodes.

Circle intersection checks are done using the radii of the nodes. This should generally always be set to true unless you want nodes to possibly overlap.

◆ noNodeIntersectionRadiusPadding

float WMG_Random_Graph.noNodeIntersectionRadiusPadding

This adds onto the radii used in the circle intersection checks used for the node intersection checks.

Increasing this value will ensure that nodes are more spaced apart from one another.

◆ numNodes

int WMG_Random_Graph.numNodes

The total number of nodes that can appear in this graph.


The documentation for this class was generated from the following file: