Packagecom.yworks.yfiles.layout.organic
Classpublic class InteractiveOrganicLayouter
InheritanceInteractiveOrganicLayouter Inheritance YObject Inheritance Object
Implements Layouter

The InteractiveOrganicLayouter is a special organic layouter that offers functionality to change the laid out graph while the layouter is running. This layouter may be used in a threaded environment. The read-access getCenter() does not have to be synchronized. The setters (e.g. setCenter()) are scheduled and executed at a specific point within the life-cycle of the layouter. If a com.yworks.yfiles.layout.CopiedLayoutGraph is being laid out, structural changes (node and edge additions/removals) in the original graph are automatically scheduled and executed on the copy. The method addStructureUpdate() may be used to schedule a Runnable that is executed in a synchronized context and may safely update the structure of the graph. The layouter can also run in a single-threaded mode that is provided by a single-threaded context (startLayoutSingleThreaded()) . The com.yworks.yfiles.layout.organic.InteractiveOrganicLayouter_SingleThreadContext provides methods to control layout calculation.

See also

stop()
stopAndWait()
startLayoutSingleThreaded()
com.yworks.yfiles.layout.organic.InteractiveOrganicLayouter_SingleThreadContext
getCenter()
setCenter()
com.yworks.yfiles.layout.CopiedLayoutGraph
addStructureUpdate()
single-threaded context


Public Properties
 PropertyDefined By
  automaticStructureUpdateEnabled : Boolean
Determines whether this algorithm performs automatic structure updates.
InteractiveOrganicLayouter
  lastWakeupTime : LongImpl
[read-only] Returns the time when the last wake-up has occurred
InteractiveOrganicLayouter
  maxTime : uint
Getter: Return the maximal time the layouter will run (in milliseconds).
InteractiveOrganicLayouter
  outputRestriction : OutputRestriction
Getter: Returns the current OutputRestriction instance set for this instance.
InteractiveOrganicLayouter
  preferredEdgeLength : Number
[write-only] Sets the preferred edge length.
InteractiveOrganicLayouter
  preferredNodeDistance : Number
[write-only] Sets the preferred node distance.
InteractiveOrganicLayouter
  quality : Number
Getter: The quality time ratio set.
InteractiveOrganicLayouter
  running : Boolean
[read-only] Returns whether the layouter is running at the moment.
InteractiveOrganicLayouter
  sleeping : Boolean
[read-only] Returns whether the layouter is sleeping.
InteractiveOrganicLayouter
  stopped : Boolean
[read-only] Returns whether the layouter has been stopped.
InteractiveOrganicLayouter
  workingRatio : Number
Getter: Returns the actual working ratio.
InteractiveOrganicLayouter
Public Methods
 MethodDefined By
  
InteractiveOrganicLayouter(init:Boolean = true)
Create a new instance of the InteractiveOrganicLayouter.
InteractiveOrganicLayouter
  
Adds a structural update to the queue.
InteractiveOrganicLayouter
  
canLayout(graph:LayoutGraph):Boolean
Returns whether this layouter can layout the given graph.
InteractiveOrganicLayouter
  
This method writes the calculated positions (represented by the internal data structure of this layouter) to the LayoutGraph. This method must only be called while the layouter is running running. final InteractiveOrganicLayouter layouter = new InteractiveOrganicLayouter(); new Thread( new Runnable() { public void run() { layouter.doLayout( copiedGraph ); } } ).start(); new javax.swing.Timer( 24, new ActionListener() { public void actionPerformed( ActionEvent e ) { layouter.commitPositions(); } } ).start(); There may occur synchronization issues, if doLayout() is not called using a CopiedLayoutGraph.
InteractiveOrganicLayouter
  
commitPositionsSmoothly(maxMovement:Number, factor:Number):Number
This method transfers the calculated positions (represented by the internal data structure of this layouter) to the LayoutGraph. This method must only be called while the layouter is running running. The positions are not transferred directly.
InteractiveOrganicLayouter
  
doLayout(graph:LayoutGraph):void
Calculates the layout for the graph.
InteractiveOrganicLayouter
  
Makes sure that the core of this layouter will not use the usual com.yworks.yfiles.layout.LayoutStage s, like com.yworks.yfiles.layout.ComponentLayouter, com.yworks.yfiles.layout.ParallelEdgeLayouter, etc.
InteractiveOrganicLayouter
 Inherited
equals(o:Object):Boolean
YObject
  
Return the actual center of the node
InteractiveOrganicLayouter
  
getCenterX(node:Node):Number
Return the actual center of the node.
InteractiveOrganicLayouter
  
getCenterY(node:Node):Number
Return the actual center of the node.
InteractiveOrganicLayouter
  
getClass():Class
[override]
InteractiveOrganicLayouter
  
getStress(node:Node):Number
Gets the stress for the given node.
InteractiveOrganicLayouter
 Inherited
hashCode():int
YObject
  
[static] Create a new instance of the InteractiveOrganicLayouter.
InteractiveOrganicLayouter
  
setCenter(node:Node, x:Number, y:Number):void
Sets the center for the node.
InteractiveOrganicLayouter
  
setCenterX(node:Node, x:Number):void
Sets the center of the node.
InteractiveOrganicLayouter
  
setCenterY(node:Node, y:Number):void
Sets the center of the node.
InteractiveOrganicLayouter
  
setInertia(node:Node, inertia:Number):void
Set the inertia for the node.
InteractiveOrganicLayouter
  
setPreferredEdgeLength(edge:Edge, newEdgeLength:Number):void
Sets the preferred edge length for the given edge.
InteractiveOrganicLayouter
  
setRadius(node:Node, radius:Number):void
Sets the radius for the given node
InteractiveOrganicLayouter
  
setStress(node:Node, stress:Number):void
Sets the stress for the given node.
InteractiveOrganicLayouter
  
Creates a context object that provides methods to continue (com.yworks.yfiles.layout.organic.InteractiveOrganicLayouter_SingleThreadContext.doLayout()) and stop (com.yworks.yfiles.layout.organic.InteractiveOrganicLayouter_SingleThreadContext.stopLayout()) the layout calculation.
InteractiveOrganicLayouter
  
stop():void
Stops the layouter.
InteractiveOrganicLayouter
  
Stops a previously started (startLayout()) layout Thread and blocks until the layout is completed.
InteractiveOrganicLayouter
  
This method synchronizes the CopiedLayoutGraph given as parameter to doLayout() with the original graph.
InteractiveOrganicLayouter
  
wakeUp():void
This method may be called if something has "changed" and the layouter shall restart/continue layout calculation.
InteractiveOrganicLayouter
Protected Methods
 MethodDefined By
  
Initializes this object.
InteractiveOrganicLayouter
Property Detail
automaticStructureUpdateEnabledproperty
automaticStructureUpdateEnabled:Boolean

Determines whether this algorithm performs automatic structure updates. If set to true this algorithm will register a listener on the graph to be laid out to automatically update internal data structures as soon as the structure of the original graph changes.

The default is false.


Implementation
    public function get automaticStructureUpdateEnabled():Boolean
    public function set automaticStructureUpdateEnabled(value:Boolean):void
lastWakeupTimeproperty 
lastWakeupTime:LongImpl  [read-only]

Returns the time when the last wake-up has occurred


Implementation
    public function get lastWakeupTime():LongImpl
maxTimeproperty 
maxTime:uint

Getter: Return the maximal time the layouter will run (in milliseconds).

Setter: Sets the maximal time the layouter will run. After this time it will sleep - independent of the actual result.


Implementation
    public function get maxTime():uint
    public function set maxTime(value:uint):void
outputRestrictionproperty 
outputRestriction:OutputRestriction

Getter: Returns the current OutputRestriction instance set for this instance. The default is com.yworks.yfiles.layout.organic.OutputRestriction.NONE.

Setter: Sets a restriction on the output generated by this layouter


Implementation
    public function get outputRestriction():OutputRestriction
    public function set outputRestriction(value:OutputRestriction):void

See also

preferredEdgeLengthproperty 
preferredEdgeLength:Number  [write-only]

Sets the preferred edge length. The edges should not become smaller than this amount.


Implementation
    public function set preferredEdgeLength(value:Number):void
preferredNodeDistanceproperty 
preferredNodeDistance:Number  [write-only]

Sets the preferred node distance.


Implementation
    public function set preferredNodeDistance(value:Number):void
qualityproperty 
quality:Number

Getter: The quality time ratio set.

Setter: Sets the quality ratio (value between 0.0 and 1.0) The higher this value is, the better will be the quality for the resulting layout but also the needed time.


Implementation
    public function get quality():Number
    public function set quality(value:Number):void
runningproperty 
running:Boolean  [read-only]

Returns whether the layouter is running at the moment.


Implementation
    public function get running():Boolean
sleepingproperty 
sleeping:Boolean  [read-only]

Returns whether the layouter is sleeping. A sleeping layouter can be awakened using wakeUp() and will continue its work.


Implementation
    public function get sleeping():Boolean

See also

stoppedproperty 
stopped:Boolean  [read-only]

Returns whether the layouter has been stopped.


Implementation
    public function get stopped():Boolean
workingRatioproperty 
workingRatio:Number

Getter: Returns the actual working ratio. The working ratio is the planned ratio of working time to waiting time.

Setter: Sets the working ratio. The working ratio represents the amount of processor time the layouter tries to grab. If the working ratio is set to 1 the layouter will try to run as fast as possible. Lower values will lead to small breaks after each round.


Implementation
    public function get workingRatio():Number
    public function set workingRatio(value:Number):void

See also

Number.MIN_VALUE
Constructor Detail
InteractiveOrganicLayouter()Constructor
public function InteractiveOrganicLayouter(init:Boolean = true)

Create a new instance of the InteractiveOrganicLayouter.

Parameters
init:Boolean (default = true) — An internally used switch to help handle proper instance initialization in inheritance chains where classes can have multiple constructor-like factory methods. This parameter can safely be ignored/omitted when calling the constructor.
Method Detail
addStructureUpdate()method
public function addStructureUpdate(runnable:Runnable):void

Adds a structural update to the queue. The given Runnable will be queued and executed at a specific time. Within this Runnable structural changes (like edge/node removals or adds) may be done. They are synchronized with the layouter. This method should only be used when changes to the structure of the graph are done. Every structural change involves a rebuild of the internal data structure. So "lightweight" changes like modifications of the positions of the nodes should be done using the corresponding methods setCenter().

Parameters

runnable:Runnable

See also

canLayout()method 
public function canLayout(graph:LayoutGraph):Boolean

Returns whether this layouter can layout the given graph.

Parameters

graph:LayoutGraph

Returns
Booleantrue if the graph may be laid out, false otherwise.
commitPositions()method 
public function commitPositions():void

This method writes the calculated positions (represented by the internal data structure of this layouter) to the LayoutGraph. This method must only be called while the layouter is running running.

 final InteractiveOrganicLayouter layouter = new InteractiveOrganicLayouter(); new Thread( new Runnable() { public void run() { layouter.doLayout( copiedGraph ); } } ).start(); new javax.swing.Timer( 24, new ActionListener() { public void actionPerformed( ActionEvent e ) { layouter.commitPositions(); } } ).start(); 

There may occur synchronization issues, if doLayout() is not called using a CopiedLayoutGraph.

See also

commitPositionsSmoothly()method 
public function commitPositionsSmoothly(maxMovement:Number, factor:Number):Number

This method transfers the calculated positions (represented by the internal data structure of this layouter) to the LayoutGraph. This method must only be called while the layouter is running running.

The positions are not transferred directly. Instead the nodes are moved towards the calculated position in each step. "Good" values for this method may be about 50 for the maxMovement and about 0.15 as factor (when the positions are updates about 25 times a second).

Parameters

maxMovement:Number — the maximal distance a node is moved
 
factor:Number — determines the node movement (movement = factor * distance between calculated and actual location)

Returns
Number — the biggest movement. This value can be used to estimate the difference between calculated layout and actual positions. If the return value is "0" the calculated layout has been transferred completely.

See also

doLayout()method 
public function doLayout(graph:LayoutGraph):void

Calculates the layout for the graph. The calculated layout is *NOT AUTOMATICALLY APPLIED*. The graph has to be updated with the actual calculated positions automatically.

Attention: It is recommended to use a CopiedLayoutGraph to buffer the original graph. If automaticStructureUpdateEnabled is set to true, structural changes to the original graph are automatically transferred to the copy.

 InteractiveOrganicLayouter layouter = new InteractiveOrganicLayouter(); Graph2D originalGraph = new Graph2D(); CopiedLayoutGraph copy = new CopiedLayoutGraph( originalGraph ); layouter.setAutomaticStructureUpdateEnabled( true ); layouter.doLayout( copy ); 

If an instance of CopiedLayoutGraph is laid out, the setters and getters having a node or edge as parameter may be used with instances from the original graph *or* the copied graph. This call will not return until stop() is called.

Parameters

graph:LayoutGraph — the graph that is laid out

See also

enableOnlyCore()method 
public function enableOnlyCore():void

Makes sure that the core of this layouter will not use the usual com.yworks.yfiles.layout.LayoutStage s, like com.yworks.yfiles.layout.ComponentLayouter, com.yworks.yfiles.layout.ParallelEdgeLayouter, etc. If you really need this feature, override this method and return silently.

See also

getCenter()method 
public function getCenter(node:Node):YPoint

Return the actual center of the node

Parameters

node:Node

Returns
YPoint — the center of the node or null if the layouter does not know anything about the node.
getCenterX()method 
public function getCenterX(node:Node):Number

Return the actual center of the node.

Parameters

node:Node

Returns
Number — the center of the node.
getCenterY()method 
public function getCenterY(node:Node):Number

Return the actual center of the node.

Parameters

node:Node

Returns
Number — the center of the node.
getClass()method 
override public function getClass():Class

Returns
Class
getStress()method 
public function getStress(node:Node):Number

Gets the stress for the given node. The higher the stress of a node is, the farther this node will be moved.

Parameters

node:Node

Returns
Number
initInteractiveOrganicLayouter()method 
protected final function initInteractiveOrganicLayouter():void

Initializes this object. See the documentation of the corresponding factory method newInteractiveOrganicLayouter() for details.

See also

newInteractiveOrganicLayouter()method 
public static function newInteractiveOrganicLayouter():InteractiveOrganicLayouter

Create a new instance of the InteractiveOrganicLayouter.

Returns
InteractiveOrganicLayouter
setCenter()method 
public function setCenter(node:Node, x:Number, y:Number):void

Sets the center for the node. This method does not affect the graph itself. Instead the internal data structure of the layouter is changed. This method may be used to update node positions due to user interaction (e.g. dragging).

Parameters

node:Node
 
x:Number
 
y:Number

setCenterX()method 
public function setCenterX(node:Node, x:Number):void

Sets the center of the node.

Parameters

node:Node
 
x:Number

setCenterY()method 
public function setCenterY(node:Node, y:Number):void

Sets the center of the node.

Parameters

node:Node
 
y:Number

setInertia()method 
public function setInertia(node:Node, inertia:Number):void

Set the inertia for the node. The inertia represents how "easy" a node will move. Inertia "1.0": The node will not move Inertia "0.5": The node will only move half as wide as it would with an inertia of "0.0" Inertia "0.0": The node will move as fast as possible

Parameters

node:Node
 
inertia:Number

setPreferredEdgeLength()method 
public function setPreferredEdgeLength(edge:Edge, newEdgeLength:Number):void

Sets the preferred edge length for the given edge.

Parameters

edge:Edge
 
newEdgeLength:Number

setRadius()method 
public function setRadius(node:Node, radius:Number):void

Sets the radius for the given node

Parameters

node:Node
 
radius:Number

setStress()method 
public function setStress(node:Node, stress:Number):void

Sets the stress for the given node. The higher the stress of a node is, the farther this node will be moved.

Parameters

node:Node
 
stress:Number — a value between 0 and 1

startLayoutSingleThreaded()method 
public function startLayoutSingleThreaded(graph:LayoutGraph):InteractiveOrganicLayouter_SingleThreadContext

Creates a context object that provides methods to continue (com.yworks.yfiles.layout.organic.InteractiveOrganicLayouter_SingleThreadContext.doLayout()) and stop (com.yworks.yfiles.layout.organic.InteractiveOrganicLayouter_SingleThreadContext.stopLayout()) the layout calculation. Note that simply calling this method will not perform any layout. Repeated calls to com.yworks.yfiles.layout.organic.InteractiveOrganicLayouter_SingleThreadContext.doLayout() need to be made in order for the layout calculation to be performed.

Parameters

graph:LayoutGraph — the graph that gets layouted.

Returns
InteractiveOrganicLayouter_SingleThreadContext — the context object to control layout calculation.

See also

stop()method 
public function stop():void

Stops the layouter. The layouter will stop after the actual round. This means that the layouter cannot be awakened again.

stopAndWait()method 
public function stopAndWait():void

Stops a previously started (startLayout()) layout Thread and blocks until the layout is completed.

See also

syncStructure()method 
public function syncStructure():void

This method synchronizes the CopiedLayoutGraph given as parameter to doLayout() with the original graph. This method

See also

wakeUp()method 
public function wakeUp():void

This method may be called if something has "changed" and the layouter shall restart/continue layout calculation. This is e.g. useful if the layouter is sleeping and some user interaction has occurred.