Repository: flex-asjs Updated Branches: refs/heads/develop 5d52dc685 -> 1dac61548
Added ArrayList parallels for Chart classes. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/f9c4a01d Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/f9c4a01d Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/f9c4a01d Branch: refs/heads/develop Commit: f9c4a01d99b0ab4dd338a3f95c8d0aad19468cef Parents: 241d202 Author: Peter Ent <p...@apache.org> Authored: Mon Sep 19 15:37:41 2016 -0400 Committer: Peter Ent <p...@apache.org> Committed: Mon Sep 19 15:37:41 2016 -0400 ---------------------------------------------------------------------- frameworks/projects/Charts/pom.xml | 13 ++ .../src/main/config/compile-as-config.xml | 1 + .../Charts/src/main/flex/ChartsClasses.as | 11 ++ ...ItemRendererFactoryForSeriesArrayListData.as | 139 ++++++++++++++++++ .../charts/beads/HorizontalCategoryAxisBead.as | 2 +- .../HorizontalCategoryAxisForArrayListBead.as | 85 +++++++++++ .../charts/beads/HorizontalLinearAxisBead.as | 4 +- .../HorizontalLinearAxisForArrayListBead.as | 121 ++++++++++++++++ .../charts/beads/VerticalCategoryAxisBead.as | 2 +- .../VerticalCategoryAxisForArrayListBead.as | 98 +++++++++++++ .../flex/charts/beads/VerticalLinearAxisBead.as | 4 +- .../beads/VerticalLinearAxisForArrayListBead.as | 119 +++++++++++++++ .../beads/layouts/BarChartLayoutForArrayList.as | 129 +++++++++++++++++ .../layouts/ColumnChartLayoutForArrayList.as | 129 +++++++++++++++++ .../beads/layouts/PieChartLayoutForArrayList.as | 142 ++++++++++++++++++ .../StackedBarChartLayoutForArrayList.as | 145 +++++++++++++++++++ .../StackedColumnChartLayoutForArrayList.as | 142 ++++++++++++++++++ .../models/ChartArrayListSelectionModel.as | 75 ++++++++++ .../src/main/resources/basic-manifest.xml | 21 +++ 19 files changed, 1376 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/pom.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/pom.xml b/frameworks/projects/Charts/pom.xml index 9eefdf8..394fcfe 100644 --- a/frameworks/projects/Charts/pom.xml +++ b/frameworks/projects/Charts/pom.xml @@ -81,6 +81,19 @@ </dependency> <dependency> <groupId>org.apache.flex.flexjs.framework</groupId> + <artifactId>Collections</artifactId> + <version>0.8.0-SNAPSHOT</version> + <type>swc</type> + </dependency> + <dependency> + <groupId>org.apache.flex.flexjs.framework</groupId> + <artifactId>Collections</artifactId> + <version>0.8.0-SNAPSHOT</version> + <type>swc</type> + <classifier>typedefs</classifier> + </dependency> + <dependency> + <groupId>org.apache.flex.flexjs.framework</groupId> <artifactId>Binding</artifactId> <version>0.8.0-SNAPSHOT</version> <type>swc</type> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/config/compile-as-config.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/config/compile-as-config.xml b/frameworks/projects/Charts/src/main/config/compile-as-config.xml index 1fc9bce..728b5ca 100644 --- a/frameworks/projects/Charts/src/main/config/compile-as-config.xml +++ b/frameworks/projects/Charts/src/main/config/compile-as-config.xml @@ -24,6 +24,7 @@ <external-library-path> <path-element>${env.AIR_HOME}/frameworks/libs/air/airglobal.swc</path-element> <path-element>../../../../../libs/Core.swc</path-element> + <path-element>../../../../../libs/Collections.swc</path-element> <path-element>../../../../../libs/Graphics.swc</path-element> <path-element>../../../../../libs/HTML.swc</path-element> </external-library-path> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/ChartsClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/ChartsClasses.as b/frameworks/projects/Charts/src/main/flex/ChartsClasses.as index 97b998e..79de855 100644 --- a/frameworks/projects/Charts/src/main/flex/ChartsClasses.as +++ b/frameworks/projects/Charts/src/main/flex/ChartsClasses.as @@ -47,20 +47,31 @@ internal class ChartsClasses import org.apache.flex.charts.beads.ChartView; ChartView; import org.apache.flex.charts.beads.ChartItemRendererFactory; ChartItemRendererFactory; import org.apache.flex.charts.beads.DataItemRendererFactoryForSeriesData; DataItemRendererFactoryForSeriesData; + import org.apache.flex.charts.beads.DataItemRendererFactoryForSeriesArrayListData; DataItemRendererFactoryForSeriesArrayListData; import org.apache.flex.charts.beads.DataTipBead; DataTipBead; import org.apache.flex.charts.beads.HorizontalCategoryAxisBead; HorizontalCategoryAxisBead; + import org.apache.flex.charts.beads.HorizontalCategoryAxisForArrayListBead; HorizontalCategoryAxisForArrayListBead; import org.apache.flex.charts.beads.HorizontalLinearAxisBead; HorizontalLinearAxisBead; + import org.apache.flex.charts.beads.HorizontalLinearAxisForArrayListBead; HorizontalLinearAxisForArrayListBead; import org.apache.flex.charts.beads.VerticalCategoryAxisBead; VerticalCategoryAxisBead; + import org.apache.flex.charts.beads.VerticalCategoryAxisForArrayListBead; VerticalCategoryAxisForArrayListBead; import org.apache.flex.charts.beads.VerticalLinearAxisBead; VerticalLinearAxisBead; + import org.apache.flex.charts.beads.VerticalLinearAxisForArrayListBead; VerticalLinearAxisForArrayListBead; import org.apache.flex.charts.beads.controllers.ChartSeriesMouseController; ChartSeriesMouseController; import org.apache.flex.charts.beads.layouts.BarChartLayout; BarChartLayout; + import org.apache.flex.charts.beads.layouts.BarChartLayoutForArrayList; BarChartLayoutForArrayList; import org.apache.flex.charts.beads.layouts.ColumnChartLayout; ColumnChartLayout; + import org.apache.flex.charts.beads.layouts.ColumnChartLayoutForArrayList; ColumnChartLayoutForArrayList; import org.apache.flex.charts.beads.layouts.LineChartCategoryVsLinearLayout; LineChartCategoryVsLinearLayout; import org.apache.flex.charts.beads.layouts.LineChartLinearVsLinearLayout; LineChartLinearVsLinearLayout; import org.apache.flex.charts.beads.layouts.PieChartLayout; PieChartLayout; + import org.apache.flex.charts.beads.layouts.PieChartLayoutForArrayList; PieChartLayoutForArrayList; import org.apache.flex.charts.beads.layouts.StackedBarChartLayout; StackedBarChartLayout; + import org.apache.flex.charts.beads.layouts.StackedBarChartLayoutForArrayList; StackedBarChartLayoutForArrayList; import org.apache.flex.charts.beads.layouts.StackedColumnChartLayout; StackedColumnChartLayout; + import org.apache.flex.charts.beads.layouts.StackedColumnChartLayoutForArrayList; StackedColumnChartLayoutForArrayList; import org.apache.flex.charts.beads.models.ChartArraySelectionModel; ChartArraySelectionModel; + import org.apache.flex.charts.beads.models.ChartArrayListSelectionModel; ChartArrayListSelectionModel; import org.apache.flex.charts.supportClasses.BarSeries; BarSeries; import org.apache.flex.charts.supportClasses.LineSeries; LineSeries; import org.apache.flex.charts.supportClasses.PieSeries; PieSeries; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/DataItemRendererFactoryForSeriesArrayListData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/DataItemRendererFactoryForSeriesArrayListData.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/DataItemRendererFactoryForSeriesArrayListData.as new file mode 100644 index 0000000..7010627 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/DataItemRendererFactoryForSeriesArrayListData.as @@ -0,0 +1,139 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads +{ + import org.apache.flex.charts.core.IChart; + import org.apache.flex.charts.core.IChartDataGroup; + import org.apache.flex.charts.core.IChartItemRenderer; + import org.apache.flex.charts.core.IChartSeries; + import org.apache.flex.collections.ArrayList; + import org.apache.flex.core.IBead; + import org.apache.flex.core.IDataProviderItemRendererMapper; + import org.apache.flex.core.IItemRendererClassFactory; + 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.beads.IListView; + + /** + * The DataItemRendererFactoryForSeriesData creates the itemRenderers necessary for series-based + * charts. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class DataItemRendererFactoryForSeriesArrayListData implements IBead, IDataProviderItemRendererMapper + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function DataItemRendererFactoryForSeriesArrayListData() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(_strand).addEventListener("initComplete", initComplete); + } + public function get strand():IStrand + { + return _strand; + } + + private function initComplete(event:Event):void + { + var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel; + selectionModel.addEventListener("dataProviderChanged", dataProviderChangeHandler); + + dataProviderChangeHandler(null); + } + + /** + * For series data, the 'global' itemRendererFactory is not used. Each series supplies + * its own itemRendererFactory. + */ + public function get itemRendererFactory():IItemRendererClassFactory + { + return null; + } + public function set itemRendererFactory(value:IItemRendererClassFactory):void + { + } + + /** + * @private + */ + private function dataProviderChangeHandler(event:Event):void + { + var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel; + var dp:ArrayList = selectionModel.dataProvider as ArrayList; + if (!dp) + return; + + var listView:IListView = _strand.getBeadByType(IListView) as IListView; + var dataGroup:IChartDataGroup = listView.dataGroup as IChartDataGroup; + dataGroup.removeAllElements(); + + var chart:IChart = _strand as IChart; + var series:Array = chart.series; + + for (var s:int=0; s < series.length; s++) + { + var n:int = dp.length; + var chartSeries:IChartSeries = series[s] as IChartSeries; + + for (var i:int = 0; i < n; i++) + { + if (chartSeries.itemRenderer) + { + var ir:IChartItemRenderer = chartSeries.itemRenderer.newInstance() as IChartItemRenderer; + dataGroup.addElement(ir); + ir.itemRendererParent = dataGroup; + ir.index = i; + ir.data = dp.getItemAt(i) + ir.series = chartSeries; + } + } + + } + + IEventDispatcher(_strand).dispatchEvent(new Event("itemsCreated")); + IEventDispatcher(_strand).dispatchEvent(new Event("layoutNeeded")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as index 9efbd72..171a848 100644 --- a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as @@ -157,7 +157,7 @@ package org.apache.flex.charts.beads /** * @private */ - private function handleItemsCreated(event:Event):void + protected function handleItemsCreated(event:Event):void { var model:ArraySelectionModel = strand.getBeadByType(ISelectionModel) as ArraySelectionModel; var items:Array; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisForArrayListBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisForArrayListBead.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisForArrayListBead.as new file mode 100644 index 0000000..e93add0 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalCategoryAxisForArrayListBead.as @@ -0,0 +1,85 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads +{ + import org.apache.flex.collections.ArrayList; + import org.apache.flex.charts.core.IHorizontalAxisBead; + import org.apache.flex.core.IBead; + 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.beads.models.ArrayListSelectionModel; + + /** + * The HorizontalCategoryAxisForArrayListBead displays a horizontal axis with + * tick marks corresponding to data points identified by the + * categoryField property. This type of axis is useful for non-numeric + * plots. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class HorizontalCategoryAxisForArrayListBead extends HorizontalCategoryAxisBead + { + public function HorizontalCategoryAxisForArrayListBead() + { + super(); + } + + /** + * @private + */ + override protected function handleItemsCreated(event:Event):void + { + var model:ArrayListSelectionModel = strand.getBeadByType(ISelectionModel) as ArrayListSelectionModel; + var items:ArrayList; + if (model.dataProvider is ArrayList) items = model.dataProvider as ArrayList; + else return; + + clearGraphics(); + + var xpos:Number = 0; + var useWidth:Number = UIBase(axisGroup).width; + + // place the labels below the axis enough to account for the tick marks + var labelY:Number = 7; + var itemWidth:Number = (useWidth - gap*(items.length-1))/items.length; + + for(var i:int=0; i < items.length; i++) + { + var item:Object = items.getItemAt(i); + addTickLabel(item[categoryField], xpos, labelY, itemWidth, 0); + + // add a tick mark, too + addTickMark(xpos + itemWidth/2, 0, 0, 5); + + xpos += itemWidth + gap; + } + + // draw the axis and the tick marks + drawAxisPath(0, 0, useWidth, 1); + drawTickPath(0, 1); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisBead.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisBead.as index 6e24b2c..f375927 100644 --- a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisBead.as +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisBead.as @@ -160,7 +160,7 @@ package org.apache.flex.charts.beads /** * @private */ - private function formatLabel(n:Number):String + protected function formatLabel(n:Number):String { var sign:Number = n < 0 ? -1 : 1; n = Math.abs(n); @@ -183,7 +183,7 @@ package org.apache.flex.charts.beads /** * @private */ - private function handleItemsCreated(event:Event):void + protected function handleItemsCreated(event:Event):void { var model:ArraySelectionModel = strand.getBeadByType(ISelectionModel) as ArraySelectionModel; var items:Array; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisForArrayListBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisForArrayListBead.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisForArrayListBead.as new file mode 100644 index 0000000..4ade000 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/HorizontalLinearAxisForArrayListBead.as @@ -0,0 +1,121 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads +{ + import org.apache.flex.collections.ArrayList; + import org.apache.flex.charts.core.IChart; + import org.apache.flex.charts.core.IHorizontalAxisBead; + import org.apache.flex.core.IBead; + 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.beads.models.ArrayListSelectionModel; + + /** + * The HorizontalLinearAxisForArrayListBead class provides a horizontal axis that uses a numeric + * range. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class HorizontalLinearAxisForArrayListBead extends HorizontalLinearAxisBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function HorizontalLinearAxisForArrayListBead() + { + super(); + } + + /** + * @private + */ + override protected function handleItemsCreated(event:Event):void + { + var model:ArrayListSelectionModel = strand.getBeadByType(ISelectionModel) as ArrayListSelectionModel; + var items:ArrayList; + if (model.dataProvider is ArrayList) items = model.dataProvider as ArrayList; + else return; + + clearGraphics(); + + var xpos:Number = 0; + var useWidth:Number = UIBase(axisGroup).width; + var series:Array = IChart(strand).series; + var maxValue:Number = Number.MIN_VALUE; + var minValue:Number = Number.MAX_VALUE; + + // determine minimum and maximum values, if needed + if (isNaN(minimum)) { + for(var i:int=0; i < items.length; i++) { + var item:Object = items.getItemAt(i); + var value:Number = Number(item[valueField]); + if (!isNaN(value)) minValue = Math.min(minValue,value); + else minValue = Math.min(minValue,0); + } + } else { + minValue = minimum; + } + if (isNaN(maximum)) { + for(i=0; i < items.length; i++) { + item = items.getItemAt(i); + value = Number(item[valueField]); + if (!isNaN(value)) maxValue = Math.max(maxValue,value); + else maxValue = Math.max(maxValue,0); + } + } else { + maxValue = maximum; + } + + var numTicks:Number = 10; // should determine this some other way, I think + var tickStep:Number = (maxValue - minValue)/numTicks; + var tickSpacing:Number = useWidth/numTicks; + var tickValue:Number = minValue; + + // place the labels below the axis enough to account for the tick marks + var labelY:Number = 7; + + for(i=0; i < numTicks+1; i++) + { + var label:Object = addTickLabel(formatLabel(tickValue), xpos, labelY, tickSpacing, 0); + label.x = xpos - label.width/2; + + // add a tick mark, too + addTickMark(xpos, 0, 0, 5); + + xpos += tickSpacing; + tickValue += tickStep; + } + + // draw the axis and tick marks + drawAxisPath(0, 0, useWidth, 0); + drawTickPath(0, 1); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as index 577bd5a..94f72e5 100644 --- a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as @@ -159,7 +159,7 @@ package org.apache.flex.charts.beads /** * @private */ - private function handleItemsCreated(event:Event):void + protected function handleItemsCreated(event:Event):void { var model:ArraySelectionModel = strand.getBeadByType(ISelectionModel) as ArraySelectionModel; var items:Array; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisForArrayListBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisForArrayListBead.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisForArrayListBead.as new file mode 100644 index 0000000..07a6685 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalCategoryAxisForArrayListBead.as @@ -0,0 +1,98 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads +{ + import org.apache.flex.collections.ArrayList; + import org.apache.flex.charts.core.IChart; + import org.apache.flex.charts.core.IVerticalAxisBead; + import org.apache.flex.core.IBead; + 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.beads.models.ArrayListSelectionModel; + + /** + * The VerticalCategoryAxisForArrayListBead displays a vertical axis with + * tick marks corresponding to data points identified by the + * categoryField property. This type of axis is useful for non-numeric + * plots. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VerticalCategoryAxisForArrayListBead extends VerticalCategoryAxisBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VerticalCategoryAxisForArrayListBead() + { + super(); + } + + /** + * @private + */ + override protected function handleItemsCreated(event:Event):void + { + var model:ArrayListSelectionModel = strand.getBeadByType(ISelectionModel) as ArrayListSelectionModel; + var items:ArrayList; + if (model.dataProvider is ArrayList) items = model.dataProvider as ArrayList; + else return; + + clearGraphics(); + + var series:Array = IChart(strand).series; + + var useHeight:Number = UIBase(axisGroup).height; + var useWidth:Number = UIBase(axisGroup).width; + var itemHeight:Number = (useHeight - gap*(items.length-1)) / items.length; + var xpos:Number = 0; + var ypos:Number = useHeight - itemHeight/2; + + var numTicks:Number = items.length; + var tickSpacing:Number = itemHeight + gap; + + for(var i:int=0; i < items.length; i++) + { + var item:Object = items.getItemAt(i); + var label:Object = addTickLabel(item[categoryField], 0, ypos, 0, itemHeight); + label.y = ypos - label.height/2; + + // add a tick mark, too. + addTickMark(useWidth-6, ypos, 5, 0); + + ypos -= tickSpacing; + } + + // draw the axis and tick marks + drawAxisPath(useWidth-1, 0, 0, useHeight); + drawTickPath(useWidth-6, 0); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisBead.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisBead.as index 4cd2e63..91cf168 100644 --- a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisBead.as +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisBead.as @@ -144,7 +144,7 @@ package org.apache.flex.charts.beads /** * @private */ - private function formatLabel(n:Number):String + protected function formatLabel(n:Number):String { var sign:Number = n < 0 ? -1 : 1; n = Math.abs(n); @@ -167,7 +167,7 @@ package org.apache.flex.charts.beads /** * @private */ - private function handleItemsCreated(event:Event):void + protected function handleItemsCreated(event:Event):void { var model:ArraySelectionModel = strand.getBeadByType(ISelectionModel) as ArraySelectionModel; var items:Array; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisForArrayListBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisForArrayListBead.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisForArrayListBead.as new file mode 100644 index 0000000..2d7b199 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/VerticalLinearAxisForArrayListBead.as @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads +{ + import org.apache.flex.collections.ArrayList; + import org.apache.flex.charts.core.IChart; + import org.apache.flex.charts.core.IVerticalAxisBead; + import org.apache.flex.core.IBead; + 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.beads.models.ArrayListSelectionModel; + + /** + * The VerticalLinearAxisBead class provides a vertical axis that uses a numeric + * range. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VerticalLinearAxisForArrayListBead extends VerticalLinearAxisBead + { + public function VerticalLinearAxisForArrayListBead() + { + super(); + } + + /** + * @private + */ + override protected function handleItemsCreated(event:Event):void + { + var model:ArrayListSelectionModel = strand.getBeadByType(ISelectionModel) as ArrayListSelectionModel; + var items:ArrayList; + if (model.dataProvider is ArrayList) items = model.dataProvider as ArrayList; + else return; + + clearGraphics(); + + var series:Array = IChart(strand).series; + + var useHeight:Number = UIBase(axisGroup).height; + var useWidth:Number = UIBase(axisGroup).width; + var xpos:Number = 0; + var ypos:Number = useHeight; + var minValue:Number = Number.MAX_VALUE; + var maxValue:Number = Number.MIN_VALUE; + + // determine minimum and maximum values, if needed + if (isNaN(minimum)) { + for(var i:int=0; i < items.length; i++) { + var item:Object = items.getItemAt(i); + var value:Number = Number(item[valueField]); + if (!isNaN(value)) minValue = Math.min(minValue,value); + else minValue = Math.min(minValue,0); + } + } else { + minValue = minimum; + } + if (isNaN(maximum)) { + for(i=0; i < items.length; i++) { + item = items.getItemAt(i); + value = Number(item[valueField]); + if (!isNaN(value)) maxValue = Math.max(maxValue,value); + else maxValue = Math.max(maxValue,0); + } + } else { + maxValue = maximum; + } + + var range:Number = maxValue - minValue; + var numTicks:Number = 10; // should determine this some other way, I think + var tickStep:Number = range/numTicks; + var tickSpacing:Number = useHeight/numTicks; + var tickValue:Number = minimum; + + // place the labels below the axis enough to account for the tick marks + var labelY:Number = UIBase(axisGroup).height + 8; + + for(i=0; i < numTicks+1; i++) + { + var label:Object = addTickLabel(formatLabel(tickValue), 0, ypos, 0, tickSpacing); + label.y = ypos - label.height/2; + + // add a tick mark, too. + addTickMark(useWidth-6, ypos, 5, 0); + + ypos -= tickSpacing; + tickValue += tickStep; + } + + // draw the axis and the tick marks + drawAxisPath(useWidth-1, 0, 0, useHeight); + drawTickPath(useWidth-6, 0); + + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/BarChartLayoutForArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/BarChartLayoutForArrayList.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/BarChartLayoutForArrayList.as new file mode 100644 index 0000000..bea8734 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/BarChartLayoutForArrayList.as @@ -0,0 +1,129 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads.layouts +{ + import org.apache.flex.charts.core.ICartesianChartLayout; + import org.apache.flex.charts.core.IChartItemRenderer; + import org.apache.flex.charts.core.IChartSeries; + import org.apache.flex.charts.supportClasses.BarSeries; + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.ArrayList; + + /** + * The BarChartLayoutForArrayList class calculates the size and position of all of the itemRenderers for + * all of the series in a BarChart. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class BarChartLayoutForArrayList extends BarChartLayout + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function BarChartLayoutForArrayList() + { + super(); + } + + /** + * @private + */ + override protected function performLayout():void + { + var selectionModel:ISelectionModel = chart.getBeadByType(ISelectionModel) as ISelectionModel; + var dp:ArrayList = selectionModel.dataProvider as ArrayList; + if (!dp) + return; + + var n:int = dp.length; + var useWidth:Number = UIBase(chartDataGroup).width; + var useHeight:Number = UIBase(chartDataGroup).height; + var itemHeight:Number = (useHeight - gap*(dp.length-1))/dp.length; + var seriesHeight:Number = itemHeight/chart.series.length; + var ypos:Number = useHeight; + + var maxXValue:Number = 0; + var minXValue:Number = 0; + var scaleFactor:Number = 1.0; + var determineScale:Boolean = true; + + if (horizontalAxisBead != null && !isNaN(horizontalAxisBead.maximum)) { + maxXValue = horizontalAxisBead.maximum; + determineScale = false; + } + if (horizontalAxisBead != null && !isNaN(horizontalAxisBead.minimum)) { + minXValue = horizontalAxisBead.minimum; + } + + for (var s:int = 0; s < chart.series.length; s++) + { + var bcs:BarSeries = chart.series[s] as BarSeries; + + for (var i:int = 0; i < n; i++) + { + var data:Object = dp.getItemAt(i); + var field:String = bcs.xField; + + var xValue:Number = Number(data[field]); + if (determineScale) maxXValue = Math.max(xValue, maxXValue); + } + } + + var range:Number = maxXValue - minXValue; + scaleFactor = useWidth/range; + + for (i = 0; i < n; i++) + { + data = dp.getItemAt(i); + + for (s=0; s < chart.series.length; s++) + { + bcs = chart.series[s] as BarSeries; + + var child:IChartItemRenderer = chartDataGroup.getItemRendererForSeriesAtIndex(bcs,i); + xValue = Number(data[bcs.xField]) - minXValue; + if (xValue > maxXValue) xValue = maxXValue; + xValue = xValue * scaleFactor; + + child.x = 0; + child.y = ypos - seriesHeight; + child.width = xValue; + child.height = seriesHeight; + ypos -= seriesHeight; + } + + ypos -= gap; + } + + IEventDispatcher(chart).dispatchEvent(new Event("layoutComplete")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/ColumnChartLayoutForArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/ColumnChartLayoutForArrayList.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/ColumnChartLayoutForArrayList.as new file mode 100644 index 0000000..f1c3396 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/ColumnChartLayoutForArrayList.as @@ -0,0 +1,129 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads.layouts +{ + import org.apache.flex.charts.core.ICartesianChartLayout; + import org.apache.flex.charts.core.IChartItemRenderer; + import org.apache.flex.charts.core.IVerticalAxisBead; + import org.apache.flex.charts.supportClasses.ColumnSeries; + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.ArrayList; + + /** + * The ColumnChartLayoutForArrayList class calculates the size and position of all of the itemRenderers for + * all of the series in a BarChart. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ColumnChartLayoutForArrayList extends ColumnChartLayout + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ColumnChartLayoutForArrayList() + { + super(); + } + + /** + * @private + */ + override protected function performLayout():void + { + var selectionModel:ISelectionModel = chart.getBeadByType(ISelectionModel) as ISelectionModel; + var dp:ArrayList = selectionModel.dataProvider as ArrayList; + if (!dp) + return; + + var n:int = dp.length; + var xpos:Number = 0; + var useWidth:Number = UIBase(chartDataGroup).width; + var useHeight:Number = UIBase(chartDataGroup).height; + var itemWidth:Number = (useWidth - gap*(dp.length-1))/dp.length; + var seriesWidth:Number = itemWidth/chart.series.length; + + var maxYValue:Number = 0; + var minYValue:Number = 0; + var scaleFactor:Number = 1; + var determineScale:Boolean = true; + + if (verticalAxisBead != null && !isNaN(verticalAxisBead.maximum)) { + maxYValue = verticalAxisBead.maximum; + determineScale = false; + } + if (verticalAxisBead != null && !isNaN(verticalAxisBead.minimum)) { + minYValue = verticalAxisBead.minimum; + } + + for (var s:int = 0; s < chart.series.length; s++) + { + var bcs:ColumnSeries = chart.series[s] as ColumnSeries; + + for (var i:int = 0; i < n; i++) + { + var data:Object = dp.getItemAt(i); + var field:String = bcs.yField; + + var yValue:Number = Number(data[field]); + if (determineScale) maxYValue = Math.max(yValue, maxYValue); + } + } + + var range:Number = maxYValue - minYValue; + scaleFactor = useHeight/range; + + for (i = 0; i < n; i++) + { + data = dp.getItemAt(i); + + for (s=0; s < chart.series.length; s++) + { + bcs = chart.series[s] as ColumnSeries; + + var child:IChartItemRenderer = chartDataGroup.getItemRendererForSeriesAtIndex(bcs,i); + yValue = Number(data[bcs.yField]) - minYValue; + if (yValue > maxYValue) yValue = maxYValue; + yValue = yValue * scaleFactor; + + child.y = useHeight - yValue; + child.x = xpos; + child.width = seriesWidth; + child.height = yValue; + xpos += seriesWidth; + } + + xpos += gap; + } + + IEventDispatcher(chart).dispatchEvent(new Event("layoutComplete")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/PieChartLayoutForArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/PieChartLayoutForArrayList.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/PieChartLayoutForArrayList.as new file mode 100644 index 0000000..09418f3 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/PieChartLayoutForArrayList.as @@ -0,0 +1,142 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads.layouts +{ + import org.apache.flex.charts.core.IChartItemRenderer; + import org.apache.flex.charts.core.IChartSeries; + import org.apache.flex.charts.supportClasses.IWedgeItemRenderer; + import org.apache.flex.charts.supportClasses.PieSeries; + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.ILayoutHost; + import org.apache.flex.core.IParentIUIBase; + import org.apache.flex.graphics.IFill; + import org.apache.flex.graphics.SolidColor; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.ArrayList; + + /** + * The PieChartLayoutForArrayList class calculates the size and position of all of the itemRenderers for + * a PieChart. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class PieChartLayoutForArrayList extends PieChartLayout + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function PieChartLayoutForArrayList() + { + super(); + } + + /** + * @private + */ + override protected function performLayout():void + { + var selectionModel:ISelectionModel = chart.getBeadByType(ISelectionModel) as ISelectionModel; + var dp:ArrayList = selectionModel.dataProvider as ArrayList; + if (!dp) + return; + + var layoutParent:ILayoutHost = strand.getBeadByType(ILayoutHost) as ILayoutHost; + var contentView:IParentIUIBase = layoutParent.contentView as IParentIUIBase; + + var n:int = dp.length; + + var xpos:Number = 0; + var useWidth:Number = contentView.width; + var useHeight:Number = contentView.height; + + var maxYValue:Number = 0; + var seriesMaxes:Array = []; + var colors:Array = [0xFF964D, 0x964DFF, 0xF80012, 0x96FF4D, 0x4D96FF, 0x8A8A01, 0x23009C, 0x4A4A4A, 0x23579D]; + + for (var s:int = 0; s < chart.series.length; s++) + { + var pcs:PieSeries = chart.series[s] as PieSeries; + + for (var i:int = 0; i < n; i++) + { + var data:Object = dp.getItemAt(i); + var field:String = pcs.dataField; + + var yValue:Number = Number(data[field]); + maxYValue += yValue; + + seriesMaxes.push( {yValue:yValue, percent:0, arc:0} ); + } + + for (i=0; i < n; i++) + { + var obj:Object = seriesMaxes[i]; + obj.percent = obj.yValue / maxYValue; + obj.arc = 360.0*obj.percent; + } + + var start:Number = 0; + var end:Number = 0; + var radius:Number = Math.min(useWidth,useHeight)/2; + var centerX:Number = useWidth/2; + var centerY:Number = useHeight/2; + + for (i=0; i < n; i++) + { + obj = seriesMaxes[i]; + data = dp.getItemAt(i); + + var fill:SolidColor = new SolidColor(); + fill.color = colors[i%colors.length]; + fill.alpha = 1.0; + + var child:IWedgeItemRenderer = chartDataGroup.getItemRendererForSeriesAtIndex(chart.series[s],i) as IWedgeItemRenderer; + child.fill = fill; + + end = start + (360.0 * obj.percent); + var arc:Number = 360.0 * obj.percent; + + child.x = 0; + child.y = 0; + child.width = useWidth; + child.height = useHeight; + child.centerX = centerX; + child.centerY = centerY; + child.startAngle = start*Math.PI/180; + child.arc = arc*Math.PI/180; + child.radius = radius; + + start += arc; + } + } + + IEventDispatcher(chart).dispatchEvent(new Event("layoutComplete")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/StackedBarChartLayoutForArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/StackedBarChartLayoutForArrayList.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/StackedBarChartLayoutForArrayList.as new file mode 100644 index 0000000..f0f87dc --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/StackedBarChartLayoutForArrayList.as @@ -0,0 +1,145 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads.layouts +{ + import org.apache.flex.charts.core.ICartesianChartLayout; + import org.apache.flex.charts.core.IChartItemRenderer; + import org.apache.flex.charts.core.IChartSeries; + import org.apache.flex.charts.supportClasses.BarSeries; + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.ILayoutHost; + import org.apache.flex.core.IParentIUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.ArrayList; + + /** + * The StackedBarChartLayoutForArrayList class calculates the size and position of all of the itemRenderers for + * all of the series in a BarChart. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class StackedBarChartLayoutForArrayList extends StackedBarChartLayout + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function StackedBarChartLayoutForArrayList() + { + super(); + } + + /** + * @private + */ + override protected function performLayout():void + { + var selectionModel:ISelectionModel = chart.getBeadByType(ISelectionModel) as ISelectionModel; + var dp:ArrayList = selectionModel.dataProvider as ArrayList; + if (!dp) + return; + + var layoutParent:ILayoutHost = strand.getBeadByType(ILayoutHost) as ILayoutHost; + var contentView:IParentIUIBase = layoutParent.contentView as IParentIUIBase; + + var n:int = dp.length; + var maxXValue:Number = 0; + var minXValue:Number = 0; + var determineScale:Boolean = true; + var seriesMaxes:Array = []; + + var useWidth:Number = contentView.width; + var useHeight:Number = contentView.height; + var itemHeight:Number = (useHeight - gap*(dp.length-1))/n; + var seriesHeight:Number = itemHeight; + var xpos:Number = 0; + var ypos:Number = useHeight; + + var barValues:Array = []; + var scaleFactor:Number = 1; + + if (horizontalAxisBead != null && !isNaN(horizontalAxisBead.maximum)) { + maxXValue = horizontalAxisBead.maximum; + determineScale = false; + } + if (horizontalAxisBead != null && !isNaN(horizontalAxisBead.minimum)) { + minXValue = horizontalAxisBead.minimum; + } + + for (var i:int=0; i < n; i++) + { + barValues.push({totalValue:0, scaleFactor:0}); + + var data:Object = dp.getItemAt(i); + + for (var s:int = 0; s < chart.series.length; s++) + { + var bcs:BarSeries = chart.series[s] as BarSeries; + var field:String = bcs.xField; + + var xValue:Number = Number(data[field]); + barValues[i].totalValue += xValue; + } + + if (determineScale) { + maxXValue = Math.max(maxXValue, barValues[i].totalValue); + } + } + + scaleFactor = useWidth/(maxXValue - minXValue); + + for (i=0; i < n; i++) + { + data = dp.getItemAt(i); + + xpos = 0; + + for (s=0; s < chart.series.length; s++) + { + bcs = chart.series[s] as BarSeries; + + var child:IChartItemRenderer = chartDataGroup.getItemRendererForSeriesAtIndex(bcs,i); + xValue = Number(data[bcs.xField]) - minXValue; + xValue = xValue * scaleFactor; + + child.x = xpos; + child.width = Math.floor(xValue); + child.y = Math.floor(ypos - seriesHeight); + child.height = seriesHeight; + + xpos += xValue; + } + + ypos -= (itemHeight + gap); + } + + IEventDispatcher(chart).dispatchEvent(new Event("layoutComplete")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/StackedColumnChartLayoutForArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/StackedColumnChartLayoutForArrayList.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/StackedColumnChartLayoutForArrayList.as new file mode 100644 index 0000000..716aff5 --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/layouts/StackedColumnChartLayoutForArrayList.as @@ -0,0 +1,142 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads.layouts +{ + import org.apache.flex.charts.core.ICartesianChartLayout; + import org.apache.flex.charts.core.IChartItemRenderer; + import org.apache.flex.charts.supportClasses.ColumnSeries; + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.ILayoutHost; + import org.apache.flex.core.IParentIUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.ArrayList; + + /** + * The StackedColumnChartLayoutForArrayList class calculates the size and position of all of the itemRenderers for + * all of the series in a BarChart. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class StackedColumnChartLayoutForArrayList extends StackedColumnChartLayout + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function StackedColumnChartLayoutForArrayList() + { + super(); + } + + /** + * @private + */ + override protected function performLayout():void + { + var selectionModel:ISelectionModel = chart.getBeadByType(ISelectionModel) as ISelectionModel; + var dp:ArrayList = selectionModel.dataProvider as ArrayList; + if (!dp) + return; + + var layoutParent:ILayoutHost = strand.getBeadByType(ILayoutHost) as ILayoutHost; + var contentView:IParentIUIBase = layoutParent.contentView as IParentIUIBase; + + var n:int = dp.length; + var useWidth:Number = contentView.width; + var useHeight:Number = contentView.height; + var itemWidth:Number = (useWidth - gap*(dp.length-1))/dp.length; + var seriesWidth:Number = itemWidth; + var xpos:Number = 0; + var ypos:Number = 0; + + var maxYValue:Number = 0; + var minYValue:Number = 0; + var determineScale:Boolean = true; + + var barValues:Array = []; + var scaleFactor:Number = 1; + + if (verticalAxisBead != null && !isNaN(verticalAxisBead.maximum)) { + maxYValue = verticalAxisBead.maximum; + determineScale = false; + } + if (verticalAxisBead != null && !isNaN(verticalAxisBead.minimum)) { + minYValue = verticalAxisBead.minimum; + } + + for (var i:int=0; i < n; i++) + { + barValues.push({totalValue:0}); + var data:Object = dp.getItemAt(i); + + for (var s:int = 0; s < chart.series.length; s++) + { + var bcs:ColumnSeries = chart.series[s] as ColumnSeries; + var field:String = bcs.yField; + + var yValue:Number = Number(data[field]); + barValues[i].totalValue += yValue; + } + + if (determineScale) { + maxYValue = Math.max(maxYValue, barValues[i].totalValue); + } + } + + scaleFactor = useHeight / (maxYValue - minYValue); + + for (i=0; i < n; i++) + { + data = dp.getItemAt(i); + ypos = useHeight; + + for (s=0; s < chart.series.length; s++) + { + bcs = chart.series[s] as ColumnSeries; + + var child:IChartItemRenderer = chartDataGroup.getItemRendererForSeriesAtIndex(bcs,i); + + yValue = Number(data[field]) - minYValue; + yValue = yValue * scaleFactor; + + child.x = xpos; + child.width = itemWidth; + child.y = ypos - Math.ceil(yValue); + child.height = Math.floor(yValue); + + ypos = child.y; + } + + xpos += gap + itemWidth; + } + + IEventDispatcher(chart).dispatchEvent(new Event("layoutComplete")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/models/ChartArrayListSelectionModel.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/models/ChartArrayListSelectionModel.as b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/models/ChartArrayListSelectionModel.as new file mode 100644 index 0000000..72a8fbc --- /dev/null +++ b/frameworks/projects/Charts/src/main/flex/org/apache/flex/charts/beads/models/ChartArrayListSelectionModel.as @@ -0,0 +1,75 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.charts.beads.models +{ + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + + import org.apache.flex.html.beads.models.ArrayListSelectionModel; + + import org.apache.flex.charts.core.IChartDataModel; + import org.apache.flex.charts.core.IChartSeries; + + /** + * The ArraySelectionModel class is a selection model for + * a dataProvider that is an array. It assumes that items + * can be fetched from the dataProvider + * dataProvider[index]. Other selection models + * would support other kinds of data providers. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ChartArrayListSelectionModel extends ArrayListSelectionModel implements IChartDataModel + { + public function ChartArrayListSelectionModel() + { + super(); + } + + private var _series:IChartSeries; + public function get selectedSeries():IChartSeries + { + return _series; + } + public function set selectedSeries(value:IChartSeries):void + { + if (value != _series) { + _series = value; + dispatchEvent(new Event("selectedSeriesChanged")); + } + } + + private var _rollOverSeries:IChartSeries; + public function get rollOverSeries():IChartSeries + { + return _rollOverSeries; + } + public function set rollOverSeries(value:IChartSeries):void + { + if (value != _rollOverSeries) { + _rollOverSeries = value; + dispatchEvent(new Event("rollOverSeriesChanged")); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f9c4a01d/frameworks/projects/Charts/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Charts/src/main/resources/basic-manifest.xml b/frameworks/projects/Charts/src/main/resources/basic-manifest.xml index d25b3fb..24c61ee 100644 --- a/frameworks/projects/Charts/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/Charts/src/main/resources/basic-manifest.xml @@ -32,9 +32,30 @@ <component id="StackedBarChart" class="org.apache.flex.charts.StackedBarChart" /> <component id="DataTipBead" class="org.apache.flex.charts.beads.DataTipBead" /> <component id="HorizontalCategoryAxisBead" class="org.apache.flex.charts.beads.HorizontalCategoryAxisBead" /> + <component id="HorizontalCategoryAxisForArrayListBead" class="org.apache.flex.charts.beads.HorizontalCategoryAxisForArrayListBead" /> <component id="HorizontalLinearAxisBead" class="org.apache.flex.charts.beads.HorizontalLinearAxisBead" /> + <component id="HorizontalLinearAxisForArrayListBead" class="org.apache.flex.charts.beads.HorizontalLinearAxisForArrayListBead" /> <component id="VerticalCategoryAxisBead" class="org.apache.flex.charts.beads.VerticalCategoryAxisBead" /> + <component id="VerticalCategoryAxisForArrayListBead" class="org.apache.flex.charts.beads.VerticalCategoryAxisForArrayListBead" /> <component id="VerticalLinearAxisBead" class="org.apache.flex.charts.beads.VerticalLinearAxisBead" /> + <component id="VerticalLinearAxisForArrayListBead" class="org.apache.flex.charts.beads.VerticalLinearAxisForArrayListBead" /> + + <component id="ChartArraySelectionModel" class="org.apache.flex.charts.beads.models.ChartArraySelectionModel" /> + <component id="ChartArrayListSelectionModel" class="org.apache.flex.charts.beads.models.ChartArrayListSelectionModel" /> + + <component id="BarChartLayout" class="org.apache.flex.charts.beads.layouts.BarChartLayout" /> + <component id="BarChartLayoutForArrayList" class="org.apache.flex.charts.beads.layouts.BarChartLayoutForArrayList" /> + <component id="ColumnChartLayout" class="org.apache.flex.charts.beads.layouts.ColumnChartLayout" /> + <component id="ColumnChartLayoutForArrayList" class="org.apache.flex.charts.beads.layouts.ColumnChartLayoutForArrayList" /> + <component id="PieChartLayout" class="org.apache.flex.charts.beads.layouts.PieChartLayout" /> + <component id="PieChartLayoutForArrayList" class="org.apache.flex.charts.beads.layouts.PieChartLayoutForArrayList" /> + <component id="StackedBarChartLayout" class="org.apache.flex.charts.beads.layouts.StackedBarChartLayout" /> + <component id="StackedBarChartLayoutForArrayList" class="org.apache.flex.charts.beads.layouts.StackedBarChartLayoutForArrayList" /> + <component id="StackedColumnChartLayout" class="org.apache.flex.charts.beads.layouts.StackedColumnChartLayout" /> + <component id="StackedColumnChartLayoutForArrayList" class="org.apache.flex.charts.beads.layouts.StackedColumnChartLayoutForArrayList" /> + + <component id="DataItemRendererFactoryForSeriesData" class="org.apache.flex.charts.beads.DataItemRendererFactoryForSeriesData" /> + <component id="DataItemRendererFactoryForSeriesArrayListData" class="org.apache.flex.charts.beads.DataItemRendererFactoryForSeriesArrayListData" /> <component id="BoxItemRenderer" class="org.apache.flex.charts.supportClasses.BoxItemRenderer" /> <component id="WedgeItemRenderer" class="org.apache.flex.charts.supportClasses.WedgeItemRenderer" />