Repository: flex-asjs Updated Branches: refs/heads/develop 86916b5eb -> 2f078fd62
Replaced XAxisBead and YAxisBead with HorizontalCategoryAxisBead and VerticalCategoryAxisBead. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/2f078fd6 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/2f078fd6 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/2f078fd6 Branch: refs/heads/develop Commit: 2f078fd62495f34e979602b71754145b531cab9a Parents: 86916b5 Author: Peter Ent <[email protected]> Authored: Mon Aug 25 16:04:14 2014 -0400 Committer: Peter Ent <[email protected]> Committed: Mon Aug 25 16:04:14 2014 -0400 ---------------------------------------------------------------------- .../as/projects/FlexJSJX/basic-manifest.xml | 4 +- .../as/projects/FlexJSJX/src/FlexJSJXClasses.as | 4 +- .../charts/beads/HorizontalCategoryAxisBead.as | 191 ++++++++++++++++++ .../charts/beads/VerticalCategoryAxisBead.as | 195 +++++++++++++++++++ .../org/apache/flex/charts/beads/XAxisBead.as | 189 ------------------ .../org/apache/flex/charts/beads/YAxisBead.as | 193 ------------------ 6 files changed, 390 insertions(+), 386 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2f078fd6/frameworks/as/projects/FlexJSJX/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSJX/basic-manifest.xml b/frameworks/as/projects/FlexJSJX/basic-manifest.xml index b911e60..e5b969e 100644 --- a/frameworks/as/projects/FlexJSJX/basic-manifest.xml +++ b/frameworks/as/projects/FlexJSJX/basic-manifest.xml @@ -37,8 +37,8 @@ <component id="PieChartSeries" class="org.apache.flex.charts.supportClasses.PieChartSeries" /> <component id="StackedColumnChart" class="org.apache.flex.charts.StackedColumnChart" /> <component id="StackedBarChart" class="org.apache.flex.charts.StackedBarChart" /> - <component id="XAxisBead" class="org.apache.flex.charts.beads.XAxisBead" /> - <component id="YAxisBead" class="org.apache.flex.charts.beads.YAxisBead" /> + <component id="HorizontalCategoryAxisBead" class="org.apache.flex.charts.beads.HorizontalCategoryAxisBead" /> + <component id="VerticalCategoryAxisBead" class="org.apache.flex.charts.beads.VerticalCategoryAxisBead" /> <component id="VerticalColumnLayout" class="org.apache.flex.html.beads.layouts.VerticalColumnLayout" /> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2f078fd6/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as b/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as index 4fc206b..34d0502 100644 --- a/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as +++ b/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as @@ -30,8 +30,8 @@ internal class FlexJSJXClasses import org.apache.flex.charts.beads.BarChartView; BarChartView; import org.apache.flex.charts.beads.ChartItemRendererFactory; ChartItemRendererFactory; import org.apache.flex.charts.beads.PieChartView; PieChartView; - import org.apache.flex.charts.beads.XAxisBead; XAxisBead; - import org.apache.flex.charts.beads.YAxisBead; YAxisBead; + import org.apache.flex.charts.beads.HorizontalCategoryAxisBead; HorizontalCategoryAxisBead; + import org.apache.flex.charts.beads.VerticalCategoryAxisBead; VerticalCategoryAxisBead; import org.apache.flex.charts.beads.layouts.BarChartLayout; BarChartLayout; import org.apache.flex.charts.beads.layouts.ColumnChartLayout; ColumnChartLayout; import org.apache.flex.charts.beads.layouts.PieChartLayout; PieChartLayout; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2f078fd6/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as new file mode 100644 index 0000000..25bbd6f --- /dev/null +++ b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/HorizontalCategoryAxisBead.as @@ -0,0 +1,191 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IHorizontalAxisBead; + import org.apache.flex.core.FilledRectangle; + import org.apache.flex.core.IBead; + import org.apache.flex.core.IDataProviderItemRendererMapper; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.Label; + import org.apache.flex.html.beads.models.ArraySelectionModel; + + /** + * The HorizontalCategoryAxisBead 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 HorizontalCategoryAxisBead implements IBead, IHorizontalAxisBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function HorizontalCategoryAxisBead() + { + } + + private var _axisHeight:Number = 30; + + /** + * The height of the horizontal axis. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get axisHeight():Number + { + return _axisHeight; + } + public function set axisHeight(value:Number):void + { + _axisHeight = value; + } + + private var _categoryField:String; + + /** + * The name of field within the chart data to used to categorize each of the + * axis data points. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get categoryField():String + { + return _categoryField; + } + public function set categoryField(value:String):void + { + _categoryField = value; + } + + private var _gap:Number = 20; + + /** + * The amount of space to leave between series. If a chart has several series, + * the bars for an X value are side by side with a gap between the groups of + * bars. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get gap():Number + { + return _gap; + } + public function set gap(value:Number):void + { + _gap = value; + } + + 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; + + // in order to draw or create the labels, need to know when the series has been created. + IEventDispatcher(_strand).addEventListener("layoutComplete",handleItemsCreated); + } + + /** + * @private + */ + private function handleItemsCreated(event:Event):void + { + var charter:ChartItemRendererFactory = + _strand.getBeadByType(IDataProviderItemRendererMapper) as ChartItemRendererFactory; + + var model:ArraySelectionModel = _strand.getBeadByType(ISelectionModel) as ArraySelectionModel; + var items:Array; + if (model.dataProvider is Array) items = model.dataProvider as Array; + else return; + + var renderers:Array = charter.seriesRenderers; + var series:Array = IChart(_strand).series; + + var xpos:Number = 0; + var xAxisHeightOffset:Number = axisHeight; + var useWidth:Number = UIBase(_strand).width / renderers.length; + + // draw the horzontal axis + var horzLine:FilledRectangle = new FilledRectangle(); + horzLine.fillColor = 0x111111; + horzLine.x = 0; + horzLine.y = UIBase(_strand).height - xAxisHeightOffset; + horzLine.height = 1; + horzLine.width = UIBase(_strand).width; + UIBase(_strand).addElement(horzLine); + + // place the labels below the axis enough to account for the tick marks + var labelY:Number = UIBase(_strand).height + 8; + + for(var i:int=0; i < items.length; i++) { + var label:Label = new Label(); + label.text = items[i][categoryField]; + label.x = xpos; + label.y = labelY - xAxisHeightOffset; + + UIBase(_strand).addElement(label); + + // add a tick mark, too + var tick:FilledRectangle = new FilledRectangle(); + tick.fillColor = 0x111111; + tick.x = xpos + useWidth/2 - gap; + tick.y = UIBase(_strand).height - xAxisHeightOffset; + tick.width = 1; + tick.height = 5; + UIBase(_strand).addElement(tick); + + var r:UIBase = UIBase(renderers[i][0]); + xpos += useWidth; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2f078fd6/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as new file mode 100644 index 0000000..6b907fc --- /dev/null +++ b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/VerticalCategoryAxisBead.as @@ -0,0 +1,195 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IVerticalAxisBead; + import org.apache.flex.core.FilledRectangle; + import org.apache.flex.core.IBead; + import org.apache.flex.core.IDataProviderItemRendererMapper; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.Label; + import org.apache.flex.html.beads.models.ArraySelectionModel; + + /** + * The VerticalCategoryAxisBead 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 VerticalCategoryAxisBead implements IBead, IVerticalAxisBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VerticalCategoryAxisBead() + { + } + + 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; + + // in order to draw or create the labels, need to know when the series has been created. + IEventDispatcher(_strand).addEventListener("layoutComplete",handleItemsCreated); + } + + private var _categoryField:String; + + /** + * The name of field within the chart data to used to categorize each of the + * axis data points. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get categoryField():String + { + return _categoryField; + } + public function set categoryField(value:String):void + { + _categoryField = value; + } + + private var _axisWidth:Number = 100; + + /** + * The overall width of the axis. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get axisWidth():Number + { + return _axisWidth; + } + + public function set axisWidth(value:Number):void + { + _axisWidth = value; + } + + private var _gap:Number = 20; + + /** + * The amount of space to leave between series. If a chart has several series, + * the bars for an X value are side by side with a gap between the groups of + * bars. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get gap():Number + { + return _gap; + } + public function set gap(value:Number):void + { + _gap = value; + } + + /** + * @private + */ + private function handleItemsCreated(event:Event):void + { + var charter:ChartItemRendererFactory = + _strand.getBeadByType(IDataProviderItemRendererMapper) as ChartItemRendererFactory; + + var model:ArraySelectionModel = _strand.getBeadByType(ISelectionModel) as ArraySelectionModel; + var items:Array; + if (model.dataProvider is Array) items = model.dataProvider as Array; + else return; + + var renderers:Array = charter.seriesRenderers; + var series:Array = IChart(_strand).series; + + var yAxisWidthOffset:Number = axisWidth; + var useHeight:Number = UIBase(_strand).height / renderers.length; + var seriesHeight:Number = useHeight/series.length; + var xpos:Number = yAxisWidthOffset; + var ypos:Number = UIBase(_strand).height - seriesHeight - gap; + + // draw the vertical axis + var horzLine:FilledRectangle = new FilledRectangle(); + horzLine.fillColor = 0x111111; + horzLine.x = yAxisWidthOffset; + horzLine.y = 0; + horzLine.height = UIBase(_strand).height; + horzLine.width = 1; + UIBase(_strand).addElement(horzLine); + + // place the labels left of the axis enough to account for the tick marks + var labelX:Number = 0; + + for(var i:int=0; i < items.length; i++) { + var label:Label = new Label(); + label.text = items[i][categoryField]; + label.x = 0; + label.y = (ypos + useHeight/2) - label.height/2; + label.width = yAxisWidthOffset; + + UIBase(_strand).addElement(label); + + // add a tick mark, too + var tick:FilledRectangle = new FilledRectangle(); + tick.fillColor = 0x111111; + tick.x = yAxisWidthOffset - 5; + tick.y = ypos + useHeight/2; + tick.width = 5; + tick.height = 1; + UIBase(_strand).addElement(tick); + + var r:UIBase = UIBase(renderers[i][0]); + ypos -= useHeight; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2f078fd6/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/XAxisBead.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/XAxisBead.as b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/XAxisBead.as deleted file mode 100644 index 2df96b1..0000000 --- a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/XAxisBead.as +++ /dev/null @@ -1,189 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// 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.IHorizontalAxisBead; - import org.apache.flex.core.FilledRectangle; - import org.apache.flex.core.IBead; - import org.apache.flex.core.IDataProviderItemRendererMapper; - import org.apache.flex.core.ISelectionModel; - import org.apache.flex.core.IStrand; - import org.apache.flex.core.UIBase; - import org.apache.flex.events.Event; - import org.apache.flex.events.IEventDispatcher; - import org.apache.flex.html.Label; - import org.apache.flex.html.beads.models.ArraySelectionModel; - - /** - * The XAxisBead displays a linear value axis horizontally for - * a Cartesian-style chart. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public class XAxisBead implements IBead, IHorizontalAxisBead - { - /** - * constructor. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function XAxisBead() - { - } - - private var _axisHeight:Number = 30; - - /** - * The height of the horizontal axis. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get axisHeight():Number - { - return _axisHeight; - } - public function set axisHeight(value:Number):void - { - _axisHeight = value; - } - - private var _labelField:String; - - /** - * The name of field witin the chart data to use to label each of the - * axis data points. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get labelField():String - { - return _labelField; - } - public function set labelField(value:String):void - { - _labelField = value; - } - - private var _gap:Number = 20; - - /** - * The amount of space to leave between series. If a chart has several series, - * the bars for an X value are side by side with a gap between the groups of - * bars. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get gap():Number - { - return _gap; - } - public function set gap(value:Number):void - { - _gap = value; - } - - 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; - - // in order to draw or create the labels, need to know when the series has been created. - IEventDispatcher(_strand).addEventListener("layoutComplete",handleItemsCreated); - } - - /** - * @private - */ - private function handleItemsCreated(event:Event):void - { - var charter:ChartItemRendererFactory = - _strand.getBeadByType(IDataProviderItemRendererMapper) as ChartItemRendererFactory; - - var model:ArraySelectionModel = _strand.getBeadByType(ISelectionModel) as ArraySelectionModel; - var items:Array; - if (model.dataProvider is Array) items = model.dataProvider as Array; - else return; - - var renderers:Array = charter.seriesRenderers; - var series:Array = IChart(_strand).series; - - var xpos:Number = 0; - var xAxisHeightOffset:Number = axisHeight; - var useWidth:Number = UIBase(_strand).width / renderers.length; - - // draw the horzontal axis - var horzLine:FilledRectangle = new FilledRectangle(); - horzLine.fillColor = 0x111111; - horzLine.x = 0; - horzLine.y = UIBase(_strand).height - xAxisHeightOffset; - horzLine.height = 1; - horzLine.width = UIBase(_strand).width; - UIBase(_strand).addElement(horzLine); - - // place the labels below the axis enough to account for the tick marks - var labelY:Number = UIBase(_strand).height + 8; - - for(var i:int=0; i < items.length; i++) { - var label:Label = new Label(); - label.text = items[i][labelField]; - label.x = xpos; - label.y = labelY - xAxisHeightOffset; - - UIBase(_strand).addElement(label); - - // add a tick mark, too - var tick:FilledRectangle = new FilledRectangle(); - tick.fillColor = 0x111111; - tick.x = xpos + useWidth/2 - gap; - tick.y = UIBase(_strand).height - xAxisHeightOffset; - tick.width = 1; - tick.height = 5; - UIBase(_strand).addElement(tick); - - var r:UIBase = UIBase(renderers[i][0]); - xpos += useWidth; - } - } - } -} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/2f078fd6/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/YAxisBead.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/YAxisBead.as b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/YAxisBead.as deleted file mode 100644 index b5ae47e..0000000 --- a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/charts/beads/YAxisBead.as +++ /dev/null @@ -1,193 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// 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.IVerticalAxisBead; - import org.apache.flex.core.FilledRectangle; - import org.apache.flex.core.IBead; - import org.apache.flex.core.IDataProviderItemRendererMapper; - import org.apache.flex.core.ISelectionModel; - import org.apache.flex.core.IStrand; - import org.apache.flex.core.UIBase; - import org.apache.flex.events.Event; - import org.apache.flex.events.IEventDispatcher; - import org.apache.flex.html.Label; - import org.apache.flex.html.beads.models.ArraySelectionModel; - - /** - * The YAxisBead displays a linear value axis vertically for - * a Cartesian-style chart. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public class YAxisBead implements IBead, IVerticalAxisBead - { - /** - * constructor. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function YAxisBead() - { - } - - 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; - - // in order to draw or create the labels, need to know when the series has been created. - IEventDispatcher(_strand).addEventListener("layoutComplete",handleItemsCreated); - } - - private var _labelField:String; - - /** - * The name of field witin the chart data to use to label each of the - * axis data points. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get labelField():String - { - return _labelField; - } - public function set labelField(value:String):void - { - _labelField = value; - } - - private var _axisWidth:Number = 100; - - /** - * The overall width of the axis. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get axisWidth():Number - { - return _axisWidth; - } - - public function set axisWidth(value:Number):void - { - _axisWidth = value; - } - - private var _gap:Number = 20; - - /** - * The amount of space to leave between series. If a chart has several series, - * the bars for an X value are side by side with a gap between the groups of - * bars. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get gap():Number - { - return _gap; - } - public function set gap(value:Number):void - { - _gap = value; - } - - /** - * @private - */ - private function handleItemsCreated(event:Event):void - { - var charter:ChartItemRendererFactory = - _strand.getBeadByType(IDataProviderItemRendererMapper) as ChartItemRendererFactory; - - var model:ArraySelectionModel = _strand.getBeadByType(ISelectionModel) as ArraySelectionModel; - var items:Array; - if (model.dataProvider is Array) items = model.dataProvider as Array; - else return; - - var renderers:Array = charter.seriesRenderers; - var series:Array = IChart(_strand).series; - - var yAxisWidthOffset:Number = axisWidth; - var useHeight:Number = UIBase(_strand).height / renderers.length; - var seriesHeight:Number = useHeight/series.length; - var xpos:Number = yAxisWidthOffset; - var ypos:Number = UIBase(_strand).height - seriesHeight - gap; - - // draw the vertical axis - var horzLine:FilledRectangle = new FilledRectangle(); - horzLine.fillColor = 0x111111; - horzLine.x = yAxisWidthOffset; - horzLine.y = 0; - horzLine.height = UIBase(_strand).height; - horzLine.width = 1; - UIBase(_strand).addElement(horzLine); - - // place the labels left of the axis enough to account for the tick marks - var labelX:Number = 0; - - for(var i:int=0; i < items.length; i++) { - var label:Label = new Label(); - label.text = items[i][labelField]; - label.x = 0; - label.y = ypos; - label.width = yAxisWidthOffset; - - UIBase(_strand).addElement(label); - - // add a tick mark, too - var tick:FilledRectangle = new FilledRectangle(); - tick.fillColor = 0x111111; - tick.x = yAxisWidthOffset - 5; - tick.y = ypos + useHeight/2; - tick.width = 5; - tick.height = 1; - UIBase(_strand).addElement(tick); - - var r:UIBase = UIBase(renderers[i][0]); - ypos -= useHeight; - } - } - } -} \ No newline at end of file
