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 class
Represents a specific category for a chart or graphical element, extending the functionality ofPointSymbol
to include a category name.static class
Represents a directional edge between two nodes in a graph structure.static class
Represents a force-directed layout configuration as a property of a chart component.static enum
The Layout enum defines various layout options that can be used for organizational or structural representation.static class
The abstract class Node serves as the base class for components within a graph structure.static class
TheValueNode
class represents a type ofNode
that holds a numerical value.static class
A concrete implementation of theGraphData.Node
class representing a node in a 2D space. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of GraphData and initializes default properties. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Adds 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.Edge
Establishes a connection between a source node and a target node.final GraphData.Edge
connectFromLastNode
(N target) Connects the last node in the current structure to the specified target node.final GraphData.Edge
connectToLastNode
(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 PointSymbol
Retrieves the symbol representing the end of an edge in the graph.final PointSymbol
Returns the symbol representing the start of an edge in the graph.final N
Retrieves the first node from the list of nodes.getForce
(boolean createIfNotExist) Retrieves the instance of theForce
object.final N
Retrieves the last node in the list.Retrieves the layout configuration for the graph.final N
getNode
(int index) Retrieves the node at the specified index from the collection of nodes.final N
Retrieves the node with the specified name from the collection of nodes.Retrieves theTextLabel
associated with this instance of the class.boolean
Determines whether the auto-curveness feature is enabled.boolean
Checks whether the object is draggable or not.boolean
isRoam()
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 int
Returns 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.void
setAutoCurveness
(boolean autoCurveness) Sets whether the curveness of edges in the graph should be automatically determined.void
Sets the center offset for the graph data.void
setDefaultCategory
(GraphData.Category defaultCategory) Sets the default category for the graph data.void
setDraggable
(boolean draggable) Sets whether the graph is draggable or not.void
setEdgeEndSymbol
(PointSymbol symbol) Sets the symbol used to represent the end of an edge in the graph.void
setForce
(GraphData.Force force) Sets theForce
configuration for the graph layout.void
setLayout
(GraphData.Layout layout) Sets the layout for the graph.void
setRoam
(boolean roam) Sets whether the graph is in roam mode or not.void
setTextLabel
(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
Category
instance.
-
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
- theTextLabel
object 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 parametercreateIfNotExist
istrue
, a newOffset
instance 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:
true
if roaming is enabled,false
otherwise.
-
getForce
Retrieves the instance of theForce
object. If the instance does not exist andcreateIfNotExist
istrue
, a newForce
object is created and returned.- Parameters:
createIfNotExist
- Aboolean
value indicating whether to create a newForce
instance if it does not already exist.- Returns:
- The
Force
instance. Returnsnull
if the instance does not exist andcreateIfNotExist
isfalse
.
-
force
Sets the force layout configuration for the graph data.- Parameters:
force
- TheGraphData.Force
object containing the configuration parameters of the force layout.- Returns:
- The current instance of
GraphData<N>
for method chaining.
-
setForce
Sets theForce
configuration for the graph layout.- Parameters:
force
- theForce
instance 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
PointSymbol
object 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
- thePointSymbol
to 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
-