<?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/"
	>

<channel>
	<title>Odds and Sodds</title>
	<atom:link href="http://www.scottlogic.co.uk/blog/graham/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk/blog/graham</link>
	<description>Odds and Sodds</description>
	<lastBuildDate>Wed, 16 Nov 2011 09:49:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Change is afoot in the lands of Flash and Flex</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2011/11/change-is-afoot-in-the-lands-of-flash-and-flex/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2011/11/change-is-afoot-in-the-lands-of-flash-and-flex/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 18:32:02 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=609</guid>
		<description><![CDATA[Adobe has recently made a number of rather muddled announcements around Flash and Flex that have caused confusion and concern in the development community. In this post I hope to clarify what actually has been said and present my take on what it might actually mean for those of us on the receiving end. Adobe [...]]]></description>
			<content:encoded><![CDATA[
<p><em>Adobe has recently made a number of rather muddled announcements around Flash and Flex that have caused confusion and concern in the development community.  In this post I hope to clarify what actually has been said and present my take on what it might actually mean for those of us on the receiving end.</em></p>
<p>Adobe has made it clear over the past while that, like the other big players, they see HTML5 as a major force for expressive and rich content on the web.  Actions such as the acquisitions of <a href="http://phonegap.com/2011/10/03/nitobi-enters-into-acquisition-agreement-with-adobe-2/" target="_blank">PhoneGap</a> and <a href="http://blog.typekit.com/2011/10/03/adobe-acquires-typekit/" target="_blank">Typekit</a>, the development of <a href="http://labs.adobe.com/technologies/edge/" target="_blank">Edge</a> and <a href="http://labs.adobe.com/technologies/wallaby/" target="_blank">Wallaby</a> and their contributions to <a href="http://opensource.adobe.com/wiki/display/webkit/Webkit" target="_blank">WebKit</a>, <a href="http://blogs.adobe.com/adobeandjquery/" target="_blank">jQuery</a> and <a href="http://www.adobe.com/devnet/html5/articles/css3-regions.html" target="_blank">the CSS3 specification</a> have backed up their openness about where they see the future heading.  Unfortunately, how they see Flash (and Flex) fitting into this vision has been a little unclear, and recent announcements have only confused matters further.</p>
<p><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/11/2655008175_8320c16153.jpg" alt="" title="Storms Coming" width="500" height="375" class="aligncenter size-full wp-image-617" /></p>
<p><small>Image used under creative commons licence from <a href="http://www.flickr.com/photos/janiellebeh/" target="_blank">Janielle Beh</a></small></p>
<h4>Flash</h4>
<p>The most misunderstood and misreported of the <a href="http://blogs.adobe.com/conversations/2011/11/flash-focus.html">announcements</a> is that Adobe is ceasing active development of the Flash Player plug-in for mobile browsers, i.e. there will be no new versions of the browser plug-in for your mobile phone or tablet (except for critical patches).  Development of the desktop browser version of the plug-in is very much continuing, with various interesting <a href="http://matthewfabb.com/blog/2011/09/02/multithreading-in-flash-update/" target="_blank">new APIs</a> and <a href="http://tv.adobe.com/watch/max-2011-sneak-peeks/max-2011-sneak-peek-monocle/" target="_blank">features</a> already announced for Flash Player 12.  Personally, I am not surprised by the announcement regarding the plug-in for mobile browsers.</p>
<p>As users on mobile devices we don&#8217;t really use, expect or want overly rich content on the browser because it tends to be cumbersome due to high network latency and expensive (depending on your data tariff).  Rather, we go to apps whenever we want anything more than fairly static content.  Without an equivalent ubiquity to that on desktop browsers, Flash Player is never going to be in any kind of position to even attempt to change that behaviour, and attempting to achieve that penetration looks like a complete non-starter considering the platforms blocking it outright and the vast resources <a href="http://www.mikechambers.com/blog/2011/11/11/clarifications-on-flash-player-for-mobile-browsers-the-flash-platform-and-the-future-of-flash/">apparently required</a> to support it for the others</p>
<p>In addition to these reasons, the ubiquity of modern, HTML5-supporting browsers on mobile devices undermines one of the other strong motivations for the use of Flash Player.  Namely, that it is a solution to the issue of backwards-compatibility and feature support that plagues development for desktop browsers.  Few would argue that HTML5 as it currently stands on mobile devices is unable to reliably provide the (limited) richness desired for web content.</p>
<h4>Flex</h4>
<p>The (rather tepid) <a href="http://blogs.adobe.com/flex/2011/11/your-questions-about-flex.html" target="_blank">announcement regarding Flex</a> that Adobe has made is that after the release of Flex 4.6 in a few weeks, governance of the SDK development is going to change significantly.  It is going to be handed over to an open source foundation consisting of members of the current development team, developers from the community, members of the <a href="http://www.spoon.as/" target="_blank">Spoon Project</a> and contributors from enterprise companies.  In some respects Adobe has in the past hinted that something like this might happen.  At AdobeMAX 2010, <a href="http://iamdeepa.com/blog/" target="_blank">Deepa Subramaniam</a> mentioned that they were considering allowing community developers to submit patches that would have to pass through Adobe&#8217;s test suits before becoming candidates for inclusion, and this move seems like a logical extension of that train of thought.  I feel the Flex SDK actually now requires the kind of TLC only a more open governance can provide because I think it could do with a focus on behind-the-scenes fixing and improving rather than glamorous, headline-grabbing new features.</p>
<p>Flex developers are understandably confused and frustrated by this announcement.  As recently as AdobeMAX 2011, Adobe appeared to be giving a strong message about the future of Flex as its solution for enterprise-grade development, with a clear roadmap.  The change of governance inevitably means a change of roadmap, regardless of how strong an influence Adobe might have over the new foundation.  With hindsight, it is perhaps more obvious that Adobe&#8217;s enterprise-related angle has actually related to the future of Flash Player rather than Flex.  However, rather than being upset by the timidity with which Adobe has approached this change and seeing it as a negative move, I think the Flex community and business and enterprises with a stake in the technology should embrace this change and realise the opportunity it potentially provides.  There is a lot of money and time committed to Flex other than Adobe&#8217;s and Adobe is still fully committed to the technologies that underpin Flex, both Flash and AIR, so it is all but guaranteed for the foreseeable future at the very least.</p>
<p><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/11/5351119509_093dc7b9d0.jpg" alt="" title="Rays of hope" width="500" height="375" class="aligncenter size-full wp-image-618" /></p>
<p><small>Image used under creative commons licence from <a href="http://www.flickr.com/photos/janiellebeh/" target="_blank">Janielle Beh</a></small></p>
<h4>AIR</h4>
<p>At the same time as all of this, Adobe has firmly re-stated its commitment to AIR.  Most of the development of the desktop Flash Player plug-in carries over into AIR, and a whole number of new AIR features primarily targeting mobile devices have also been announced.  With the recognition that users go to apps for rich content on mobile devices this makes absolute sense, given that, in my opinion, AIR is one of the best genuinely cross-platform development targets.  Flex developers in particular should take heart from this, considering the close coupling between the Flex framework and the AIR API.  Over time, we may start seeing the runtime shift more towards its JavaScript and HTML capabilities or, at least, applications taking more explicit advantage those capabilities, but at worst AIR would allow a smooth and transparent transition between the technologies.</p>
<h4>Summary</h4>
<p>Overall, my impression is that Adobe have a similar view on how HTML5 and Flash will play out in the short and long term to the one we laid out in <a href="http://www.scottlogic.co.uk/blog/colin/2011/05/flex-silverlight-html5-time-to-decide/" target="_blank">our white paper</a>.  Namely, in the short term, the richer, more interactive and dynamic the content/application being developed requires, the clearer the choice for Flash/Flex over HTML5 is.  However, over time, as tooling, developer skills and technology improve, and the spread of mobile devices continues at its current pace, HTML5 is likely to become the &#8220;better&#8221; choice rather than Flash/Flex.</p>
<p><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/11/TechnologyChoice1.png" alt="" title="Technology Choice" width="400" height="225" class="aligncenter size-full wp-image-613" /></p>
<p>The exciting prospect here is that, historically, what Adobe has excelled at is tooling rather than technology.  Photoshop, Premiere, Illustrator, Flash Professional and others are unquestionably fantastic tools, and Edge has already hinted that Adobe could reach similar standards for HTML5 authoring.  Adobe&#8217;s experience in bona fide IDEs comes primarily from its Flash and Flex tools so it would be reasonable to expect that any new HTML5 tools will feel fairly natural to any developers used to their existing IDEs.  Again, Edge supports this view, since it is remarkably similar to the older Flash authoring tools.</p>
<p>It is interesting to contrast Adobe&#8217;s apparent approach to the future with HTML5 against that of Google and Microsoft.  Where as Adobe appears to content to position itself strongly somewhat on the sidelines from where it might have a better vantage point to allow it to dive in when appropriate, Google and Microsoft seem, to some degree, more intent on outright dictation of the direction we&#8217;re all heading in.  Regardless of how things pan out, it&#8217;s going to continue to make for a fascinating spectacle.</p>
<p>UPDATE: <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/the-untimely-demise-of-the-plugin-and-how-lob-developments-will-suffer/" target="_blank">Head here for my colleague Colin&#8217;s more general thoughts relating to these announcements</a>, they are well worth a read</p>
<p>UPDATE: The Flex team have added <a href="http://blogs.adobe.com/flex/2011/11/your-questions-about-flex.html" target="_blank">further information to their announcement</a> that further justify my call for optimism.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2011/11/change-is-afoot-in-the-lands-of-flash-and-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Critique of Radar Charts</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2011/09/a-critique-of-radar-charts/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2011/09/a-critique-of-radar-charts/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 18:03:19 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Visualisation]]></category>
		<category><![CDATA[Charts]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=568</guid>
		<description><![CDATA[This article presents a critique of radar charts, a chart type commonly used to display multivariate data, highlighting how they are poorly designed to effectively communicate information in the underlying data, and presents a number of more effective alternatives Introduction Radar charts, sometimes known as spider, start or web charts, are a two-dimensional chart type [...]]]></description>
			<content:encoded><![CDATA[
<p><em>This article presents a critique of radar charts, a chart type commonly used to display multivariate data, highlighting how they are poorly designed to effectively communicate information in the underlying data, and presents a number of more effective alternatives</em></p>
<h2>Introduction</h2>
<p><a href="http://en.wikipedia.org/wiki/Radar_chart" target="_blank">Radar charts</a>, sometimes known as spider, start or web charts, are a two-dimensional chart type designed to plot one or more series of values over multiple common quantitative variables by providing an axis for each variable, arranged radially as equi-angular spokes around a central point.  The values for adjacent variables in a single series are connected by lines, and, frequently, the polygonal shape created by these lines in filled with a colour.  Beyond this there are many subtle variations that have different consequences with respect to the efficacy of the chart.  These variations will be covered at appropriate points in the following critique.</p>
<p><a name="chart1"></a><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/Spider_Chart_wikipedia.jpg" alt="Radar Chart from Wikipedia" title="Radar Chart from Wikipedia" width="538" height="295" class="aligncenter" /></a></p>
<p style="font-style: italic; margin-left: 180px;">Chart 1: Radar chart from <a href="http://en.wikipedia.org/wiki/File:Spider_Chart.jpg" target="_blank">Wikipedia</a></p>
<h2 style="margin-bottom: 5px">Critique</h2>
<h4>Axes and Values</h4>
<p>The axes of radar charts represent independent scales for each of the quantitative variables under consideration.  Therefore, barring <a href="#occlusion">occlusion</a>, comparing values for a single variable between series is straightforward and relatively effortless since it merely consists of assessing their position along a line, something we are able to do without any thought.  However, a number of distinct issues arise when attempting to compare values across different axes.</p>
<p>Firstly (and most easily grasped), by definition there is nothing prohibiting axes representing wildly different scales since they are nominally independent.  This is shown at its extreme in <a href="#chart2">Chart 2</a>.  Clearly comparison across variables is pointless in this case, yet it is something a radar chart is designed to encourage us to do.  Hopefully from this extreme example you are also able to appreciate that even in subtler cases where the scales are genuinely independent, whether that be the inversion of the scale on one axis or slightly different ranges of values being represented, comparison is rather absurd.  So much so that very few charting libraries or applications support this in any way.</p>
<p><a name="chart2"></a><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/few.png" alt="Radar Chart by Stephen Few" title="Radar Chart by Stephen Few" width="428" height="288" class="aligncenter" /></a></p>
<p style="font-style: italic; margin-left: 130px;">Chart 2: <a href="www.perceptualedge.com/articles/dmreview/radar_graphs.pdf" target="_blank">Artificial radar chart by Stephen Few to show independent axis scales</a></p>
<p>Unfortunately, even with a common scale between axes, comparing values across them remains cumbersome and error-prone.  This is because rather than the simple straight-line comparison our visual perception is hard-wired to perform that is found in &#8220;conventional&#8221; chart types, comparison in radar charts requires conscious thought to mentally project a sort of arc of rotation to map a value from one axis onto another, something we are not particularly adept at.</p>
<p><a name="chart3"></a><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/radar_chart_visiblox.png" alt="Radar Chart by Visiblox" title="Radar Chart by Visiblox" width="531" height="336" class="aligncenter" /></a></p>
<p style="font-style: italic; margin-left: 250px;">Chart 3: Radar chart by<a href="http://www.visiblox.com/examples/RadarChart" target="_blank">Visiblox</a></p>
<p>In order to help general perception and, in particular, comparison across axes, radar charts usually display gridlines connecting axes when they share a common scale (giving them their traditional spider-web-like appearance).  However, even with these gridlines it remains cumbersome to compare values on non-adjacent axes.  For example, try comparing the Space and Comfort scores for Monster Truck in <a href="chart3">Chart 3</a>.  It requires a surprising amount of conscious effort, doesn&#8217;t it?</p>
<p><a name="chart4"></a><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/radar_chart_kaplab.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/radar_chart_kaplab.png" alt="Radar Chart by Kap Lab" title="Radar Chart by Kap Lab" width="537" height="432" class="aligncenter" /></a></p>
<p style="font-style: italic; margin-left: 260px;">Chart 4: Radar chart by <a href="http://lab.kapit.fr/display/radarchart/Radar+Chart" target="_blank">Kap Lab</a></p>
<p>Aside from the <a href="http://www.infovis-wiki.net/index.php/Data-Ink_Ratio" target="_blank">non-data ink</a> gridlines inevitably add, they also introduce further issues to radar charts.  Mainly, they tend to add confusion around axis value labelling by breaking the association by proximity used to associate a particular value label with a mark on an axis.  This is very clearly demonstrated in <a href="#chart1">Chart 1</a>.  It requires active thought to disassociate the labels from the gridlines over which they inadvertently lie.  For example, what is actually the $60 gridline appears to be labelled $50 instead.  <a href="chart3">Chart 3</a> demonstrates a commonly attempted solution to this problem that unfortunately makes the chart just as difficult to read, only in a different way.  Here the labels are so far away from the axis that, once again, conscious effort is required to comprehend what should be an inconspicuous, almost sub-conscious interpretation aide for the chart.</p>
<p><a name="chart5"></a><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/radar_chart_dundas.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/radar_chart_dundas.png" alt="Radar Chart by Dundas Data Visualisation" title="Radar Chart by Dundas Data Visualisation" width="417" height="336" class="aligncenter" /></a></p>
<p style="font-style: italic; margin-left: 215px;">Chart 5: Radar chart by <a href="http://support2.dundas.com/OnlineDocumentation/winchart2005/RadarChart.html" target="_blank">Dundas Data Visualisation</a></p>
<p><em>Occasionally the gridlines on a radar chart are presented as circles rather than straight connecting lines between equivalent values on adjacent axes, as in <a href="#chart5">Chart 5</a>.  Conceptually, I do not understand how a chart can combine circular connections between axis values and straight line connections between series values.  Surely they must adhere to the same notional underlying data space?!  Otherwise the chart is fundamentally broken.  If anyone feels like creating a radar chart using strictly <a href="http://en.wikipedia.org/wiki/Polar_coordinate_system" target="_blank">polar data space</a> for both gridlines and series shapes, could you please send me a link?  I&#8217;ve never actually seen one, and always like a giggle&#8230;</em></p>
<h4><a name="lines"></a>Connecting Lines and Nominal Scales</h4>
<p>The quantitative variables and their values represented on the various axes of a radar chart are, with the exception of some less common cases such as when plotting timeseries data, distinct and unrelated.  Yet, by design, radar charts force the suggestion of some relationship between the variables by having a connecting line between values on different axis in order to create the series grouping, thereby misleading the user.  To help clarify this point, the chart below is identical to <a href="chart5">Chart 5</a> except that the information is plotted using &#8220;conventional&#8221; <a href="http://en.wikipedia.org/wiki/Cartesian_coordinate_system" target="_blank">cartesian coordinates</a> rather than the (pseudo-)<a href="http://en.wikipedia.org/wiki/Polar_coordinate_system" target="_blank">polar coordinates</a> of a radar chart.</p>
<p><a name="chart6"></a><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/line_chart_dundas.png" alt="Line Chart of Radar Chart by Dundas Data Visualisation" title="Line Chart of Radar Chart by Dundas Data Visualisation" width="586" height="263"  class="aligncenter" /></p>
<p>In this more familiar, non-circular format it is hopefully much more obvious that we are in fact dealing with a nominal scale on the x axis.  That is, the categories on the x axis are simply named entities that have no intrinsic order and do not represent quantitative values.  As such, the relationship and incline or decline in value the connecting line implies is grossly misleading since we could arbitrarily change the relationships by rearranging the categories (something we are free to do because of their lack of intrinsic ordering).  When shown this way, many of you will recognise that this kind of information is likely to be best presented as a bar chart in some form, depending on the specific purpose of the chart, as shown for <a href="chart5>Chart 5</a> below.</p>
<p><a name="chart7"></a><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/bar_chart_dundas.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/bar_chart_dundas.png" alt="Bar Chart of Radar Chart (Dundas)" title="Bar Chart of Radar Chart (Dundas)" width="573" height="300" class="aligncenter" /></a></p>
<h4><a name="occlusion"></a>Occlusion</h4>
<p>Occlusion, in data visualisation, refers to the phenomenon where a part of the visualisation obscures another part.  Clearly this should be avoided, or at least minimised, since hidden visuals prevents you from interpreting the information correctly.  Unfortunately, the design of radar charts means significant occlusion is inevitable when multiple series are plotted, since they must be &#8220;on top&#8221; of each other.  In cases where the fill colour of the shape of a series is relatively or completely opaque, such as <a href="chart5">Chart 5</a>, it can be nigh on impossible to see particular values.  In these cases, the gridlines are also at best partially obscured, thereby making it even more cumbersome to discern the value any any given point.  In <a href="#chart5">Chart 5</a> this is has been somewhat overcome by adding tick marks on top of the series, which, unfortunately, also adds to the overall clutter on the chart.</p>
<p>When transparency is used to circumvent the problems caused by solid fill colours it creates a new problem: the unavoidable tinting effect can make differentiating the underlying series or matching them to a legend very difficult.  As such, the approach that suffers least from occlusion is when no fill colour is used, as in <a href="#chart1">Chart 1</a>.</p>
<h4>Shapes</h4>
<p>One argument given by proponents of radar charts is that we are naturally adept at seeing and evaluating simple shapes.  Although this is true, it overlooks the major issue that the overall shape presented for a series on a radar chart does not leverage any of the <a href="http://en.wikipedia.org/wiki/Pre-attentive_processing" target="_blank">pre-attentive attributes</a> we perceive quantitatively.  In essence, this means we are unable to attribute much genuine meaning to the shape of a series.  The only patterns our visual perception can really discern in a data set presented as a radar chart are similarity and extreme outliers.  Both patterns are just as easy, if not easier, to recognise in more effective <a href="#alternatives">alternative visualisations</a>, such as line and bar charts, where the shapes also have quantitative perception.  Consider the example radar charts above, can you reliably say anything useful about the respective series based on their shapes other than where they are similar or there is an outlier?</p>
<p>A further issue with the shapes presented by radar charts are that the area of the shapes increases as a square of the values rather than linearly.  This can cause us to misinterpret the data since a small difference in values results in a significant difference in area, thereby exaggerating any difference when we follow our natural inclination to compare the size of the shapes.</p>
<h2><a name="alternatives"></a>Alternatives</h2>
<p>There are numerous more effective alternatives to radar charts, depending on the information being presented.  These include bar charts, <a href="#lines">as shown above</a>, line charts (particularly for timeseries data), <a href="http://www.perceptualedge.com/articles/b-eye/parallel_coordinates.pdf" target="_blank">parallel coordinates charts</a> and, quite simply, tables showing the raw figures.  The latter is commonly overlooked, but when dealing with relatively small, simple data sets it is frequently the most immediate and clear way to represent the information.  In more complex cases, a more effective alternative to a radar chart can be to use a concept called <a href="http://en.wikipedia.org/wiki/Small_multiple" target="_blank">small multiples</a>, devised by <a href="http://www.edwardtufte.com/tufte/" target="_blank">Edward Tufte</a>, in conjunction with bar charts.  Using this approach, individual series are separated onto individual charts, all sharing a common x and/or y axis scale to enable meaningful comparison across them.  This way it is easier to gain both a higher level overview and investigate at more detail because the clutter, occlusion and related issues common to complex charts, and particularly radar charts, are removed.  The following chart is a redesign of <a href="#chart4>Chart 4</a> using small multiples.  Notice how much easier it is to absorb the information in this form.</p<</p>
<p><a name="chart8"></a><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/kaplab_multiple.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/kaplab_multiple.png" alt="Small Multiples of Radar Chart by KapLab" title="Small Multiples of Radar Chart by KapLab" width="933" height="160" class="aligncenter" /></a></p>
<p><em>Note that the x axis scale labels have been omitted because they were not present in the original example and, even after a little background research, I was unable to deduce them.  As far as I can tell, the data used to create the original chart is fictional.  If the genuine figures are of interest, I would suggest using Google&#8217;s <a href="http://www.google.co.uk/publicdata/directory" target="_blank">Public Data Explorer</a>.</em></p>
<p>An immediate advantage of using tables, bar columns or small multiples is that they naturally support ordering.  With a radar chart, introducing ordering would require the starting point and direction to be explicitly indicated somehow since neither can be inherently deduced from the radar chart design.  In the aforementioned alternatives, left-to-right or top-to-bottom ordering is immediately evident.  Although ordering is rarely a strict necessity for a chart with a nominal scale, it can provide useful structure to the information that reinforces or enhances the story being told.  For example, an ordering of best to worst for some value can add a great deal of clarity to a chart.</p>
<h4>Worked Example</h4>
<p>Based on what has been explained so far, it is hopefully clear that there are many more effective ways to represent the information shown in radar charts.  To further underscore this and to show how a little more thought and effort put into the design of a chart can have a significant effect on its efficacy, here follows a worked example based on <a href="chart1">Chart 1</a>.</p>
<p><a href="#lines">As previously highlighted</a>, the axis categories of a radar chart are frequently a nominal scale, meaning there is no relationship between their respective values.  Therefore, it is immediately clear that a bar chart would be a better representation of the data shown in <a href="chart1">Chart 1</a>.</p>
<p><a name="chart9"></a><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/wikipedia_simple.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/wikipedia_simple.png" alt="Alternative Approach Bar Chart 1" title="Alternative Approach Bar Chart 1" width="486" height="378" class="aligncenter" /></a></p>
<p>In the particular case of <a href="#chart1">Chart 1</a>, it is a fairly safe assumption to say that the chart is ultimately trying to convey the over- and under-spend of the respective departments.  As such, the following redesign focuses on the more important value, the actual spending, and its relationship to the budget, by reducing the visual salience of the budget values.</p>
<p><a name="chart10"></a><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/wikipedia_market.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/wikipedia_market.png" alt="Alternative Approach Bar Chart 2" title="Alternative Approach Bar Chart 2" width="486" height="378" class="aligncenter" /></a></p>
<p>Furthermore, it can be assumed that in this case the relative over- and under-spend of the respective departments is the primary concern.  By charting this difference as a percentage of the original budget and ordering the resulting bar chart from biggest overspend to biggest underspend, we have a very clear story of which departments are the worst offenders at both ends of the scale.</p>
<p><a name="chart11"></a><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/wikipedia_diff.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/wikipedia_diff.png" alt="Alternative Approach Bar Chart 3" title="Alternative Approach Bar Chart 3" width="467" height="360" class="aligncenter" /></a></p>
<h2>Conclusion</h2>
<p>Hopefully it is clear that radar charts, despite the initial appeal due to their interesting appearance, are ultimately useless, in that they are unable to efficiently and effectively communicate information to users.  Regrettably, many vendors of charting products continue to include them and users seem more interested in that first 5-second &#8220;cool&#8221; reaction than their ability to serve their purpose.  Furthermore, vendors are, quite justifiably, assumed to be experts in their field, or at least to have more expertise than consumers.  Therefore, so long as vendors of charting products continue to support and encourage fundamentally flawed features like radar charts, users will, unless educated otherwise, understandably continue to assume these features are perfectly suitable.  Vendors then often argue that consumers request these features.  And so a feedback loop of delusion has developed&#8230;</p>
<p>So I implore vendors of charting products to take a &#8220;brave&#8221; stance: please stop pointlessly including functionality that allows users to create flawed visualisations.  Or, at the very least, stop implying they are good practice by featuring them on your websites and marketing material.  You are collectively undermining the power of data visualisation by encouraging users towards cumbersome, frustrating charts that do not work, when really you should know better.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2011/09/a-critique-of-radar-charts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash On The Beach 2011</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2011/09/flash-on-the-beach-2011-2/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2011/09/flash-on-the-beach-2011-2/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 15:10:00 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[UI Design]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[user interface]]></category>
		<category><![CDATA[Visualisation]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=553</guid>
		<description><![CDATA[Yesterday I spoke at the Flash On The Beach conference in Brighton as part of the Elevator Pitch session. I think the session went really well, with a great mixture of topics so (hopefully) everyone was suitably entertained. As previously mentioned, my 3-minute talk was titled How I Learned to Stop Drawing Lines and Love [...]]]></description>
			<content:encoded><![CDATA[
<p>Yesterday I spoke at the <a href="http://www.flashonthebeach.com/" target="_blank">Flash On The Beach</a> conference in Brighton as part of the <a href="http://www.flashonthebeach.com/speakers/index.php?pageid=1999" target="_blank">Elevator Pitch</a> session.  I think the session went really well, with a great mixture of topics so (hopefully) everyone was suitably entertained.</p>
<p>As <a href="http://www.scottlogic.co.uk/blog/graham/2011/07/flash-on-the-beach-2011/" target="_blank">previously mentioned</a>, my 3-minute talk was titled <b><em>How I Learned to Stop Drawing Lines and Love Whitespace</em></b>.  It tries to encourage designers to create more subtle structure in designs, using whitespace, rather than excessive lines and boxes, by understanding the Gestalt Principles.  For anyone interested, here are my slides and speil (I believe a video may follow in due course):</p>
<p><iframe src="http://docs.google.com/viewer?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fgraham%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhitespace.pdf&#038;embedded=true" width="700" height="610" style="border: none;"></iframe><br />
<span style="font-size: 0.8em; font-style: italic;"><a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/whitespace.pdf'>Download</a></span></p>
<p>Overall, the whole conference was wonderfully interesting and inspirational.  The sessions I particularly enjoyed and people I would recommend checking out are:</p>
<ul>
<li><a href="http://elliotjaystocks.com/" target="_blank">Elliot Jay Stocks</a> (<a href="http://twitter.com/elliotjaystocks" target="_blank">@elliotjaystocks</a>)</li>
<li><a href="http://www.jessicahische.is/" target="_blank">Jessica Hische</a> (<a href="http://twitter.com/jessicahische" target="_blank">@jessicahische</a>)</li>
<li><a href="http://sebleedelisle.com/" target="_blank">Seb Lee-Delisle</a> (<a href="http://twitter.com/seb_ly" target="_blank">@seb_ly</a>)</li>
<li><a href="http://blog.joa-ebert.com/" target="_blank">Joa Ebert</a> (<a href="http://twitter.com/joa" target="_blank">@joa</a>)</li>
<li><a href="http://www.jonburgerman.com/" target="_blank">Jon Burgerman</a> (<a href="http://twitter.com/jonburgerman" target="_blank">@jonburgerman</a>)</li>
</ul>
<p>Oh, and here&#8217;s an image of me looking suitably po-faced, in full flow:</p>
<p><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/09/6146953492_0b7896dd74_b.jpg" alt="Graham at FOTB2011" title="Graham at FOTB2011" width="80%" /><br />
<span style="font-size: 0.8em; font-style: italic;">Image courtesy of <a href="http://www.flickr.com/photos/marcthiele" target="_blank">Marc Thiele</a></span></p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2011/09/flash-on-the-beach-2011-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Static Initialisation in Flex</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2011/07/static-initialisation-in-flex/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2011/07/static-initialisation-in-flex/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 17:11:00 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=537</guid>
		<description><![CDATA[For reasons best ignored I recently investigated the different ways in which static initialisation code can be run in Flex. As well as a direct equivalent to the static initialiser blocks available in Java and C#, Flex has a couple of subtle variants that can prove useful in different circumstances. First up, the &#8220;standard&#8221; static [...]]]></description>
			<content:encoded><![CDATA[
<p>For reasons best ignored I recently investigated the different ways in which static initialisation code can be run in Flex.  As well as a direct equivalent to the static initialiser blocks available in <a href="http://java.sun.com/docs/books/jls/third_edition/html/classes.html#39245" target="_blank">Java</a> and <a href="http://msdn.microsoft.com/en-us/library/aa645612(v=vs.71).aspx" target="_blank">C#</a>, Flex has a couple of subtle variants that can prove useful in different circumstances.</p>
<p>First up, the &#8220;standard&#8221; static initialisation technique, the direct equivalent to that found in <a href="http://java.sun.com/docs/books/jls/third_edition/html/classes.html#39245" target="_blank">Java</a> and <a href="http://msdn.microsoft.com/en-us/library/aa645612(v=vs.71).aspx" target="_blank">C#</a>.  The block of code shown below will execute once, the first time an instance of <code>MyClass</code> is created before that first constructor call is executed.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> initialised:<span style="color: #0066CC;">Boolean</span> = initialise<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> initialise<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;static initialisation block that will execute&quot;</span> +
              <span style="color: #ff0000;">&quot; the first time 'new MyClass()' is called anywhere&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If the intention of your code block is to create and initialise a static variable then this approach is clear and obvious.  However, if you want to run some general initialisation code you still require a dummy variable and a return type on the static function.  This is because the variable initialisation is the hook required to execute the function.  This technique was used throughout the Flex 3 Framework code for style initialisation on components (an approach no longer in Flex 4 because of the <a href="http://www.scottlogic.co.uk/blog/graham/2011/04/updating-flex-sparkline-to-flex-4/ target=_"blank">improvements to style initialisation</a>).</p>
<p>The second technique is that used by the <a href="http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7ec5.html" target="_blank">Automation framework</a> that is included with the SDK.  This approach allows code to be executed when an application or module is loaded.  The code would look as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Mixin<span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span>root:DisplayObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;static initialisation block that will execute&quot;</span> +
              <span style="color: #ff0000;">&quot; when the application or module first loads&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The <code>root</code> argument will be an <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/ISystemManager.html" target="_blank">ISystemManager</a> or <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/IFlexModuleFactory.html" target="_blank">IFlexModuleFactory</a> instance depending on whether the class was loaded as part of an application or module.  Note that for the <code>[Mixin]</code> to be picked up the class must be included in the application or module, i.e. it must be referenced elsewhere in code or explicitly added using appropriate compiler arguments</p>
<p>The final technique comes from <a href="http://en.wikipedia.org/wiki/ActionScript" target="_blank">ActionScript&#8217;s</a> <a href="http://en.wikipedia.org/wiki/ECMAScript" target="_blank">ECMAScript</a> heritage, in particular its <a href="http://en.wikipedia.org/wiki/Prototype-based_programming" target="_blank">prototype-based</a> object model.  In this case, code is written directly into the <code>class</code> scope, i.e. not inside a <code>function</code> block.  This code will be executed the first time the class is executed in any way.  That is, if the class uses the <code>[Mixin]</code> technique then it will execute along with the mix-ins <code>static init</code> function, otherwise it will be the equivalent to the &#8220;standard&#8221; approach and execute the first time the class is instantiated.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;static initialisation taking advantage of prototype-based object model&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><em>I know it looks odd, but it genuinely is valid!</em></p>
<p>So putting it all together in the most artificial of examples, the following class would produce the trace output 1, 2, 3, 4 (with 3 and 4 only appearing when an instance of the class is instantiated):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Mixin<span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyClass
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span>root:DisplayObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> initialised:<span style="color: #0066CC;">Boolean</span> = initialise<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initialise<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;4&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2011/07/static-initialisation-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash On The Beach 2011</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2011/07/flash-on-the-beach-2011/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2011/07/flash-on-the-beach-2011/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 13:05:29 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[UI Design]]></category>
		<category><![CDATA[Visualisation]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=528</guid>
		<description><![CDATA[Yesterday I received the exciting news that I will be speaking at the fantastic Flash On The Beach conference in Brighton this September. As Europe&#8217;s biggest annual Flash conference it brings together leading minds from all over the industry and focuses on design and development in equal share. I will be presenting as part of [...]]]></description>
			<content:encoded><![CDATA[
<p>Yesterday I received the exciting news that I will be speaking at the fantastic <a href="http://www.flashonthebeach.com/" target="_blank">Flash On The Beach</a> conference in Brighton this September.  As Europe&#8217;s biggest annual Flash conference it brings together leading minds from all over the industry and focuses on design and development in equal share.</p>
<p><a href="http://www.flashonthebeach.com/" target="_blank"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/07/fotb_logo.png" alt="Flash On The Beach 2011" title="Flash On The Beach 2011" width="100%" /></a></p>
<p>I will be presenting as part of the Elevator Pitch session, which consists of an hour of 3-minute talks by different speakers on completely different topics covering the full spectrum from design to coding.  By all accounts the session is always intense but fun and inspirational and it is a wonderful opportunity for new talent to gain some exposure.  My talk is entitled <strong>&#8220;How I Learned to Stop Drawing Lines and Love Whitespace&#8221;</strong> and I will be posting more details about it closer to the time.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2011/07/flash-on-the-beach-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex, Silverlight or HTML5? Time to decide…</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2011/05/flex-silverlight-or-html5/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2011/05/flex-silverlight-or-html5/#comments</comments>
		<pubDate>Fri, 06 May 2011 13:25:20 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=521</guid>
		<description><![CDATA[Building on the experience and expertise within Scott Logic, my colleague, Colin Eberhardt, has produced an excellent whitepaper considering the three big web technologies at the moment: Flex, Silverlight and HTML5. Recent advances in web technologies have resulted in a complex landscape for application developers to navigate. Coupled with the recent boom in new platforms, [...]]]></description>
			<content:encoded><![CDATA[
<p>Building on the experience and expertise within <a href="http://www.scottlogic.co.uk" target="_blank">Scott Logic</a>, my colleague, <a href="http://www.scottlogic.co.uk/blog/colin" target="_blank">Colin Eberhardt</a>, has produced <a href="http://www.scottlogic.co.uk/blog/colin/2011/05/flex-silverlight-html5-time-to-decide/" target="_blank">an excellent whitepaper</a> considering the three big web technologies at the moment: Flex, Silverlight and HTML5.  </p>
<blockquote><p><em><br />
Recent advances in web technologies have resulted in a complex landscape for application<br />
developers to navigate. Coupled with the recent boom in new platforms, from desktops, netbooks,<br />
smartphones to tablets, making an informed and future proof technology choice is all the more<br />
difficult. In this paper we will set technology bias and politics aside to navigate the similarities and<br />
differences between Flex, Silverlight and HTML5 and give you the power to decide.</p>
<p>This white-paper is aimed at technical decision makers who are looking to choose the correct<br />
technology for web application development.<br />
</em></p></blockquote>
<p>Head over to <a href="http://www.scottlogic.co.uk/blog/colin" target="_blank">Colin&#8217;s blog</a> to <a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/05/Flex-Silverlight-HTML5.pdf" target="_blank">download</a> or read the full paper and to add to the conversation.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2011/05/flex-silverlight-or-html5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Updating Flex Sparkline to Flex 4</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2011/04/updating-flex-sparkline-to-flex-4/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2011/04/updating-flex-sparkline-to-flex-4/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 16:50:59 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Visualisation]]></category>
		<category><![CDATA[Charts]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=516</guid>
		<description><![CDATA[In a previous post I presented a library of]]></description>
			<content:encoded><![CDATA[
<p>In <a href="http://www.scottlogic.co.uk/blog/graham/2010/02/flex-sparkline/" target="_blank">a previous post</a> I presented a library of <a href="http://en.wikipedia.org/wiki/Sparkline target="_blank">sparkline</a> implementations for Flex 3.  I have finally gotten round to updating it for Flex 4.  The new source code, documentation and pre-compiled swf (namespace: <code>http://www.scottlogic.com/sparkline</code>) can be obtained from <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/04/Sparkline.zip'>here</a>.  As before, the components are being made available under the <a href='http://www.gnu.org/licenses/gpl.html'>GNU General Public License</a>.</p>
<p>As you can see, the versions appear identical:</p>
<p><b>Flex 3</b><br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="sparklines_3" width="445" height="85" align="center">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/SparklineApp.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/SparklineApp.swf" width="445" height="85" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
</p>
<p><b>Flex 4</b><br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="sparklines_4" width="445" height="85" align="center">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/04/SparklineApp.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/04/SparklineApp.swf" width="445" height="85" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
 </p>
<h4>Updating to Flex 4</h4>
<p>For those of you interested in some of the changes required to migrate code from Flex 3 to Flex 4, here follow some of the details required to update this particular code.</p>
<p>The main change was due to Flex 4 essentially deprecating the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/StyleManager.html" target="_blank"><code>StyleManager</code></a> class and its static methods in order to provide mechanisms allowing <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=modular_5.html" target="_blank">modules</a> to have independent style declarations.  At the forefront of this change is the new <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/IStyleManager2.html" target="_blank"><code>IStyleManager2</code></a> interface, an instance of which can be obtained from the static <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/StyleManager.html#getStyleManager%28%29" target="_blank"><code>getStyleManager</code></a> method on <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/styles/StyleManager.html" target="_blank"><code>StyleManager</code></a> or, preferably, the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/UIComponent.html#styleManager" target="_blank"><code>styleManager</code></a> property of <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/UIComponent.html" target="_blank"><code>UIComponent</code></a>.  In practice, using the <code>Sparkline</code> class as an example, this means changing from the static Flex 3 style declaration approach:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Sparkline <span style="color: #0066CC;">extends</span> SparklineBase
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/**
     *  @private
     */</span>
    <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> stylesInited:<span style="color: #0066CC;">Boolean</span> = initStyles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #808080; font-style: italic;">/**
     *  @private
     */</span>
    <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> initStyles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> sd:CSSStyleDeclaration = StyleManager.<span style="color: #006600;">getStyleDeclaration</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Sparkline&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>sd<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            sd = <span style="color: #000000; font-weight: bold;">new</span> CSSStyleDeclaration<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            StyleManager.<span style="color: #006600;">setStyleDeclaration</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Sparkline&quot;</span>, sd, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        sd.<span style="color: #006600;">defaultFactory</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">lineStroke</span> = <span style="color: #000000; font-weight: bold;">new</span> Stroke<span style="color: #66cc66;">&#40;</span>0x828282, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">markerFill</span> = <span style="color: #000000; font-weight: bold;">new</span> SolidColor<span style="color: #66cc66;">&#40;</span>0x2963a3<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">markerStroke</span> = <span style="color: #000000; font-weight: bold;">new</span> Stroke<span style="color: #66cc66;">&#40;</span>0x2963a3, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">markerRadius</span> = <span style="color: #cc66cc;">2</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">normalRangeFill</span> = <span style="color: #000000; font-weight: bold;">new</span> SolidColor<span style="color: #66cc66;">&#40;</span>0x000000, <span style="color: #cc66cc;">0.1</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    ...
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>To overriding <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/UIComponent.html" target="_blank"><code>UIComponent</code></a>&#8216;s <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/UIComponent.html#moduleFactory" target="_blank"><code>moduleFactory</code></a> property to provide the &#8220;hook&#8221; for invoking the style declaration:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Sparkline <span style="color: #0066CC;">extends</span> SparklineBase
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/**
     * @private
     */</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _moduleFactoryInitialized:<span style="color: #0066CC;">Boolean</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * @private
     */</span>
    <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> moduleFactory<span style="color: #66cc66;">&#40;</span>factory:IFlexModuleFactory<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">super</span>.<span style="color: #006600;">moduleFactory</span> = factory;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_moduleFactoryInitialized<span style="color: #66cc66;">&#41;</span>
            <span style="color: #b1b100;">return</span>;
        _moduleFactoryInitialized = <span style="color: #000000; font-weight: bold;">true</span>;
        initStyles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * @private
     */</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initStyles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> sd:CSSStyleDeclaration = styleManager.<span style="color: #006600;">getStyleDeclaration</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;com.scottlogic.sparkline.Sparkline&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>sd<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            sd = <span style="color: #000000; font-weight: bold;">new</span> CSSStyleDeclaration<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            styleManager.<span style="color: #006600;">setStyleDeclaration</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;com.scottlogic.sparkline.Sparkline&quot;</span>, sd, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        sd.<span style="color: #006600;">defaultFactory</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">lineStroke</span> = <span style="color: #000000; font-weight: bold;">new</span> SolidColorStroke<span style="color: #66cc66;">&#40;</span>0x828282, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">markerFill</span> = <span style="color: #000000; font-weight: bold;">new</span> SolidColor<span style="color: #66cc66;">&#40;</span>0x2963a3<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">markerStroke</span> = <span style="color: #000000; font-weight: bold;">new</span> SolidColorStroke<span style="color: #66cc66;">&#40;</span>0x2963a3, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">markerRadius</span> = <span style="color: #cc66cc;">2</span>;
            <span style="color: #0066CC;">this</span>.<span style="color: #006600;">normalRangeFill</span> = <span style="color: #000000; font-weight: bold;">new</span> SolidColor<span style="color: #66cc66;">&#40;</span>0x000000, <span style="color: #cc66cc;">0.1</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    ...
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>You will also see that as of Flex 4, getting style declarations now requires a fully qualified class name rather than just the name of the class, e.g. <code>com.scottlogic.sparkline.Sparkline</code> rather than <code>Sparkline</code>.  As before, this change is required due to the underlying shift in the approach used for style management by the framework in order to support independence between modules.</p>
<p>The other update required was due to the changed <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/IFill.html" target="_blank"><code>IFill</code></a> and <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/IStroke.html" target="_blank"><code>IStroke</code></a> interfaces.  In particular, the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/IFill.html#begin%28%29" target="_blank"><code>begin</code></a> method on <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/IFill.html" target="_blank"><code>IFill</code></a> takes an additional <code>targetOrigin</code> argument of type <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Point.html" target="_blank"><code>Point</code></a> that specifies intended origin of the shape drawing.  Similarly, <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/IStroke.html" target="_blank"><code>IStroke</code></a>&#8216;s <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/IStroke.html#apply%28%29" target="_blank"><code>apply</code></a> method now takes two additional arguments, <code>targetBounds</code> and <code>targetOrigin</code>, to provide the same drawing manipulation/restriction as <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/IFill.html" target="_blank"><code>IFill</code></a>.  Fortunately, the SDK team appear to have anticipated the potential complications and frustrations arising from these changes and have implemented them so that specifying a <code>null</code> value for the additional arguments results in identical behaviour to that which would have occurred in the Flex 3 code.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2011/04/updating-flex-sparkline-to-flex-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presentation Model (or MVVM) with Mate</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2011/01/presentation-model-with-mate/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2011/01/presentation-model-with-mate/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 22:41:14 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Code Structure]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Mate]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=432</guid>
		<description><![CDATA[This post introduces the Presentation Model (or MVVM) architectural pattern as one approach for creating &#8220;better&#8221; large-scale Flex applications and shows how the Mate Framework can be leveraged to not only achieve this pattern but increase separation of concerns above that of a &#8220;standard&#8221; Flex application. Background One of the great advantages Flex is that [...]]]></description>
			<content:encoded><![CDATA[
<p><em>This post introduces the <a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Presentation Model</a> (or <a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank">MVVM</a>) architectural pattern as one approach for creating &#8220;better&#8221; large-scale <a href="http://www.adobe.com/devnet/flex.html" target="_blank">Flex</a> applications and shows how the <a href="http://mate.asfusion.com/" target="_blank">Mate Framework</a> can be leveraged to not only achieve this pattern but increase <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" target="_blank">separation of concerns</a> above that of a &#8220;standard&#8221; <a href="http://www.adobe.com/devnet/flex.html" target="_blank">Flex</a> application.</em></p>
<h2>Background</h2>
<p>One of the great advantages <a href="http://www.adobe.com/devnet/flex.html" target="_blank">Flex</a> is that it makes creating applications very quick and easy by allowing ad-hoc mixing of <a href="http://en.wikipedia.org/wiki/MXML" target="_blank">MXML</a> and <a href="http://en.wikipedia.org/wiki/ActionScript" target="_blank">ActionScript</a>.  This is ideal for rapid prototyping and can be all that is required for small applications.  It also means anyone new to the technology can easily get started and relatively quickly put together quite rich applications.  However, this architectural pattern, termed <a href="http://martinfowler.com/eaaDev/AutonomousView.html" target="_blank">Autonomous View</a>, does not scale well for larger, real-world projects.  Fortunately, there are a numerous other architectural patterns &#8211; most famously(?) <a href="http://en.wikipedia.org/wiki/Model_view_controller" target="_blank">Model-View-Controller (MVC)</a> &#8211; that attempt to directly address these concerns.  Furthermore, various frameworks have been developed for Flex that specifically target these patterns.  For example, both <a href="" target="_blank">Cairngorm</a> and <a href="" target="_blank">PureMVC</a> were designed for developing applications using the MVC architecture.  There are <a href="http://www.codeproject.com/KB/aspnet/ArchitectureComparison.aspx" target="_blank">many</a> <a href="http://www.dehats.com/drupal/?q=node/36" target="_blank">articles</a> on the web considering <a href="http://blogs.adobe.com/paulw/" target"_blank">the merits of different architectural patterns</a> (and related Flex-specific <a href="http://robsondesign.com/blog/index.php/2009/04/02/puremvc-vs-cairngorm-revisited/">frameworks</a>).  This article focuses on the <a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Presentation Model</a> architectural pattern, and a specific implementation of it using the <a href="http://mate.asfusion.com/" target="_blank">Mate Framework</a>, as a particularly useful approach to application development in Flex.  Note that Mate is not designed to target any particular architectural pattern and that I am merely introducing its use with the Presentation Model pattern as one of many possible approaches, not a definitive or necessarily best one.</p>
<h4>Presentation Model (or Model-View-ViewModel)</h4>
<p><a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Presentation Model</a> is an architectural pattern derived from <a href="http://en.wikipedia.org/wiki/Model_view_controller" target="_blank">Model-View-Controller (MVC)</a> and originally introduced by <a href="http://martinfowler.com/" target="_blank">Martin Fowler</a>.  Since then, Microsoft has introduced the <a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank">Model View ViewModel (MVVM)</a> pattern as a specialisation of Presentation Model that extends the original concept by adding a Model to make it more relevant to modern application development.  I have adopted the MVVM terminology as I believe it better defines the entities involved in the pattern (purely because of its name).</p>
<p>The key features of the pattern are:</p>
<ul>
<li>Model is the object model representation of state (whether as real state or as a data-access layer representation of the state)</li>
<li>View is the GUI elements</li>
<li>View model contains all GUI state and logic</li>
<li>View observes the view model and updates accordingly</li>
<li>View is &#8220;aware&#8221; of the view model</li>
<li>View model has no knowledge of the view</li>
</ul>
<p>The observation required by the view is one of the reasons Flex is particularly suited to this pattern, as its <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_1.html" target="_blank">binding functionality</a> is simple and powerful implementation of observation.  Additionally, the pattern ties in neatly to the relative merits of Flex&#8217;s two languages, creating a simple conceptual model for developers:</p>
<ul>
<li>View = MXML = components &#038; layout</li>
<li>ViewModel = ActionScript = behaviour &#038; state</li>
</ul>
<p>The main advantages of Presentation Model (or MVVM) are the clear code separation between GUI layout and behaviour and the testability this inherently introduces (compared to Autonomous View and similar).  As well as the advantages this brings in all object-oriented technologies, in Flex this is particularly useful when its <a href="http://www.flexafterdark.com/docs/Flex-Modules" target="_blank">Module</a> functionality is leveraged, as it creates clear and easy cut points.  The disadvantages of this pattern is that it can be relatively verbose and sometimes requires information to be passed through view model instances in order to appropriately traverse the display tree.  However, as I&#8217;ll show in the worked example below, the <a href="http://mate.asfusion.com/" target="_blank">Mate framework</a> provides some mechanisms that can drastically reduce the latter problem.</p>
<h4>Mate</h4>
<p><a href="http://mate.asfusion.com/" target="_blank">Mate</a> is an event-driven Flex framework that provides both <a href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">dependency injection</a> and mechanisms to &#8220;glue&#8221; your code together, thereby enabling you to produce very loosely coupled code.  The worked example below assumes some basic understanding of how Mate works, so if it is unfamiliar I recommend at least running through their <a href="http://mate.asfusion.com/page/documentation/getting-started" target="_blank">Getting Started</a> tutorial.  There are also other excellent <a href="" target="_blank">introductory articles</a> and <a href="http://mate.asfusion.com/page/examples" target="_blank">examples</a>.</p>
<h2>Worked Example</h2>
<p>Here follows a worked example showing how the <a href="http://mate.asfusion.com/" target="_blank">Mate framework</a> can be leveraged to not only use the <a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Presentation Model</a> architectural pattern, but also add further elegance by using some of its core features.  As previously mentioned, <a href="http://www.flexstuff.co.uk/" target="_blank">Gilles Guillemin</a> has produced an excellent <a href="http://www.flexstuff.co.uk/tag/mate-framework/" target="_blank">set of articles introducing Mate</a>, and he even has an article that focuses on the exact same topic as this article.  Unfortunately, <a href="http://www.flexstuff.co.uk/2009/08/25/mate-examples-10-presentation-model/" target="_blank">his Presentation Model article</a> does not continue with the nice example application he used in his <a href="http://www.flexstuff.co.uk/tag/mate-framework/" target="_blank">previous articles</a> and instead uses an overly simplistic example that does not present an overly compelling case.</p>
<p>The example below applies the Presentation Model (or MVVM) architectural pattern to the example Gilles Guillemin created for his <a href="http://www.flexstuff.co.uk/tag/mate-framework/" target="_blank">introductory series to Mate</a>.  That is, an application with a global count that can be increased and decreased both directly and by manipulating a dynamic number of counters.  Each counter maintains a sub-total that is the sum of its two sub-counters.  Additionally, there is a global countdown that on reaching 0 resets all counts at all levels.</p>
<p>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="705" height="600" align="center">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/01/MatePresentationModel.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/01/MatePresentationModel.swf" width="705" height="600" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<span style="font-size: 0.8em; font-style: italic;"><a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/01/MatePresentationModel-src.zip'>Source code</a></span></p>
<h4>Core code</h4>
<p>In order to not get too bogged down in application specifics and better focus on how Presentation Model (or MVVM) and Mate are used, I will focus on the sub-counter block of the user interface and logic.  As shown in the class diagram below, the entities involved are: the view, <code>SubCounterView</code>; the view model interface, <code>ISubCounterViewModel</code>; and, an implementation of the view model interface, <code>SubCounterViewModel</code>.  The diagram also shows how I have added some unifying interfaces for views and view models and a base class for view models containing some common functionality (more detail on this later when explaining the Mate-related specifics).</p>
<p><em>The observant among you will have spotted that there are no model classes mentioned.  This is because in this particular example the models are the integer counts and as such do not require a custom class type.  In more real-world applications it would be normal to have custom model classes that are used by the view models to maintain state.</em></p>
<p><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/01/presentation_model.png" alt="Presentation Model UML" title="presentation_model" width="701" height="415" class="aligncenter size-full wp-image-460" /><br />
<span style="font-size: 0.8em; font-style: italic;">Class diagram abstractly showing presentation model example</span></p>
<p>The <code>SubCounterView</code> MXML consists of the viewModel property, a Mate <a href="http://mate.asfusion.com/page/documentation/tags/localeventmap" target="_blank">map</a> (more detail on this later when explaining the Mate-related specifics), a <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/containers/Grid.html" target"_blank">Grid</a> to neatly lay out the local and sub-total counts and a couple of buttons to increase and decrease the local count.  All state, such as the two count labels, is observed from the view model using binding and all logic/behaviour, such as the count increasing and decreasing, is delegated to the view model:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:VBox</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:map</span>=<span style="color: #ff0000;">&quot;maps.*&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">implements</span>=<span style="color: #ff0000;">&quot;views.IView&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">            import viewModels.ISubCounterViewModel;</span>
<span style="color: #339933;">            import viewModels.IViewModel;</span>
&nbsp;
<span style="color: #339933;">            [Bindable]</span>
<span style="color: #339933;">            private var _viewModel:ISubCounterViewModel;</span>
<span style="color: #339933;">            /**</span>
<span style="color: #339933;">             * @see IView.viewModel</span>
<span style="color: #339933;">             */</span>
<span style="color: #339933;">            public function get viewModel():IViewModel</span>
<span style="color: #339933;">            {</span>
<span style="color: #339933;">                return _viewModel;</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">            /**</span>
<span style="color: #339933;">             * @private</span>
<span style="color: #339933;">             */</span>
<span style="color: #339933;">            public function set viewModel(value:IViewModel):void</span>
<span style="color: #339933;">            {</span>
<span style="color: #339933;">                if (!(value is ISubCounterViewModel))</span>
<span style="color: #339933;">                {</span>
<span style="color: #339933;">                    throw new Error(&quot;ISubCounterViewModel instance expected&quot;);</span>
<span style="color: #339933;">                }</span>
<span style="color: #339933;">                _viewModel = ISubCounterViewModel(value);</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;map:SubCounterViewMap</span> <span style="color: #000066;">dispatcher</span>=<span style="color: #ff0000;">&quot;{this}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Grid</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:GridRow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:GridItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Subtotal:&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:GridItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:GridItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{_viewModel.subTotal}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:GridItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:GridRow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:GridRow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:GridItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Amount:&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:GridItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:GridItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;{_viewModel.count}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:GridItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:GridRow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;+&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;_viewModel.increaseCount()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;_viewModel.decreaseCount()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:VBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>As can be seen in the above code and class diagram, the view is tied to a view model interface rather than concrete class.  Although this may seem unnecessarily verbose it brings some powerful benefits.  it allows different view models, and therefore different logic and behaviour, to be used with the same view (i.e. <a href="http://en.wikipedia.org/wiki/Inversion_of_control" target="_blank">inversion of control</a>).  This is both a relatively common code requirement and a useful mechanism for activities such as testing.  It allows for the potential case of a single view model being shared across multiple views.  A final (more arguable) benefit is that it encourages the developer to focus solely on the view rather than be distracted by behavioural details.</p>
<p>The <code>ISubCounterViewModel</code> interface looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Interface for any presentation model that is to be used
 * with the SubCounterView view.
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">interface</span> ISubCounterViewModel <span style="color: #0066CC;">extends</span> IViewModel
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;subTotalChanged&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #808080; font-style: italic;">/**
	 * The total of all grouped sub-counter's counts.
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> subTotal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>;
	<span style="color: #808080; font-style: italic;">/**
	 * @private
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> subTotal<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
&nbsp;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;countChanged&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #808080; font-style: italic;">/**
	 * The local count.
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> count<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Increases the local count.
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> increaseCount<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Decreases the local count.
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> decreaseCount<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The implementation of the interface, <code>SubCounterViewModel</code>, then looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Default implementation of ISubCounterViewModel.
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SubCounterViewModel <span style="color: #0066CC;">extends</span> ViewModelBase <span style="color: #0066CC;">implements</span> ISubCounterViewModel
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SUB_TOTAL_CHANGED:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;subTotalChanged&quot;</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const COUNT_CHANGED:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;countChanged&quot;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//------------------------------------</span>
	<span style="color: #808080; font-style: italic;">//</span>
	<span style="color: #808080; font-style: italic;">//           Constructor</span>
	<span style="color: #808080; font-style: italic;">//</span>
	<span style="color: #808080; font-style: italic;">//------------------------------------</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Constructor
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SubCounterViewModel<span style="color: #66cc66;">&#40;</span>dispatcher:IEventDispatcher<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span>dispatcher<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #808080; font-style: italic;">//------------------------------------</span>
	<span style="color: #808080; font-style: italic;">//</span>
	<span style="color: #808080; font-style: italic;">//           Properties</span>
	<span style="color: #808080; font-style: italic;">//</span>
	<span style="color: #808080; font-style: italic;">//------------------------------------</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//----------------------------------</span>
	<span style="color: #808080; font-style: italic;">//  subTotal</span>
	<span style="color: #808080; font-style: italic;">//----------------------------------</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _subTotal:<span style="color: #0066CC;">int</span>;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;subTotalChanged&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #808080; font-style: italic;">/**
	 * @see ISubCounterViewModel.subTotal
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> subTotal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> _subTotal;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/**
	 * @private
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> subTotal<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>value <span style="color: #66cc66;">!</span>= _subTotal<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_subTotal = value;
			dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>SUB_TOTAL_CHANGED<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//----------------------------------</span>
	<span style="color: #808080; font-style: italic;">//  count</span>
	<span style="color: #808080; font-style: italic;">//----------------------------------</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _count:<span style="color: #0066CC;">int</span>;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;countChanged&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #808080; font-style: italic;">/**
	 * @see ISubCounterViewModel.count
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> count<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> _count;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/**
	 * @private
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> count<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>value <span style="color: #66cc66;">!</span>= _count<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_count = value;
			dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>COUNT_CHANGED<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #808080; font-style: italic;">//------------------------------------</span>
	<span style="color: #808080; font-style: italic;">//</span>
	<span style="color: #808080; font-style: italic;">//           Functions</span>
	<span style="color: #808080; font-style: italic;">//</span>
	<span style="color: #808080; font-style: italic;">//------------------------------------</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * @see ISubCounterViewModel.increaseCount
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> increaseCount<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		count++;
		subTotal++;
&nbsp;
		<span style="color: #808080; font-style: italic;">// inform everyone else that the count has changed</span>
		dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CountEvent<span style="color: #66cc66;">&#40;</span>CountEvent.<span style="color: #006600;">LOCAL_UPDATE</span>, _subTotal<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * @see ISubCounterViewModel.decreaseCount
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> decreaseCount<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		count--;
		subTotal--;
&nbsp;
		<span style="color: #808080; font-style: italic;">// inform everyone else that the count has changed</span>
		dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CountEvent<span style="color: #66cc66;">&#40;</span>CountEvent.<span style="color: #006600;">LOCAL_UPDATE</span>, _subTotal<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The <code>count</code> and <code>subTotal</code> properties are straightforward <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.html" target="_blank">Bindable</a> properties with custom binding events.  The <code>increaseCount</code> and <code>decreaseCount</code> methods are also very simple: they increase or decrease both the local count and the sub-total and then dispatch an event to inform that the sub-total has changed.  The assumption here is that its local knowledge of the sub-total is correct and that it will appropriately be informed if that sub-total is changed elsewhere (much as it informs &#8220;others&#8221; of any change it makes, by dispatching the <code>CountEvent</code>).  By making this assumption and using events for functional communication rather than explicit method calls we introduce loose coupling by using the <a href="http://en.wikipedia.org/wiki/Observer_pattern" target="_blank">observer pattern</a>.  Normally this would require some quite messy code to introduce and handle, but, as I will show, the Mate framework provides mechanisms that elegantly support this approach.</p>
<h4>Glueing everything together</h4>
<p>At this point we have all the constituent parts of the application, but they are not actually combined together in any functional way.  Mate&#8217;s <a href="http://mate.asfusion.com/page/documentation/tags/eventmap" target="_blank">EventMap</a> and <a href="http://mate.asfusion.com/page/documentation/tags/localeventmap" target="_blank">LocalEventMap</a> components are a powerful mechanism whereby this glue code can be introduced with minimal impact on any of the core code and easily swapped in and out.  As exemplified in the <code>SubCounterView</code> code, maps are introduced as a simple MXML tag and beyond that are entirely self-contained.  They leverage Flex&#8217;s <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=events_08.html" target="_blank">event mechanism</a> by hooking into an application&#8217;s <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=05_Display_Programming_02.html" target="_blank">display tree</a>, either at the global <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html" target="_blank">stage</a> level in the case of EventMap or at the level of a specific <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html" target="_blank">DisplayObject</a> in the case of LocalEventMap (see how the <a href="http://mate.asfusion.com/api_docs/com/asfusion/mate/core/LocalEventMap.html#dispatcher" target="_blank">dispatcher</a> of the <code>SubCounterViewMap</code> in the <code>SubCounterView</code> above is set to be the view).  To achieve better separation of concerns (and to avoid coding using what can quickly become little more than a global variable mechanism) LocalEventMaps are always preferable to EventMaps.</p>
<p>The first part of pulling the parts of the application together is to appropriately combine views with their view model instances.  Mate&#8217;s map components allow us to inject these dependencies <a href="http://mate.asfusion.com/page/documentation/tags/injectors" target="_blank">Injectors</a> tags.  The Injectors component can target any class instance that is added to the <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=05_Display_Programming_02.html" target="_blank">display tree</a> below the map&#8217;s dispatcher or that is created within the scope of the map.  With this hook, an <a href="http://mate.asfusion.com/page/documentation/tags/objectbuilder" target="_blank">ObjectBuilder</a> is used to create the desired view model before being injected into the view using the <a href="http://mate.asfusion.com/page/documentation/tags/propertyinjector" target="_blank">PropertyInjector</a>.  This way we can very specifically target (and easily change) any desired view/view-model combinations.  Here is what combining the <code>SubCounterView</code> with its <code>SubCounterViewModel</code> looks like in the <code>SubCounterViewMap</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mate:Injectors</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;{SubCounterView}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mate:ObjectBuilder</span></span>
<span style="color: #009900;">        <span style="color: #000066;">generator</span>=<span style="color: #ff0000;">&quot;{SubCounterViewModel}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">constructorArguments</span>=<span style="color: #ff0000;">&quot;{scope.dispatcher}&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mate:PropertyInjector</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;{lastReturn}&quot;</span> <span style="color: #000066;">targetKey</span>=<span style="color: #ff0000;">&quot;viewModel&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mate:Injectors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The second part of glue code required for the fully functional application is to turn the event communication assumption(s) of the view models (see <code>SubCounterViewModel</code> code and explanation above) into reality.  Once again, Mate&#8217;s map components form the basis, but here it is the <a href="http://mate.asfusion.com/page/documentation/tags/eventhandlers" target="_blank">EventHandlers</a> tag that provides the desired hook.  The EventHandlers component allows a response to any event <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=events_08.html" target="_blank">bubbled</a> past the map&#8217;s dispatcher (or globally, depending on both the map type and the EventHandlers own <a href="http://mate.asfusion.com/api_docs/com/asfusion/mate/actionLists/AbstractHandlers.html#dispatcherType" target="_blank">dispatcherType</a>).  This response can be any sequence of <a href="http://mate.asfusion.com/api_docs/com/asfusion/mate/actions/IAction.html" target="_blank">actions</a>, such as invoking a method on a class (<a href="http://mate.asfusion.com/page/documentation/tags/methodinvoker" target="_blank">MethodInvoker</a>), setting a property (<a href="http://mate.asfusion.com/api_docs/com/asfusion/mate/actions/builders/PropertySetter.html" target="_blank">PropertySetter</a>) or even creating another event (<a href="http://mate.asfusion.com/page/documentation/tags/eventannouncer" target="_blank">EventAnnouncer</a>).  An example from the application above is the reset event that is dispatched when the countdown reaches zero and all counters should be reset.  For the <code>SubCounterViewModel</code> this is handled by setting the zero value from the reset as its local count value, as shown in the following code snippet from <code>SubCounterViewMap</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mate:EventHandlers</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;{CountEvent.RESET}&quot;</span> <span style="color: #000066;">dispatcherType</span>=<span style="color: #ff0000;">&quot;global&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mate:PropertySetter</span></span>
<span style="color: #009900;">        <span style="color: #000066;">generator</span>=<span style="color: #ff0000;">&quot;{SubCounterViewModel}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;event&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">sourceKey</span>=<span style="color: #ff0000;">&quot;newCount&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">targetKey</span>=<span style="color: #ff0000;">&quot;count&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mate:EventHandlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><em>As shown in the class diagram and <code>SubCounterViewModel</code> code above (and highlighted by the ObjectBuilder in the view/view-model injection code above), the view model classes all require a reference to an <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/IEventDispatcher.html" target="_blank">IEventDispatcher</a> instance to act as its event dispatcher despite themselves also being IEventDispatcher implementations.  This is the compromise required to use Presentation Model in conjunction with Mate.  As previously mentioned, Mate&#8217;s key components, EventMap and LocalEventMap, hook into the display tree&#8217;s event hierarchy.  Therefore, the view model classes must dispatch their events into the display tree to appropriately tie in with the maps.  Hence the IEventDispatcher reference required by all view models.  Fortunately this functionality is easily captured by a common base class for all view models in such a way that this becomes all but transparent to specific view model types.  See the <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/01/MatePresentationModel-src.zip'>source code</a> for the worked example for further details.</em></p>
<p>And there you have it, the Presentation Model (or MVVM) building blocks and how to combine them into an application using the Mate framework in such a way that the various concerns of the code are cleanly separated.</p>
<h4>Testing</h4>
<p>As mentioned in the background information, testability is one of the strong drivers behind the Presentation Model (or MVVM) architectural pattern.  To highlight this, the <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/01/MatePresentationModel-src.zip'>source code</a> for the example above includes unit tests (using <a href="http://opensource.adobe.com/wiki/display/flexunit/FlexUnit" target="_blank">FlexUnit</a>) for, amongst others, the view model classes, thereby showing how the pattern allows testing of view-related logic.  By appropriately using interfaces and <a href="http://en.wikipedia.org/wiki/Inversion_of_control" target="_blank">inversion of control</a> throughout, the testability of the code is further enhanced as this allows us to leverage <a href="http://en.wikipedia.org/wiki/Mock_object" target="_blank">mock objects</a> in the unit tests.  I have used <a href="http://code.google.com/p/mock4as/" target="_blank">Mock4AS</a> because I happened to have it to hand, but there are several other good mocking libraries for ActionScript, such as <a href="http://asmock.sourceforge.net/" target="_blank">asMock</a> and <a href="http://mockolate.org/mockolate.html" target="_blank">Mockolate</a>, so take a look at the different ones and pick your favourite (I don&#8217;t have one yet).</p>
<h2>Summary</h2>
<p>Hopefully this article has highlighted the reason to consider the design of your Flex application in order to improve its maintainability and testability, and has introduced the <a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Presentation Model</a> pattern coupled with the <a href="http://mate.asfusion.com/" target="_blank">Mate Framework</a> as one of the potential approaches to solving these problems.  I have only introduced a small sub-set of Mate&#8217;s components and their capabilities so would encourage you to delve deeper into the <a href="http://mate.asfusion.com/page/documentation" target="_blank">documentation</a>, <a href="http://mate.asfusion.com/page/resources" target="_blank">tutorials</a> and <a href="http://mate.asfusion.com/page/examples" target="_blank">examples</a> to gain a better understanding of the full Mate framework and its subtleties even if you are not interested in the Presentation Model pattern.</p>
<p>You can download the full source code for the Flex example given in this blog post here: <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/01/MatePresentationModel-src.zip'>MatePresentationModel-src.zip</a>.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2011/01/presentation-model-with-mate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex Charts vs Silverlight Charts &#8211; a test of Performance</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2010/11/flex-charts-vs-silverlight-charts-a-test-of-performance/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2010/11/flex-charts-vs-silverlight-charts-a-test-of-performance/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 09:02:27 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Charts]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=368</guid>
		<description><![CDATA[This post follows on from the comparison of two Silverlight chart libraries produced by my colleague, Colin Eberhardt, by adding an implementation of the simple image processing tool in Flex using the Flex Charting library to the comparison. The results show that the Flex Charts perform easily as well as the Visiblox charts without the [...]]]></description>
			<content:encoded><![CDATA[
<p><em>This post follows on from the <a href="http://www.scottlogic.co.uk/blog/colin/2010/11/visiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2/" target="_blank">comparison of two Silverlight chart libraries</a> produced by my colleague, <a href="http://www.scottlogic.co.uk/blog/colin/" target="_blank">Colin Eberhardt</a>, by adding an implementation of the simple image processing tool in <a href="http://www.adobe.com/devnet/flex.html" target="_blank">Flex</a> using the <a href="http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf65518-7ff9.html" target="_blank">Flex Charting</a> library to the comparison.  The results show that the Flex Charts perform easily as well as the Visiblox charts without the need to specifically consider performance.</em></p>
<p>Since <a href="http://www.scottlogic.co.uk/blog/colin/" target="_blank">Colin</a> produced his comparison of the <a href="http://www.silverlight.net/content/samples/sl2/toolkitcontrolsamples/run/default.html" target="_blank">Silverlight Toolkit</a> and <a href="http://www.visiblox.com/" target="_blank">Visiblox</a> charts there has been some noted interest in how <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash</a> stacks up against them.  This seems to be part of a general drive across the development community to gain a better understanding of the relative strengths of Flash/Flex, Silverlight and HTML5.  In order to contribute a little to this, I produced a comparable application to those of Colin using the charting library that is part of the free, open-source <a href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4" target="_blank">Flex 4 SDK</a>.</p>
<p>Here are my Flex application and the &#8220;winning&#8221; application from Colin&#8217;s investigation side-by-side.  Click and drag a line across the image to plot the RGB pixel intensities along the line in the chart above.  From these examples, it is clear that there is little to differentiate them performance-wise.</p>
<table>
<tr>
<th style="text-align: center;">Flex Chart</th>
<th style="text-align: center;">Visiblox Chart</th>
</tr>
<tr>
<td style="text-align:center;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_3" width="280" height="380">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/11/FlexChartsPerformance.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/11/FlexChartsPerformance.swf" width="280" height="380">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
</td>
<td style="text-align:center;">
<object height="400" width="300" type="application/x-silverlight-2" data="data:application/x-silverlight,"><param value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/HistogramVisiblox.xap" name="source"><a style="text-decoration: none;" href="http://go.microsoft.com/fwlink/?LinkID=124807"><br />
<img style="border-style: none;" alt="Get Microsoft Silverlight" src="http://go.microsoft.com/fwlink/?LinkId=108181"><br />
</a><br />
</object>
</td>
</tr>
</table>
<p><span style="font-size: 0.8em;">[Squirrel image used royalty free from <a href="http://www.sxc.hu/photo/1079708" target="_blank">stock.xchng</a>; hare image used under CC licence from <a href="http://www.flickr.com/photos/heliocentric/2643028940/" target="_blank">flickr</a>]</span></p>
<h2>Implementation</h2>
<p>For details of the implementation of the Visiblox example above, see <a href="http://www.scottlogic.co.uk/blog/colin/2010/11/visiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2/">the original post</a>.  The mark-up for the Flex example above is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Application</span> <span style="color: #000066;">xmlns:fx</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">xmlns:s</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:VerticalLayout</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fx:Declarations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:SolidColorStroke</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;axisStroke&quot;</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#cccccc&quot;</span> <span style="color: #000066;">weight</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fx:Declarations<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Group</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:CartesianChart</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;chart&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">visible</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:horizontalAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:LinearAxis</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;xAxis&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:horizontalAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:horizontalAxisRenderers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:AxisRenderer</span> <span style="color: #000066;">axis</span>=<span style="color: #ff0000;">&quot;{xAxis}&quot;</span> <span style="color: #000066;">axisStroke</span>=<span style="color: #ff0000;">&quot;{axisStroke}&quot;</span></span>
<span style="color: #009900;">                                 <span style="color: #000066;">showLabels</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">tickPlacement</span>=<span style="color: #ff0000;">&quot;none&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:horizontalAxisRenderers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:verticalAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:LinearAxis</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;yAxis&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:verticalAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:verticalAxisRenderers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:AxisRenderer</span> <span style="color: #000066;">axis</span>=<span style="color: #ff0000;">&quot;{yAxis}&quot;</span> <span style="color: #000066;">axisStroke</span>=<span style="color: #ff0000;">&quot;{axisStroke}&quot;</span></span>
<span style="color: #009900;">                                 <span style="color: #000066;">tickPlacement</span>=<span style="color: #ff0000;">&quot;outside&quot;</span> <span style="color: #000066;">tickStroke</span>=<span style="color: #ff0000;">&quot;{axisStroke}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:verticalAxisRenderers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:LineSeries</span> <span style="color: #000066;">yField</span>=<span style="color: #ff0000;">&quot;red&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:lineStroke<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:SolidColorStroke</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#aa0000&quot;</span> <span style="color: #000066;">weight</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:lineStroke<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:LineSeries</span> <span style="color: #000066;">yField</span>=<span style="color: #ff0000;">&quot;green&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:lineStroke<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:SolidColorStroke</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#00aa00&quot;</span> <span style="color: #000066;">weight</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:lineStroke<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:LineSeries</span> <span style="color: #000066;">yField</span>=<span style="color: #ff0000;">&quot;blue&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:lineStroke<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:SolidColorStroke</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#0000aa&quot;</span> <span style="color: #000066;">weight</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:lineStroke<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:CartesianChart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Label</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;instructions&quot;</span> <span style="color: #000066;">visible</span>=<span style="color: #ff0000;">&quot;{!chart.visible}&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">horizontalCenter</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">verticalCenter</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">fontSize</span>=<span style="color: #ff0000;">&quot;9&quot;</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#cccccc&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Use the mouse to 'drag' a line across the image below.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Image</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;image&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;@Embed(source='squirrel.jpg')&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">mouseDown</span>=<span style="color: #ff0000;">&quot;imageMouseDownHandler(event)&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">mouseUp</span>=<span style="color: #ff0000;">&quot;imageMouseUpHandler(event)&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">mouseMove</span>=<span style="color: #ff0000;">&quot;imageMouseMoveHandler(event)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Line</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;line&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:stroke<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:SolidColorStroke</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#000000&quot;</span> <span style="color: #000066;">weight</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:stroke<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Line<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The above mark-up creates two <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/Group.html" target="_blank">Groups</a>: one containing the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/chartClasses/CartesianChart.html" target="_blank">CartesianChart</a> and instructions, and the other the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Image.html" target="_blank">Image</a> and <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/primitives/Line.html" target="_blank">Line</a>.  This is remarkably similar to the mark-up of Colin&#8217;s Silverlight examples, if slightly more verbose.  The verboseness is the result of both <a href="http://www.adobe.com/devnet/flex.html" target="_blank">Flex</a> technicalities and my overriding the rather ugly default styles axis styles for aesthetic reasons.  Note that the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/chartClasses/CartesianChart.html" target="_blank">CartesianChart</a> was used rather than <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/LineChart.html" target="_blank">LineChart</a> purely because of the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/LineChart.html" target="_blank">LineChart</a> using the ugly <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/renderers/ShadowLineRenderer.html" target="_blank">ShadowLineRenderer</a> by default for <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/series/LineSeries.html" target="_blank">LineSeries</a> (the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/chartClasses/CartesianChart.html" target="_blank">CartesianChart</a> uses the simple <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/charts/renderers/LineRenderer.html" target="_blank">LineRenderer</a>).</p>
<p>Unlike in Silverlight, there is no need to do anything <a href="http://www.scottlogic.co.uk/blog/colin/2010/06/throttling-silverlight-mouse-events-to-keep-the-ui-responsive/" target="_blank">funky</a> with mouse event handling Flex, as the <a href="http://www.developmentarc.com/site/wp-content/uploads/pdfs/understanding_the_flex_3_lifecycle_v1.0.pdf" target="_blank">Flex component lifecycle</a> means the UI will always have a chance to render.  This means a simple mouse move event handler can be used to construct the chart&#8217;s data:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> imageMouseMoveHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>_mouseDown<span style="color: #000000;">&#41;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	line<span style="color: #000066; font-weight: bold;">.</span>xTo = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">localX</span><span style="color: #000066; font-weight: bold;">;</span>
	line<span style="color: #000066; font-weight: bold;">.</span>yTo = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">localY</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// compute length of line</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sqrt</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">.</span>xFrom <span style="color: #000066; font-weight: bold;">-</span> line<span style="color: #000066; font-weight: bold;">.</span>xTo<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span>
				   <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">.</span>yFrom <span style="color: #000066; font-weight: bold;">-</span> line<span style="color: #000066; font-weight: bold;">.</span>yTo<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// build the chart data</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>image<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">content</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> chartData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> xIndex<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> yIndex<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> pixel<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> point<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		point= <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span>
		xIndex = line<span style="color: #000066; font-weight: bold;">.</span>xFrom <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">.</span>xTo <span style="color: #000066; font-weight: bold;">-</span> line<span style="color: #000066; font-weight: bold;">.</span>xFrom<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> i <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
		yIndex = line<span style="color: #000066; font-weight: bold;">.</span>yFrom <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>line<span style="color: #000066; font-weight: bold;">.</span>yTo <span style="color: #000066; font-weight: bold;">-</span> line<span style="color: #000066; font-weight: bold;">.</span>yFrom<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> i <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
		pixel = <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getPixel</span><span style="color: #000000;">&#40;</span>xIndex<span style="color: #000066; font-weight: bold;">,</span> yIndex<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		point<span style="color: #000066; font-weight: bold;">.</span>red = pixel <span style="color: #000066; font-weight: bold;">&amp;</span> 0xff<span style="color: #000066; font-weight: bold;">;</span>
		pixel <span style="color: #000066; font-weight: bold;">&gt;&gt;</span>= <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span>
		point<span style="color: #000066; font-weight: bold;">.</span>green = pixel <span style="color: #000066; font-weight: bold;">&amp;</span> 0xff<span style="color: #000066; font-weight: bold;">;</span>
		pixel <span style="color: #000066; font-weight: bold;">&gt;&gt;</span>= <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span>
		point<span style="color: #000066; font-weight: bold;">.</span>blue = pixel <span style="color: #000066; font-weight: bold;">&amp;</span> 0xff<span style="color: #000066; font-weight: bold;">;</span>
		chartData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	chart<span style="color: #000066; font-weight: bold;">.</span>dataProvider = chartData<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Once again, this code is very similar to that used in the Silverlight examples to construct chart data.  However, notice that here we can choose to take advantage of ActionScript 3&#8242;s dynamic objects to drive our chart for simplicity&#8217;s sake.  Furthermore, there has also been no need to pre-process the image data to obtain pixel information since the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Image.html" target="_blank">Image</a>, <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Bitmap.html" target="_blank">Bitmap</a> and <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html" target="_blank">BitmapData</a> classes are designed and optimised for exactly this kind of pixel-level manipulation.</p>
<h2>Conclusions</h2>
<p>From the above examples it is apparent that there is little, if anything, to differentiate their relative performance.  Furthermore, it would be fair to say that the outright technology choice of Flash/Flex or Silverlight has not differentiated these examples.  Rather, the choice of charting library in either technology is far more significant with respect to performance.  Therefore, in this case, the technology choice would have to be driven by some other factor than performance, for example, plug-in penetration, cost or existing developer expertise.</p>
<p>However, at a more technical level there are some interesting points to consider alongside the comparative performance of the two applications.  The Silverlight examples were created with specific techniques for improving their performance.  The implication is that a naive Silverlight implementation of the application is likely to have noticeable performance issues.  In contrast, the Flex example has purposefully been created without any of the known performance improvement techniques, yet is still as responsive.</p>
<p>It is also worthwhile contrasting the respective charting libraries.  The Visiblox charting library has specifically been designed for performance over flexibility, where as the Flex charting library is the opposite.  The result is that although they are roughly equal in performance, the Flex charting library has many more options for customisation and extension than the Visiblox charting library.  However, it should be noted that the Flex charting library is relatively mature (~4 years old) compared to the Visiblox charts (~2 months old).</p>
<p>You can download the full source code for the Flex example given in this blog post here: <a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/11/FlexChartPerformance.zip" target="_blank">FlexChartPerformance.zip</a>; and the full source code for the Silverlight examples given in Colin&#8217;s blog post here: <a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/10/ChartPerformance.zip" target="_blank">ChartPerformance.zip</a></p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2010/11/flex-charts-vs-silverlight-charts-a-test-of-performance/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Logging to Server from Flex</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2010/08/logging-to-server-from-flex/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2010/08/logging-to-server-from-flex/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 15:22:01 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=343</guid>
		<description><![CDATA[An issue that can crop up with Flex applications is the lack of any log information to match up against users&#8217; bug reports. It is possible to configure the debug version of Flash Player to record trace() output, but most users do not have this setup. Additionally, it is much more desirable to maintain this [...]]]></description>
			<content:encoded><![CDATA[
<p>An issue that can crop up with Flex applications is the lack of any log information to match up against users&#8217; bug reports.  It is possible to <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=logging_07.html" target="_blank">configure</a> the debug version of Flash Player to record <a href="http://livedocs.adobe.com/flex/3/langref/package.html#trace%28%29" target="_blank">trace()</a> output, but most users do not have this setup.  Additionally, it is much more desirable to maintain this kind of information server-side, where the development team have control, rather than relying on users&#8217; whilst also clogging up their machines.  A general approach to this problem is relatively obvious &#8211; send the information back to the server &#8211; but there are all sorts of ways this could be implemented.  Of course, sending lots of logging information to the server creates an overhead in the application, so this should very much be considered on a case by case basis.</p>
<p>A solution that we use takes advantage of Flex&#8217;s native <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=logging_09.html" target="_blank">logging API</a>, allowing it to be transparently added or removed from an application while providing us with the benefits of a decent logging framework, for example logging levels.  Flex provides the <a href="http://livedocs.adobe.com/flex/3/langref/mx/logging/ILogger.html" target="_blank">ILogger</a> class, instances of which are obtained using <a href="http://livedocs.adobe.com/flex/3/langref/mx/logging/Log.html" target="_blank">Log</a>&#8216;s <a href="http://livedocs.adobe.com/flex/3/langref/mx/logging/Log.html#getLogger%28%29" target="_blank">getLogger()</a> method, to log messages.  In turn, these messages are sent to one or more <a href="http://livedocs.adobe.com/flex/3/langref/mx/logging/ILoggingTarget.html" target="_blank">ILoggingTargets</a>, the most common of which, <a href="http://livedocs.adobe.com/flex/3/langref/mx/logging/targets/TraceTarget.html" target="_blank">TraceTarget</a> outputs the logging information using the <a href="http://livedocs.adobe.com/flex/3/langref/package.html#trace%28%29" target="_blank">trace()</a> method.  The <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=logging_09.html">logging API documentation</a> provides details and examples for how to get started with this basic logging setup.</p>
<p>On the Flex side, our solution consists of little more than a custom <a href="http://livedocs.adobe.com/flex/3/langref/mx/logging/ILoggingTarget.html" target="_blank">ILoggingTarget</a> implementation, <a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/08/RemoteLogging.zip" target="_blank">RemoteTarget</a>, that attempts to send the logging information to a specified URL and the appropriate code to initialise the target.  Note that <a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/08/RemoteLogging.zip" target="_blank">RemoteTarget</a> uses <a href="http://livedocs.adobe.com/flex/3/langref/flash/net/URLLoader.html" target="_blank">URLLoaders</a> rather than <a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/http/HTTPService.html" target="_blank">HTTPServices</a> because <a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/http/HTTPService.html" target="_blank">HTTPService</a> itself uses the logging API, thereby causing an infinite loop.  Another feature worth highlighting is that our implementation stops logging if it has encounters any errors when sending the information to the server, so that, for example, an application does not repeatedly hit a server that is unavailable.  All source code and examples associated with this article can be found <a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/08/RemoteLogging.zip" target="_blank">here</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>scottlogic<span style="color: #000066; font-weight: bold;">.</span>logging
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLLoader</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequest</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLVariables</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>logging<span style="color: #000066; font-weight: bold;">.</span>AbstractTarget<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>logging<span style="color: #000066; font-weight: bold;">.</span>ILogger<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>logging<span style="color: #000066; font-weight: bold;">.</span>LogEvent<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>StringUtil<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #3f5fbf;">/**
     * ILoggingTarget implementation that sends logging details
     * to a remote service.  The following details are sent as
     * request parameters:
     *  - level: the log level as an integer (see LogEventLevel)
     *  - category: the log category
     *  - timestamp: as milliseconds from 1st Jan 1970
     *  - message: the log message
     */</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> RemoteTarget <span style="color: #0033ff; font-weight: bold;">extends</span> AbstractTarget
    <span style="color: #000000;">&#123;</span>
        <span style="color: #3f5fbf;">/**
         * Flag to indicate whether remote logging is enabled
         * or not.  The RemoteTarget will automatically disable
         * itself if it encounters any errors.
         */</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">enabled</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #3f5fbf;">/**
         * Constructor
         */</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> RemoteTarget<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _url<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #3f5fbf;">/**
         * The URL of the service to which to log.
         */</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">url</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> _url<span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #3f5fbf;">/**
         * @private
         */</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">url</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            _url = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #3f5fbf;">/**
         * @private
         */</span>
        override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> logEvent<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>LogEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #009900; font-style: italic;">// if there has been any issue with remote logging</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">enabled</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #009900; font-style: italic;">// if no url is set then do nothing</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>_url <span style="color: #000066; font-weight: bold;">||</span> StringUtil<span style="color: #000066; font-weight: bold;">.</span>trim<span style="color: #000000;">&#40;</span>_url<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// attempt to log to the server</span>
            <span style="color: #0033ff; font-weight: bold;">try</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> variables<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLVariables</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLVariables</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                variables<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">level</span> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">level</span><span style="color: #000066; font-weight: bold;">;</span>
                variables<span style="color: #000066; font-weight: bold;">.</span>category = ILogger<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>category<span style="color: #000066; font-weight: bold;">;</span>
                variables<span style="color: #000066; font-weight: bold;">.</span>timestamp = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">time</span><span style="color: #000066; font-weight: bold;">;</span>
                variables<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span>_url<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">method</span> = <span style="color: #990000;">&quot;POST&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = variables<span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = createLoader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getStackTrace</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #3f5fbf;">/**
         * Creates a URLLoader with all the appropriate event listeners.
         */</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createLoader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span>
                                    ioErrorHandler<span style="color: #000066; font-weight: bold;">,</span>
                                    <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SECURITY_ERROR</span><span style="color: #000066; font-weight: bold;">,</span>
                                    securityErrorHandler<span style="color: #000066; font-weight: bold;">,</span>
                                    <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #3f5fbf;">/**
         * Disables the remote logging and traces debug information
         * when there is an IO error during logging to the remote server.
         */</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> ioErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ERROR - IO error in RemoteTarget&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #3f5fbf;">/**
         * Disables the remote logging and traces debug information
         * when there is a security error during logging to the remote
         * server.
         */</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> securityErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ERROR - Security error in RemoteTarget&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Here is a small example showing how <a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/08/RemoteLogging.zip" target="_blank">RemoteTarget</a> can be used:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;horizontal&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">applicationComplete</span>=<span style="color: #ff0000;">&quot;initialise()&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">            import com.scottlogic.logging.RemoteTarget;</span>
<span style="color: #339933;">            import mx.logging.Log;</span>
<span style="color: #339933;">            import mx.logging.LogEventLevel;</span>
<span style="color: #339933;">            import mx.logging.ILogger;</span>
&nbsp;
<span style="color: #339933;">            private static const LOG:ILogger = Log.getLogger(&quot;RemoteLogging&quot;);</span>
&nbsp;
<span style="color: #339933;">            private function initialise():void</span>
<span style="color: #339933;">            {</span>
<span style="color: #339933;">                var target:RemoteTarget = new RemoteTarget();</span>
<span style="color: #339933;">                target.url = &quot;&quot;; // set logging service URL here</span>
<span style="color: #339933;">                target.level = LogEventLevel.INFO;</span>
<span style="color: #339933;">                Log.addTarget(target);</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Text:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;input&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Log Text&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;LOG.info(input.text);&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>As the information is being sent back as a standard <a href="http://en.wikipedia.org/wiki/HTTP_POST" target="_blank>HTTP POST</a> with parameters, we are free to handle this however we want to, using whichever server-side technology desired.  The <a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/08/RemoteLogging.zip" target="_blank">example</a> server-side code I have included is in <a href="http://www.java.com/en/" target="_blank">Java</a> and consists of a relatively simple <a href="http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServlet.html" target="_blank">HttpServlet</a> that parses the information and mirrors it onto its own logging framework, in this case <a href="http://logging.apache.org/log4j/1.2/" target="_blank">log4j</a>.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2010/08/logging-to-server-from-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stephen Few Data Visualisation Workshop</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2010/06/stephen-few-data-visualisation-workshop/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2010/06/stephen-few-data-visualisation-workshop/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 08:05:31 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Visualisation]]></category>
		<category><![CDATA[Charts]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=246</guid>
		<description><![CDATA[Last week I attended a series of information visualisation workshops run by Stephen Few. The classes were based around his three books to date: Show Me The Numbers, Information Dashboard Design and Now You See It. Here follows an overview of the material covered and my thoughts on the event. Show Me The Numbers Day [...]]]></description>
			<content:encoded><![CDATA[
<p>Last week I attended a series of information visualisation workshops run by <a href="http://www.perceptualedge.com" target="_blank">Stephen Few</a>.  The classes were based around his three books to date: <a href="" target="_blank">Show Me The Numbers</a>, <a href="" target="_blank">Information Dashboard Design</a> and <a href="" target="_blank">Now You See It</a>.  Here follows an overview of the material covered and my thoughts on the event.</p>
<p><span style="font-size: 1.2em; font-weight: bold">Show Me The Numbers</span></p>
<p>Day one of the workshops was titled &#8220;Designing Tables and Graphs to Enlighten&#8221; and focused on how to effectively communicate a single story in a data set using a table or graph.  The starting point was to highlight that the <a href="http://en.wikipedia.org/wiki/Gricean_maxims" target="_blank">Gricean Maxims</a> apply equally well to the communication of quantitative data as they do conversational communication, i.e. information visualisation should:</p>
<ul>
<li>be as informative as necessary but not more informative than necessary (maxim of quantity)</li>
<li>not convey any message that is believed to be false or for which there is a lack of evidence (maxim of quality)</li>
<li>be relevant (maxim of relation)</li>
<li>be brief and orderly, avoiding ambiguity and obscurity of expression</li>
</ul>
<p>Fundamentally, to achieve this, <a href="http://www.perceptualedge.com" target="_blank">Stephen Few</a> proposes 2 major steps.  First, you should determine the medium that tells the story best.  (Should you use a table or a graph?  If a graph, then which kind of graph?)  Then you must design the chosen component so that the story is told clearly.  </p>
<p>For the first step, the relative strengths and weaknesses of tables and graphs and different graph types were presented.  Regarding graphs, <a href="http://www.perceptualedge.com" target="_blank">Stephen</a> presented what he considers to be the 7 relationships commonly displayed in graphs &#8211; time-series, ranking, part-to-whole, deviation, distribution, correlation and nominal comparison &#8211; and which graph types most concisely convey these relationships.  Unsurprisingly, <a href="http://en.wikipedia.org/wiki/Pie_chart" target="_blank">pie charts</a> were a graph type singled out for their general ineffectiveness (see <a href="http://www.perceptualedge.com/articles/visual_business_intelligence/save_the_pies_for_dessert.pdf">Save The Pies For Dessert</a> for details).  In addition to graph types, the concept of <a href="http://en.wikipedia.org/wiki/Small_multiple" target="_blank">small multiples</a> was highlighted as a simple technique for improving the <a href="http://en.wikipedia.org/wiki/Affordance" target="_blank">affordance</a> of graphs that endeavour to compare across data that differs only along a single variable.</p>
<p>Oh, and 3D charts, where to begin&#8230;  The almost guaranteed occlusion (where something is hidden behind something else) meaning it is impossible to see the entire picture at once?  The inability to directly compare values, sizes and/or positions due to depth?  The colour variation due to &#8220;lovely&#8221; lighting effects?</p>
<p>With determining the appropriate medium covered, a range of techniques and areas for consideration were introduced with the aim of maximising the effectiveness of the chosen component(s).  <a href="http://www.edwardtufte.com/tufte/" target="_blank">Edward Tufte</a>&#8216;s argument that the &#8220;data-ink ratio&#8221; should be maximised by removing, de-emphasising and/or regularising the unnecessary and emphasising the most important was introduced as the foundation of good table and graph design.  Additionally, the fundementals of visual perception were considered and how they can be harnessed to improve the clarity of the story being portrayed.  In particular, attributes such as size, shape, orientation and colour are <a href="http://www.infovis-wiki.net/index.php/Preattentive_processing" target="_blank">processed pre-attentively</a>.  That is, we perceive and process them instantaneously, in a highly parallelised fashion and without conscious thought, thereby laying down an  immediate interpretation before conscious thought is required.  Further to this, the pre-attentive attributes of length, 2-dimensional position, width, size and colour intensity are perceived quantitatively, i.e. some values are greater than others, and are therefore powerful building blocks for data visualisation.</p>
<p>As well as covering areas such as where best to locate the scale, how to arrange the visualisation to avoid label rotation and how to minimise problems associated with legends, there was an emphasis on the importance of colour, from when and where it is (not) required to palette choice.  A fair amount of <a href="http://www.perceptualedge.com" target="_blank">Stephen</a>&#8216;s thoughts on colour are covered in his article <a href="http://www.perceptualedge.com/articles/visual_business_intelligence/rules_for_using_color.pdf" target="_blank">Rules for Using Color</a>.  A couple of useful links that came up were <a href="http://www.personal.psu.edu/cab38/" target="_blank">Cynthia Brewer</a>&#8216;s <a href="http://www.colorbrewer.org" target="_blank">Color Brewer</a>, a tool for colour palette choice, and <a href="http://www.vischeck.com/" target="_blank">VisCheck</a>, a tool for simulating colour blindness.</p>
<p><span style="font-size: 1.2em; font-weight: bold">Information Dashboard Design</span></p>
<p>The 2nd day of the workshops, &#8220;Dashboard Design for at-a-glance monitoring&#8221;, built heavily on the first day&#8217;s lessons and focused on techniques and constructs that are of use when designing dashboards.  First up was the problem that the term &#8220;dashboard&#8221; is used for all manner of products.  <a href="http://www.perceptualedge.com" target="_blank">Stephen</a> defines a dashboard as &#8220;<em>a visual display of the most important information needed to achieve one or more objectives that has been consolidated on a single computer screen so it can be monitored and understood at a glance</em>&#8221; and states that &#8220;<em>dashboards are not comprehensive tools for analysis, decision making or management</em>&#8220;.  The monitoring requirement suggests that to some extent there must be a &#8220;live&#8221; element to the screen, while their not being comprehensive tools suggests that there should not be an abundance of controls to facilitate filtering, etc.  In my opinion <a href="http://www.perceptualedge.com" target="_blank">Stephen</a> is potentially limiting his audience with this, as most of what he presents under the context of dashboard design is just as valuable to report design and data presentation and/or analysis applications in general.</p>
<p>We started by focussing on the common mistakes made in dashboard design, such as introducing meaningless variety, arranging data poorly, misusing or overusing colour and introducing useless decoration.  Unfortunately, many of these problems appear to stem from vendors.  They are (understandably) assumed to be experts, yet their examples are usually little more than marketing fluff, so their designs are usually more concerned with graphical glitz than the actual intended purpose of a dashboard: communication.</p>
<p>Moving on to considering the techniques and practices that will improve dashboard design, the core idea was once again <a href="http://www.edwardtufte.com/tufte/" target="_blank">Tufte</a>&#8216;s &#8220;data-ink ratio&#8221; argument: &#8220;<em>reduce the non-data ink; enhance the data ink</em>&#8220;.  A number of objectives specifically for the visual design of dashboards were also prescribed: eliminate clutter and distraction, group data into logical sections, highlight what&#8217;s most important, support meaningful comparisons and discourage meaningless comparisons.  Each of 6 categories of dashboard display mechanisms (graphs, icons, text, images, drawings and organisers) was considered with the aim of achieving these goals.  The most time was spent addressing graphs; re-iterating some of the previous day&#8217;s content and introducing a couple of graph types more specifically designed for the dashboard context: <a href="http://en.wikipedia.org/wiki/Bullet_graph" target="_blank">bullet graphs</a> (see image below) and <a href="http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR&#038;topic_id=1" target="_blank">sparklines</a>.  <a href="http://en.wikipedia.org/wiki/Bullet_graph" target="_blank">Bullet graphs</a> are <a href="http://www.perceptualedge.com" target="_blank">Stephen Few</a>&#8216;s own <a href="http://www.perceptualedge.com/articles/misc/Bullet_Graph_Design_Spec.pdf" target="_blank">development</a> to address the requirement (unfortunately) usually fulfilled using gauges, i.e. the display of a single quantitative value against one or more comparative measures within the context of some qualitative ranges, e.g. poor, satisfactory, good.  The benefits that bullet graphs have over gauges are numerous, but in particular they take up significantly less space and are more conducive to the aforementioned objectives.  <a href="http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR&#038;topic_id=1" target="_blank">Sparklines</a>, on the other hand, were introduced by <a href="http://www.edwardtufte.com/tufte/" target="_blank">Tufte</a> in his book <a href="http://www.amazon.co.uk/Visual-Display-Quantitative-Information/dp/0961392142/ref=sr_1_2?ie=UTF8&#038;s=books&#038;qid=1277909297&#038;sr=8-2" target="_blank">The Visual Display of Quantitative Information</a>, and are designed to present trends or variations in a simple, space-saving way.</p>
<p><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/06/bullet_graph.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/06/bullet_graph.png" alt="" title="bullet_graph" width="642" height="218" class="aligncenter size-full wp-image-304" /></a></p>
<p>After touching on the <a href="http://www.jnd.org/dn.mss/CH01.pdf" target="_blank">importance of the aesthetics</a> of the design (it <a href="http://www.alistapart.com/articles/indefenseofeyecandy" target="_blank">should look appealing</a> without impeding the aforementioned visual design objectives), we moved to critiqueing dashboard examples submitted by attendees.  This proved to be a good exercise of the day&#8217;s lessons both for the submitters and class as a whole.</p>
<p><span style="font-size: 1.2em; font-weight: bold">Now You See It</span></p>
<p>The final day, titled &#8220;Simple Visualisation Techniques for Quantitative Analysis&#8221;, was quite different to the preceeding days as it was focused on how to gain an understanding of and insights into data sets, rather than the communication of existing understanding.  As a basis for the rest of the day&#8217;s material, the power of sight compared to our other senses was introduced and used as the argument for why data visualisation is a vital tool for exploring and understanding data sets.  This was followed by a brief history of data visualisation, from the first evidence of tabular arrangement of data in the 2nd Century, through <a href="http://en.wikipedia.org/wiki/William_Playfair" target="_blank">William Playfair</a>&#8216;s invention of line charts, bar charts and pie charts, to the spread of home computers in the 1980s and beyond.  </p>
<p>The traits of a skilled data analyst and characteristics of good data were considered before emphasising the necessity for a solid understanding of visual perception and cognition to be able to take advantage of those traits and characteristics through visual analysis.  Consequently, some time was then spent introducing a number of core aspects of visual perception and cognition.  As during the previous classes, it was highlighted that visual perception is selective, meaning that we must encode data in such a way that what is potentially interesting or meaningful pops out by contrasting with the norm.  <a href="http://www.infovis-wiki.net/index.php/Preattentive_processing" target="_blank">Pre-attentive visual attributes</a> were again introduced as the means by which this can be achieved, with length, 2-dimensional position, width, size and colour intensity able to encode quantitative values and shape and colour hue ideal for indicating categorisation.  The limitations of perception were highlighted, with particular emphasis on the issue of <a href="http://en.wikipedia.org/wiki/Inattentional_blindness" target="_blank">inattentional blindness</a> (the fun <a href="http://psyclab1.psych.ubc.ca/~viscoglab/demonstrations/" target="_blank">examples</a> caught most of us out).  Finally, some attention was given to the meaningful characteristics of data: trends, patterns and outliers; how to highlight those characteristics; and, which patterns and comparisons in data are meaningful, e.g. steep vs gradual and random vs repeating.</p>
<p>The final stretch of the class focused on techniques for performing meaningful data analysis by attempting to bring the characteristics and patterns introduced in the preceeding material to the fore.  First we considered the various types of useful analytical interactions, such as comparing, filtering, aggregating, drilling and zooming/panning.  Specific analysis techniques were then introduced for each of 7 categories of data analysis: time series, ranking and part-to-whole, deviation, distribution, correlation, multivariate and geospatial.  <a href="http://www.perceptualedge.com" target="_blank">Stephen</a> used a number of different analytical tools &#8211; <a href="" target="_blank">Spotfire</a>, <a href="" target="_blank">Tableau</a> and <a href="" target="_blank">Panopticon</a> &#8211; to demonstrate not only some of these techniques, but also the state of what he considers to be the best of the current crop of data analysis tools.  This crossed over into discussion of what the ultimate data analysis tool would provide: a tool that provides the appropriate set of visualisations and aforementioned analytical interactions that has no distracting lag between seeing something, thinking about it and manipulating it.</p>
<p><span style="font-size: 1.2em; font-weight: bold">Closing Thoughts</span></p>
<p>My overall reaction to the workshops is definitely positive.  <a href="http://www.perceptualedge.com" target="_blank">Stephen Few</a> is an engaging presenter who is able to eloquently convey many practical techniques and principles for information visualisation.  The workshops appropriately complement the corresponding books by presenting similar material in a different way, with the group exercises and interactivity of the classes more actively re-inforcing the concepts.</p>
<p>The minor negative I would highlight about both his books and the workshops is that they appear to overly target the <a href="http://en.wikipedia.org/wiki/Business_intelligence" target="_blank">business intelligence</a> domain.  This in itself is not a problem, but I think it potentially sells short some of the ideas and information in the material, as I believe they are potentially much further reaching.  Many of the fundemental concepts he teaches are too frequently ignored or simply not appreciated by those producing even the most basic of data visualisations.  Moreover, visualisation and visual perception are key to other areas such as <a href="http://en.wikipedia.org/wiki/User_experience" target="_blank">user experience</a> and <a href="http://en.wikipedia.org/wiki/Human%E2%80%93computer_interaction" target="_blank">human-computer interaction</a>, so it is unsurprising that most of his lessons cross over to such areas.</p>
<p>For those who like the sound of this course, it is being run again later in the year in <a href="http://info.marketingqed.com/Information_Visualisation_Courses_Brochure.pdf" target="_blank">London</a>, as well as in the <a href="http://www.perceptualedge.com" target="_blank">States and Australasia</a>.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2010/06/stephen-few-data-visualisation-workshop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contextual cues in user interface design</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2010/05/contextual-cues-in-ui-design/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2010/05/contextual-cues-in-ui-design/#comments</comments>
		<pubDate>Wed, 19 May 2010 14:44:18 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[UI Design]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=112</guid>
		<description><![CDATA[Contextual cues are frequently used in user interface design to communicate functionality and behaviour to the user, removing the need for the user to guess. For example, on the web, the underlining of text is commonly used to indicate a hyperlink. In addition to underlining, one or more of a different text colour, colour change [...]]]></description>
			<content:encoded><![CDATA[
<p>Contextual cues are frequently used in user interface design to communicate functionality and behaviour to the user, removing the need for the user to guess.  For example, on the web, the underlining of text is commonly used to indicate a hyperlink.  In addition to underlining, one or more of a different text colour, colour change on mouse-over and cursor change on mouse-over is usually also seen.  This stems from the convention that all interactive elements of a modern user interface will display some state change on mouse-over, as it clearly indicates to the user that they are &#8220;active&#8221;.  Conversely, disabled functionality is commonly greyed out and do not react to the mouse to indicate that they are &#8220;inactive&#8221;.  Neither the state-changes nor the greying-out are essential to the functionality of the interface.  However, they are key to informing the user of the interface&#8217;s behaviour and to guiding their interaction with the interface.  Without these subtle contextual cues, the user will forever be guessing at what they can do and will inevitably be left frustrated and lost.</p>
<p>Many modern development technologies come pre-packaged with an abundance of features, such as drop shadows, translucency and transitional animations, for creating &#8220;shiny&#8221; user interfaces.  Unfortunately, it seems that they are frequently misused and/or overused, usually due to their being used solely in an attempt to make an interface more visually appealing, rather than to enhance usability.  However, they should be considered additions to our arsenal of contextual cues, with the bonus of an aesthetic side-effect, rather than mere prettifying graphic design flourishes.  When used appropriately, as with the now &#8220;standard&#8221; cues such as those mentioned above, they can be invaluable in effectively communicating the functionality and behaviour of our increasingly complex user interfaces.</p>
<p><span style="font-size: 1.2em; font-weight: bold">Drop Shadows</span></p>
<p>Drop shadows imply an element of depth in user interfaces due to our natural interpretation of shadows in the real world.  In accordance with this intrinsic understanding, they should be used when a user interface element is &#8220;over&#8221; another element, as it clarifies the layering that is occuring.  A simple, common example is a pop-up dialog, as shown here:<br />
<a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/pop-up_dialog.png"><img class="aligncenter size-full wp-image-140" title="pop-up_dialog" src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/pop-up_dialog.png" alt="Pop-up dialog" width="378" height="186" /></a></p>
<p>Furthermore, they can be used subtly, yet effectively, to provide a more real-world understanding of a user interface&#8217;s behaviour, as in this example:</p>
<p><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/adobe_reader.png"><img class="aligncenter size-full wp-image-135" title="adobe_reader" src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/adobe_reader.png" alt="Adobe Reader - Drop Shadow" width="579" height="132" /></a><br />
This is a screen capture of a <a href="http://en.wikipedia.org/wiki/Pdf" target="_blank">PDF</a> displayed in <a href="http://get.adobe.com/uk/reader/" target="_blank">Adobe Reader</a>.  Notice how the drop shadow under the control bar at the top result in our instinctively understanding that the pages will go &#8220;under&#8221; the control bar. The interface&#8217;s behaviour would be acceptably clear without the drop shadow, due to the positioning of the scrollbar indicating the pages will scroll but not the control bar, however, the natural interpretation would be that the pages magically disappear off at the top.  Although users are probably accustomed to this idea through general computer use, the &#8220;goes under&#8221; concept is understood more instinctively as it is more natural.</p>
<p>The main concern regarding drop shadows is that they can horribly mislead when misused or overused.  Misuse is usually a case of a shadow suggesting an above-below relationship between elements of the user interface when there isn&#8217;t one, i.e. behaviour has been implied that is not the case.  In contrast, overuse simply results in difficulty interpreting the behaviour due to drop shadows only creating a pseudo-3D effect that does not scale beyond a relatively small number of layers.  Related to this is the issue that drop shadows only provid a layering cue in their immediate vicinity.  Therefore, a design should never rely on the user naturally interpreting the relationship of user interface elements with drop shadows in different areas of the the interface.</p>
<p><span style="font-size: 1.2em; font-weight: bold">Transitional Animations</span></p>
<p>Transitional animations are short animations of user interface elements when changing from a particular state to another.  Their aim is to infuse the interface with a more organic feel by providing a context for the appearing, disappearing and changing of elements, rather than having the &#8220;magically&#8221; flick between appearances, whilst not impeding the user by forcing them to wait for animations to complete.  When used appropriately, the context provided by the animation reassures the user of what is happening and ensures that they do need to guess what has changed.  For example, in the following tree explorer control, the animated expanding and collapsing of nodes complements the indentation in conveying the parent-child relationships by suggesting the child nodes are &#8220;coming out of&#8221; or &#8220;going into&#8221; the parent node as we navigate through the tree.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="explorer_tree" width="400" height="250" align="center">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/TreeExample.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/TreeExample.swf" width="400" height="250" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>Transitional animations can be taken even further than such subtle enhancements and become a quite pronounced aspect of a tool.  For example, a common feature of data visualisation is the concept of drilling down (or up) on datasets.  Frequently, an understanding of the context in which lower-level details reside is as useful as the details themselves.  The example below shows a bar chart of some abstract data that allows the user to drill down on individual bars.  Without the transitional animation the user can still work out the context into or out of which it is drilling, but the transitional animation allows the user to passively consume this information instead, resulting in a more powerful experience for the user.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="drilldown" width="500" height="400" align="center">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/DrillDown.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/DrillDown.swf" width="500" height="400" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<em>Note: the code for this example is based on <a href="http://www.quietlyscheming.com/blog/" target="_blank">Ely Greenfield</a>&#8216;s <a href="http://www.quietlyscheming.com/blog/charts/chart-drilldown-animations/" target="_blank">chart drill-down article</a>.</em></p>
<p>Another example is on display in the <a href="http://www.scottlogic.co.uk/market_overview/marketmap.php" target="_blank">Market Map</a> tool we have developed.  Once again the transitional animation when drilling down or up assists the user&#8217;s understanding of the data by clearly portraying relationships and context.</p>
<p>As mentioned, the key to using transitional animations as contextual cues is that they do not impede the user whilst communicating their additional information.  Therefore, the duration of a transitional animation is vital to getting the &#8220;feel&#8221; right.  Unfortunately, my experience has shown that working out the ideal duration is not an exact science and requires a largely trial and error approach.  However, as a general rule of thumb, the more contextual information there is for the user to absorb, the longer the animation can take.</p>
<p><span style="font-size: 1.2em; font-weight: bold">Translucency</span></p>
<p>A translucent user interface element is one which is neither wholly invisible nor fully solid, i.e. it is semi-transparent, resulting in the user being able to see the user interface detail &#8220;underneath&#8221; the translucent element to some extent.  It inherently loses an element&#8217;s contrast and makes it appear somewhat insubstantial, or ghost-like.  This can be leveraged for two purposes: to enable user interface elements to be layered whilst not fully obscuring underlying details and/or to draw the focus away from an element.  For example, in the pop-up dialog image used above to illustrate drop shadow use, there is visually no suggestion that the user cannot continue to interact with the underlying text.  Here is a screenshot of the same application, but this time there is a (slightly blurred) translucent layer over the underlying text.  It is now clear that the user can only interact with the pop-up dialog, whilst also satisfying the user that the text has not been lost, as they are still able to see it.  At the same time, the translucent overlay pushes attention away from the text, i.e. towards the pop-up dialog to which the user must respond.</p>
<p><a href="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/translucent-overlay-popup.png"><img src="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/translucent-overlay-popup.png" alt="Translucent overlay pop-up." title="translucent-overlay-popup" width="417" height="168" class="aligncenter size-full wp-image-190" /></a></p>
<p>Notice how the border of the pop-up dialog is also translucent.  Once again this allows the user to see a rough outline of the underlying detail whilst softening the border&#8217;s visual strength so that the user is pushed toward the only &#8220;solid&#8221; part of the interface, the area with which they must interact.</p>
<p><span style="font-size: 1.2em; font-weight: bold">All together now&#8230;</span></p>
<p>To better understand how these contextual cues can improve an interface, here is an example based on an interface component devised for our <a href="http://www.scottlogic.co.uk/market_overview/hindsight" target="_blank">Hindsight</a> application which has subsequently been used in a variety of applications for our <a href="http://www.scottlogic.co.uk/services/examples-of-our-work/" target="_blank">clients</a>.  This example shows the same functional component, but with different contextual cues enabled and disabled.</p>
<p>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="pullout" width="650" height="600" align="center">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/Pullout.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/05/Pullout.swf" width="650" height="600" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>The contextual cues vastly improve the understanding of the component&#8217;s behaviour, since they help communicate the concept of a pullout tab (like in a pop-up picture book): the drop shadow indicates that the tab is &#8220;on top&#8221;; the transitional animation clarifies that the tab is pulled out and pushed back; and, the subtle translucency ensures the underlying content is not completely obscured whilst still providing sufficient contrast for the tab&#8217;s contents to be usable.</p>
<p><span style="font-size: 1.2em; font-weight: bold">Closing Thoughts</span></p>
<p>Contextual cues are an important aspect of user interface design.  They communicate information to the user about an interface&#8217;s behaviour without the need for explicit instructions.  As users increasingly expect entirely intuitive applications, this form of communication is vital to modern user interfaces.  Basic contextual cues are already commonplace in all applications, usually in the form of cues such as mouse-over state changes that guide the user but, arguably, do not necessarily add a great deal to the aesthetics of user interfaces.  </p>
<p>More modern contextual cues such as drop shadows, transitional animations and translucency are able to both act as contextual cues and prettifying additions in user interfaces when used appropriately.  As the importance of the visual appeal of devices and applications is increasingly <a href="http://www.jnd.org/dn.mss/CH01.pdf" target="_blank">recognised</a> and <a href="http://www.alistapart.com/articles/indefenseofeyecandy" target="_blank">encouraged</a> it becomes vital that, as developers and designers, we fully understand the tools at our disposal so that we can strike the appropriate balance between aesthetics and functionality in a user interface.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2010/05/contextual-cues-in-ui-design/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flex Sparkline</title>
		<link>http://www.scottlogic.co.uk/blog/graham/2010/02/flex-sparkline/</link>
		<comments>http://www.scottlogic.co.uk/blog/graham/2010/02/flex-sparkline/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 15:58:41 +0000</pubDate>
		<dc:creator>Graham Odds</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Visualisation]]></category>
		<category><![CDATA[Charts]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/graham/?p=90</guid>
		<description><![CDATA[Sparklines are described by their inventor, Edward Tufte, as &#8220;data-intense, design-simple, word-sized graphics&#8221;. They are an ideal tool for displaying trends for single entries within large data sets, for example, stock prices. As well as the standard miniature line series, Tufte&#8217;s original specification introduces a ternary sparkline, a.k.a. win-loss sparkline, where small columns are used [...]]]></description>
			<content:encoded><![CDATA[
<p><a href='http://en.wikipedia.org/wiki/Sparkline'>Sparklines</a> are described by their inventor, <a href='http://www.edwardtufte.com/tufte/'>Edward Tufte</a>, as &#8220;data-intense, design-simple, word-sized graphics&#8221;.  They are an ideal tool for displaying trends for single entries within large data sets, for example, <a href='http://www.scottlogic.co.uk/market_overview/'>stock prices</a>.  As well as the standard miniature line series, <a href='http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR&#038;topic_id=1'>Tufte&#8217;s original specification</a> introduces a ternary sparkline, a.k.a. win-loss sparkline, where small columns are used to indicate &#8220;win&#8221; or &#8220;loss&#8221; and no column to indicate &#8220;draw&#8221;.</p>
<p>This article is intended to present, and distribute, <a href='http://www.adobe.com/products/flex/'>Flex</a> <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/Sparkline.zip'>implementations of sparklines, win-loss sparklines and another common variation, column sparklines</a>.  The Flex 3 version of the code and documentation can be obtained from <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/Sparkline.zip'>here</a>, while the Flex 4 version can be found <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/04/Sparkline.zip'>here</a>.  The following is an example showing some of the variations available:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="sparklines" width="445" height="85" align="center">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/SparklineApp.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/SparklineApp.swf" width="445" height="85" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>The <code>Sparkline</code>, <code>TernarySparkline</code> and <code>ColumnSparkline</code> classes are all implemented using core <a href=''>Flex</a> functionality, i.e. there are no dependencies.  They all implement <a href='http://livedocs.adobe.com/flex/3/langref/mx/controls/listClasses/IListItemRenderer.html'>IListItemRenderer</a> and <a href='http://livedocs.adobe.com/flex/3/langref/mx/controls/listClasses/IDropInListItemRenderer.html'>IDropInListItemRenderer</a> interfaces, so can readily be used as standalone components or as item renderers in a <a href='http://livedocs.adobe.com/flex/3/langref/mx/controls/DataGrid.html'>DataGrid</a> or other list control.  Based on the <a href='http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR&#038;topic_id=1'>original specification</a>, the <code>Sparkline</code> allows the user to optionally show a normal range, x-axis min and max points and y-axis min and max points.  All of these features and the line itself can be styled.  Similarly, the <code>TernarySparkline</code> and <code>ColumnSparkline</code> allow the user to specify the &#8220;zero&#8221; value, and style positive, negative and zero styles independently.  A final feature of the sparklines is that they will update automatically based on <code>dataProvider</code> updates, as shown in the following example, which plots a constantly-updating, randomly generated series of numbers:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_8" width="100" height="25" align="center">
      <param name="movie" value="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/SparklineUpdatingApp.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/SparklineUpdatingApp.swf" width="100" height="25" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>It is worth noting that there are a number of alternative <a href='http://www.adobe.com/products/flex/'>Flex</a> implementations available.  However, they all have further dependencies, potentially making them more heavyweight.  For example, <a href='http://www.brightpointinc.com/flexdemos/360flex/MicroChartsSample.html'>Tom Gonzalez</a> and <a href='http://www.insideria.com/2008/04/degrafa-data-part-2-the-sparkl.html'>Andrew Trice</a> both present implementations using the <a href='http://www.degrafa.org/'>Degrafa</a> graphics framework.  Because of their use of <a href='http://www.degrafa.org/'>Degrafa</a>, these implementations inherently allow users to easily use any number of extravagant styling.  Although potentially initially appealing, this goes against the good data visualisation practices suggested by experts such as <a href='http://www.perceptualedge.com'>Stephen Few</a> and <a href='http://www.edwardtufte.com/tufte/'>Tufte</a> himself; &#8220;eloquence through simplicity&#8221;[<a href='http://books.google.co.uk/books?id=NomqOzZfHqoC&#038;pg=PA96&#038;lpg=PA96&#038;dq=eloquence+through+simplicity&#038;source=bl&#038;ots=LQ2czEgImI&#038;sig=7lvX-7V8fjEI7rCsLhC1oKsuJVk&#038;hl=en&#038;ei=LzJwS5zpMYT60wT0wq3UBA&#038;sa=X&#038;oi=book_result&#038;ct=result&#038;resnum=3&#038;ved=0CBAQ6AEwAg#v=onepage&#038;q=eloquence%20through%20simplicity&#038;f=false'>ref</a>].  <a href='http://aheadofthewave.wordpress.com/2007/08/20/sparklines-in-flex/'>Lucas Pereira</a> and <a href='http://sherlockinformatics.com/wordpress/flex-code-examples/flex-sparklines'>Sherlock Informatics</a> both present implementations using the <a href='http://www.adobe.com/devnet/flex/articles/data_visualization.html'>Flex Data Visualization</a> library.  The charts contained in the library are wonderfully feature-rich and flexible.  However, this means that they are also rather heavyweight components and, therefore, using a large number of these as item renderers in an application is likely to use a lot of memory and/or make the application non-performant.  A final potential alternative are the micro-charts available in the <a href='http://code.google.com/p/birdeye/'>BirdEye</a> visualisation library.  Much like the examples using the <a href='http://www.adobe.com/devnet/flex/articles/data_visualization.html'>Flex Data Visualization</a> library, these can be perfect in situations where small numbers of instances are present, but again they introduce features that cause them to be more heavyweight than necessary.</p>
<p>The components are being made available under the <a href='http://www.gnu.org/licenses/gpl.html'>GNU General Public License</a> and can be obtained from <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2010/02/Sparkline.zip'>here (Flex 3)</a> or <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/04/Sparkline.zip'>here (Flex 4)</a>.  The zips also include some documentation and a pre-compiled swc of components, using the namespace <code>http://www.scottlogic.com/sparkline</code>.</p>
<p><strong>UPDATE 19/04/2011:</strong> I have created an updated version of the library that is Flex 4 compatible.  This is available <a href='http://www.scottlogic.co.uk/blog/graham/wp-content/uploads/2011/04/Sparkline.zip'>here</a> and a short article detailing the migratory changes can be found <a href="http://www.scottlogic.co.uk/blog/graham/2011/04/flex-sparkline-updated/" target="_blank">here</a>.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/graham/2010/02/flex-sparkline/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

