CurveFittingStage fits a piecewise cubic Bezier curve to given arbitrary edge paths.
Remarks
Concept
The path of an edge, i.e., its start and end point as well as the intermediate control points, are interpreted as the set of input points. A cubic Bezier curve is then fitted to these points.
After the fitting, the points of the processed edges can be interpreted as cubic Bezier control points. Each four consecutive points form a Bezier curve, where the first and last of the four points represent the start and end of the curve and the second and third point are the control points defining how the curve looks. The second and third point do not necessarily lie on the actual curve.
There are two exceptions to the stated rules:
- If an input edge only consists of a source and a target point, it will be ignored by this stage.
- Self-loop edges with only one intermediate control point are also ignored. Note that self-loops with more control points are, however, handled by this stage.
Features
The maximum allowed error for the fitting process can be selected to control how high the precision should be. A high allowed error means that the approximation process has a lot of freedom. Curves are only loosely bound to the original edge path. If this is not desired, e.g., because no new intersection with other graph elements should be introduced, then a rather low error value should be specified. The lower the error value, the larger the number of bend points of an approximated edge will be.
It is possible to define the set of edges that should be processed by this layout stage. Therefore, only paths of a sub-set of edges can be changed. Use an IMapper<K,V> registered with the selection key to mark edges which should be part of the considered sub-set.
Default Values of Properties
maximumError | 4.0 | |
straightControlPointRatio | 0.33 |
Type Details
- yFiles module
- algorithms
Constructors
Creates a new CurveFittingStage with an optional core layout algorithm.
Parameters
A map of options to pass to the method.
- coreLayout - ILayoutAlgorithm
- The core layout algorithm.
- maximumError - number
- The maximum allowed error for the fitting process. This option sets the maximumError property on the created object.
- straightControlPointRatio - number
- The ratio that defines the distance between the intermediate control points and the end points of a cubic segment which actually represents a straight line, i.e., in case the four points are collinear. This option sets the straightControlPointRatio property on the created object.
- enabled - boolean
Properties
Gets or sets the core ILayoutAlgorithm that is wrapped by this stage.
Gets or sets a value that determines whether this stage should do anything but execute the coreLayout.
Remarks
By default, when constructed, stages should be enabled. Users may disable a stage's functionality by setting this property to false
.
Stages that can guarantee that the graph will not change can choose to not even execute the coreLayout when disabled.
Implements
Gets or sets the maximum allowed error for the fitting process.
Remarks
The error is defined as the minimum distance between an original input control point (i.e. bend) of and edge and the fitted bezier curve.
The maximum error must be greater than or equal to zero.
Default Value
4.0
.Property Value
Throws
- Exception({ name: 'ArgumentError' })
- if the specified maximum error is negative
Gets or sets the ratio that defines the distance between the intermediate control points and the end points of a cubic segment which actually represents a straight line, i.e., in case the four points are collinear.
Remarks
0.33
- the second and third control point are equally distributed between the first and fourth point.0.0
- the first and second control point as well as the third and fourth point are equal.0.5
- the second and third control point are equal and exactly the mid-point between the first and fourth point.
[0.0, 0.5]
.Default Value
0.33
.Property Value
Throws
- Exception({ name: 'ArgumentError' })
- if the specified ratio is outside the interval
[0.0, 0.5]
Methods
Implementation of the ILayoutAlgorithm interface and main entry point for the layout calculation.
Remarks
Parameters
A map of options to pass to the method.
- graph - LayoutGraph
- The graph to apply the layout to.
Implements
Changes the edge paths of selected edges of the given graph such that they represent piecewise cubic Bezier curves which approximate the original points of the path.
Parameters
A map of options to pass to the method.
- graph - LayoutGraph
- the input graph
Implements
createLayoutData
(graph: LayoutGraph) : EdgeScopeData<LayoutNode,LayoutEdge,LayoutNodeLabel,LayoutEdgeLabel,boolean>Returns an instance of LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel> that can be used to define the edges affected by the CurveFittingStage.
Remarks
Parameters
A map of options to pass to the method.
- graph - LayoutGraph
- the graph that determines the generic type arguments of the created layout data
Returns
- ↪EdgeScopeData<LayoutNode,LayoutEdge,LayoutNodeLabel,LayoutEdgeLabel,boolean>
- an instance of layout data that can be used to perform item-specific configurations for the given CurveFittingStage.
Returns an instance of LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel> that can be used to define the edges affected by the CurveFittingStage.
Remarks
Parameters
A map of options to pass to the method.
- graph - IGraph
- the graph that determines the generic type arguments of the created layout data
Returns
- ↪EdgeScopeData<INode,IEdge,ILabel,ILabel,boolean>
- an instance of layout data that can be used to perform item-specific configurations for the given CurveFittingStage.
LayoutExecutor
type is available at runtime.Constants
A data key for selecting edges for curve fitting.
Remarks
Assign true
to an edge if a bezier curve should be fitted to the edge's path, or false
otherwise.
If there is no IMapper<K,V> registered with this key, a curve is fitted to all edges.