Updated Branches: refs/heads/develop b6afedb61 -> 0e8662b08
BarChart example for FlexJS: includes source to BarChart in the project so it can be cross-compiled 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/d78fdc0d Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/d78fdc0d Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/d78fdc0d Branch: refs/heads/develop Commit: d78fdc0d7c4c12903c5ead28d8b9e531e6a1c4fc Parents: b6afedb Author: Peter Ent <[email protected]> Authored: Tue Dec 17 15:36:21 2013 -0500 Committer: Peter Ent <[email protected]> Committed: Tue Dec 17 15:36:21 2013 -0500 ---------------------------------------------------------------------- .../BarChartExample/src/BarChartExample.mxml | 37 ++++++ examples/BarChartExample/src/MyInitialView.mxml | 56 +++++++++ examples/BarChartExample/src/README.txt | 27 +++++ .../BarChartExample/src/models/ProductsModel.as | 49 ++++++++ .../src/org/apache/flex/html/custom/BarChart.as | 46 ++++++++ .../flex/html/custom/beads/BarChartView.as | 45 +++++++ .../custom/beads/ChartItemRendererFactory.as | 100 ++++++++++++++++ .../org/apache/flex/html/custom/beads/IChart.as | 26 +++++ .../html/custom/beads/IChartItemRenderer.as | 39 +++++++ .../flex/html/custom/beads/IChartSeries.as | 37 ++++++ .../html/custom/beads/layout/BarChartLayout.as | 116 +++++++++++++++++++ .../custom/supportClasses/BarChartSeries.as | 70 +++++++++++ .../custom/supportClasses/BoxItemRenderer.as | 116 +++++++++++++++++++ .../BarChartExample/src/products/Product.as | 43 +++++++ 14 files changed, 807 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/BarChartExample.mxml ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/BarChartExample.mxml b/examples/BarChartExample/src/BarChartExample.mxml new file mode 100644 index 0000000..baa95f8 --- /dev/null +++ b/examples/BarChartExample/src/BarChartExample.mxml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!--- +// +// 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. +// +//////////////////////////////////////////////////////////////////////////////// +--> +<basic:Application xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:local="*" + xmlns:models="models.*" + xmlns:basic="library://ns.apache.org/flexjs/basic" + > + + <basic:valuesImpl> + <basic:SimpleCSSValuesImpl /> + </basic:valuesImpl> + <basic:model> + <models:ProductsModel /> + </basic:model> + <basic:initialView> + <local:MyInitialView /> + </basic:initialView> +</basic:Application> + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/MyInitialView.mxml ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/MyInitialView.mxml b/examples/BarChartExample/src/MyInitialView.mxml new file mode 100644 index 0000000..c631c1e --- /dev/null +++ b/examples/BarChartExample/src/MyInitialView.mxml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +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. + +--> +<basic:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:basic="library://ns.apache.org/flexjs/basic" + xmlns:local="*" + xmlns:models="models.*"> + <fx:Script> + <![CDATA[ + + + ]]> + </fx:Script> + + <basic:Label id="output" x="450" y="30" width="100" /> + + <basic:BarChart id="barChart" x="20" y="20" width="400" height="200"> + <basic:beads> + <basic:ConstantBinding + sourceID="applicationModel" + sourcePropertyName="productList" + destinationPropertyName="dataProvider" /> + </basic:beads> + <basic:series> + <basic:BarChartSeries yField="sales" + fillColor="0xFF964D"> + <basic:itemRenderer> + <basic:BoxItemRenderer /> + </basic:itemRenderer> + </basic:BarChartSeries> + <basic:BarChartSeries yField="detail" + fillColor="0x964DFF"> + <basic:itemRenderer> + <basic:BoxItemRenderer /> + </basic:itemRenderer> + </basic:BarChartSeries> + </basic:series> + </basic:BarChart> + +</basic:ViewBase> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/README.txt ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/README.txt b/examples/BarChartExample/src/README.txt new file mode 100644 index 0000000..71f2f34 --- /dev/null +++ b/examples/BarChartExample/src/README.txt @@ -0,0 +1,27 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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. +// +//////////////////////////////////////////////////////////////////////////////// + +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 http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/models/ProductsModel.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/models/ProductsModel.as b/examples/BarChartExample/src/models/ProductsModel.as new file mode 100644 index 0000000..88f6662 --- /dev/null +++ b/examples/BarChartExample/src/models/ProductsModel.as @@ -0,0 +1,49 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 models +{ + import org.apache.flex.events.EventDispatcher; + + import products.Product; + + public class ProductsModel extends EventDispatcher + { + public function ProductsModel() + { + } + + private var _productList:Array = [ + new Product("ps100","Widgets",44,200,"smallbluerect.jpg"), + new Product("tx200","Thingys",5,285,"smallgreenrect.jpg"), + new Product("rz300","Sprockets",80,105,"smallyellowrect.jpg"), + new Product("dh440","Doohickies",10,340,"smallredrect.jpg"), + new Product("ps220","Weejets",35,190,"smallorangerect.jpg") + ]; + public function get productList():Array + { + return _productList; + } + + private var _labelFields:Array = [ "id", "title", "sales", "detail" ]; + public function get labelFields():Array + { + return _labelFields; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/org/apache/flex/html/custom/BarChart.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/BarChart.as b/examples/BarChartExample/src/org/apache/flex/html/custom/BarChart.as new file mode 100644 index 0000000..3232e94 --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/BarChart.as @@ -0,0 +1,46 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.events.Event; + import org.apache.flex.html.custom.beads.BarChartView; + import org.apache.flex.html.custom.beads.IChart; + import org.apache.flex.html.staticControls.List; + import org.apache.flex.html.staticControls.supportClasses.NonVirtualDataGroup; + + public class BarChart extends List implements IChart + { + public function BarChart() + { + super(); + } + + private var _series:Array; + public function get series():Array + { + return _series; + } + public function set series(value:Array):void + { + _series = value; + dispatchEvent(new Event("seriesChanged")); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/org/apache/flex/html/custom/beads/BarChartView.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/BarChartView.as b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/BarChartView.as new file mode 100644 index 0000000..481ac98 --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/BarChartView.as @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IBeadLayout; + import org.apache.flex.core.IParent; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.html.staticControls.beads.ListView; + import org.apache.flex.html.staticControls.supportClasses.NonVirtualDataGroup; + + public class BarChartView extends ListView + { + public function BarChartView() + { + super(); + } + + private var _strand:IStrand; + private var listModel:ISelectionModel; + + override public function set strand(value:IStrand):void + { + _strand = value; + super.strand = value; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/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 new file mode 100644 index 0000000..eb63fc3 --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/ChartItemRendererFactory.as @@ -0,0 +1,100 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IBead; + 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 + { + public function ChartItemRendererFactory() + { + } + + private var selectionModel:ISelectionModel; + protected var dataGroup:IItemRendererParent; + + private var _seriesRenderers:Array; + public function get seriesRenderers():Array + { + return _seriesRenderers; + } + + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + selectionModel = value.getBeadByType(ISelectionModel) as ISelectionModel; + var listView:IListView = value.getBeadByType(IListView) as IListView; + dataGroup = listView.dataGroup; +// selectionModel.addEventListener("dataProviderChanged", dataProviderChangeHandler); + + var dp:Array = selectionModel.dataProvider as Array; + if (!dp) + return; + + _seriesRenderers = new Array(); + + dataGroup.removeAllElements(); + + var series:Array = IChart(_strand).series; + + for( var j:int=0; j < dp.length; j++) + { + var renderers:Array = new Array(); + + for( var i:int=0; i < series.length; i++) + { + var s:IChartSeries = series[i] as IChartSeries; + var k:IChartItemRenderer = s.itemRenderer.newInstance() as IChartItemRenderer; + k.xField = s.xField; + k.yField = s.yField; + k.fillColor = s.fillColor; + k.data = dp[j]; + k.index = j; + + renderers.push(k); + + dataGroup.addElement(k); + } + + _seriesRenderers.push(renderers); + } + + IEventDispatcher(_strand).dispatchEvent(new Event("itemsCreated")); + } + + public function get itemRendererFactory():IItemRendererClassFactory + { + return null; + } + + public function set itemRendererFactory(value:IItemRendererClassFactory):void + { + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChart.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChart.as b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChart.as new file mode 100644 index 0000000..49f7eea --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChart.as @@ -0,0 +1,26 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 IChart + { + function get series():Array; + function set series(value:Array):void; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartItemRenderer.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartItemRenderer.as b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartItemRenderer.as new file mode 100644 index 0000000..d484b9d --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartItemRenderer.as @@ -0,0 +1,39 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IItemRenderer; + + public interface IChartItemRenderer extends IItemRenderer + { + function get xField():String; + function set xField(value:String):void; + + function get yField():String; + function set yField(value:String):void; + + function get fillColor():uint; + function set fillColor(value:uint):void; + + function set x(value:Number):void; + function set y(value:Number):void; + function set width(value:Number):void; + function set height(value:Number):void; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartSeries.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartSeries.as b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartSeries.as new file mode 100644 index 0000000..a975c86 --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/IChartSeries.as @@ -0,0 +1,37 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IItemRendererFactory; + + public interface IChartSeries + { + function get xField():String; + function set xField(value:String):void; + + function get yField():String; + function set yField(value:String):void; + + function get fillColor():uint; + function set fillColor(value:uint):void; + + function get itemRenderer():IItemRendererFactory; + function set itemRenderer(value:IItemRendererFactory):void; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/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 new file mode 100644 index 0000000..9a8b4a0 --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/beads/layout/BarChartLayout.as @@ -0,0 +1,116 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.layout +{ + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ILayoutParent; + 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.custom.beads.ChartItemRendererFactory; + 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 + { + public function BarChartLayout() + { + } + + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(value).addEventListener("widthChanged", changeHandler); + IEventDispatcher(value).addEventListener("childrenAdded", changeHandler); + IEventDispatcher(value).addEventListener("itemsCreated", changeHandler); + } + + private var _gap:Number = 20; + public function get gap():Number + { + return _gap; + } + public function set gap(value:Number):void + { + _gap = value; + } + + private function changeHandler(event:Event):void + { + var layoutParent:ILayoutParent = _strand.getBeadByType(ILayoutParent) as ILayoutParent; + + var factory:ChartItemRendererFactory = _strand.getBeadByType(IDataProviderItemRendererMapper) as ChartItemRendererFactory; + var n:int = factory.seriesRenderers.length; + + var xpos:Number = 0; + var useWidth:Number = (UIBase(_strand).width / n) - gap; + var useHeight:Number = UIBase(_strand).height; + + var maxYValue:Number = 0; + var series:Array = IChart(_strand).series; + trace("There are "+series.length+" series in this chart"); + var seriesMaxes:Array = []; + + for (var s:int = 0; s < series.length; s++) + { + var bcs:BarChartSeries = series[s] as BarChartSeries; + seriesMaxes.push({maxValue:0,scaleFactor:0}); + + for (var i:int = 0; i < n; i++) + { + var m:Array = factory.seriesRenderers[i] as Array; + var item:IChartItemRenderer = m[s] as IChartItemRenderer; + var data:Object = item.data; + var field:String = bcs.yField; + + var yValue:Number = Number(data[field]); + seriesMaxes[s].maxValue = Math.max(seriesMaxes[s].maxValue,yValue); + } + + seriesMaxes[s].scaleFactor = useHeight/seriesMaxes[s].maxValue; + } + + for (i = 0; i < n; i++) + { + m = factory.seriesRenderers[i] as Array; + for (s=0; s < m.length; s++) + { + var seriesWidth:Number = useWidth/series.length; + var child:IChartItemRenderer = m[s] as IChartItemRenderer; + data = child.data + yValue = Number(data[child.yField]); + + child.y = useHeight - yValue*seriesMaxes[s].scaleFactor; + child.x = xpos; + child.width = seriesWidth; + child.height = yValue*seriesMaxes[s].scaleFactor; + xpos += seriesWidth; + } + + xpos += gap; + + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/org/apache/flex/html/custom/supportClasses/BarChartSeries.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/supportClasses/BarChartSeries.as b/examples/BarChartExample/src/org/apache/flex/html/custom/supportClasses/BarChartSeries.as new file mode 100644 index 0000000..b4e17ed --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/supportClasses/BarChartSeries.as @@ -0,0 +1,70 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.supportClasses +{ + import org.apache.flex.core.IItemRendererFactory; + import org.apache.flex.html.custom.beads.IChartSeries; + + public class BarChartSeries implements IChartSeries + { + public function BarChartSeries() + { + } + + private var _xField:String = "x"; + public function get xField():String + { + return _xField; + } + public function set xField(value:String):void + { + _xField = value; + } + + private var _yField:String; + public function get yField():String + { + return _yField; + } + public function set yField(value:String):void + { + _yField = value; + } + + private var _fillColor:uint; + public function get fillColor():uint + { + return _fillColor; + } + public function set fillColor(value:uint):void + { + _fillColor = value; + } + + private var _itemRenderer:IItemRendererFactory; + public function get itemRenderer():IItemRendererFactory + { + return _itemRenderer; + } + public function set itemRenderer(value:IItemRendererFactory):void + { + _itemRenderer = value; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/org/apache/flex/html/custom/supportClasses/BoxItemRenderer.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/org/apache/flex/html/custom/supportClasses/BoxItemRenderer.as b/examples/BarChartExample/src/org/apache/flex/html/custom/supportClasses/BoxItemRenderer.as new file mode 100644 index 0000000..a39a441 --- /dev/null +++ b/examples/BarChartExample/src/org/apache/flex/html/custom/supportClasses/BoxItemRenderer.as @@ -0,0 +1,116 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.supportClasses +{ + import org.apache.flex.core.FilledRectangle; + import org.apache.flex.core.IItemRenderer; + import org.apache.flex.core.IItemRendererFactory; + import org.apache.flex.html.custom.beads.IChartItemRenderer; + import org.apache.flex.html.staticControls.supportClasses.UIItemRendererBase; + + public class BoxItemRenderer extends UIItemRendererBase implements IChartItemRenderer, IItemRendererFactory + { + public function BoxItemRenderer() + { + super(); + } + + override public function newInstance():IItemRenderer + { + return new BoxItemRenderer(); + } + + private var _itemRendererParent:Object; + public function get itemRendererParent():Object + { + return _itemRendererParent; + } + public function set itemRendererParent(value:Object):void + { + _itemRendererParent = value; + } + + private var filledRect:FilledRectangle; + + private var _yField:String = "y"; + public function get yField():String + { + return _yField; + } + public function set yField(value:String):void + { + _yField = value; + } + + private var _xField:String = "x"; + public function get xField():String + { + return _xField; + } + public function set xField(value:String):void + { + _xField = value; + } + + private var _fillColor:uint; + public function get fillColor():uint + { + return _fillColor; + } + public function set fillColor(value:uint):void + { + _fillColor = value; + } + + override public function addedToParent():void + { + super.addedToParent(); + } + + override public function set data(value:Object):void + { + super.data = value; + + if (filledRect == null) { + filledRect = new FilledRectangle(); + addElement(filledRect); + } + } + + override public function set width(value:Number):void + { + super.width = value; + drawBar(); + } + + override public function set height(value:Number):void + { + super.height = value; + drawBar(); + } + + protected function drawBar():void + { + if (filledRect) { + filledRect.fillColor = fillColor; + filledRect.drawRect(0,0,this.width,this.height); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d78fdc0d/examples/BarChartExample/src/products/Product.as ---------------------------------------------------------------------- diff --git a/examples/BarChartExample/src/products/Product.as b/examples/BarChartExample/src/products/Product.as new file mode 100644 index 0000000..fd4b31e --- /dev/null +++ b/examples/BarChartExample/src/products/Product.as @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 products +{ + public class Product + { + public function Product(id:String,title:String,detail:Number,sales:Number,image:String) + { + this.id = id; + this.title = title; + this.detail = detail; + this.sales = sales; + this.image = image; + } + + public var id:String; + public var title:String; + public var detail:Number; + public var image:String; + public var sales:Number; + + public function toString():String + { + return title; + } + } +} \ No newline at end of file
