GraphForceDirectedLayoutStrategy class base
A physics-based layout strategy using a force-directed algorithm.
Uses spring forces between linked nodes and Coulomb forces for repulsion, resulting in naturally spaced layouts. Positions can be adjusted through spring length, stiffness, damping, and other physics parameters.
Example:
final layout = GraphForceDirectedLayoutStrategy(
springLength: 150,
springConstant: 0.2,
damping: 0.9,
centerNodeId: rootId,
);
return GraphView(
graph: graph,
layoutStrategy: layout,
);
See also:
- GraphTreeLayoutStrategy for hierarchical layouts
- GraphManualLayoutStrategy for precise control
- Inheritance
-
- Object
- GraphLayoutStrategy
- GraphForceDirectedLayoutStrategy
Constructors
- GraphForceDirectedLayoutStrategy({double? springLength, double? springConstant, double? damping, double? coulombConstant, double? maxDisplacement, int? maxIterations, double? tolerance, GraphId? centerNodeId, int? seed, EdgeInsets padding = const EdgeInsets.all(100)})
- Creates a force-directed layout with physics-based node positioning.
Properties
- centerNodeId → GraphId?
-
ID of the node to fix at the center of the layout area.
final
- coulombConstant → double
-
Coulomb force coefficient for node repulsion.
final
- damping → double
-
Velocity reduction factor for node movement.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxDisplacement → double
-
Maximum allowed node movement per iteration.
final
- maxIterations → int
-
Maximum number of simulation iterations.
final
-
nodePositions
→ List<
GraphNodeLayoutPosition> -
List of predefined node positions.
finalinherited
- padding → EdgeInsets
-
Padding around the layout area.
finalinherited
- random → Random
-
Random number generator initialized with seed.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- seed → int?
-
Optional seed for reproducible random number generation.
finalinherited
- springConstant → double
-
Spring stiffness coefficient.
final
- springLength → double
-
Natural length of springs between linked nodes.
final
- tolerance → double
-
Convergence threshold for total node movement.
final
Methods
-
baseEquals(
covariant GraphLayoutStrategy oldStrategy) → bool -
Compares basic layout properties for equality.
inherited
-
getNodePosition(
GraphNode node) → GraphNodeLayoutPosition? -
Gets the predefined position for a node, if any exists.
inherited
-
getNodeSize(
GraphNode node) → Size? -
Retrieves the current size of a node.
inherited
-
isNodeFixed(
GraphNode node) → bool -
Checks if a node's position should remain fixed during layout.
inherited
-
isSameStrategy(
GraphLayoutStrategy other) → bool -
Checks if the given strategy is of the same type as this one.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
performLayout(
Graph graph, Size size) → void -
Calculates and applies node positions based on the layout algorithm.
override
-
positionNode(
GraphNode node, Offset position) → void -
Positions a node at the specified coordinates.
inherited
-
shouldRelayout(
covariant GraphForceDirectedLayoutStrategy oldStrategy) → bool -
Determines if the layout needs to be recalculated.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited