Package com.storedobject.chart
Class GraphData<N extends GraphData.Node>
java.lang.Object
com.storedobject.chart.GraphData<N>
- Type Parameters:
N- The type of nodes that the graph will handle.
The GraphData class represents a data structure used for managing and visualizing graph-based data.
It supports operations such as adding nodes, connecting edges, and configuring various graph properties.
- Author:
- Syam
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a specific category for a chart or graphical element, extending the functionality ofPointSymbolto include a category name.static classRepresents a directional edge between two nodes in a graph structure.static classRepresents a force-directed layout configuration as a property of a chart component.static enumThe Layout enum defines various layout options that can be used for organizational or structural representation.static classThe abstract class Node serves as the base class for components within a graph structure.static classTheValueNodeclass represents a type ofNodethat holds a numerical value.static classA concrete implementation of theGraphData.Nodeclass representing a node in a 2D space. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of GraphData and initializes default properties. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds one or more nodes to the list of nodes if they are not null.autoCurveness(boolean autoCurveness) Sets whether automatic curveness is enabled or not and returns the current instance for method chaining.Sets the center offset for the graph and returns the updated graph data instance.final GraphData.EdgeEstablishes a connection between a source node and a target node.final GraphData.EdgeconnectFromLastNode(N target) Connects the last node in the current structure to the specified target node.final GraphData.EdgeconnectToLastNode(N source) Connects the given source node to the last node in the graph.defaultCategory(GraphData.Category defaultCategory) Sets the default category for the graph and returns the current instance ofGraphData.draggable(boolean draggable) Sets the draggable property of the GraphData object.edgeEndSymbol(PointSymbol symbol) Sets the symbol for the end of edges in the graph and returns the updated GraphData instance.edgeStartSymbol(PointSymbol symbol) Sets the start symbol for edges in the graph.force(GraphData.Force force) Sets the force layout configuration for the graph data.getCenter(boolean createIfNotExist) Retrieves the center offset configuration for this object.Retrieves the default category associated with the graph data.final PointSymbolRetrieves the symbol representing the end of an edge in the graph.final PointSymbolReturns the symbol representing the start of an edge in the graph.final NRetrieves the first node from the list of nodes.getForce(boolean createIfNotExist) Retrieves the instance of theForceobject.final NRetrieves the last node in the list.Retrieves the layout configuration for the graph.final NgetNode(int index) Retrieves the node at the specified index from the collection of nodes.final NRetrieves the node with the specified name from the collection of nodes.Retrieves theTextLabelassociated with this instance of the class.booleanDetermines whether the auto-curveness feature is enabled.booleanChecks whether the object is draggable or not.booleanisRoam()Checks whether roaming is enabled.layout(GraphData.Layout layout) Sets the layout type for the graph data and returns the updated instance.Adds one or more nodes to the graph and returns the updated graph data.final intReturns the total number of nodes present.nodes()Provides a sequential Stream of nodes contained in the current collection.roam(boolean roam) Sets whether roaming is enabled or disabled for the graph data.voidsetAutoCurveness(boolean autoCurveness) Sets whether the curveness of edges in the graph should be automatically determined.voidSets the center offset for the graph data.voidsetDefaultCategory(GraphData.Category defaultCategory) Sets the default category for the graph data.voidsetDraggable(boolean draggable) Sets whether the graph is draggable or not.voidsetEdgeEndSymbol(PointSymbol symbol) Sets the symbol used to represent the end of an edge in the graph.voidsetForce(GraphData.Force force) Sets theForceconfiguration for the graph layout.voidsetLayout(GraphData.Layout layout) Sets the layout for the graph.voidsetRoam(boolean roam) Sets whether the graph is in roam mode or not.voidsetTextLabel(TextLabel textLabel) Sets the text label associated with this GraphData object.
-
Constructor Details
-
GraphData
public GraphData()Constructs a new instance of GraphData and initializes default properties. Specifically, the default category's size is set to 10 during construction.
-
-
Method Details
-
getDefaultCategory
Retrieves the default category associated with the graph data.- Returns:
- The default
Categoryinstance.
-
defaultCategory
Sets the default category for the graph and returns the current instance ofGraphData.- Parameters:
defaultCategory- The default category to be set. Ifnull, a default category with the name "Default" will be created and set.- Returns:
- The current
GraphData<N>instance with the updated default category.
-
setDefaultCategory
Sets the default category for the graph data. If the provided category is null, a new category named "Default" will be assigned.- Parameters:
defaultCategory- The category to set as default. If null, a default category with the name "Default" is created.
-
getTextLabel
-
setTextLabel
Sets the text label associated with this GraphData object.- Parameters:
textLabel- theTextLabelobject to set
-
setCenter
Sets the center offset for the graph data.- Parameters:
center- The center position specified as an Offset object containing x and y coordinates.
-
center
-
getCenter
Retrieves the center offset configuration for this object. If the center has not been initialized and the parametercreateIfNotExististrue, a newOffsetinstance will be created and assigned. -
setLayout
Sets the layout for the graph.- Parameters:
layout- The layout to set. Possible values areFORCE,CIRCULAR, orNONE.
-
layout
Sets the layout type for the graph data and returns the updated instance.- Parameters:
layout- The layout type to be set for the graph. Possible values includeGraphData.Layout.FORCE,GraphData.Layout.CIRCULAR, andGraphData.Layout.NONE.- Returns:
- The updated instance of
GraphData<N>with the specified layout.
-
getLayout
Retrieves the layout configuration for the graph.- Returns:
- The current layout configuration of the graph, which determines the arrangement of elements such as nodes and edges in the graph.
-
setRoam
public void setRoam(boolean roam) Sets whether the graph is in roam mode or not.- Parameters:
roam- A boolean value indicating if roam mode should be enabled (true) or disabled (false).
-
roam
-
isRoam
public boolean isRoam()Checks whether roaming is enabled.- Returns:
trueif roaming is enabled,falseotherwise.
-
getForce
Retrieves the instance of theForceobject. If the instance does not exist andcreateIfNotExististrue, a newForceobject is created and returned.- Parameters:
createIfNotExist- Abooleanvalue indicating whether to create a newForceinstance if it does not already exist.- Returns:
- The
Forceinstance. Returnsnullif the instance does not exist andcreateIfNotExistisfalse.
-
force
Sets the force layout configuration for the graph data.- Parameters:
force- TheGraphData.Forceobject containing the configuration parameters of the force layout.- Returns:
- The current instance of
GraphData<N>for method chaining.
-
setForce
Sets theForceconfiguration for the graph layout.- Parameters:
force- theForceinstance containing the configuration settings for the graph's physical simulation.
-
setAutoCurveness
public void setAutoCurveness(boolean autoCurveness) Sets whether the curveness of edges in the graph should be automatically determined.- Parameters:
autoCurveness- A boolean value indicating whether auto-curveness is enabled or not. If true, the curveness of edges will be automatically adjusted; if false, no automatic adjustment will be applied.
-
autoCurveness
-
isAutoCurveness
public boolean isAutoCurveness()Determines whether the auto-curveness feature is enabled.- Returns:
- true if auto-curveness is enabled, false otherwise.
-
setDraggable
public void setDraggable(boolean draggable) Sets whether the graph is draggable or not.- Parameters:
draggable- true to enable dragging, false to disable it.
-
draggable
Sets the draggable property of the GraphData object.- Parameters:
draggable- determines whether the graph data elements are draggable. If true, the elements can be dragged; otherwise, they cannot.- Returns:
- the updated GraphData object with the modified draggable property.
-
isDraggable
public boolean isDraggable()Checks whether the object is draggable or not.- Returns:
- true if the object is draggable, false otherwise
-
getEdgeStartSymbol
Returns the symbol representing the start of an edge in the graph.- Returns:
- the symbol representing the start of an edge as a PointSymbol object
-
edgeStartSymbol
Sets the start symbol for edges in the graph. If the provided symbol is null, a default symbol of type NONE will be used.- Parameters:
symbol- the PointSymbol to set as the start symbol for edges. If null, a default symbol with type NONE is used.- Returns:
- the current
GraphData<N>instance for method chaining.
-
getEdgeEndSymbol
Retrieves the symbol representing the end of an edge in the graph.- Returns:
- the
PointSymbolobject representing the edge's end symbol.
-
edgeEndSymbol
Sets the symbol for the end of edges in the graph and returns the updated GraphData instance. If the provided symbol is null, a default point symbol with type NONE is used.- Parameters:
symbol- the PointSymbol to set for the edge end; if null, a default symbol with type NONE is used- Returns:
- the updated GraphData instance
-
setEdgeEndSymbol
Sets the symbol used to represent the end of an edge in the graph. If the provided symbol is null, it defaults to a symbol of typePointSymbolType.NONE.- Parameters:
symbol- thePointSymbolto set as the edge end symbol, or null to reset to the default symbol
-
addNode
Adds one or more nodes to the list of nodes if they are not null.- Parameters:
nodes- the nodes to be added. Each node is checked for null before being added to the list.
-
node
Adds one or more nodes to the graph and returns the updated graph data.- Parameters:
nodes- the nodes to be added to the graph- Returns:
- the updated graph data instance after adding the nodes
-
connect
Establishes a connection between a source node and a target node.- Parameters:
source- the source node to connect fromtarget- the target node to connect to- Returns:
- the created Edge representing the connection between the source and target nodes
-
connectFromLastNode
Connects the last node in the current structure to the specified target node.- Parameters:
target- the target node to connect to the last node- Returns:
- the edge created between the last node and the target node, or null if there is no last node
-
connectToLastNode
Connects the given source node to the last node in the graph.- Parameters:
source- the source node to be connected to the last node- Returns:
- the edge created by connecting the source node to the last node, or null if there is no last node available
-
getLastNode
Retrieves the last node in the list.- Returns:
- the last node if the list is not empty, or null if the list is empty
-
getFirstNode
Retrieves the first node from the list of nodes.- Returns:
- the first node if the list is not empty; otherwise, returns null
-
getNode
Retrieves the node at the specified index from the collection of nodes.- Parameters:
index- the index of the node to retrieve, must be within the bounds of the nodes collection- Returns:
- the node at the specified index if the index is valid; otherwise, returns null
-
getNode
-
nodeCount
public final int nodeCount()Returns the total number of nodes present.- Returns:
- the count of nodes as an integer
-
nodes
-