<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://organizeseries.com/"
	>

<channel>
	<title>SitePen Blog &#187; JavaScript</title>
	<atom:link href="http://www.sitepen.com/blog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepen.com/blog</link>
	<description>SitePen Services and notes about Dojo, Persevere, CometD, JavaScript, and the Web</description>
	<lastBuildDate>Wed, 15 May 2013 22:02:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>AMD Module and Local Variable Naming Conventions</title>
		<link>http://www.sitepen.com/blog/2012/12/07/amd-module-and-local-variable-naming-conventions/</link>
		<comments>http://www.sitepen.com/blog/2012/12/07/amd-module-and-local-variable-naming-conventions/#comments</comments>
		<pubDate>Fri, 07 Dec 2012 08:33:25 +0000</pubDate>
		<dc:creator>Matthew Maxwell</dc:creator>
				<category><![CDATA[AMD]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5741</guid>
		<description><![CDATA[<p>Client-Side web application development is becoming more and more robust. There are many amazing tools and technologies available for creating an immersive and interactive user experience. With the demand from users rising, the importance of creating code efficiently is paramount. When working with Dojo and other AMD compatible tools, you can easily harness the power [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>
	Client-Side web application development is becoming more and more robust.  There are many amazing tools and technologies available for creating an immersive and interactive user experience.  With the demand from users rising, the importance of creating code efficiently is paramount.  When working with Dojo and other <a href="http://www.sitepen.com/blog/2012/06/25/amd-the-definitive-source/">AMD</a> compatible tools, you can easily harness the power of writing very modular source code. Two common challenges you might face when working with AMD are choosing meaningful names for your modules and determining naming conventions for local variable references to your modules.
</p>
<p><span id="more-5741"></span></p>
<p>
	First, let&#8217;s review some terminology for working with AMD.
</p>
<h3>
	<a id="packages" href="#packages">Packages</a><br />
</h3>
<p>
	Simply put, packages are collections of modules. <code>dojo</code>, <code>dijit</code>, and <code>dgrid</code> are examples of packages. Unlike a simple collection of modules in a directory, however, packages are ingrained with extra features that can significantly enhance module portability and ease-of-use.
</p>
<p>
	There are three main package configuration options. <code>name</code> is the name of the package. <code>location</code> is the location of the package, and can either be a path relative to <code>baseUrl</code> or an absolute path. <code>main</code> is an optional parameter that defaults to &#8220;main&#8221; and is used to discover the correct module to load if someone tries to require the package itself. For example, if you were to try to require &#8220;dojo&#8221;, the actual file that would be loaded is &#8220;/dojo/main.js&#8221;.
</p>
<p>
	Properly packaging your modules is important, as you want to limit the number of dependencies each package has.  If you have packages that depend on all of your other packages, you will have a really hard time using your packages independently.  You will also want to package your modules in a way that makes sense.  For example, you would not want to put a module that has math calculations for pi in the same package with a module that has form widgets.
</p>
<h3>
	<a id="modules" href="#modules">Modules</a><br />
</h3>
<p>
	A module can be a <code>class</code>, a <code>function</code>, an <code>object</code> with <code>properties</code> and <code>methods</code>, or just a piece of code that executes when it is loaded.  Modules are great because they allow you to write highly decoupled, succinct code that is extremely reusable.
</p>
<p>
	The name for your module is automatically derived from its file location.  If a module is located in the <code>art/shapes.js</code> file, then it can be referenced via the identifier <code>art/shapes</code>.  More detailed information on the naming of modules as well as defining them and requiring them can be found in the <a href="https://github.com/amdjs/amdjs-api/wiki/AMD">AMD API specification</a>.
</p>
<p>
	The Dojo Loader makes relocation an easy process.  If you need to reuse a module, you can simply copy its file and place it in any other directory.  For example, if you move a file for your module from <code>art/shapes.js</code> to <code>geometry/shapes.js</code>, you can reference this module by its new identifier <code>geometry/shapes</code>.  As you can see, moving modules to different packages is simple.  This makes decoupling and reusing your code extremely easy.
</p>
<p>
	The Dojo Loader allows you to map these modules to any local variable name that you specify.  Choosing these names and how your code is packaged is one of the most crucial decisions you can make as a Dojo developer.  Let&#8217;s take a couple of minutes to explore these areas in more detail and see how they can benefit your development efforts.
</p>
<h3>
	<a id="what-should-i-name-my-modules" href="#what-should-i-name-my-modules">What Should I Name My Modules?</a><br />
</h3>
<p>
	When developing modules, using proper naming conventions improves development efficiency, keeps your API clean, and reduces the need to remember the exact name of a module. This allows you to spend your time on more meaningful tasks, such as enhancements or bug fixes.  Considerations you should look at when deciding what to name your modules are things such as, &#8220;Is this a constructor?&#8221; or &#8220;Is this a mixin?&#8221;, etc.  These things can change the recommended naming conventions for your modules.
</p>
<p>
	If your module is a constructor, such as a widget, it should be in an <code>UpperCamelCase</code> format.  If it is a mixin, it should follow the <code>_UnderscoreMixin</code> format.  If it is neither of these, it should follow the <code>lowerCamelCase</code> format, typically used for a singleton.
</p>
<p>
	Aside from naming your modules properly, it&#8217;s also a good idea to have a standard for what variable you map your modules to when using them in a <code>require</code> callback.  In Dojo development, this is called the &#8220;Preferred Arg Alias&#8221;, and some of these are recommended in the <a href="https://docs.google.com/spreadsheet/ccc?key=0Avm8Hjje-xiXdFBVSURNdFpHSmNzOXlMcnU5V3k1Rmc#gid=0">dojo.XX AMD modules spreadsheet</a>.  As you can see in this spreadsheet, most of the module names are concise and meaningful.  Their preferred arg alias is similar, if not exact, to the module name, and the modules are packaged in a way that makes sense.  We are striving to improve this, and efforts for those improvements can be seen in the <a href="http://dojotoolkit.org/reference-guide/1.8/releasenotes/migration-2.0.html">1.x to 2.0 migration document</a>. The benefits of choosing consistent local variable names are as follows:
</p>
<ul>
<li>Preserve the recommended naming conventions for constructors, mixins, and singletons</li>
<li>Provide names that are easily related to the source module</li>
<li>Choosing consistent local variable names makes it easier to reuse Dojo example and tutorials</li>
</ul>
<p>Local variable names for modules are simply references to the module included. Sometimes a module identifier does not make for an ideal local variable. For example, if the name is a common JavaScript word such as array, we recommend adding a suffix to make it arrayUtil. Or, if the module name contains a hyphen, such as <code>dojo/dom-construct</code>, we recommend <code>domConstruct</code>, which is a valid JavaScript variable. Because these variable are simply locally scoped references to the returned value of a required module dependency, you are free to name them whatever you want, but we believe that following these consistent patterns will simplify your approach to using AMD effectively.</p>
<h3>Conclusion</h3>
<p>
	Naming your modules properly, mapping them to logical argument names, and packaging them in a way that makes sense can make your code more portable and easier to maintain and understand.
</p>
<p>
	If you are interested in diving into <a href="http://www.sitepen.com/blog/2012/06/25/amd-the-definitive-source/">AMD in depth</a>, <a href="http://www.sitepen.com/">SitePen</a> provides great <a href="http://www.sitepen.com/workshops">Dojo workshops</a> that can help take you from a novice Dojo programmer to a Dojo master.  If you&#8217;ve already got code implemented and would like assistance in migrating it to later versions of Dojo, or help rewriting or debugging it, SitePen also offers comprehensive <a href="http://www.sitepen.com/support">JavaScript support</a>.</p>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/12/07/amd-module-and-local-variable-naming-conventions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Dojo 1.8</title>
		<link>http://www.sitepen.com/blog/2012/12/06/learning-dojo-1-8/</link>
		<comments>http://www.sitepen.com/blog/2012/12/06/learning-dojo-1-8/#comments</comments>
		<pubDate>Thu, 06 Dec 2012 15:22:57 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[AMD]]></category>
		<category><![CDATA[dgrid]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5904</guid>
		<description><![CDATA[<p>Since we last posted an article on Learning Dojo, things have changed dramatically. Dojo has become an early adopter of AMD, with a new build tool to match; there is a new grid; the documentation has been vastly improved, and there are tutorials galore! In fact, there is so much information out there on learning [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>Since we last posted an article on <a href="http://www.sitepen.com/blog/2010/03/05/learning-dojo/">Learning Dojo</a>, things have changed dramatically. Dojo has become an early adopter of <a href="http://www.sitepen.com/blog/2012/06/25/amd-the-definitive-source/">AMD</a>, with a new build tool to match; there is a <a href="http://www.sitepen.com/blog/2011/10/26/introducing-the-next-grid-dgrid/">new grid</a>; the <a href="http://dojotoolkit.org/reference-guide/1.8/">documentation</a> has been vastly improved, and there are <a href="http://dojotoolkit.org/documentation/">tutorials</a> galore!</p>
<p>In fact, there is so much information out there on learning Dojo, it might be overwhelming. In a way, Dojo 1.7&#8242;s migration to AMD amplifies the problem, in that many previously-published articles no longer reflect the most recent best practices. This post aims to start you off on the right foot by pointing to relevant up-to-date resources for getting started with &mdash; or catching up on &mdash; Dojo 1.8.</p>
<h2>Why Dojo</h2>
<p><a href="http://net.tutsplus.com/tutorials/javascript-ajax/10-reasons-why-your-projects-should-use-the-dojo-toolkit/">10 Reasons your Projects Should use the Dojo Toolkit</a><br />
<a href="http://www.slideshare.net/sitepen/dojo-20-modular-mobile-and-reinventing-web-app-development">Slides: Dojo 2.0: Modular, Mobile, and Reinventing Web App Development</a><br />
<a href="http://net.tutsplus.com/articles/interviews/an-interview-with-dojo-toolkit-creator-dylan-schiemann/">Interview with Dojo Toolkit Co-creator Dylan Schiemann</a></p>
<h2>Getting Started</h2>
<p><a href="http://dojotoolkit.org/documentation/tutorials/1.8/start/">Tutorial: Dojo Start</a> &#8211; Answers many common questions asked by newcomers<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/hello_dojo/">Tutorial: Hello Dojo</a> &#8211; Guides through the first steps in exploring Dojo</p>
<h2>Transitioning from Dojo 1.6</h2>
<p><a href="http://dojotoolkit.org/documentation/tutorials/1.8/modern_dojo/">Tutorial: Modern Dojo</a> &#8211; Explains key differences between Dojo before and after 1.7<br />
<a href="http://www.slideshare.net/jthomas/moving-to-dojo-17-and-the-path-to-20">Slides: Moving to Dojo 1.7 and the path to 2.0</a> &#8211; Presents features new to Dojo 1.7 and up</p>
<h2>AMD Resources</h2>
<p><a href="http://dojotoolkit.org/documentation/tutorials/1.8/modules/">Tutorial: Defining Modules</a> &#8211; Explains how to define and load modules, and configure the loader<br />
<a href="http://www.sitepen.com/blog/2012/06/25/amd-the-definitive-source/">AMD: The Definitive Source</a> &#8211; Explains the reasoning and benefits of AMD<br />
<a href="http://bryanforbes.github.com/amd-commonjs-modules-presentation/2011-10-29/#0">Slides: Modular JavaScript: AMD &#038; CommonJS modules</a> &#8211; Discusses the evolution of AMD<br />
<a href="https://github.com/amdjs/amdjs-api/wiki">AMD API</a> &#8211; Wiki containing AMD API specifications</p>
<h2>Learning Dojo</h2>
<p><a href="http://dojotoolkit.org/documentation/tutorials/1.8/hitch">Tutorial: Making Functions with hitch and partial</a> &#8211; Explains execution context and how to control it<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/declare">Tutorial: Classy JavaScript with dojo/_base/declare</a> &#8211; Explains Dojo&#8217;s chief inheritance mechanism<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/ajax">Tutorial: Ajax with dojo/request</a> &#8211; Introduces Dojo 1.8&#8242;s new Ajax API<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/deferreds/">Tutorial: Getting Started with Deferreds</a> &#8211; Introduces Deferreds, crucial for asynchronous logic<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/promises/">Tutorial: Dojo Deferreds and Promises</a> &#8211; Discusses Promises and their relation to Deferreds<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/intro_dojo_store">Tutorial: Dojo Object Stores</a> &#8211; Explains the dojo/store API, new since Dojo 1.6<br />
<a href="http://dojotoolkit.org/reference-guide/1.8/dojo/">Reference Guide: Dojo</a> &#8211; Index of reference material for the Dojo package</p>
<h2>Learning Dijit</h2>
<p><a href="http://dojotoolkit.org/documentation/tutorials/1.8/understanding_widgetbase">Tutorial: Understanding _WidgetBase</a> &#8211; Details the module forming the basis of all widgets<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/dijit_layout">Tutorial: Layout with Dijit</a> &#8211; Discusses Dijit&#8217;s layout widgets<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/templated">Tutorial: Creating Template-based Widgets</a> &#8211; Describes Dijit&#8217;s templating capabilities<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/recipes/custom_widget">Recipe: Creating a Custom Widget</a> &#8211; Walks through implementing a widget<br />
<a href="http://dojotoolkit.org/reference-guide/1.8/dijit/">Reference Guide: Dijit</a> &#8211; Index of reference material for the Dojo package</p>
<h2>Developing Applications</h2>
<p><a href="http://dojotoolkit.org/documentation/tutorials/1.8/hash">Tutorial: Using dojo/hash and dojo/router</a> &#8211; Discusses Dojo&#8217;s utilities for managing the browser hash<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/recipes/app_controller">Recipe: Application Controller</a> &#8211; enumerates an approach to writing a small app<br />
<a href="https://github.com/csnover/dojo-boilerplate">Dojo Boilerplate</a> &#8211; Provides a starting point for creating a Web application with Dojo<br />
<a href="http://dojotoolkit.org/documentation/tutorials/1.8/mobile/tweetview/getting_started">Tutorial: Getting Started with dojox/mobile</a> &#8211; The first in a series of tutorials to build a mobile app</p>
<h2>Build Tool Resources</h2>
<p><a href="http://dojotoolkit.org/documentation/tutorials/1.8/build">Tutorial: Creating Builds</a> &#8211; Thoroughly explains the various facets of a custom build<br />
<a href="http://www.sitepen.com/blog/2012/08/27/working-with-dojo-and-amd-in-production/">Working with Dojo and AMD in Production</a> &#8211; Enumerates approaches to loading production builds<br />
<a href="http://dojotoolkit.org/reference-guide/1.8/build/index.html">Reference Guide: The Dojo Build System</a> &#8211; Definitive documentation on the new build system<br />
<a href="http://build.dojotoolkit.org/">Dojo Web Builder</a> &#8211; An online tool for creating Dojo builds</p>
<h2>Dojo Packages</h2>
<p><a href="http://www.sitepen.com/blog/2011/07/25/dojo-foundation-packages/">Dojo Foundation Packages</a> &#8211; Explains the role packages play in Dojo&#8217;s future<br />
<a href="http://dgrid.io">dgrid</a> &#8211; Web site for dgrid, a Dojo Foundation package</p>
<h2>Community</h2>
<p>As always, the Dojo community is the best around.  If you get stumped or have an advanced question, you can get more answers by leveraging the following resources:</p>
<ul>
<li><a href="http://www.dojotoolkit.org/community/">Dojo Community</a>, including a forum interface to the dojo-interest mailing list</li>
<li><a href="http://mail.dojotoolkit.org/mailman/listinfo">Mailing Lists</a></li>
<li><a href="http://www.dojotoolkit.org/chat/">Web client for the #dojo IRC channel on irc.freenode.net</a></li>
</ul>
<p>If you find that a self-guided tour or community support is inadequate, SitePen also offers <a href="http://www.sitepen.com/services/training.php">workshops</a> taught by Dojo experts, as well as highly responsive <a href="http://www.sitepen.com/services/support.php">support services</a>.</p>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/12/06/learning-dojo-1-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dive Into Dijit with AMD</title>
		<link>http://www.sitepen.com/blog/2012/11/16/dive-into-dijit-with-amd/</link>
		<comments>http://www.sitepen.com/blog/2012/11/16/dive-into-dijit-with-amd/#comments</comments>
		<pubDate>Fri, 16 Nov 2012 09:00:42 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[UI Design]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5841</guid>
		<description><![CDATA[<p>One huge feature that sets the Dojo Toolkit apart from other JavaScript libraries is its UI component system: Dijit. A flexible, comprehensive collection of Dojo modules (complemented by corresponding resources like images, CSS files, etc.), Dijit allows you to create flexible, extensible, stylish widgets. To learn how to install, configure, and use basic Dijits within [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>One huge feature that sets the Dojo Toolkit apart from other JavaScript libraries is its UI component system: Dijit.  A flexible, comprehensive collection of Dojo modules (complemented by corresponding resources like images, CSS files, etc.), Dijit allows you to create flexible, extensible, stylish widgets.  To learn how to install, configure, and use basic Dijits within your web application, keep reading!</p>
<p>
<a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/themes/themeTester.html"><br />
<img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/themes.png" alt="themes" title="themes" width="600" height="320" class="alignnone size-full wp-image-5884" /><br />
</a></p>
<p><span id="more-5841"></span></p>
<h2>Requiring Proper Modules and Resources</h2>
<p>Since Dijit includes a collection of UI components, it comes bundled with four supported themes:  <em>nihilo, soria, tundra</em>, and <em>claro</em>.  Each theme contains images and CSS files to control the overall display of the widgets.  CSS files must be explicitly included into each HTML page:</p>
<pre lang="html4strict">
<style type="text/css">
	/* dojo.css is a CSS Reset, and is optional.
	@import "//ajax.googleapis.com/ajax/libs/dojo/1.8/dojo/resources/dojo.css";
	/* Note the protocol-less URLs make this easy to use within both http and https */
	/* Using the claro theme in this example */
	@import "//ajax.googleapis.com/ajax/libs/dojo/1.8/dijit/themes/claro/claro.css";
	/* Note that if you don't specify a minor revision, e.g. 1.8.0 or 1.7.1, the CDN will deliver the latest version */
</style>
</pre>
<p>In the body tag of your page, or in a parent node of your widgets, you need to define the class name based upon the theme you would like to use.</p>
<pre lang="html4strict">
&lt;body class="claro"&gt;
</pre>
<p>You can view each theme set using the <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/themes/themeTester.html">Dijit Theme Tester</a>.  You may also define your own theme.</p>
<h3>dojoConfig</h3>
<p>There are many options for <code>dojoConfig</code> but the two most important are <code>async</code> and <code>isDebug</code>. You&#8217;ll want <code>isDebug</code> set to true during development so you get proper warning messages. <code>async</code> is the setting to tell the AMD loader to use the new, faster way to load JavaScript modules.</p>
<pre lang="JavaScript">
	dojoConfig = {
		isDebug:true,
		async:true
	};
</pre>
<p><em>Note: <code>parseOnLoad</code> was a common property in <code>djConfig</code>, but this is no longer recommended. See information about the <code>parser</code> below.</em></p>
<p><code>dojoConfig</code> is a global and must be set before you load Dojo, or else it will be ignored. You can also set the configuration as an attribute on the script file, in which case you would use <code>data-dojo-config</code>:</p>
<pre lang="html4strict">
&lt;script src="//ajax.googleapis.com/ajax/libs/dojo/1.8/dojo/dojo.js"
	data-dojo-config="isDebug:true, async:true" type="text/javascript"&gt;&lt;/script&gt;
</pre>
<p>It&#8217;s time to add a widget. A quick test is to drop a button into the page first thing, to check that everything is set up and parsing correctly.</p>
<pre lang="html4strict">
&lt;body class="claro"&gt;
	&lt;button data-dojo-type='dijit/form/Button'&gt;Clicky&lt;/button&gt;
&lt;/body&gt;
</pre>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/parse1.png" alt="parse1" title="parse1" width="299" height="149" class="alignnone size-full wp-image-5885" /></p>
<h3><code>dojo/parser</code></h3>
<p>As you can see, the widget didn&#8217;t parse correctly. We need to load <code>dojo/parser</code> and explicitly tell it to parse. When do we do this? After the DOM is ready of course. The AMD way to determine this is with the <code>dojo/domReady</code> plugin. AMD is instructed that the loaded dependency is a plugin with an exclamation point, such as: <code>dojo/domReady!</code>. Because we won&#8217;t need Dojo to do any work before any parsing, we can safely put this code at the bottom of the <code>body</code>:</p>
<pre lang="html4strict">
&lt;body class="claro"&gt;
	&lt;button data-dojo-type='dijit/form/Button'&gt;Clicky&lt;/button&gt;
	&lt;script&gt;
		require([
			'dojo/parser',
			'dojo/domReady!'
		], function(parser){
			parser.parse(); // tell dojo to check the DOM for widgets
		});
	&lt;/script&gt;
&lt;/body&gt;
</pre>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/parser2.png" alt="parser2" title="parser2" width="580" height="268" class="alignnone size-full wp-image-5886" /></p>
<p>The widget parsed with the claro theme, but there is a warning in the console: <em>WARNING: Modules being Auto-Required: dijit/form/Button</em>. This message is shown because the widget was never specifically required anywhere, and to get maximum performance from your application, AMD and Dojo require that you explicitly define the modules and dependencies you want to use in your application. The Dojo 1.8 parser is a bit more forgiving. It is asynchronous and smart enough to find and load un-required modules. It’s not recommended to develop this way, as it&#8217;s slower than having the module already loaded before you&#8217;re trying to parse and render, but it’s helpful that it catches the mistake and then lets us know without breaking the application.  Dojo 1.7 would simply fail with an error warning. Adding <code>dijit/form/Button</code> to the <code>require</code> dependencies fixes this issue and improves our performance.</p>
<p>One of the most notable features of the Dijit system is that you may create a Dijit widget in one of two ways:  declaratively, using HTML markup and custom attributes; or programmatically, using raw JavaScript.  Let&#8217;s take a look at how we can make a basic <code>select</code> element a Dojo-enhanced widget.</p>
<h2>Creating Widgets</h2>
<h3>The Basic <code>select</code> Element</h3>
<pre lang="html4strict">
&lt;select name="character" id="character"&gt;
	&lt;option value=""&gt;Select a character&lt;/option&gt;
	&lt;option value="Leonard"&gt;Dr. Leonard Leakey Hofstadter&lt;/option&gt;
	&lt;option value="Sheldon" selected="selected"&gt;Dr. Sheldon Lee Cooper&lt;/option&gt;
	&lt;option value="Rajesh"&gt;Dr. Rajesh Ramayan Koothrappali&lt;/option&gt;
	&lt;option value="Howard"&gt;Howard Joel Wolowitz&lt;/option&gt;
&lt;/select&gt;
</pre>
<p>This is a static <code>select</code> element containing a series of <code>option</code> elements.  We know we&#8217;d like for this <code>select</code> element to become a <code>dijit/form/FilteringSelect</code> widget so we must require this module. </p>
<pre lang="javascript">
require([
	'dojo/parser',
	'dijit/form/FilteringSelect',
	'dojo/domReady!'
], function(parser, FilteringSelect){
	parser.parse();
});
</pre>
<p>Now that the <code>dijit/form/FilteringSelect</code> module is available, and the parser is looking for widgets in the DOM, we can use the declarative or programmatic method of enhancing our <code>select</code> element.</p>
<h3>Declarative Method</h3>
<p>The declarative method of enhancing the <code>select</code> element is done within the HTML element itself:</p>
<pre lang="html4strict">
&lt;select name="character" id="characterNode"
	data-dojo-type="dijit/form/FilteringSelect"
	data-dojo-props='autoComplete:true, pageSize:10' &gt;
	&lt;option value=""&gt;Select a character&lt;/option&gt;
	&lt;option value="Leonard"&gt;Dr. Leonard Leakey Hofstadter&lt;/option&gt;
	&lt;option value="Sheldon" selected="selected"&gt;Dr. Sheldon Lee Cooper&lt;/option&gt;
	&lt;option value="Rajesh"&gt;Dr. Rajesh Ramayan Koothrappali&lt;/option&gt;
	&lt;option value="Howard"&gt;Howard Joel Wolowitz&lt;/option&gt;
&lt;/select&gt;
</pre>
<p>This declarative example illustrates the use of the <code>data-dojo-type</code> attribute that identifies which Dijit the given element should become.  When we call <code>parser.parse()</code>, Dojo will find this element and instantiate and initialize the widget.</p>
<p>Options of the <code>dijit/form/FilteringSelect</code> module are also custom attributes.  This widget will autocomplete when the user types a value and page every 10 items.  Just as with a normal <code>select</code> element, &#8220;Sheldon&#8221; will be selected initially.</p>
<h3>Programmatic Method</h3>
<p>The programmatic method of enhancing the <code>select</code> element is done completely with JavaScript:</p>
<pre lang="javascript">
	require([
	'dijit/form/FilteringSelect',
	'dojo/domReady!'
], function(FilteringSelect){

	var filteringSelect = new FilteringSelect({
		autoComplete: true,
		pageSize: 10
	},'characterNode');

});
</pre>
<p>Note that <code>dojo/parser</code> was removed from the list of dependencies, as it&#8217;s not needed for programmatic instantiation of widgets.</p>
<p>We can create other widgets the same way:</p>
<pre lang="javascript">
require([
	'dijit/form/FilteringSelect',
	'dijit/form/DateTextBox',
	'dijit/form/TimeTextBox',
	'dijit/form/Textbox',
	'dijit/form/Textarea',
	'dijit/form/Checkbox',
	'dijit/form/RadioButton',
	'dojo/domReady!'
], function(FilteringSelect, DateTextBox, TimeTextBox, Textbox, Textarea, Checkbox, RadioButton){

	var filteringSelect = new FilteringSelect({
		autoComplete: true,
		pageSize: 10
	},'characterNode');

	var input = new Textbox({/*options*/},'myInputNode');
	var textarea = new Textarea({/*options*/},'myTextareaNode');
	var mySelect = new FilteringSelect({/*options*/},'mySelectNode');
	var date = new DateTextBox({/*options*/},'myDateNode');
	var time = new TimeTextBox({/*options*/},'myTimeNode');
	var checkbox = new CheckBox({/*options*/},'myCheckboxNode');
	var radio1 = new RadioButton({/*options*/},'myRadio1Node');
	var radio2 = new RadioButton({/*options*/},'myRadio2Node');
});
</pre>
<p>If you have a large form and don&#8217;t have the desire to add all the markup to individual elements for Dijitization, you could build your own mini-parser to create Dijits by selector:</p>
<pre lang="javascript">
require([
	'dojo/query',
	'dijit/form/FilteringSelect',
	'dijit/form/Button',
	'dijit/form/CheckBox',
	'dijit/form/RadioButton',
	'dojo/domReady!'
], function(query, FilteringSelect, Button, CheckBox, RadioButton){

	query('button,select,input').forEach(function(node){
		var type = node.nodeName;
		if(type === 'INPUT'){
			type = node.type.toUpperCase();
		}
		switch(type){
			case 'BUTTON':
				new Button({},node); break;
			case 'SELECT':
				new FilteringSelect({},node); break;
			case 'RADIO':
				new RadioButton({},node); break;
			case 'CHECKBOX':
				new CheckBox({},node); break;
		}
	});
});
</pre>
<p>Of course, this simple example isn&#8217;t converting the node attributes into properties and providing them to the widget, nor are any of the other special features of <code>dojo/parser</code> being done.</p>
<h2>Accessing Dijit Widgets and their Properties</h2>
<p>Accessing a specific DOM element can be easily accomplished by using the <code>dojo/dom.byId</code> method. Dijit has its own <code>dijit/registry.byId</code> method which retrieves the Dijit widget registered with the ID specified.  If the element to be made a Dijit has an ID, the widget ID will be that same value.  If the source element doesn&#8217;t have an ID attribute, a widget ID will be generated.  If we wanted to retrieve the widget object for the declaratively created &#8220;characterNode&#8221; Dijit above, we would code:</p>
<pre lang="javascript">
require([
	'dojo/parser',
	'dijit/registry',
	'dijit/form/FilteringSelect',
	'dojo/domReady!'
], function(parser, registry, FilteringSelect){
	parser.parse();
	var filteringSelect = registry.byId('characterNode');
	console.log('filteringSelect', filteringSelect);
});
</pre>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2010/07/DijitBlogPost1.jpg" alt="Dijit Form" /><br />
<em>View a listing of all properties and methods of a Dijit using <code>registry.byId</code> within Firebug.</em></p>
<p>If we wanted to access the <code>pageSize</code> property for which the Dijit widget was created from, we would access it with a Dijit getter:</p>
<pre lang="javascript">
	var pageSize = registry.byId('characterNode').get('pageSize'); // returns 10
</pre>
<p>If we wanted to change the <code>pageSize</code> for the widget, we would code:</p>
<pre lang="javascript">
	registry.byId('characterNode').set('pageSize',20); //now pageSize is 20
</pre>
<p><em>Note: Dojo 1.5 introduced &#8220;get&#8221; and &#8220;set&#8221; methods to handle property values. In Dojo 1.4 and earlier, you would use &#8220;attr&#8221; in place of both <code>get</code> and <code>set</code> in the previous example.</em></p>
<h2>Listening to Widget Events</h2>
<p>Dijit widgets use <code>dojo/on</code> method to listen to DOM events on the given widget:</p>
<pre lang="javascript">
filteringSelect.on('change', function(value){
	console.log('value', value);
});
</pre>
<p>Each widget supports a select number of events so be sure to view the documentation for the widget to ensure the event you&#8217;d like to listen to is supported.</p>
<p>It&#8217;s important to note that those are <em><strong>DOM</strong></em> events. If you wish to listen to a widget <em>method</em>, you should use <code>dojo/aspect</code>:</p>
<pre lang="javascript">
require([
	'dojo/aspect'
	// other deps...
], function(aspect){
	aspect.after(filteringSelect, 'validate', function(value){
		console.log('validate', value);
	});
});
</pre>
<h2>The Dijit Collection</h2>
<p>Dijit is also an incredible UI library that has the potential to enhance your website and save you an immense amount of time in doing so.  Dijit includes a large number of solid widgets including:</p>
<ul>
<li>Context, popup, and dropdown menus</li>
<li>Form element replacements like buttons, combo boxes, checkboxes, radio buttons, and text boxes</li>
<li>Date and time selection widgets</li>
<li>WYSIWYG Editor</li>
<li>Horizontal and Vertical Sliders</li>
<li>Progress Bars</li>
<li>Tabs and Accordions</li>
<li>Tree Structures (including Drag and Drop)</li>
<li>Dialogs and Tooltips</li>
<li>Layout widgets with slide controls and splitters</li>
</ul>
<p>And if Dijit doesn&#8217;t have a widget you want, there&#8217;s a good chance it&#8217;s available in DojoX (Dojo Extensions)! To see many of these widgets in action, visit the <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/themes/themeTester.html">Dojo Theme Tester</a>. Or, if you&#8217;re looking for an amazing grid component, you should check out <a href="http://dgrid.io/">dgrid</a>.</p>
<h2>Dijit Resources</h2>
<p>The following resources will help to aid your Dijit education:</p>
<ul>
<li><a href="http://www.dojotoolkit.org/api/1.8/">Dijit API Documentation</a></li>
<li><a href="http://dojotoolkit.org/reference-guide/1.8/dijit/index.html">Dijit Reference Guide</a></li>
<li><a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/">Dojo Nightlies</a> (test files)</li>
<li><a href="http://dojotoolkit.org/documentation/tutorials/1.8/declarative/">Using Declarative Syntax Tutorials</a></li>
<li><a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/themes/themeTester.html">Dijit Theme Tester</a></li>
</ul>
<p>Dijit contains a vast array of useful widgets to enhance your website!</p>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/11/16/dive-into-dijit-with-amd/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Dojo Charting: Dive Into Theming</title>
		<link>http://www.sitepen.com/blog/2012/11/09/dojo-charting-dive-into-theming/</link>
		<comments>http://www.sitepen.com/blog/2012/11/09/dojo-charting-dive-into-theming/#comments</comments>
		<pubDate>Fri, 09 Nov 2012 09:00:50 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[Charting]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Vector Graphics]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5775</guid>
		<description><![CDATA[<p>The previous installment of the Dive Into Dojo series shows how easy it is to Dive Into Dojo Charting. It comes with dozens of stylish themes you can effortlessly plug into any chart. But what if you want your charts to match your website&#8217;s design or business&#8217; branding? No worries: Dojo&#8217;s charting library allows you [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>The previous installment of the Dive Into Dojo series shows how easy it is to <a href="http://www.sitepen.com/blog/2012/11/09/dive-into-dojo-charting-again/">Dive Into Dojo Charting</a>. It comes with dozens of stylish themes you can effortlessly plug into any chart. But what if you want your charts to match your website&#8217;s design or business&#8217; branding? No worries: Dojo&#8217;s charting library allows you to create custom themes!</p>
<p><a href="http://download.dojotoolkit.org/release-1.8.1/dojo-release-1.8.1/dojox/charting/tests/theme_preview.html"><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/dojo-chart-creation1.jpg" alt="dojo-chart-creation" title="dojo-chart-creation" width="607" height="440" class="alignnone size-full wp-image-5798" /></a></p>
<p><span id="more-5775"></span></p>
<h2>Setting Up Your Namespace</h2>
<p>
	All of Dojo&#8217;s charting themes live with in the <code>dojox/charting/themes</code> namespace. As is the best practice with custom class creation with Dojo, we&#8217;ll create our own namespace for our custom chart themes.  Let&#8217;s give our custom theme the <code>/app/charting/themes/</code> namespace.  <code>/app</code> is a good namespace for most Dojo projects, and I&#8217;ve chosen to mimic the path DojoX uses for themes.
</p>
<pre lang="javascript">
/* create the theme files in the app namespace */
/app/charting/themes/SitePen.js
/app/charting/themes/SitePenFTW.js
</pre>
<h2>Quick Peek at a Simple Theme</h2>
<p>The levels of complexity within Dojo themes can vary greatly depending on your desire to use simply defined colors or implement advanced features like gradations, markers, scrolling, panning, and chart events. Let&#8217;s start by looking at a basic theme called <code>Dollar</code>:</p>
<pre lang="javascript">
define([
	"../SimpleTheme",
	"./common"
], function(SimpleTheme, themes){

	themes.Dollar = new SimpleTheme({
		colors: [
			"#A4CE67",
			"#739363",
			"#6B824A",
			"#343434",
			"#636563"
		]
	});
	return themes.Dollar;
});
</pre>
<p><code>Dollar</code> illustrates how simple creating a theme can be; provide a list of colors and you&#8217;ve created a custom theme!</p>
<h2>Basic Custom Theme: SitePen</h2>
<p>Now that we&#8217;ve seen how simple it is to make a basic theme, we can easily create a custom SitePen theme base on the SitePen logo colors:</p>
<pre lang="javascript">
define([
	"dojox/charting/SimpleTheme",
	"dojox/charting/themes/common"
], function(SimpleTheme, themes){
	
	themes.SitePen = new SimpleTheme({
		colors: [
			"#A4CE67",
			"#739363",
			"#6B824A",
			"#343434",
			"#636563"
		]
	});
	return themes.SitePen;
});
</pre>
<p>Your <code>colors</code> array can have any number of colors.  Colors are repeated in sequence within the chart, if necessary.  Check out a few different charts using the new SitePen theme:</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2010/07/SitePenChart1.jpg" alt="Basic Custom Chart Theme" /></p>
<h2>Advanced Chart Theming</h2>
<p>With the basic SitePen chart theme, we simply defined a series of colors we&#8217;d like used in the chart.  With advanced chart theming, you can customize everything from default plotareas, axis, series, and marker colors, fonts, and strokes.  The amount of control you can have over your charts by creating your own theme is truly incredible.  Using Tom Trenka&#8217;s &#8220;Tom&#8221; theme as a template, let&#8217;s make an advanced customization of the SitePen theme in <code>/app/charting/themes/SitePenFTW</code>:</p>
<pre lang="javascript">
define([
	"dojox/charting/Theme",
	"dojox/charting/themes/common",
	"dojox/gfx/gradutils"
], function(Theme, themes){

	var gradient = Theme.generateGradient;

    /* fill settings for gradation */
    defaultFill = {type: "linear", space: "shape", x1: 0, y1: 0, x2: 0, y2: 100};

	/* create theme */
	themes.SitePenFTW = new Theme({

		/* customize the chart wrapper */
		chart: {
			fill: "#333",
			stroke: { color: "#333" },
			pageStyle: {
				backgroundColor: "#000",
				color: "#fff"
			}
		},

		/* plotarea definition */
		plotarea: { fill: "#000" },

		/* axis definition */
		axis:{
			stroke: { // the axis itself
				color: "#fff",
				width: 1
			},
			tick: { // used as a foundation for all ticks
				color: "#fff",
				position: "center",
				font: "normal normal normal 7pt Helvetica, Arial, sans-serif",  // labels on axis
				fontColor: "#fff" // color of labels
			}
		},

		/* series definition */
		series: {
			stroke: { width: 2.5, color: "#fff" },
			outline: null,
			font: "normal normal normal 8pt Helvetica, Arial, sans-serif",
			fontColor: "#fff"
		},

		/* marker definition */
		marker: {
			stroke: { width: 1.25, color: "#fff" },
			outline: { width: 1.25, color: "#fff" },
			font: "normal normal normal 8pt Helvetica, Arial, sans-serif",
			fontColor: "#fff"
		},

		/* series theme with gradations! */
		//light => dark
		//defaultFill object holds all of our gradation settings
		seriesThemes: [
			{ fill: gradient(defaultFill, "#fff", "#f2f2f2") },
			{ fill: gradient(defaultFill, "#d5ecf3", "#bed3d9") },
			{ fill: gradient(defaultFill, "#9ff275", "#7fc25d") },
			{ fill: gradient(defaultFill, "#81ee3b", "#60b32b") },
			{ fill: gradient(defaultFill, "#4dcff4", "#277085") },
			{ fill: gradient(defaultFill, "#666", "#333") }
		],

		/* marker theme */
		markerThemes: [
			{fill: "#bf9e0a", stroke: {color: "#ecc20c"}},
			{fill: "#73b086", stroke: {color: "#95e5af"}},
			{fill: "#216071", stroke: {color: "#277084"}},
			{fill: "#c7212d", stroke: {color: "#ed2835"}},
			{fill: "#87ab41", stroke: {color: "#b6e557"}}
		]
	});

	return themes.SitePenFTW;
});
</pre>
<p>You wont need to define every property created above;  if a given property isn&#8217;t defined, a default value will be used.  On the flip side, you may also override each and any of these settings when creating chart instances.  This custom theme acts as a middle-ground between chart defaults and chart instance settings.</p>
<p>Take a look at some of our enhanced theme examples:</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2010/07/SitePenChart2.jpg" alt="Advanced Custom Chart Theme" /></p>
<h2>Using Gradients</h2>
<p>The advanced SitePen theme we created above made use of gradients thanks to the <code>dojox/gfx/gradutils</code> class and the <code>generateGradient()</code> method in<code> dojox/charting/Theme</code>.  Gradation instances can be passed to any property that desires a color (usually the <code>fill</code> property.)  The signature of the <code>generateGradient</code> method is:</p>
<pre lang="javascript">
generateGradient: function(
	fillPattern, 
	colorFrom, 
	colorTo
}
</pre>
<p>The fill pattern holds the gradient settings:</p>
<pre lang="javascript">
{
	type: "linear",		//or "radial"
	space: "shape", 
	x1: 0, 			//gradation direction
	y1: 0, 			//gradation direction
	x2: 0, 			//gradation direction
	y2: 100			//gradation direction
}
</pre>
<p>Feel free to experiment with the gradation settings to find just the right gradient for you. Or use one of the dozens of <a http://download.dojotoolkit.org/release-1.8.1/dojo-release-1.8.1/dojox/charting/tests/theme_preview.html">available Themes</a>. While Dojo&#8217;s charting library comes with a variety of stylish themes, don&#8217;t feel as though you need to choose an existing theme;  take a few minutes to create an eye-catching custom theme to match your branding!</p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://www.sitepen.com/blog/2012/11/09/dive-into-dojo-charting-again/">Dive Into Dojo Charting Again</a></li>
<li><a href="http://www.dojotoolkit.org/reference-guide/1.8/dojox/charting.html#dojox-charting">Dojox Charting Reference Guide</a></li>
<li><a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/">Nightly Charting Tests</a></li>
<li><a href="http://download.dojotoolkit.org/release-1.8.1/dojo-release-1.8.1/dojox/charting/tests/theme_preview.html">Charting Theme Preview</a></li>
<li><a href="http://www.sitepen.com/blog/2012/11/09/a-beginners-guide-to-dojo-charting-with-amd-part-1-of-2/">A Beginner’s Guide to Dojo Charting with AMD, Part 1 of 2</a></li>
<li><a href="http://www.sitepen.com/blog/2012/11/09/a-beginners-guide-to-dojo-charting-with-amd-part-1-of-2/">A Beginner’s Guide to Dojo Charting with AMD, Part 2 of 2</a></li>
<li><a href="http://www.sitepen.com/blog/2012/11/09/zooming-scrolling-and-panning-in-dojo-charting/">Dojo Charting: Zooming, Scrolling, and Panning</a></li>
</ul>
<p></p>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/11/09/dojo-charting-dive-into-theming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dojo Charting: Actions and Tooltips</title>
		<link>http://www.sitepen.com/blog/2012/11/09/dojo-charting-actions-and-tooltips/</link>
		<comments>http://www.sitepen.com/blog/2012/11/09/dojo-charting-actions-and-tooltips/#comments</comments>
		<pubDate>Fri, 09 Nov 2012 09:00:38 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[Charting]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Vector Graphics]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5699</guid>
		<description><![CDATA[<p>Actions are self-contained objects, which use events to implement certain effects when a user interact with a chart. In general they are designed to attract attention and indicate which charting element is selected, or to show additional information. While you can create your own actions, we took liberty to package some that are generally useful. [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<style>
table.elchart {padding: 1px; border: none; border: 1px solid lightgray;}
table.elchart th {margin: 1px; padding: 3px; border: none; border: 1px solid lightgray; font-weight: bold;}
table.elchart td {margin: 1px; padding: 3px; border: none; border: 1px solid lightgray;}
table.elchart td.highlight {font-weight: bold;}
</style>
<p>Actions are self-contained objects, which use events to implement certain effects when a user interact with a chart. In general they are designed to attract attention and indicate which charting element is selected, or to show additional information.</p>
<p><span id="more-5699"></span></p>
<p>While you can create your own actions, we took liberty to package some that are generally useful. The default library includes these classes: Highlight, Magnify, MoveSlice, Shake, and Tooltip. All of them take advantage of the Dojo animation support. It is best to see them live on <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_event2d.html">the demo page</a>.</p>
<p>All actions except Tooltip support the following common keyword parameters:</p>
<table class="elchart">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>duration</td>
<td>Number</td>
<td>400</td>
<td>the time of effect in milliseconds.</td>
</tr>
<tr>
<td>easing</td>
<td>Function</td>
<td><code>dojox/fx/easing/elasticOut</code></td>
<td>the easing function that specifies how controlled parameter changes over time.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h3>Highlight</h3>
<p>This action changes a color of individual elements of a chart when a user hovers over it with the mouse. Affected elements include: markers, columns, bars, circles, and pie slices.</p>
<p>Highlight supports one additional parameter:</p>
<table class="elchart">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>highlight</td>
<td><code>String, dojo/Color</code>, or <code>Function</code></td>
<td>the default highlight function</td>
<td>this parameter defines the highlight color for an individual element.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>The parameter can be any valid value for a color, e.g.,<code> "red", "#FF0000", "#F00", [255, 0, 0], {r: 255, g: 0, b: 0}</code>, and so on. In this case that color will be used to fill an element.</p>
<p>If the parameter is a function, it receives a charting event object (see <a href="http://www.sitepen.com/blog/2012/11/09/dojo-charting-events">Event Support in Dojo Charting</a> for details), and should contain a valid color.</p>
<p>The default highlight function uses special heuristics to select the highlight color. It makes it fully saturated, and light for dark colors, or dark for light colors. In many cases this default is more than adequate. But if you feel a need to implement a custom highlighting scheme, you can easily create your own function.</p>
<p>The picture below demonstrates Highlight (with a constant color) and Tooltip actions.</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/highlight.png" alt="highlight" title="highlight" width="416" height="222" class="alignnone size-full wp-image-5751" /></p>
<h3>Magnify</h3>
<p>This action magnifies an individual element of a chart, when a user hovers over it with the mouse. Affected elements include markers and circles.</p>
<p>Magnify supports one additional parameter:</p>
<table class="elchart">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>scale</code></td>
<td><code>Number</code></td>
<td>2</td>
<td>the value to scale an element.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>The picture below demonstrates Magnify and Tooltip actions.</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/magnify.png" alt="" title="magnify" width="394" height="221" class="alignnone size-full wp-image-5752" /></p>
<h3>MoveSlice</h3>
<p>This action moves slices out from a pie chart, when users hover an element with the mouse.</p>
<p>MoveSlice supports the following parameters:</p>
<table class="elchart">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>scale</code></td>
<td><code>Number</code></td>
<td>1.5</td>
<td>the value to scale an element.</td>
</tr>
<tr>
<td><code>shift</code></td>
<td><code>Number</code></td>
<td>7</td>
<td>the value in pixels to move an element from the center.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>The picture below demonstrates MoveSlice, Highlight (with default highlighting parameter), and Tooltip actions.</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/moveslice.png" alt="moveslice" title="moveslice" width="385" height="331" class="alignnone size-full wp-image-5753" /></p>
<h3>Shake</h3>
<p>This action shakes charting elements, when users hover over an element with the mouse. Affected elements include markers, columns, bars, circles, and pie slices.</p>
<p>Shake supports the following parameters:</p>
<table class="elchart">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>shiftX</code></td>
<td><code>Number</code></td>
<td>3</td>
<td>the maximal value in pixels to move an element horizontally during a shake.</td>
</tr>
<tr>
<td><code>shiftY</code></td>
<td><code>Number</code></td>
<td>3</td>
<td>the maximal value in pixels to move an element vertically during a shake.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Shake is the highly dynamic effect, so a picture cannot do a justice for it. Please go to <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_event2d.html">the demo page</a> and see it in action.</p>
<h3>Tooltip</h3>
<p>This action shows a Tooltip, when users hover over a charting element with the mouse. Affected elements include markers, columns, bars, circles, and pie slices.</p>
<p>Tooltip supports the following keyword parameters:</p>
<table class="elchart">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>text</code></td>
<td><code>Function</code></td>
<td>the default text function</td>
<td>the function to produce a Tooltip text.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>The default text function checks if a data point is an object, and uses an optional &#8220;Tooltip&#8221; member if available &mdash; this is a provision for custom Tooltips. Otherwise, it uses a numeric value. Tooltip text can be any valid HTML, so you can specify rich text multi-line Tooltips if desired.</p>
<p>The picture below demonstrates Tooltip, and Highlight actions.</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/tooltip.png" alt="tooltip" title="tooltip" width="507" height="230" class="alignnone size-full wp-image-5754" /></p>
<h3>Using Actions</h3>
<p>All action objects implement the following methods (no parameters are expected by these methods):</p>
<table class="elchart">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>connect()</code></td>
<td>Connect and start handling events. By default, when an action is created, it is connected. You may need to call fullRender() on your chart object to activate the sending of messages. Typically you create an action object after you define plots, but before the first <code>render()</code> call &mdash; it takes care of everything.</td>
</tr>
<tr>
<td><code>disconnect()</code></td>
<td>Disconnect the event handler. </td>
</tr>
<tr>
<td><code>destroy()</code></td>
<td>Call this method when you want to dispose of your action. It disconnects from its event source and destroys all internal structures, if any, preparing to be garbage-collected.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>All actions can be constructed like this:</p>
<pre lang="javascript">
require(['dojox/charting/action2d/Magnify'], function(Magnify){
	var action = new Magnify(
		chart1, 
		"default", 
		{
			duration: 200,
			scale: 1.1
		}
	);	
});
</pre>
<p>The first parameter is a chart. The second parameter is the name of a plot. The third parameter is an object (property bag) with all relevant keyword parameters.</p>
<p>An even easier options is to use <code>dojox/charting/widget/Chart</code>. The example below is taken from <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_widget2d-amd.html">the Dojo Chart widget test</a>:</p>
<pre lang="html4strict">
&lt;div dojotype="dojox/charting/widget/Chart" id="chart"
	 data-dojo-props="theme: dojox.charting.themes.PlotKit.green" style="width: 300px; height: 300px; margin:10px;"&gt;
	&lt;div class="plot" name="default" type="Pie" radius="100" fontcolor="black" labeloffset="-20"&gt;&lt;/div&gt;
	&lt;div class="series" name="A" data="5,8,10,40,20"&gt;&lt;/div&gt;
	&lt;div class="action" type="Tooltip"&gt;&lt;/div&gt;
	&lt;div class="action" type="MoveSlice" shift="2"&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Yes, it is that simple: just define a &lt;div&gt; with the class &#8220;action&#8221; and supply the type. If you want to specify a plot&#8217;s name, use the &#8220;plot&#8221; parameter: <code>plot="Plot1"</code>. By default it will connect to the plot named &#8220;default&#8221;. If you want to change default keyword parameters, just add them to the &lt;div&gt;, e.g., <code>duration="500</code>&#8220;.</p>
<h2>Conclusion</h2>
<p>As you can see you can mixin several actions. In order to avoid unnecessary interference between actions, use your best judgment when selecting them. Try to avoid actions that modify the same visual attributes, like geometry. You can safely mix Tooltip, Highlight, and one geometric action (Magnify, MoveSlice, or Shake).</p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://dojotoolkit.org/documentation/tutorials/1.8/charting/">Dojo Charting Tutorial</a></li>
<li><a href="http://dojotoolkit.org/reference-guide/1.8/dojox/charting.html#dojox-charting">Charting Reference Guide</a></li>
</ul>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/11/09/dojo-charting-actions-and-tooltips/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dojo Charting: Zooming, Scrolling, and Panning</title>
		<link>http://www.sitepen.com/blog/2012/11/09/dojo-charting-zooming-scrolling-and-panning/</link>
		<comments>http://www.sitepen.com/blog/2012/11/09/dojo-charting-zooming-scrolling-and-panning/#comments</comments>
		<pubDate>Fri, 09 Nov 2012 09:00:29 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[Charting]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Vector Graphics]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5681</guid>
		<description><![CDATA[<p>Zooming, scrolling, and panning of charts is a more complex task than than one might expect due to the little-known fact that Dojo Charting can stack multiple plots per chart and can show multiple independent axes on all 4 sides of the chart. These problems were solved with the following API in the chart object: [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>Zooming, scrolling, and panning of charts is a more complex task than than one might expect due to the little-known fact that Dojo Charting can stack multiple plots per chart and can show multiple independent axes on all 4 sides of the chart. These problems were solved with the following API in the chart object:</p>
<p><span id="more-5681"></span></p>
<ul>
<li><strong>chart.setAxisWindow(name, scale, offset)</strong> &mdash; defines a window on the named axis with a scale factor, which starts at the set offset in data coordinates.
<ul>
<li>The <strong>scale</strong> parameter must be &gt;= 1.</li>
<li>The <strong>offset</strong> parameter should be &gt;= 0.</li>
<li>For example if there is an array of 10 numeric values, and 3-8 should show, <strong>chart.setWindow(&#8220;x&#8221;, 3, 2)</strong> will do the trick.</li>
<li>This call affects only plots attached to the named axis, other plots are unaffected.</li>
</ul>
</li>
<li><strong>chart.setWindow(sx, sy, dx, dy)</strong> &mdash; sets scale and offsets on all plots of the chart.</li>
<ul>
<li>The <strong>sx</strong> parameter specifies the magnification factor on horizontal axes. It should be &gt;= 1.</li>
<li>The <strong>sy</strong> parameter specifies the magnification factor on vertical axes. It should be &gt;= 1.</li>
<li>The <strong>dx</strong> parameter specifies the offset of horizontal axes in pixels. It should be &gt;= 0.</li>
<li>The <strong>dy</strong> parameter specifies the offset of vertical axes in pixels. It should be &gt;= 0.</li>
<li>All chart&#8217;s axes (and, by extension, plots) will be affected.</li>
</ul>
</ul>
<p>Obviously these new methods do sanity checks, and don&#8217;t allow you to scroll outside of axis&#8217; boundaries, or zoom out too far.</p>
<p>As you can see these methods are enough to implement arbitrary zooming to drill down to the smallest details of your chart, scrolling, and panning (moving the chart with your mouse in two dimensions). The latter functionality is taxing on old IE, but modern browsers are well up to the task.</p>
<p>Now it is time for some show-and-tell. Below you can see a test chart in its normal state:</p>
<p><a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_win2d.html"><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/normal.png" alt="normal" title="normal" width="456" height="258" class="alignnone size-full wp-image-5760" /></a></p>
<p>As you can see this chart has four independent axes on all sides, and two plots, each with independent axes: the light brown plot uses the bottom and the the left axis, while the dark brown plot uses the axis on the top and the right sides.</p>
<p>You can access this test application in <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_win2d.html">Dojo Nightlies</a>. Warning: this link uses the raw Dojo served directly from the development server, so the initial loading will be relatively slow. In real applications you should use Dojo builds.</p>
<p>This is the code required to build this chart:</p>
<pre lang="JavaScript">
require([
	"dojox/charting/Chart",
	"dojox/charting/plot2d/Areas",
	"dojox/charting/plot2d/Grid",
	"dojox/charting/themes/PlotKit/orange",
	"dojox/charting/axis2d/Default",
	"dojo/domReady!"
	],
	function (Chart, Areas, Grid, PlotKitOrange) {
		// Create the chart
		var chart = new Chart("chartNode");

		// set a theme
		chart.setTheme(PlotKitOrange);

		// create the ordinal horizontal axis with custom visual attributes,
		// by default it will be attached to the bottom of the plot area
		chart.addAxis("x", {
			fixLower: "minor", natural: true, stroke: "grey",
			majorTick: {stroke: "black", length: 4},
			minorTick: {stroke: "gray", length: 2}
		});

		// create the ordinal vertical axis with custom visual attributes,
		// by default it will be attached to the left of the plot area
		chart.addAxis("y", {
			vertical: true, min: 0, max: 30,
			majorTickStep: 5, minorTickStep: 1, stroke: "grey",
			majorTick: {stroke: "black", length: 4},
			minorTick: {stroke: "gray", length: 2}
		});

		// add the front plot, which uses default axes (named "x" and "y")
		chart.addPlot("default", {type: "Areas"});

		// add series to the default plot
		chart.addSeries("Series A",
			[0, 25, 5, 20, 10, 15, 5, 20, 0, 25]
		);

		// create the ordinal horizontal axis with custom visual attributes,
		// we specify explicitly that it should be attached to the top
		chart.addAxis("x2", {
			fixLower: "minor", natural: true,
			leftBottom: false, stroke: "grey",
			majorTick: {stroke: "black", length: 4},
			minorTick: {stroke: "gray", length: 2}
		});

		// create the ordinal vertical axis with custom visual attributes,
		// we specify explicitly that it should be attached to the right
		chart.addAxis("y2", {
			vertical: true, min: 0, max: 20,
			leftBottom: false, stroke: "grey",
			majorTick: {stroke: "black", length: 4},
			minorTick: {stroke: "gray", length: 2}
		});

		// create the back plot, which uses our custom axes ("x2" and "y2")
		chart.addPlot("plot2", {
			type: "Areas", hAxis: "x2", vAxis: "y2"
		});

		// add series to "plot2" we just created
		chart.addSeries("Series B",
			[15, 0, 15, 0, 15, 0, 15, 0, 15,
				0, 15, 0, 15, 0, 15, 0, 15],
			{plot: "plot2"}
		);

		// add the bottom of our stack we put the grid
		// that shows major lines, and horizontal minor lines
		chart.addPlot("grid", {type: "Grid", hMinorLines: true});

		// show what we've built
		chart.render();
</pre>
<p>Now let&#8217;s see it magnified by 2 in both dimensions and moved so we can see the peaks in the middle-left part of the chart:</p>
<p><a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_win2d.html"><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/zoomed.png" alt="zoomed" title="zoomed" width="456" height="258" class="alignnone size-full wp-image-5761" /></a></p>
<p>This picture above was made from the previous picture with one call:</p>
<pre lang="JavaScript">
chart.setWindow(2, 2, 181, 143).render();
</pre>
<p>Obviously axes show new labels to reflect the new state of the chart. Using these labels we can get our bearings and understand what we are seeing.</p>
<p>If we want to return back we can always do:</p>
<pre lang="JavaScript">
chart.setWindow(1, 1, 0, 0).render();
</pre>
<h3>Further Reading</h3>
<ul>
<li><a href="http://dojotoolkit.org/documentation/tutorials/1.8/charting/">Dojo Charting Tutorial</a></li>
<li><a href="http://dojotoolkit.org/reference-guide/1.8/dojox/charting.html#dojox-charting">Charting Reference Guide</a></li>
</ul>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/11/09/dojo-charting-zooming-scrolling-and-panning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dojo Charting: Legends</title>
		<link>http://www.sitepen.com/blog/2012/11/09/dojo-charting-legends/</link>
		<comments>http://www.sitepen.com/blog/2012/11/09/dojo-charting-legends/#comments</comments>
		<pubDate>Fri, 09 Nov 2012 09:00:18 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[Charting]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Vector Graphics]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5744</guid>
		<description><![CDATA[<p>Legend The Legend widget is one of the most popular features in Dojo charting. This widget was contributed by Chris Mitchell of IBM. It can handle all existing chart and plot types and supports horizontal and vertical modes. By default it uses the &#8220;legend&#8221; parameter of a series. It reverts to the &#8220;name&#8221; parameter if [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<h2>Legend</h2>
<p>The Legend widget is one of the most popular features in Dojo charting. This widget was contributed by Chris Mitchell of IBM. It can handle all existing chart and plot types and supports horizontal and vertical modes.</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/legend.png" alt="legend" title="legend" width="580" height="599" class="alignnone size-full wp-image-5765" /></p>
<p>By default it uses the &#8220;legend&#8221; parameter of a series. It reverts to the &#8220;name&#8221; parameter if legend is not specified.</p>
<p>For a pie chart, the behavior is different: if the chart was specified with an array of numbers, it will use numbers. Otherwise it will check object properties in the following order: &#8220;legend&#8221;, &#8220;text&#8221;, and the numeric value.</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/legend2.png" alt="legend2" title="legend2" width="580" height="599" class="alignnone size-full wp-image-5766" /></p>
<p>The legend icons will change if you have more than one series. This is especially evident in Marker charts:</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/markers.png" alt="markers" title="markers" width="280" height="312" class="alignnone size-full wp-image-5767" /></p>
<p>Legends can be created programmatically as well. Just pass in the chart object instead of the chart id. The following code makes the Marker chart shown above:</p>
<pre lang="javascript">
require([
	"dojox/charting/Chart",
	"dojox/charting/widget/Legend",
	"dojox/charting/plot2d/Markers",
	"dojox/charting/themes/PlotKit/green"
], function(Chart, Legend, Markers, PlotKitGreen){

	var chart = new Chart("chartNode");
	chart.setTheme(PlotKitGreen);
	chart.addPlot("default", {type: "Markers"});
	chart.addSeries("Series A", [2.6, 1.8, 2, 1, 1.4, 0.7, 2]);
	chart.addSeries("Series B", [5.6, 1, 9, 11, 4.4, 8.7, 2]);
	chart.addSeries("Series C", [8.6, 6, 3, 6, 8, 6, 6]);
	chart.render();

	new Legend({chartRef:chart}, 'legendNode');
});
</pre>
<h3>Further Reading</h3>
<ul>
<li><a href="http://dojotoolkit.org/documentation/tutorials/1.8/charting/">Dojo Charting Tutorial</a></li>
<li><a href="http://dojotoolkit.org/reference-guide/1.8/dojox/charting.html#dojox-charting">Charting Reference Guide</a></li>
</ul>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/11/09/dojo-charting-legends/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dojo Charting: Events</title>
		<link>http://www.sitepen.com/blog/2012/11/09/dojo-charting-events/</link>
		<comments>http://www.sitepen.com/blog/2012/11/09/dojo-charting-events/#comments</comments>
		<pubDate>Fri, 09 Nov 2012 09:00:17 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[Charting]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Vector Graphics]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5685</guid>
		<description><![CDATA[<p>Chart events allow you to attach behavior in response to user actions to various chart features, such as markers, bars, columns, or pie wedges. You can interact with following elements representing your data points: Chart Element Comment Default marker This chart is responsible for lines and areas with markers, and the scatter chart. Stacked marker [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>
Chart events allow you to attach behavior in response to user actions to various chart features, such as markers, bars, columns, or pie wedges. You can interact with following elements representing your data points:</p>
<p><span id="more-5685"></span></p>
<style>
table.elchart { border: none; border: 1px solid lightgray;}
table.elchart th {padding: 3px; margin: 1px; border: none; border: 1px solid lightgray; font-weight: bold;}
table.elchart td {padding: 3px; margin: 1px; border: none; border: 1px solid lightgray;}
table.elchart td.highlight {font-weight: bold;}
</style>
<table class="elchart">
<thead>
<tr>
<th>Chart</th>
<th>Element</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>Default</td>
<td>marker</td>
<td>This chart is responsible for lines and areas with markers, and the scatter chart.</td>
</tr>
<tr>
<td>Stacked</td>
<td>marker</td>
<td>This chart is responsible for stacked lines and areas.</td>
</tr>
<tr>
<td>Bars</td>
<td>bar</td>
<td>Horizontal bars.</td>
</tr>
<tr>
<td>StackedBars</td>
<td>bar</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>ClusteredBars</td>
<td>bar</td>
<td>A clustered version of bars.</td>
</tr>
<tr>
<td>Columns</td>
<td>column</td>
<td>Vertical columns.</td>
</tr>
<tr>
<td>StackedColumns</td>
<td>column</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>ClusteredColumns</td>
<td>column</td>
<td>A clustered version of columns.</td>
</tr>
<tr>
<td>Bubble</td>
<td>circle</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Pie</td>
<td>slice</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>The Following events are supported: <strong><code>onclick</code></strong>, <strong><code>onmouseover</code></strong>, and <strong><code>onmouseout</code></strong>.</p>
<p>Users can attach event handlers to individual plots of a chart with the <code>connectToPlot()</code> method, which accepts three arguments:</p>
<pre lang="JavaScript">
chart.connectToPlot(
    plotName,    // the unique plot name you specified when creating a plot
    object,      // both object and method are the same used by dojo.connect()
    method       // you can supply a function without an object
);
</pre>
<p>The event handler receives one argument. While it tries to unify information for different charts, its exact layout depends on the chart type:</p>
<table class="elchart">
<thead>
<tr>
<th>Attribute</th>
<th>Expected Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="highlight">type</td>
<td>&#8220;onclick&#8221;, &#8220;onmouseover&#8221;, or &#8220;onmouseout&#8221;</td>
<td>Use this attribute to differentiate between different types of events.</td>
</tr>
<tr>
<td class="highlight">element</td>
<td>&#8220;marker&#8221;, &#8220;bar&#8221;, &#8220;column&#8221;, &#8220;circle&#8221;, or &#8220;slice&#8221;</td>
<td>Indicates what kind of element has sent the event. Can be used to define highlighting or animation strategies. For details consult the previous table.</td>
</tr>
<tr>
<td class="highlight">x</td>
<td>number</td>
<td>The &#8220;x&#8221; value of the point. Can be derived from the index (depends on a chart).</td>
</tr>
<tr>
<td class="highlight">y</td>
<td>number</td>
<td>The &#8220;y&#8221; value of the point. Can be derived from the index (e.g., for a bar chart).</td>
</tr>
<tr>
<td class="highlight">index</td>
<td>number</td>
<td>The index of a data point that caused the event.</td>
</tr>
<tr>
<td class="highlight">run</td>
<td>object</td>
<td>The data run object that represents a data series. Example: o.run.data[o.index] &mdash; returns the original data point value for the event (o is an event handler&#8217;s argument).</td>
</tr>
<tr>
<td class="highlight">plot</td>
<td>object</td>
<td>The plot object that hosts the event&#8217;s data point.</td>
</tr>
<tr>
<td class="highlight">hAxis</td>
<td>object</td>
<td>The axis object that is used as a horizontal axis by the plot.</td>
</tr>
<tr>
<td class="highlight">vAxis</td>
<td>object</td>
<td>The axis object that is used as a vertical axis by the plot.</td>
</tr>
<tr>
<td class="highlight">event</td>
<td>object</td>
<td>The original mouse event that started the event processing.</td>
</tr>
<tr>
<td class="highlight">shape</td>
<td>object</td>
<td>The gfx shape object that represents a data point.</td>
</tr>
<tr>
<td class="highlight">outline</td>
<td>object</td>
<td>The gfx shape object that represents an outline (a cosmetic shape). Can be null or undefined.</td>
</tr>
<tr>
<td class="highlight">shadow</td>
<td>object</td>
<td>The gfx shape object that represents a shadow (a cosmetic shape). Can be null or undefined.</td>
</tr>
<tr>
<td class="highlight">cx</td>
<td>number</td>
<td>The &#8220;x&#8221; component of the visual center of a shape in pixels. Supplied only for &#8220;marker&#8221;, &#8220;circle&#8221;, and &#8220;slice&#8221; elements. Undefined for all other elements.</td>
</tr>
<tr>
<td class="highlight">cy</td>
<td>number</td>
<td>The &#8220;y&#8221; component of the visual center of a shape in pixels. Supplied only for &#8220;marker&#8221;, &#8220;circle&#8221;, and &#8220;slice&#8221; elements. Undefined for all other elements.</td>
</tr>
<tr>
<td class="highlight">cr</td>
<td>number</td>
<td>The radius in pixels of a &#8220;circle&#8221;, or a &#8220;slice&#8221; element. Undefined for all other elements.</td>
</tr>
</tbody>
</table>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/alert.png" alt="" title="alert" width="548" height="356" class="alignnone size-full wp-image-5757" /></p>
<p>And finally it is time to see it in action: <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/tests/test_event2d.html">the event demo</a> straight from the Dojo nightly. Hover over markers, bars, columns, bubbles, and pie slices, and click on them as well.</p>
<p>Besides dojox.charting, the demo illustrates some other parts of Dojo as well:
<ul>
<li><strong>dojo/fx</strong> &mdash; the Dojo Core animation toolkit for creating and combining animations.
<ul>
<li><strong>dojox/fx/easing</strong> &mdash; a collection of easing functions to spice up visual effects.</li>
<li><strong>dojox/gfx/fx</strong> &mdash; 2D graphics-specific animation helpers.</li>
</ul>
</li>
<li><strong>dojox/lang/functional</strong> &mdash; power of functional programming at your fingertips.</li>
</ul>
<p>All of these components make it possible to code up the demo rather quickly &mdash; the modular nature of Dojo pays off.</p>
<h3>Further Reading</h3>
<ul>
<li><a href="http://dojotoolkit.org/documentation/tutorials/1.8/charting/">Dojo Charting Tutorial</a></li>
<li><a href="http://dojotoolkit.org/reference-guide/1.8/dojox/charting.html#dojox-charting">Charting Reference Guide</a></li>
</ul>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/11/09/dojo-charting-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dojo Tutorial: Augmenting Objects</title>
		<link>http://www.sitepen.com/blog/2012/11/08/dojo-tutorial-augmenting-objects/</link>
		<comments>http://www.sitepen.com/blog/2012/11/08/dojo-tutorial-augmenting-objects/#comments</comments>
		<pubDate>Thu, 08 Nov 2012 16:59:02 +0000</pubDate>
		<dc:creator>Dylan Schiemann</dc:creator>
				<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[dojo/_base/lang]]></category>
		<category><![CDATA[dojo18]]></category>
		<category><![CDATA[lang]]></category>
		<category><![CDATA[mixin]]></category>
		<category><![CDATA[objects]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5660</guid>
		<description><![CDATA[<p>As part of our great updates to the Dojo Tutorials for Dojo 1.8, we&#8217;ve been busy creating several new tutorials. Augmenting Objects In JavaScript applications, you&#8217;re working with objects all day long. This tutorial covers the features found in dojo/_base/lang for augmenting your objects efficiently. Without further ado, check out the Augmenting Objects tutorial for [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>As part of our great updates to the <a href="http://dojotoolkit.org/documentation/?ver=1.8">Dojo Tutorials for Dojo 1.8</a>, we&#8217;ve been busy creating several new tutorials.</p>
<h2>Augmenting Objects</h2>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/10/preview.jpg" alt="Augmenting Objects" title="Augmenting Objects" width="200" height="200" class="size-full wp-image-5661" style="float:left; margin:0 1em 1em 0" /> In JavaScript applications, you&#8217;re working with objects all day long. This tutorial covers the features found in <code>dojo/_base/lang</code> for augmenting your objects efficiently.</p>
<p><strong>Without further ado, check out the <a href="http://dojotoolkit.org/documentation/tutorials/1.8/augmenting_objects/">Augmenting Objects tutorial for Dojo 1.8</a>, <a href="http://dojotoolkit.org/documentation/tutorials/1.7/augmenting_objects/">1.7</a>, or <a href="http://dojotoolkit.org/documentation/tutorials/1.6/augmenting_objects/">1.6</a>!</strong></p>
<h2>Want to see a specific Tutorial? Want to Learn More?</h2>
<p>Is there something you’d like to learn how to do with Dojo? Always wanted to know how something in Dojo works? Leave us a message in the blog comments and we’ll see about getting a tutorial created for you. Or <a href="http://www.sitepen.com/workshops/">sign-up for an upcoming SitePen Dojo Workshop</a> to get a fully immersive hands-on experience with Dojo.</p>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/11/08/dojo-tutorial-augmenting-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dojo Tutorial: Dojo Start</title>
		<link>http://www.sitepen.com/blog/2012/11/07/dojo-tutorial-dojo-start/</link>
		<comments>http://www.sitepen.com/blog/2012/11/07/dojo-tutorial-dojo-start/#comments</comments>
		<pubDate>Wed, 07 Nov 2012 21:45:44 +0000</pubDate>
		<dc:creator>Dylan Schiemann</dc:creator>
				<category><![CDATA[Dojo]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[documentation]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=5778</guid>
		<description><![CDATA[<p>As part of our great updates to the Dojo Tutorials for Dojo 1.8, we&#8217;ve been busy creating several new tutorials. Dojo Start How do I start learning Dojo? Where are the docs? How do I get support and training? Which Dojo version should I use? Why do I need to use a web server? How [...]</p><p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></description>
				<content:encoded><![CDATA[<p>As part of our great updates to the <a href="http://dojotoolkit.org/documentation/?ver=1.8">Dojo Tutorials for Dojo 1.8</a>, we&#8217;ve been busy creating several new tutorials.</p>
<h2>Dojo Start</h2>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2012/11/preview3.jpg" alt="Dojo Start" title="Dojo Start" width="200" height="200" class="size-full wp-image-5661" style="float:left; margin:0 1em 1em 0" /> How do I start learning Dojo? Where are the docs? How do I get support and training? Which Dojo version should I use? Why do I need to use a web server? How can I avoid common mistakes? How do I report issues? How do I contribute and get involved? These questions and more are answered with this introductory start tutorial.</p>
<p><strong>Without further ado, check out the <a href="http://dojotoolkit.org/documentation/tutorials/1.8/start/">Dojo Start tutorial</a>!</strong></p>
<h2>Want to see a specific Tutorial? Want to Learn More?</h2>
<p>Is there something you’d like to learn how to do with Dojo? Always wanted to know how something in Dojo works? Leave us a message in the blog comments and we’ll see about getting a tutorial created for you. Or <a href="http://www.sitepen.com/workshops/">sign-up for an upcoming SitePen Dojo Workshop</a> to get a fully immersive hands-on experience with Dojo.</p>
<p>SitePen offers beginner, intermediate, and advanced Dojo Toolkit workshops to make your development team as skilled and efficient as possible when creating dynamic, responsive web applications.  <a href="http://sitepen.com/services/workshops/index.php">Sign up today!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2012/11/07/dojo-tutorial-dojo-start/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
