<!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 WireLabel.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>
> WireLabel.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"> * Label support for WireIt</span>
<span class="c"> * @module labels-plugin</span>
<span class="c"> */</span>
<span class="c">//this.options.label = options.label || "Test";</span>
<span class="c">/**</span>
<span class="c"> * Method to draw the text</span>
<span class="c"> */</span>
<span class="nx">WireIt</span><span class="p">.</span><span class="nx">Wire</span><span class="p">.</span><span class="nx">drawLabel</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">p1</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">terminal1</span><span class="p">.</span><span class="nx">getXY</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">p2</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">terminal2</span><span class="p">.</span><span class="nx">getXY</span><span class="p">();</span>
<span class="c">// Coefficient multiplicateur de direction</span>
<span class="c">// 100 par defaut, si distance(p1,p2) < 100, on passe en distance/2</span>
<span class="kd">var</span> <span class="nx">coeffMulDirection</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">coeffMulDirection</span><span class="o">;</span>
<span class="kd">var</span> <span class="nx">distance</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="nb">Math</span><span class="p">.</span><span class="nx">pow</span><span class="p">(</span><span class="nx">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="nx">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">,</span><span class="mi">2</span><span class="p">)</span><span class="o">+</span><span class="nb">Math</span><span class="p">.</span><span class="nx">pow</span><span class="p">(</span><span class="nx">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="nx">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">,</span><span class="mi">2</span><span class="p">));</span>
<span class="k">if</span><span class="p">(</span><span class="nx">distance</span> <span class="o"><</span> <span class="nx">coeffMulDirection</span><span class="p">){</span>
<span class="nx">coeffMulDirection</span> <span class="o">=</span> <span class="nx">distance</span><span class="o">/</span><span class="mi">2</span><span class="o">;</span>
<span class="p">}</span>
<span class="c">// Calcul des vecteurs directeurs d1 et d2 :</span>
<span class="kd">var</span> <span class="nx">d1</span> <span class="o">=</span> <span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">terminal1</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">direction</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="nx">coeffMulDirection</span><span class="o">,</span>
<span class="k">this</span><span class="p">.</span><span class="nx">terminal1</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">direction</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="nx">coeffMulDirection</span><span class="p">];</span>
<span class="kd">var</span> <span class="nx">d2</span> <span class="o">=</span> <span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">terminal2</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">direction</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="nx">coeffMulDirection</span><span class="o">,</span>
<span class="k">this</span><span class="p">.</span><span class="nx">terminal2</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">direction</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="nx">coeffMulDirection</span><span class="p">];</span>
<span class="kd">var</span> <span class="nx">bezierPoints</span><span class="o">=</span><span class="p">[];</span>
<span class="nx">bezierPoints</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nx">p1</span><span class="o">;</span>
<span class="nx">bezierPoints</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="nx">d1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">,</span><span class="nx">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="nx">d1</span><span class="p">[</span><span class="mi">1</span><span class="p">]];</span>
<span class="nx">bezierPoints</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="nx">d2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">,</span><span class="nx">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="nx">d2</span><span class="p">[</span><span class="mi">1</span><span class="p">]];</span>
<span class="nx">bezierPoints</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="nx">p2</span><span class="o">;</span>
<span class="kd">var</span> <span class="nx">min</span> <span class="o">=</span> <span class="p">[</span><span class="nx">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">,</span><span class="nx">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]];</span>
<span class="kd">var</span> <span class="nx">max</span> <span class="o">=</span> <span class="p">[</span><span class="nx">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">,</span><span class="nx">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]];</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">1</span> <span class="o">;</span> <span class="nx">i</span><span class="o"><</span><span class="nx">bezierPoints</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="kd">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="nx">bezierPoints</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="k">if</span><span class="p">(</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="nx">min</span><span class="p">[</span><span class="mi">0</span><span class="p">]){</span>
<span class="nx">min</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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="k">if</span><span class="p">(</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="nx">min</span><span class="p">[</span><span class="mi">1</span><span class="p">]){</span>
<span class="nx">min</span><span class="p">[</span><span class="mi">1</span><span class="p">]</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="k">if</span><span class="p">(</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="nx">max</span><span class="p">[</span><span class="mi">0</span><span class="p">]){</span>
<span class="nx">max</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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="k">if</span><span class="p">(</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="nx">max</span><span class="p">[</span><span class="mi">1</span><span class="p">]){</span>
<span class="nx">max</span><span class="p">[</span><span class="mi">1</span><span class="p">]</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="p">}</span>
<span class="c">// Redimensionnement du canvas</span>
<span class="kd">var</span> <span class="nx">margin</span> <span class="o">=</span> <span class="p">[</span><span class="mi">4</span><span class="o">,</span><span class="mi">4</span><span class="p">];</span>
<span class="nx">min</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nx">min</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="nx">margin</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="nx">min</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">min</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="nx">margin</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
<span class="nx">max</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nx">max</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="nx">margin</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="nx">max</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">max</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="nx">margin</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
<span class="kd">var</span> <span class="nx">lw</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span><span class="nx">max</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="nx">min</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
<span class="kd">var</span> <span class="nx">lh</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span><span class="nx">max</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="nx">min</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
<span class="c">//this.SetCanvasRegion(min[0],min[1],lw,lh);</span>
<span class="kd">var</span> <span class="nx">ctxt</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getContext</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="nx">bezierPoints</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="nx">bezierPoints</span><span class="p">[</span><span class="nx">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nx">bezierPoints</span><span class="p">[</span><span class="nx">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="nx">min</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="nx">bezierPoints</span><span class="p">[</span><span class="nx">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">bezierPoints</span><span class="p">[</span><span class="nx">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="nx">min</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">fontSize</span><span class="o">=</span><span class="mi">14</span><span class="o">;</span>
<span class="kd">var</span> <span class="nx">center</span> <span class="o">=</span> <span class="p">{</span>
<span class="nx">x</span><span class="o">:</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span> <span class="p">(</span><span class="nx">bezierPoints</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="nx">bezierPoints</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span><span class="o">,//</span> <span class="o">+</span> <span class="p">(</span><span class="mi">60</span> <span class="o">*</span> <span class="k">this</span><span class="p">.</span><span class="nx">terminal2</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">direction</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">,</span>
<span class="nx">y</span><span class="o">:</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span> <span class="p">(</span><span class="nx">bezierPoints</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="nx">bezierPoints</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span><span class="c">// + (60 * this.terminal2.options.direction[1])</span>
<span class="p">};</span>
<span class="kd">var</span> <span class="nx">padding</span> <span class="o">=</span> <span class="mi">8</span><span class="o">;</span>
<span class="kd">var</span> <span class="nx">hp</span> <span class="o">=</span> <span class="nx">padding</span><span class="o">/</span><span class="mi">2</span><span class="o">;</span>
<span class="c">/*var tWidth = ctxt.measureText("sans", fontSize,this.options.label) + padding;</span>
<span class="c"> var desc = ctxt.fontDescent("sans",fontSize) + hp;</span>
<span class="c"> var asc = ctxt.fontAscent("sans",fontSize) + hp;</span>
<span class="c"> var tHeight = desc+asc;</span>
<span class="c"> var lastFillStyle = ctxt.fillStyle;</span>
<span class="c"> var lastWidth = ctxt.lineWidth;</span>
<span class="c"> var lastStrokeStyle = ctxt.strokeStyle;</span>
<span class="c"> ctxt.lineWidth=1;</span>
<span class="c"> ctxt.fillStyle = "rgba(255,255,255,0.85)";</span>
<span class="c"> ctxt.fillRect(center.x - hp - (tWidth/2),center.y - hp - tHeight + desc, tWidth, tHeight);</span>
<span class="c"> ctxt.fillStyle = this.options.color;</span>
<span class="c"> ctxt.strokeRect(center.x - hp - (tWidth/2),center.y - hp - tHeight + desc, tWidth, tHeight);*/</span>
<span class="c">//ctxt.drawTextCenter("sans", fontSize, center.x-hp, center.y-hp, this.options.label);</span>
<span class="nx">ctxt</span><span class="p">.</span><span class="nx">font</span> <span class="o">=</span> <span class="s2">"1em 'arial'"</span><span class="o">;</span>
<span class="nx">ctxt</span><span class="p">.</span><span class="nx">textAlign</span> <span class="o">=</span> <span class="s1">'left'</span><span class="o">;</span>
<span class="nx">ctxt</span><span class="p">.</span><span class="nx">textBaseline</span> <span class="o">=</span> <span class="s1">'top'</span><span class="o">;</span>
<span class="nx">ctxt</span><span class="p">.</span><span class="nx">fillText</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="kd">label</span><span class="o">,</span> <span class="nx">center</span><span class="p">.</span><span class="nx">x</span><span class="o">-</span><span class="nx">hp</span><span class="o">,</span> <span class="nx">center</span><span class="p">.</span><span class="nx">y</span><span class="o">-</span><span class="nx">hp</span><span class="p">);</span>
<span class="c">/*ctxt.fillStyle = lastFillStyle;</span>
<span class="c"> ctxt.lineWidth = lastWidth;</span>
<span class="c"> ctxt.strokeStyle = lastStrokeStyle;*/</span>
<span class="p">};</span>
<span class="c">/*if(this.options.label) {</span>
<span class="c"> try {</span>
<span class="c"> this.drawLabel();</span>
<span class="c"> }catch(ex) {</span>
<span class="c"> console.log(ex);</span>
<span class="c"> }</span>
<span class="c">}*/</span>
<span class="c">// <script type="text/javascript" src="../../lib/canvas.text.js"></script></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=""><a href="module_grouping-plugin.html" title="grouping-plugin">grouping-plugin</a></li>
<li class="selected"><a href="module_inputex-plugin.html" title="inputex-plugin">inputex-plugin</a></li>
<li class=""><a href="module_labels-plugin.html" title="labels-plugin">labels-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="WireIt.FormContainer.html" title="WireIt.FormContainer">WireIt.FormContainer</a></li>
</ul>
</div>
<div id="fileList" class="module">
<h4>Files</h4>
<ul class="content">
<li class=""><a href="WirableField.js.html" title="WirableField.js">WirableField.js</a></li>
<li class="selected"><a href="WireLabel.js.html" title="WireLabel.js">WireLabel.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#method_drawLabel", "access": "", "host": "inputEx.Field", "type": "method", "name": "drawLabel"}, {"url": "WireIt.FormContainer.html#method_getValue", "access": "", "host": "WireIt.FormContainer", "type": "method", "name": "getValue"}, {"url": "inputEx.Field.html#property_Layout", "access": "", "host": "inputEx.Field", "type": "property", "name": "Layout"}, {"url": "inputEx.Field.html#method_layoutAnim", "access": "", "host": "inputEx.Field", "type": "method", "name": "layoutAnim"}, {"url": "inputEx.Field.html#method_onAddWire", "access": "", "host": "inputEx.Field", "type": "method", "name": "onAddWire"}, {"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": "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": "WireIt.FormContainer.html#method_setBackReferenceOnFieldOptionsRecursively", "access": "", "host": "WireIt.FormContainer", "type": "method", "name": "setBackReferenceOnFieldOptionsRecursively"}, {"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": "WireIt.FormContainer.html#method_setValue", "access": "", "host": "WireIt.FormContainer", "type": "method", "name": "setValue"}, {"url": "inputEx.Field.html#method_startDynamicLayout", "access": "", "host": "inputEx.Field", "type": "method", "name": "startDynamicLayout"}, {"url": "inputEx.Field.html#method_stopDynamicLayout", "access": "", "host": "inputEx.Field", "type": "method", "name": "stopDynamicLayout"}];
</script>
</body>
</html>