<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>API: inputex-plugin Layout.js (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css" />
<link rel="stylesheet" type="text/css" href="assets/api.css" />
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h1><a href="http://neyric.github.com/wireit" title="WireItLibrary">WireItLibrary</a></h1>
<h3>inputex-plugin <span class="subtitle">0.6.0</span></h3>
<a href="./index.html" title="WireItLibrary">WireItLibrary</a>
> <a href="./module_inputex-plugin.html" title="inputex-plugin">inputex-plugin</a>
> Layout.js (source view)
<form onsubmit="return false">
<div id="propertysearch">
Search: <input autocomplete="off" id="searchinput" />
<div id="searchresults">
</div>
</div>
</form>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
<fieldset>
<legend>Filters</legend>
<span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
<span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
<span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
</fieldset>
</form>
<div id="srcout">
<style>
#doc3 .classopts { display:none; }
</style>
<div class="highlight"><pre><span class="c">/**</span>
<span class="c"> * Layout Plugin</span>
<span class="c"> * TODO: provide an AbstractLayout Class</span>
<span class="c"> * @module layout-plugin</span>
<span class="c"> */</span>
<span class="c">/**</span>
<span class="c"> * Calculate the new position for the given layout and animate the layer to this position</span>
<span class="c"> */</span>
<span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">layoutAnim</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span> <span class="nx">sLayout</span><span class="o">,</span> <span class="nx">duration</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">layout</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layout</span><span class="p">[</span><span class="nx">sLayout</span> <span class="o">||</span> <span class="s2">"Spring"</span><span class="p">](</span><span class="k">this</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">newPositions</span> <span class="o">=</span> <span class="nx">layout</span><span class="p">.</span><span class="nx">run</span><span class="p">()</span><span class="o">,</span>
<span class="nx">n</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">containers</span><span class="p">.</span><span class="nx">length</span><span class="o">;</span>
<span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span> <span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">n</span> <span class="o">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">containers</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span><span class="o">,</span>
<span class="nx">p</span> <span class="o">=</span> <span class="nx">newPositions</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span><span class="o">,</span>
<span class="nx">anim</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">WireIt</span><span class="p">.</span><span class="nx">util</span><span class="p">.</span><span class="nx">Anim</span><span class="p">(</span> <span class="nx">c</span><span class="p">.</span><span class="nx">terminals</span><span class="o">,</span> <span class="nx">c</span><span class="p">.</span><span class="nx">el</span><span class="o">,</span> <span class="p">{</span> <span class="nx">left</span><span class="o">:</span> <span class="p">{</span> <span class="nx">to</span><span class="o">:</span> <span class="nx">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="p">}</span><span class="o">,</span> <span class="nx">top</span><span class="o">:</span> <span class="p">{</span><span class="nx">to</span><span class="o">:</span> <span class="nx">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]}</span> <span class="p">}</span><span class="o">,</span> <span class="nx">duration</span> <span class="o">||</span> <span class="mi">1</span><span class="o">,</span> <span class="nx">YAHOO</span><span class="p">.</span><span class="nx">util</span><span class="p">.</span><span class="nx">Easing</span><span class="p">.</span><span class="nx">easeOut</span><span class="p">);</span>
<span class="nx">anim</span><span class="p">.</span><span class="nx">animate</span><span class="p">();</span>
<span class="p">}</span>
<span class="nx">delete</span> <span class="nx">layout</span><span class="o">;</span>
<span class="p">};</span>
<span class="c">/**</span>
<span class="c"> * Start a dynamic layout</span>
<span class="c"> */</span>
<span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">startDynamicLayout</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span> <span class="nx">sLayout</span><span class="o">,</span> <span class="nx">interval</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">dynamicLayout</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">stopDynamicLayout</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">dynamicLayout</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layout</span><span class="p">[</span><span class="nx">sLayout</span> <span class="o">||</span> <span class="s2">"Spring"</span><span class="p">](</span><span class="k">this</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">dynamicTimer</span> <span class="o">=</span> <span class="nx">setInterval</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">that</span><span class="p">.</span><span class="nx">_runDynamicLayout</span><span class="p">();</span>
<span class="p">}</span><span class="o">,</span> <span class="nx">interval</span> <span class="o">||</span> <span class="mi">50</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_runDynamicLayout</span><span class="p">();</span>
<span class="p">};</span>
<span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_runDynamicLayout</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span> <span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">newPositions</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">dynamicLayout</span><span class="p">.</span><span class="nx">run</span><span class="p">()</span><span class="o">,</span>
<span class="nx">n</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">containers</span><span class="p">.</span><span class="nx">length</span><span class="o">;</span>
<span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span> <span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">n</span> <span class="o">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">containers</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span><span class="o">,</span>
<span class="nx">p</span> <span class="o">=</span> <span class="nx">newPositions</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="c">// TODO: this test should be: isDragging && container focused</span>
<span class="k">if</span><span class="p">(</span><span class="o">!</span> <span class="nx">YAHOO</span><span class="p">.</span><span class="nx">util</span><span class="p">.</span><span class="nx">Dom</span><span class="p">.</span><span class="nx">hasClass</span><span class="p">(</span><span class="nx">c</span><span class="p">.</span><span class="nx">el</span><span class="o">,</span> <span class="s2">"WireIt-Container-focused"</span><span class="p">)</span> <span class="p">)</span> <span class="p">{</span>
<span class="nx">c</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">left</span> <span class="o">=</span> <span class="nx">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="s2">"px"</span><span class="o">;</span>
<span class="nx">c</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">top</span> <span class="o">=</span> <span class="nx">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="s2">"px"</span><span class="o">;</span>
<span class="nx">c</span><span class="p">.</span><span class="nx">redrawAllWires</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="c">/**</span>
<span class="c"> * Stop the dynamic layout</span>
<span class="c"> */</span>
<span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layer</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">stopDynamicLayout</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">clearInterval</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">dynamicTimer</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">dynamicTimer</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">dynamicLayout</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="p">};</span>
<span class="c">/**</span>
<span class="c"> * @static</span>
<span class="c"> */</span>
<span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layout</span> <span class="o">=</span> <span class="p">{};</span>
<span class="c">/** </span>
<span class="c"> * Spring Layout (TODO: use different eges k)</span>
<span class="c"> * @class WireIt.Layout.Spring</span>
<span class="c"> * @constructor</span>
<span class="c"> */</span>
<span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layout</span><span class="p">.</span><span class="nx">Spring</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">layer</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">layer</span> <span class="o">=</span> <span class="nx">layer</span><span class="o">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">init</span><span class="p">();</span>
<span class="p">};</span>
<span class="nx">WireIt</span><span class="p">.</span><span class="nx">Layout</span><span class="p">.</span><span class="nx">Spring</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="p">{</span>
<span class="c">/**</span>
<span class="c"> * Init the default structure</span>
<span class="c"> */</span>
<span class="nx">init</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">nodes</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">this</span><span class="p">.</span><span class="nx">edges</span> <span class="o">=</span> <span class="p">[];</span>
<span class="c">// Extract wires</span>
<span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span> <span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="k">this</span><span class="p">.</span><span class="nx">layer</span><span class="p">.</span><span class="nx">wires</span><span class="p">.</span><span class="nx">length</span> <span class="o">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">wire</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">layer</span><span class="p">.</span><span class="nx">wires</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="k">this</span><span class="p">.</span><span class="nx">edges</span><span class="p">.</span><span class="nx">push</span><span class="p">([</span><span class="k">this</span><span class="p">.</span><span class="nx">layer</span><span class="p">.</span><span class="nx">containers</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">wire</span><span class="p">.</span><span class="nx">terminal1</span><span class="p">.</span><span class="nx">container</span><span class="p">)</span><span class="o">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">layer</span><span class="p">.</span><span class="nx">containers</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">wire</span><span class="p">.</span><span class="nx">terminal2</span><span class="p">.</span><span class="nx">container</span><span class="p">)</span> <span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * TODO: split iterations into "step" method</span>
<span class="c"> */</span>
<span class="nx">run</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">i</span><span class="o">,</span> <span class="nx">j</span><span class="o">,</span> <span class="nx">l</span><span class="o">;</span>
<span class="c">// Extract nodes positions</span>
<span class="k">this</span><span class="p">.</span><span class="nx">nodes</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">for</span><span class="p">(</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span> <span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="k">this</span><span class="p">.</span><span class="nx">layer</span><span class="p">.</span><span class="nx">containers</span><span class="p">.</span><span class="nx">length</span> <span class="o">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">pos</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">layer</span><span class="p">.</span><span class="nx">containers</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">terminals</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">getXY</span><span class="p">();</span>
<span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">layoutPosX</span><span class="o">:</span> <span class="p">(</span><span class="nx">pos</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="mi">400</span><span class="p">)</span><span class="o">/</span><span class="mi">200</span><span class="o">,</span>
<span class="nx">layoutPosY</span><span class="o">:</span> <span class="p">(</span><span class="nx">pos</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="mi">400</span><span class="p">)</span><span class="o">/</span><span class="mi">200</span><span class="o">,</span>
<span class="nx">layoutForceX</span><span class="o">:</span> <span class="mi">0</span><span class="o">,</span>
<span class="nx">layoutForceY</span><span class="o">:</span> <span class="mi">0</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="c">// Spring layout parameters</span>
<span class="kd">var</span> <span class="nx">iterations</span> <span class="o">=</span> <span class="mi">100</span><span class="o">,</span>
<span class="nx">maxRepulsiveForceDistance</span> <span class="o">=</span> <span class="mi">6</span><span class="o">,</span>
<span class="nx">k</span> <span class="o">=</span> <span class="mf">0.3</span><span class="o">,</span>
<span class="nx">c</span> <span class="o">=</span> <span class="mf">0.01</span><span class="o">;</span>
<span class="kd">var</span> <span class="nx">d</span><span class="o">,</span><span class="nx">dx</span><span class="o">,</span><span class="nx">dy</span><span class="o">,</span><span class="nx">d2</span><span class="o">,</span><span class="nx">node</span><span class="o">,</span><span class="nx">node1</span><span class="o">,</span><span class="nx">node2</span><span class="o">;</span>
<span class="c">// Iterations</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">l</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="nx">l</span> <span class="o"><</span> <span class="nx">iterations</span><span class="o">;</span> <span class="nx">l</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="c">// Forces on nodes due to node-node repulsions</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node1</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">j</span> <span class="o">=</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="o">;</span> <span class="nx">j</span> <span class="o"><</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">j</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node2</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">[</span><span class="nx">j</span><span class="p">];</span>
<span class="nx">dx</span> <span class="o">=</span> <span class="nx">node2</span><span class="p">.</span><span class="nx">layoutPosX</span> <span class="o">-</span> <span class="nx">node1</span><span class="p">.</span><span class="nx">layoutPosX</span><span class="o">;</span>
<span class="nx">dy</span> <span class="o">=</span> <span class="nx">node2</span><span class="p">.</span><span class="nx">layoutPosY</span> <span class="o">-</span> <span class="nx">node1</span><span class="p">.</span><span class="nx">layoutPosY</span><span class="o">;</span>
<span class="nx">d2</span> <span class="o">=</span> <span class="nx">dx</span> <span class="o">*</span> <span class="nx">dx</span> <span class="o">+</span> <span class="nx">dy</span> <span class="o">*</span> <span class="nx">dy</span><span class="o">;</span>
<span class="k">if</span><span class="p">(</span><span class="nx">d2</span> <span class="o"><</span> <span class="mf">0.01</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">dx</span> <span class="o">=</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">+</span> <span class="mf">0.1</span><span class="o">;</span>
<span class="nx">dy</span> <span class="o">=</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">+</span> <span class="mf">0.1</span><span class="o">;</span>
<span class="nx">d2</span> <span class="o">=</span> <span class="nx">dx</span> <span class="o">*</span> <span class="nx">dx</span> <span class="o">+</span> <span class="nx">dy</span> <span class="o">*</span> <span class="nx">dy</span><span class="o">;</span>
<span class="p">}</span>
<span class="nx">d</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">sqrt</span><span class="p">(</span><span class="nx">d2</span><span class="p">);</span>
<span class="k">if</span><span class="p">(</span><span class="nx">d</span> <span class="o"><</span> <span class="nx">maxRepulsiveForceDistance</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">repulsiveForce</span> <span class="o">=</span> <span class="nx">k</span> <span class="o">*</span> <span class="nx">k</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="nx">node2</span><span class="p">.</span><span class="nx">layoutForceX</span> <span class="o">+=</span> <span class="nx">repulsiveForce</span> <span class="o">*</span> <span class="nx">dx</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="nx">node2</span><span class="p">.</span><span class="nx">layoutForceY</span> <span class="o">+=</span> <span class="nx">repulsiveForce</span> <span class="o">*</span> <span class="nx">dy</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="nx">node1</span><span class="p">.</span><span class="nx">layoutForceX</span> <span class="o">-=</span> <span class="nx">repulsiveForce</span> <span class="o">*</span> <span class="nx">dx</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="nx">node1</span><span class="p">.</span><span class="nx">layoutForceY</span> <span class="o">-=</span> <span class="nx">repulsiveForce</span> <span class="o">*</span> <span class="nx">dy</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="c">// Forces on this.nodes due to edge attractions</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="k">this</span><span class="p">.</span><span class="nx">edges</span><span class="p">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">edge</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">edges</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="nx">node1</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">[</span> <span class="nx">edge</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="p">];</span>
<span class="nx">node2</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">[</span> <span class="nx">edge</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="p">];</span>
<span class="nx">dx</span> <span class="o">=</span> <span class="nx">node2</span><span class="p">.</span><span class="nx">layoutPosX</span> <span class="o">-</span> <span class="nx">node1</span><span class="p">.</span><span class="nx">layoutPosX</span><span class="o">;</span>
<span class="nx">dy</span> <span class="o">=</span> <span class="nx">node2</span><span class="p">.</span><span class="nx">layoutPosY</span> <span class="o">-</span> <span class="nx">node1</span><span class="p">.</span><span class="nx">layoutPosY</span><span class="o">;</span>
<span class="nx">d2</span> <span class="o">=</span> <span class="nx">dx</span> <span class="o">*</span> <span class="nx">dx</span> <span class="o">+</span> <span class="nx">dy</span> <span class="o">*</span> <span class="nx">dy</span><span class="o">;</span>
<span class="k">if</span><span class="p">(</span><span class="nx">d2</span> <span class="o"><</span> <span class="mf">0.01</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">dx</span> <span class="o">=</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">+</span> <span class="mf">0.1</span><span class="o">;</span>
<span class="nx">dy</span> <span class="o">=</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">+</span> <span class="mf">0.1</span><span class="o">;</span>
<span class="nx">d2</span> <span class="o">=</span> <span class="nx">dx</span> <span class="o">*</span> <span class="nx">dx</span> <span class="o">+</span> <span class="nx">dy</span> <span class="o">*</span> <span class="nx">dy</span><span class="o">;</span>
<span class="p">}</span>
<span class="nx">d</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">sqrt</span><span class="p">(</span><span class="nx">d2</span><span class="p">);</span>
<span class="k">if</span><span class="p">(</span><span class="nx">d</span> <span class="o">></span> <span class="nx">maxRepulsiveForceDistance</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">d</span> <span class="o">=</span> <span class="nx">maxRepulsiveForceDistance</span><span class="o">;</span>
<span class="nx">d2</span> <span class="o">=</span> <span class="nx">d</span> <span class="o">*</span> <span class="nx">d</span><span class="o">;</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">attractiveForce</span> <span class="o">=</span> <span class="p">(</span><span class="nx">d2</span> <span class="o">-</span> <span class="nx">k</span> <span class="o">*</span> <span class="nx">k</span><span class="p">)</span> <span class="o">/</span> <span class="nx">k</span><span class="o">;</span>
<span class="nx">node2</span><span class="p">.</span><span class="nx">layoutForceX</span> <span class="o">-=</span> <span class="nx">attractiveForce</span> <span class="o">*</span> <span class="nx">dx</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="nx">node2</span><span class="p">.</span><span class="nx">layoutForceY</span> <span class="o">-=</span> <span class="nx">attractiveForce</span> <span class="o">*</span> <span class="nx">dy</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="nx">node1</span><span class="p">.</span><span class="nx">layoutForceX</span> <span class="o">+=</span> <span class="nx">attractiveForce</span> <span class="o">*</span> <span class="nx">dx</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="nx">node1</span><span class="p">.</span><span class="nx">layoutForceY</span> <span class="o">+=</span> <span class="nx">attractiveForce</span> <span class="o">*</span> <span class="nx">dy</span> <span class="o">/</span> <span class="nx">d</span><span class="o">;</span>
<span class="p">}</span>
<span class="c">// Move by the given force</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="kd">var</span> <span class="nx">xmove</span> <span class="o">=</span> <span class="nx">c</span> <span class="o">*</span> <span class="nx">node</span><span class="p">.</span><span class="nx">layoutForceX</span><span class="o">;</span>
<span class="kd">var</span> <span class="nx">ymove</span> <span class="o">=</span> <span class="nx">c</span> <span class="o">*</span> <span class="nx">node</span><span class="p">.</span><span class="nx">layoutForceY</span><span class="o">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">layoutPosX</span> <span class="o">+=</span> <span class="nx">xmove</span><span class="o">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">layoutPosY</span> <span class="o">+=</span> <span class="nx">ymove</span><span class="o">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">layoutForceX</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">layoutForceY</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">newPositions</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">for</span><span class="p">(</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span> <span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="k">this</span><span class="p">.</span><span class="nx">layer</span><span class="p">.</span><span class="nx">containers</span><span class="p">.</span><span class="nx">length</span> <span class="o">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nodes</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="nx">newPositions</span><span class="p">.</span><span class="nx">push</span><span class="p">([</span><span class="nx">node</span><span class="p">.</span><span class="nx">layoutPosX</span><span class="o">*</span><span class="mi">200</span><span class="o">+</span><span class="mi">400</span><span class="o">-</span><span class="mi">40</span><span class="o">,</span> <span class="nx">node</span><span class="p">.</span><span class="nx">layoutPosY</span><span class="o">*</span><span class="mi">200</span><span class="o">+</span><span class="mi">400</span><span class="o">-</span><span class="mi">20</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">newPositions</span><span class="o">;</span>
<span class="p">}</span>
<span class="p">};</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div id="moduleList" class="module">
<h4>Modules</h4>
<ul class="content">
<li class=""><a href="module_animations-plugin.html" title="animations-plugin">animations-plugin</a></li>
<li class=""><a href="module_composable-plugin.html" title="composable-plugin">composable-plugin</a></li>
<li class=""><a href="module_editor-plugin.html" title="editor-plugin">editor-plugin</a></li>
<li class="selected"><a href="module_inputex-plugin.html" title="inputex-plugin">inputex-plugin</a></li>
<li class=""><a href="module_layout-plugin.html" title="layout-plugin">layout-plugin</a></li>
<li class=""><a href="module_wireit.html" title="WireIt">WireIt</a></li>
</ul>
</div>
<div id="classList" class="module">
<h4>Classes</h4>
<ul class="content">
<li class=""><a href="inputEx.BaseField.html" title="inputEx.BaseField">inputEx.BaseField</a></li>
<li class=""><a href="inputEx.Field.html" title="inputEx.Field">inputEx.Field</a></li>
<li class=""><a href="inputEx.LayerContainer.html" title="inputEx.LayerContainer">inputEx.LayerContainer</a></li>
<li class=""><a href="WireIt.FormContainer.html" title="WireIt.FormContainer">WireIt.FormContainer</a></li>
<li class=""><a href="WireIt.TextareaContainer.html" title="WireIt.TextareaContainer">WireIt.TextareaContainer</a></li>
</ul>
</div>
<div id="fileList" class="module">
<h4>Files</h4>
<ul class="content">
<li class=""><a href="fields.js.html" title="fields.js">fields.js</a></li>
<li class=""><a href="LayerContainer.js.html" title="LayerContainer.js">LayerContainer.js</a></li>
<li class="selected"><a href="Layout.js.html" title="Layout.js">Layout.js</a></li>
<li class=""><a href="TextareaContainer.js.html" title="TextareaContainer.js">TextareaContainer.js</a></li>
<li class=""><a href="WirableField.js.html" title="WirableField.js">WirableField.js</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2010 Eric Abouaf All rights reserved.
</div>
</div>
<script type="text/javascript">
var ALL_YUI_PROPS = [{"url": "inputEx.Field.html#property__addElement", "access": "", "host": "inputEx.Field", "type": "property", "name": "_addElement"}, {"url": "inputEx.LayerContainer.html#property_className", "access": "", "host": "inputEx.LayerContainer", "type": "property", "name": "className"}, {"url": "WireIt.FormContainer.html#property_collapsible", "access": "", "host": "WireIt.FormContainer", "type": "property", "name": "collapsible"}, {"url": "inputEx.LayerContainer.html#property_ddHandle", "access": "", "host": "inputEx.LayerContainer", "type": "property", "name": "ddHandle"}, {"url": "WireIt.FormContainer.html#property_fields", "access": "", "host": "WireIt.FormContainer", "type": "property", "name": "fields"}, {"url": "WireIt.FormContainer.html#method_getValue", "access": "", "host": "WireIt.FormContainer", "type": "method", "name": "getValue"}, {"url": "inputEx.LayerContainer.html#property_height", "access": "", "host": "inputEx.LayerContainer", "type": "property", "name": "height"}, {"url": "inputEx.LayerContainer.html#property_Layout", "access": "", "host": "inputEx.LayerContainer", "type": "property", "name": "Layout"}, {"url": "inputEx.LayerContainer.html#method_layoutAnim", "access": "", "host": "inputEx.LayerContainer", "type": "method", "name": "layoutAnim"}, {"url": "WireIt.FormContainer.html#property_legend", "access": "", "host": "WireIt.FormContainer", "type": "property", "name": "legend"}, {"url": "inputEx.Field.html#method_onAddWire", "access": "", "host": "inputEx.Field", "type": "method", "name": "onAddWire"}, {"url": "inputEx.LayerContainer.html#method_onDrag", "access": "", "host": "inputEx.LayerContainer", "type": "method", "name": "onDrag"}, {"url": "inputEx.Field.html#method_onRemoveWire", "access": "", "host": "inputEx.Field", "type": "method", "name": "onRemoveWire"}, {"url": "WireIt.FormContainer.html#method_render", "access": "", "host": "WireIt.FormContainer", "type": "method", "name": "render"}, {"url": "inputEx.Field.html#method_render", "access": "", "host": "inputEx.Field", "type": "method", "name": "render"}, {"url": "inputEx.LayerContainer.html#method_render", "access": "", "host": "inputEx.LayerContainer", "type": "method", "name": "render"}, {"url": "WireIt.FormContainer.html#method_renderForm", "access": "", "host": "WireIt.FormContainer", "type": "method", "name": "renderForm"}, {"url": "inputEx.Field.html#method_renderTerminal", "access": "", "host": "inputEx.Field", "type": "method", "name": "renderTerminal"}, {"url": "inputEx.Field.html#method_setContainer", "access": "", "host": "inputEx.Field", "type": "method", "name": "setContainer"}, {"url": "inputEx.Field.html#method_setFieldName", "access": "", "host": "inputEx.Field", "type": "method", "name": "setFieldName"}, {"url": "WireIt.FormContainer.html#method_setOptions", "access": "", "host": "WireIt.FormContainer", "type": "method", "name": "setOptions"}, {"url": "inputEx.Field.html#method_setOptions", "access": "", "host": "inputEx.Field", "type": "method", "name": "setOptions"}, {"url": "inputEx.LayerContainer.html#method_setTerminals", "access": "", "host": "inputEx.LayerContainer", "type": "method", "name": "setTerminals"}, {"url": "WireIt.FormContainer.html#method_setValue", "access": "", "host": "WireIt.FormContainer", "type": "method", "name": "setValue"}, {"url": "inputEx.LayerContainer.html#method_startDynamicLayout", "access": "", "host": "inputEx.LayerContainer", "type": "method", "name": "startDynamicLayout"}, {"url": "inputEx.LayerContainer.html#method_stopDynamicLayout", "access": "", "host": "inputEx.LayerContainer", "type": "method", "name": "stopDynamicLayout"}, {"url": "inputEx.LayerContainer.html#property_width", "access": "", "host": "inputEx.LayerContainer", "type": "property", "name": "width"}, {"url": "inputEx.LayerContainer.html#property__WireItTerminals", "access": "", "host": "inputEx.LayerContainer", "type": "property", "name": "_WireItTerminals"}, {"url": "WireIt.FormContainer.html#property_xtype", "access": "", "host": "WireIt.FormContainer", "type": "property", "name": "xtype"}, {"url": "inputEx.LayerContainer.html#property_xtype", "access": "", "host": "inputEx.LayerContainer", "type": "property", "name": "xtype"}];
</script>
</body>
</html>