<?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>Iwo Banaś - Flex Blog &#187; zoom</title>
	<atom:link href="http://www.iwobanas.com/tag/zoom/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iwobanas.com</link>
	<description>Adobe Flex and AIR thoughts, custom components, how-to’s...</description>
	<lastBuildDate>Tue, 02 Feb 2010 22:54:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scrolling and zooming chart with CategoryAxis</title>
		<link>http://www.iwobanas.com/2009/08/scrolling-and-zooming-chart-with-categoryaxis/</link>
		<comments>http://www.iwobanas.com/2009/08/scrolling-and-zooming-chart-with-categoryaxis/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 20:12:44 +0000</pubDate>
		<dc:creator>Iwo Banas</dc:creator>
				<category><![CDATA[charts]]></category>
		<category><![CDATA[reusable components]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[zoom]]></category>

		<guid isPermaLink="false">http://www.iwobanas.com/?p=144</guid>
		<description><![CDATA[Title of this post is a little bit misleading because it is not possible to use ChartScroller directly with CategoryAxis. This is because ChartScroller relays on axis minimum/maximum properties which are not present in CategoryAxis. Luckily it is possible to simulate CategoryAxis behavior with LinearAxis which is supported by ChartScroller. I will describe how to [...]]]></description>
			<content:encoded><![CDATA[<p>Title of this post is a little bit misleading because it is not possible to use ChartScroller directly with CategoryAxis. This is because ChartScroller relays on axis minimum/maximum properties which are not present in CategoryAxis. Luckily it is possible to simulate CategoryAxis behavior with LinearAxis which is supported by ChartScroller. I will describe how to do it in this post.<br />
<span id="more-144"></span></p>
<h3>Simple scenario</h3>
<p>The simplest and quite common scenario is having one data provider containing objects with single property determining category and further properties determining values of the series. Such data provider may look something like this (code copied from Flex API examples):</p>
<pre>
[Bindable]
public var dp:ArrayCollection = new ArrayCollection( [
    { Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450 },
    { Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600 },
    { Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300 },
    { Month: "Apr", Profit: 1800, Expenses: 1200, Amount: 900 },
    { Month: "May", Profit: 2400, Expenses: 575, Amount: 500 } ]);
</pre>
<p>In such case we have to do three things to simulate CategoryAxis behavior with LinearAxis:</p>
<ul>
<li>Declare only yField property of series (not xField).</li>
<li>Create label function converting data provider index to category name.</li>
<li>Declare LinearAxis using created label function with interval property set to 1.</li>
</ul>
<p>Label function may look like this (If xField of series is not specified Flex passes item index as labelValue so all we have to do is find correct item and return category value):</p>
<pre>
public function categoryLabelFunction(labelValue:Object,
                        previousValue:Object, axis:IAxis):String
{
    var index:int = int(labelValue);

    if (index >= 0 &#038;&#038; index < dp.length)
        return dp[index].Month;
    return "";
}
</pre>
<p>As you can see chart MXML code is only slightly modified compared to code using standard CategoryAxis:</p>
<pre>
&lt;mx:ColumnChart id="columnChart" width="100%" height="100%"
    gutterLeft="50" gutterRight="40" dataProvider="{dp}"&gt;
    &lt;mx:series&gt;
        &lt;!-- Note that xField is not specified --&gt;
        &lt;mx:ColumnSeries yField="Profit" /&gt;
        &lt;mx:ColumnSeries yField="Expenses" /&gt;
        &lt;mx:ColumnSeries yField="Amount" /&gt;
    &lt;/mx:series&gt;
    &lt;mx:horizontalAxis&gt;
        &lt;!-- LinearAxis simulating CategoryAxis --&gt;
        &lt;mx:LinearAxis interval="1"
            labelFunction="categoryLabelFunction" /&gt;
    &lt;/mx:horizontalAxis&gt;
&lt;/mx:ColumnChart&gt;
</pre>
<p><a title="Sources" href="/wp-content/uploads/chart_scroller_category_axis_01/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="ChartScroller example sources" href="/wp-content/uploads/chart_scroller_category_axis_01/srcview/ChartScrollerCategoryAxis01.zip">here</a>.</p>
<p><iframe src="/wp-content/uploads/chart_scroller_category_axis_01/ChartScrollerCategoryAxis01.html" width="100%" height="350" frameborder="no"  onMouseWheel="return false;" ></iframe></p>
<h3>More complex scenario</h3>
<p>In some cases you may need to use xField series properties. For example you may be using separate data providers of different length for different series. In such case additional parse function have to be created to convert category name to numeric value which can be placed along LinearAxis. You can find full example of such scenario <a title="Sources" href="/wp-content/uploads/chart_scroller_category_axis_02/srcview/index.html" target="_blank">here</a>.</p>
<p><a title="Sources" href="/wp-content/uploads/chart_scroller_category_axis_02/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="ChartScroller example sources" href="/wp-content/uploads/chart_scroller_category_axis_02/srcview/ChartScrollerCategoryAxis02.zip">here</a>.</p>
<p><iframe src="/wp-content/uploads/chart_scroller_category_axis_02/ChartScrollerCategoryAxis02.html" width="100%" height="350" frameborder="no"  onMouseWheel="return false;" ></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwobanas.com/2009/08/scrolling-and-zooming-chart-with-categoryaxis/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Scrolling and zooming chart with ChartScroller</title>
		<link>http://www.iwobanas.com/2009/07/scrolling-and-zooming-chart-with-chartscroller/</link>
		<comments>http://www.iwobanas.com/2009/07/scrolling-and-zooming-chart-with-chartscroller/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 14:00:54 +0000</pubDate>
		<dc:creator>Iwo Banas</dc:creator>
				<category><![CDATA[charts]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[zoom]]></category>

		<guid isPermaLink="false">http://www.iwobanas.com/?p=129</guid>
		<description><![CDATA[Some time ago I presented scrolling chart by using modified axis renderer (ScrollableAxisRenderer). I rethought this concept and come to the point that axis renderer should render axis not scroll the chart, so chart scrolling should be implemented as separate component. This is especially true in case of charts with many axes and renderers. My [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I presented scrolling chart by using modified axis renderer (ScrollableAxisRenderer). I rethought this concept and come to the point that axis renderer should render axis not scroll the chart, so chart scrolling should be implemented as separate component. This is especially true in case of charts with many axes and renderers. My new idea was to create nonvisual component which will take reference to a chart and add appropriate listeners modifying axes minimum/maximum to achieve scrolling /zooming.<br />
<span id="more-129"></span></p>
<p>It was the challenge to find the way to easily convert mouse position to data coordinates and vice versa. According to documentation DataTransform objects should be used for this purpose, but unfortunately this documentation is quite incomplete. I especially like this sentence <em>&#8220;In theory, a chart can contain multiple overlaid DataTransform objects.&#8221;</em> – what does it mean <em>&#8220;in theory&#8221;</em> ? Having two vertical or horizontal axes is quite common case and in such case different data transformation have to be done for each axis. If charting sources were open it would at least be possible to figure out how data transformation is working reading code…</p>
<p>Anyway, finally I have found that chart series (<a href="http://livedocs.adobe.com/flex/3/langref/mx/charts/chartClasses/Series.html" target="_blank">Series</a>) inherits two function (<code>localToData()</code> and <code>dataToLocal()</code>) to transform points to and from data coordinates. Using these functions I have implemented component named <a href="/wp-content/uploads/chart_scroller_01/srcview/source/com/iwobanas/charts/ChartScroller.as.html" target="_blank">ChartScrolle</a>r.</p>
<p>All you have to do to enable chart scrolling/zooming using ChartScroller is create instance of ChartScroller and pass reference to the chart to it. You can do it in MXML using the code similar to the one below:</p>
<pre>
&lt;charts:ChartScroller id="scroller" chart="{chart}" /&gt;

&lt;mx:ColumnChart id="chart" width="100%" height="100%"
    gutterLeft="40" gutterRight="10" dataProvider="{dp}"&gt;
    &lt;mx:series&gt;
        &lt;mx:ColumnSeries id="series1" xField="x" yField="y2" /&gt;
        &lt;mx:ColumnSeries id="series2" xField="x" yField="y1" /&gt;
    &lt;/mx:series&gt;
&lt;/mx:ColumnChart&gt;
</pre>
<p>ChartScroller is hosted on <a href="http://code.google.com/p/reusable-fx/" target="_blank">http://code.google.com/p/reusable-fx/</a>. Currently charts with LinearAxis or DateTimeAxis are supported.</p>
<h3>Basic Example</h3>
<p><a title="Sources" href="/wp-content/uploads/chart_scroller_01/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="ChartScroller example sources" href="/wp-content/uploads/chart_scroller_01/srcview/ChartScrollerExample01.zip">here</a>.</p>
<p><iframe src="/wp-content/uploads/chart_scroller_01/ChartScrollerExample01.html" width="100%" height="350" frameborder="no"  onMouseWheel="return false;" ></iframe></p>
<h3>Example &#8211; using ChartScroller with many axes</h3>
<p>You can use ChartScroller for chart with multiple axes, so that different axes can be scrolled separately. To scroll/zoom concrete axis grab series using this axis or axis renderer.</p>
<p><a title="Sources" href="/wp-content/uploads/chart_scroller_02/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="ChartScroller example sources" href="/wp-content/uploads/chart_scroller_02/srcview/ChartScrollerExample02.zip">here</a>.</p>
<p><iframe src="/wp-content/uploads/chart_scroller_02/ChartScrollerExample02.html" width="100%" height="350" frameborder="no"  onMouseWheel="return false;" ></iframe></p>
<h3>Example &#8211; ChartScroller properties</h3>
<p><a href="/wp-content/uploads/chart_scroller_03/ChartScrollerExample.html" target="_blank">This example</a> demonstrates  how you can adjust behavior of ChartScroller by setting some of it public properties.</p>
<p>ChartScroller dispatches change event every time axis minimum/maximum value is modified. It also dispatches valueCommit event after specified time from last modification. This event may be used to retrieve new data or update other controls based on new axes minimum/maximum values. I will present example retrieving data from remote service on valueCommit event in separate post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwobanas.com/2009/07/scrolling-and-zooming-chart-with-chartscroller/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Scrollable Chart Axis Renderer</title>
		<link>http://www.iwobanas.com/2009/06/scrollable-chart-axis-renderer/</link>
		<comments>http://www.iwobanas.com/2009/06/scrollable-chart-axis-renderer/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 22:51:03 +0000</pubDate>
		<dc:creator>Iwo Banas</dc:creator>
				<category><![CDATA[charts]]></category>
		<category><![CDATA[reusable components]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[zoom]]></category>

		<guid isPermaLink="false">http://www.iwobanas.com/?p=64</guid>
		<description><![CDATA[Some time ago I was asked to create column chart representing data in time with user friendly interface to change period of analysis. Current solution was consisted of two data fields to select date range and it was OK but it wasn’t really Flexy.
I decided to enable scrolling the chart by dragging the axis so [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I was asked to create column chart representing data in time with user friendly interface to change period of analysis. Current solution was consisted of two data fields to select date range and it was OK but it wasn’t really Flexy.</p>
<p>I decided to enable scrolling the chart by dragging the axis so that if one wants to see what’s beyond the left edge of chart (s)he can simply drag the charts horizontal axis and scroll it right. To enable zooming the data I chose to use mouse wheel. Generally these ideas was based on popular maps services interfaces.</p>
<p><strong>This example is deprecated, consider using <a href="http://www.iwobanas.com/2009/07/scrolling-and-zooming-chart-with-chartscroller/">ChartScroller</a> instead!!!</strong><br />
<span id="more-64"></span></p>
<h3>Prototype implementation</h3>
<p>Implementation of fully working prototype was really straightforward. In just a few hours I tangled standard column chart with a bunch of event listeners and scrolling/zooming was working. This is what I like in Flex. The next challenge was to create reusable component which could be applied to any chart.</p>
<h3>Reusable component implementation</h3>
<p>After some investigation I decided to create a subclass of AxisRenderer which will automatically register required listeners and modify corresponding axis minimum and maximum values. I have faced some problems with lack of (or undocumented) functions transforming mouse position along axis renderer to data values. It’s a pity that Flex charting sources are closed, if they were open surely I will find much useful code hidden as private or mx_internal. Anyway, after some playing with debugger I have created my own implementation based on axis minimum/maximum values and renderers gutters. You can see the result below.</p>
<h3>TODOs</h3>
<p>There are still few things to be done to improve this component.</p>
<ul>
<li>The most important is to add event dispatched certain time after user finished moving or zooming the chart. Such event would allow developer to update chart data provider basing on selected minimum and maximum values.</li>
<li>Cursor might be changed to indicate grabbing axis.</li>
<li>Area of axis containing labels might also be mouse sensitive.</li>
<li>If you have any other ideas add a comment!</li>
</ul>
<p>This example demonstrates scrolling and zooming chart using ScrollableAxisRenderer.<br />
<a title="Sources" href="http://www.iwobanas.com/wp-content/uploads/scrollable_chart_01/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="ScrollabeleAxisRenderer sources" href="http://www.iwobanas.com/wp-content/uploads/scrollable_chart_01/srcview/ScrollableAxisRenderer02.zip">here</a>.</p>
<p><iframe src="http://www.iwobanas.com/wp-content/uploads/scrollable_chart_01/ScrollableAxisRendererExample.html" width="100%" height="350" frameborder="no" onMouseWheel="return false;" ></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwobanas.com/2009/06/scrollable-chart-axis-renderer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
