6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
17
<a href="#toc" class="jump">Jump to Table of Contents</a>
21
<div id="main" class="yui3-u">
22
<div class="content"><div class="intro" style="min-height:181px;">
24
<img src="../assets/dial/images/dial_drag.png" alt="Screenshot of the Dial widget" style="border: 1px solid #bfbfbf; float:right; height:146px; margin: 0 0 8px 8px; width:154px;">
25
The Dial widget is a circular value input control. It's like a real-world, analog volume control dial, but with much finer UI control.
26
Have you ever needed a slider with a 2000 unit range, wanted 1 unit accuracy, but didn't have 2000 pixels of real estate for a slider?
27
The Dial widget is made for cases like this.
30
The user sets the value of the dial by dragging its handle or clicking on the ring.
34
<h2 id="getting-started">Getting Started</h2>
37
To include the source files for Dial and its dependencies, first load
38
the YUI seed file if you haven't already loaded it.
41
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script></pre>
45
Next, create a new YUI instance for your application and populate it with the
46
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
47
YUI will automatically load any dependencies required by the modules you
51
<pre class="code prettyprint">// Create a new YUI instance and populate it with the required modules.
52
YUI().use('dial', function (Y) {
53
// Dial is available and ready for use. Add implementation
54
// code here.
59
For more information on creating YUI instances and on the
60
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
61
documentation for the <a href="../yui/index.html">YUI Global object</a>.
65
<h2 id="using-the-dial-widget">Using the Dial Widget</h2>
66
<h3 id="anatomy-of-a-dial">Anatomy of a Dial</h3>
68
<h4 id="dom-structure">Dom Structure</h4>
70
The major parts of the Dial are:
74
<li>User-draggable handle</li>
77
The ring is the background element and container of the other elements.
78
The marker is always displayed at a fixed but configurable distance from the dial center.
79
Its position around the dial indicates the current value as the user drags the handle or clicks
80
on the ring to adjust the value.
81
When not being dragged, the handle occupies the same space as the marker, and the marker is not displayed.
82
When the keyboard is used for input, the marker is not displayed.
83
The reset button restores the dial to the initial configuration value.
85
<p>A label string and a value string are dislayed above the dial.
87
<p>Like other form controls, Dials are inline elements.</p>
88
<img src="../assets/dial/images/dial_anatomy.png" alt="illustration of the parts of a Dial">
90
<h3 id="markup-structure">Markup Structure</h3>
91
<p>The final rendered Dial has the markup structure shown below:</p>
93
<pre class="code prettyprint"><div id="demo">
94
<div class="yui3-widget yui3-dial">
95
<div class="yui3-dial-content">
96
<div class="yui3-dial-label" id="[custom YUI gen id for screen reader]">
97
<span class="yui3-dial-label-string">My label</span>
98
<span class="yui3-dial-value-string">30</span>
100
<div class="yui3-dial-ring">
101
<div class="yui3-dial-north-mark"></div>
102
<div class="yui3-dial-marker yui3-dial-marker-hidden"></div>
103
<div class="yui3-dial-center-button">
104
<div class="yui3-dial-reset-str"></div>
106
<div class="yui3-dial-handle yui3-dd-draggable" title="Drag to set value" tabindex="0" role="slider" aria-valuenow="30" aria-valuemin="-220" aria-valuemax="220" aria-valuetext="30" aria-labelledby="[custom YUI gen id for screen reader]"></div>
110
</div></pre>
112
<h3 id="instantiating-the-dial">Instantiating the Dial</h3>
114
The only markup required to instantiate a <code>Dial</code> is an HTML tag into which the widget will be rendered.
116
<pre class="code prettyprint"><div id="demo"></div></pre>
118
<p><code>Dial</code> extends the <code>Widget</code> class, following the same pattern
119
as any widget constructor, accepting a configuration object to
120
set the initial configuration for the widget.</p>
121
<p>Some commonly used configuration attributes are shown below.</p>
122
<pre class="code prettyprint">YUI().use('dial', function(Y) {
123
var dial = new Y.Dial({
126
stepsPerRevolution:100,
132
After creating and configuring the new <code>Dial</code>,
133
Call the <code>render</code> method on your <code>Dial</code> object, passing it
134
the <code>selector</code> of a container object.
135
This renders it in the container and makes it usable.
137
<pre class="code prettyprint">var dial = new Y.Dial();
138
dial.render("#demo");</pre>
141
<h4 id="attributes">Attributes</h4>
142
<p>The following configuration properties are provided to define default values for each Dial widget:</p>
154
<td><code>min</code></td>
155
<td>Minimum input value allowed</td>
156
<td><code>-220</code></td>
159
<td><code>max</code></td>
160
<td>Maximum input value allowed</td>
161
<td><code>220</code></td>
164
<td><code>diameter</code></td>
165
<td>Diameter of the dial control in pixels</td>
166
<td><code>100</code></td>
169
<td><code>centerButtonDiameter</code></td>
170
<td>The diameter of the center button. This value is a percentage of the diameter of the Dial widget.</td>
171
<td><code>0.5</code></td>
174
<td><code>markerDiameter</code></td>
175
<td>The diameter of the marker that follows the angle of the handle as it is dragged. This value is a percentage of the diameter of the Dial widget.</td>
176
<td><code>0.1</code></td>
179
<td><code>handleDiameter</code></td>
180
<td>The diameter of the handle that sets the Dial value. This value is a percentage of the diameter of the Dial widget.</td>
181
<td><code>0.2</code></td>
184
<td><code>value</code></td>
185
<td>The initial value which will set the UI display</td>
186
<td><code>0</code></td>
189
<td><code>minorStep</code></td>
190
<td>Value is incremented/decremented by this value on arrow key press.</td>
191
<td><code>1</code></td>
194
<td><code>majorStep</code></td>
195
<td>Value is incremented/decremented by this value on page up/down key press.</td>
196
<td><code>10</code></td>
199
<td><code>stepsPerRevolution</code></td>
200
<td>One revolution of the dial adds/subtracts this many value units.</td>
201
<td><code>100</code></td>
204
<td><code>decimalPlaces</code></td>
205
<td>Number of digits to the right of decimal point to retain in the value.</td>
206
<td><code>0</code></td>
209
<td><code>strings</code></td>
210
<td>Display text strings are isolated in object literals and are handled through YUI's Internationalization utility.
211
See the examples for ways to replace these strings.
213
<td><code>{label:'My label', resetStr:'Reset', tooltipHandle:'Drag to set value'}</code></td>
216
<td><code>handleDistance</code></td>
217
<td>This is the distance from the center of the dial to the center of the marker and handle when at rest. This value is a percentage of the radius of the Dial widget.</td>
218
<td><code>0.75</code></td>
222
<h4 id="setting-and-constraining-the-dial-value">Setting and Constraining the Dial Value</h4>
224
<h5 id="setting-and-getting-dial-values">Setting and Getting Dial Values</h5>
226
<p>Like any input element, the most important thing about a Dial is its <code>value</code>.
227
<code>value</code> is managed as an attribute.</p>
229
<pre class="code prettyprint">// Specify value at construction
230
var dial = new Y.Dial({
234
// Get and set the value as an attribute
235
var val = dial.get('value');
237
dial.set('value',val + 10);</pre>
239
<h5 id="constraining-dial-values">Constraining Dial Values</h5>
240
<p>A Dial's <code>value</code> is constrained between the configured <code>min</code> and <code>max</code> attribute values.
241
Values outside this range are treated as the closer of <code>min</code> or <code>max</code>.</p>
244
<p>Configuring values for <code>max</code> and <code>min</code> that are respectively larger or smaller than the configured
245
<code>stepsPerRevolution</code> or <code>-stepsPerRevolution</code> can be used to configure a Dial to allow the user to drag the handle more than 360°.
246
By this means, a <code>Dial</code> can be configured to "go around and around," allowing a very large range of values.</p>
248
<pre class="code prettyprint">YUI().use("dial", function(Y) {
250
var dial = new Y.Dial({
253
stepsPerRevolution:100,
256
dial.render("#demo");
261
<h5 id="sync-the-ui-if-the-dial-was-rendered-off-the-dom">Sync the UI If the Dial Was Rendered off the DOM</h5>
262
<p>If a Dial is rendered off the DOM, you must call the Dial's <code>syncUI()</code> method after attaching it to the DOM
263
in order for the handle to be placed correctly.
264
When off DOM, the dimensional information necessary to place the handle is unavailable.</p>
267
<h3 id="css">CSS</h3>
269
<p>The core structural CSS for the Dial is shown below. Widths and heights of elements
270
are computed based on the "diameter" configuration property.</p>
272
<pre class="code prettyprint">/* VML implementation for IE */
276
behavior: url(#default#VML);
277
display: inline-block;
278
zoom: 1; *display: inline; /* IE < 8: fake inline-block */
282
display:-moz-inline-stack;
283
display:inline-block;
293
.yui3-dial-center-button,
294
.yui3-dial-reset-string,
295
.yui3-dial-handle-vml,
296
.yui3-dial-marker-vml,
297
.yui3-dial-center-button-vml,
298
.yui3-dial-ring-vml v\:oval,
299
.yui3-dial-center-button-vml v\:oval
303
.yui3-dial-center-button-vml v\:oval {
308
.yui3-skin-sam .yui3-dial-hidden {
310
filter:alpha(opacity=0);
320
<div id="sidebar" class="yui3-u">
322
<div id="toc" class="sidebox">
324
<h2 class="no-toc">Table of Contents</h2>
330
<a href="#getting-started">Getting Started</a>
333
<a href="#using-the-dial-widget">Using the Dial Widget</a>
336
<a href="#anatomy-of-a-dial">Anatomy of a Dial</a>
339
<a href="#dom-structure">Dom Structure</a>
344
<a href="#markup-structure">Markup Structure</a>
347
<a href="#instantiating-the-dial">Instantiating the Dial</a>
350
<a href="#attributes">Attributes</a>
353
<a href="#setting-and-constraining-the-dial-value">Setting and Constraining the Dial Value</a>
356
<a href="#setting-and-getting-dial-values">Setting and Getting Dial Values</a>
359
<a href="#constraining-dial-values">Constraining Dial Values</a>
362
<a href="#sync-the-ui-if-the-dial-was-rendered-off-the-dom">Sync the UI If the Dial Was Rendered off the DOM</a>
369
<a href="#css">CSS</a>
379
<div class="sidebox">
381
<h2 class="no-toc">Examples</h2>
385
<ul class="examples">
388
<li data-description="Create a Dial from existing markup on the page - a simple use case.">
389
<a href="dial-basic.html">Basic Dial</a>
394
<li data-description="Link a Dial with a text input field.">
395
<a href="dial-text-input.html">Dial Linked With Text Input</a>
400
<li data-description="Use image backgrounds to control the visual display of a Dial.">
401
<a href="dial-image-background.html">Dial With Image Background</a>
406
<li data-description="Use images to surround a Dial instance and provide additional styling.">
407
<a href="dial-image-surrounding.html">Dial With a Surrounding Image</a>
412
<li data-description="This example employs Dial to drive an interactive UI.">
413
<a href="dial-interactive.html">Dial With Interactive UI</a>
427
<script src="../assets/vendor/prettify/prettify-min.js"></script>
428
<script>prettyPrint();</script>