You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by pe...@apache.org on 2013/12/20 12:35:42 UTC

git commit: [flex-asjs] [refs/heads/develop] - Updated BarChartExample with XAxisBead. Left the source sample to use the BarChart code in the project (rather than the SDK) to make it easier to demonstrate cross-compiling the component into JavaScript.

Updated Branches:
  refs/heads/develop be5e298e0 -> 45c74749b


Updated BarChartExample with XAxisBead. Left the source sample to use the BarChart code in the project (rather than the SDK) to make it easier to demonstrate cross-compiling the component into JavaScript.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/45c74749
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/45c74749
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/45c74749

Branch: refs/heads/develop
Commit: 45c74749b1b3555d749351ba4c781b0df74dde6a
Parents: be5e298
Author: Peter Ent <pe...@apache.org>
Authored: Fri Dec 20 06:35:30 2013 -0500
Committer: Peter Ent <pe...@apache.org>
Committed: Fri Dec 20 06:35:30 2013 -0500

----------------------------------------------------------------------
 examples/BarChartExample/src/MyInitialView.mxml |  53 ++++++---
 examples/BarChartExample/src/README.txt         |   8 +-
 .../custom/beads/ChartItemRendererFactory.as    |   2 +-
 .../apache/flex/html/custom/beads/IChartAxis.as |  25 +++++
 .../apache/flex/html/custom/beads/XAxisBead.as  | 107 +++++++++++++++++++
 .../html/custom/beads/layout/BarChartLayout.as  |   4 +-
 6 files changed, 175 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/45c74749/examples/BarChartExample/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/examples/BarChartExample/src/MyInitialView.mxml b/examples/BarChartExample/src/MyInitialView.mxml
index c631c1e..18e93a0 100644
--- a/examples/BarChartExample/src/MyInitialView.mxml
+++ b/examples/BarChartExample/src/MyInitialView.mxml
@@ -20,7 +20,10 @@ limitations under the License.
 <basic:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009"
 				xmlns:basic="library://ns.apache.org/flexjs/basic"
 				xmlns:local="*" 
-				xmlns:models="models.*">
+				xmlns:models="models.*"
+				xmlns:custom="org.apache.flex.html.custom.*"
+				xmlns:customBeads="org.apache.flex.html.custom.beads.*"
+				xmlns:customSup="org.apache.flex.html.custom.supportClasses.*">
 	<fx:Script>
 		<![CDATA[
 			
@@ -28,29 +31,45 @@ limitations under the License.
 		]]>
 	</fx:Script>
 	
+	<fx:Style>
+		@namespace custom "org.apache.flex.html.custom.*";
+		
+		custom|BarChart
+		{
+			IBeadModel: ClassReference("org.apache.flex.html.staticControls.beads.models.ArraySelectionModel");
+			IBeadView:  ClassReference("org.apache.flex.html.custom.beads.BarChartView");
+			IBeadController: ClassReference("org.apache.flex.html.staticControls.beads.controllers.ListSingleSelectionMouseController");
+			IBeadLayout: ClassReference("org.apache.flex.html.custom.beads.layout.BarChartLayout");
+			IDataProviderItemRendererMapper: ClassReference("org.apache.flex.html.custom.beads.ChartItemRendererFactory");
+			IItemRendererClassFactory: ClassReference("org.apache.flex.core.ItemRendererClassFactory");
+			IItemRenderer: ClassReference("org.apache.flex.html.custom.supportClasses.BoxItemRenderer");
+		}
+	</fx:Style>
+	
 	<basic:Label id="output" x="450" y="30" width="100" />
 	
-	<basic:BarChart id="barChart" x="20" y="20" width="400" height="200">
-		<basic:beads>
+	<custom:BarChart id="barChart" x="20" y="20" width="400" height="200">
+		<custom:beads>
 			<basic:ConstantBinding
 				sourceID="applicationModel"
 				sourcePropertyName="productList"
 				destinationPropertyName="dataProvider" />
-		</basic:beads>
-		<basic:series>
-			<basic:BarChartSeries yField="sales" 
+			<customBeads:XAxisBead labelField="title" />
+		</custom:beads>
+		<custom:series>
+			<customSup:BarChartSeries yField="sales" 
 								  fillColor="0xFF964D">
-				<basic:itemRenderer>
-					<basic:BoxItemRenderer />
-				</basic:itemRenderer>
-			</basic:BarChartSeries>
-			<basic:BarChartSeries yField="detail" 
+				<customSup:itemRenderer>
+					<customSup:BoxItemRenderer />
+				</customSup:itemRenderer>
+			</customSup:BarChartSeries>
+			<customSup:BarChartSeries yField="detail" 
 								  fillColor="0x964DFF">
-				<basic:itemRenderer>
-					<basic:BoxItemRenderer />
-				</basic:itemRenderer>
-			</basic:BarChartSeries>
-		</basic:series>
-	</basic:BarChart>
+				<customSup:itemRenderer>
+					<customSup:BoxItemRenderer />
+				</customSup:itemRenderer>
+			</customSup:BarChartSeries>
+		</custom:series>
+	</custom:BarChart>
 	
 </basic:ViewBase>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/45c74749/examples/BarChartExample/src/README.txt
----------------------------------------------------------------------
diff --git a/examples/BarChartExample/src/README.txt b/examples/BarChartExample/src/README.txt
index 71f2f34..63330b5 100644
--- a/examples/BarChartExample/src/README.txt
+++ b/examples/BarChartExample/src/README.txt
@@ -20,8 +20,6 @@
 This example demonstrates how to construct a BarChart. The example shows a chart
 with two BarSeries on the same axis. 
 
-The MyInitialView file references <basic:BarChart>. However, you will also find
-a complete copy of the BarChart source (strand, beads, etc.) in this project 
-contained in the org.apache.flex.html.custom package. This copy can be cross-
-compiled into JavaScript; just change <basic:BarChart> to <custom:BarChart>,
-along with additional namespaces, and this chart can be displayed in HTML.
\ No newline at end of file
+The sample uses the BarChart source files found in the project, not in the FlexJS
+SDK. This allows you to cross-compile the component to JavaScript and produce an
+HTML chart.

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/45c74749/examples/BarChartExample/src/org/apache/flex/html/custom/beads/ChartItemRendererFactory.as
----------------------------------------------------------------------
diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/ChartItemRendererFactory.as b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/ChartItemRendererFactory.as
index eb63fc3..76e6b97 100644
--- a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/ChartItemRendererFactory.as
+++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/ChartItemRendererFactory.as
@@ -19,13 +19,13 @@
 package org.apache.flex.html.custom.beads
 {
 	import org.apache.flex.core.IBead;
+	import org.apache.flex.core.IDataProviderItemRendererMapper;
 	import org.apache.flex.core.IItemRendererClassFactory;
 	import org.apache.flex.core.IItemRendererParent;
 	import org.apache.flex.core.ISelectionModel;
 	import org.apache.flex.core.IStrand;
 	import org.apache.flex.events.Event;
 	import org.apache.flex.events.IEventDispatcher;
-	import org.apache.flex.html.staticControls.beads.IDataProviderItemRendererMapper;
 	import org.apache.flex.html.staticControls.beads.IListView;
 	
 	public class ChartItemRendererFactory implements IBead, IDataProviderItemRendererMapper

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/45c74749/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartAxis.as
----------------------------------------------------------------------
diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartAxis.as b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartAxis.as
new file mode 100644
index 0000000..5131a50
--- /dev/null
+++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartAxis.as
@@ -0,0 +1,25 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.html.custom.beads
+{
+	public interface IChartAxis
+	{
+		
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/45c74749/examples/BarChartExample/src/org/apache/flex/html/custom/beads/XAxisBead.as
----------------------------------------------------------------------
diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/XAxisBead.as b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/XAxisBead.as
new file mode 100644
index 0000000..2670d8f
--- /dev/null
+++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/XAxisBead.as
@@ -0,0 +1,107 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.html.custom.beads
+{	
+	import org.apache.flex.core.FilledRectangle;
+	import org.apache.flex.core.IBead;
+	import org.apache.flex.core.IDataProviderItemRendererMapper;
+	import org.apache.flex.core.ISelectionModel;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.UIBase;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.html.staticControls.Label;
+	import org.apache.flex.html.staticControls.beads.models.ArraySelectionModel;
+	
+	public class XAxisBead implements IBead, IChartAxis
+	{
+		public function XAxisBead()
+		{
+		}
+		
+		private var _labelField:String;
+		public function get labelField():String
+		{
+			return _labelField;
+		}
+		public function set labelField(value:String):void
+		{
+			_labelField = value;
+		}
+		
+		private var _strand:IStrand;
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			
+			// in order to draw or create the labels, need to know when the series has been created.
+			IEventDispatcher(_strand).addEventListener("layoutComplete",handleItemsCreated);
+		}
+		
+		private function handleItemsCreated(event:Event):void
+		{
+			var charter:ChartItemRendererFactory =
+				_strand.getBeadByType(IDataProviderItemRendererMapper) as ChartItemRendererFactory;
+			
+			var model:ArraySelectionModel = _strand.getBeadByType(ISelectionModel) as ArraySelectionModel;
+			var items:Array;
+			if (model.dataProvider is Array) items = model.dataProvider as Array;
+			else return;
+			
+			var renderers:Array = charter.seriesRenderers;
+			var series:Array = IChart(_strand).series;
+					
+			var xpos:Number = 0;
+			var useWidth:Number = UIBase(_strand).width / renderers.length;
+			
+			// draw the horzontal axis
+			var horzLine:FilledRectangle = new FilledRectangle();
+			horzLine.fillColor = 0x111111;
+			horzLine.x = 0;
+			horzLine.y = UIBase(_strand).height;
+			horzLine.height = 1;
+			horzLine.width = UIBase(_strand).width;
+			UIBase(_strand).addElement(horzLine);
+			
+			// place the labels below the axis enough to account for the tick marks
+			var labelY:Number = UIBase(_strand).height + 8;
+			
+			for(var i:int=0; i < items.length; i++) {				
+				var label:Label = new Label();
+				label.text = items[i][labelField];
+				label.x = xpos;
+				label.y = labelY;
+				
+				UIBase(_strand).addElement(label);
+				
+				// add a tick mark, too
+				var tick:FilledRectangle = new FilledRectangle();
+				tick.fillColor = 0x111111;
+				tick.x = xpos + useWidth/2;
+				tick.y = UIBase(_strand).height;
+				tick.width = 1;
+				tick.height = 5;
+				UIBase(_strand).addElement(tick);
+				
+				var r:UIBase = UIBase(renderers[i][0]);
+				xpos += useWidth;
+			}
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/45c74749/examples/BarChartExample/src/org/apache/flex/html/custom/beads/layout/BarChartLayout.as
----------------------------------------------------------------------
diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/layout/BarChartLayout.as b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/layout/BarChartLayout.as
index 9a8b4a0..4553229 100644
--- a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/layout/BarChartLayout.as
+++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/layout/BarChartLayout.as
@@ -19,6 +19,7 @@
 package org.apache.flex.html.custom.beads.layout
 {	
 	import org.apache.flex.core.IBeadLayout;
+	import org.apache.flex.core.IDataProviderItemRendererMapper;
 	import org.apache.flex.core.ILayoutParent;
 	import org.apache.flex.core.IStrand;
 	import org.apache.flex.core.UIBase;
@@ -28,7 +29,6 @@ package org.apache.flex.html.custom.beads.layout
 	import org.apache.flex.html.custom.beads.IChart;
 	import org.apache.flex.html.custom.beads.IChartItemRenderer;
 	import org.apache.flex.html.custom.supportClasses.BarChartSeries;
-	import org.apache.flex.html.staticControls.beads.IDataProviderItemRendererMapper;
 	
 	public class BarChartLayout implements IBeadLayout
 	{
@@ -111,6 +111,8 @@ package org.apache.flex.html.custom.beads.layout
 				xpos += gap;
 				
 			}
+			
+			IEventDispatcher(_strand).dispatchEvent(new Event("layoutComplete"));
 		}
 	}
 }
\ No newline at end of file