1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2009 Adobe Systems Incorporated 5// All Rights Reserved. 6// 7// NOTICE: Adobe permits you to use, modify, and distribute this file 8// in accordance with the terms of the license agreement accompanying it. 9// 10//////////////////////////////////////////////////////////////////////////////// 11 12package mx.charts 13{ 14 15import mx.charts.chartClasses.CartesianChart; 16import mx.charts.chartClasses.DataTip; 17import mx.charts.chartClasses.IAxis; 18import mx.charts.chartClasses.Series; 19import mx.charts.series.BubbleSeries; 20import mx.charts.styles.HaloDefaults; 21import mx.core.IFlexModuleFactory; 22import mx.core.mx_internal; 23import mx.graphics.SolidColor; 24import mx.graphics.SolidColorStroke; 25import mx.graphics.Stroke; 26import mx.styles.CSSStyleDeclaration; 27 28use namespace mx_internal; 29 30//-------------------------------------- 31// Styles 32//-------------------------------------- 33 34/** 35 * The maximum radius of the largest chart element, in pixels 36 * Flex assigns this radius to the data point with the largest value; 37 * all other data points are assigned a smaller radius 38 * based on their value relative to the smallest and largest value. 39 * The default value is 50 pixels. 40 * 41 * @langversion 3.0 42 * @playerversion Flash 9 43 * @playerversion AIR 1.1 44 * @productversion Flex 3 45 */ 46[Style(name="maxRadius", type="Number", format="Length", inherit="no")] 47 48/** 49 * The minimum radius of the smallest chart element, in pixels 50 * Flex assigns this radius to the data point with the smallest value; 51 * all other data points are assigned a larger radius 52 * based on their value relative to the smallest and largest value. 53 * The default value is 0 pixels. 54 * 55 * @langversion 3.0 56 * @playerversion Flash 9 57 * @playerversion AIR 1.1 58 * @productversion Flex 3 59 */ 60[Style(name="minRadius", type="Number", format="Length", inherit="no")] 61 62//-------------------------------------- 63// Other metadata 64//-------------------------------------- 65 66[DefaultBindingProperty(destination="dataProvider")] 67 68[DefaultTriggerEvent("itemClick")] 69 70[IconFile("BubbleChart.png")] 71 72/** 73 * The BubbleChart control represents data with three values 74 * for each data point. 75 * Each data point is defined by a value determining its position 76 * along the horizontal axis, a value determining its position 77 * along the vertical axis, and a value determining the size 78 * of the chart element, relative to the other data points on the chart. 79 * 80 * <p>The BubbleChart control expects its <code>series</code> property 81 * to contain an array of BubbleSeries objects.</p> 82 * 83 * @mxml 84 * 85 * The <code><mx:BubbleChart></code> tag inherits all the properties 86 * of its parent classes and adds the following properties:</p> 87 * 88 * <pre> 89 * <mx:BubbleChart 90 * <strong>Properties</strong> 91 * radiusAxis="<i>LinearAxis</i>" 92 * 93 * <strong>Styles</strong> 94 * maxRadius="50" 95 * minRadius="0" 96 * /> 97 * </pre> 98 * 99 * @includeExample examples/BubbleChartExample.mxml 100 * 101 * @see mx.charts.series.BubbleSeries 102 * 103 * @langversion 3.0 104 * @playerversion Flash 9 105 * @playerversion AIR 1.1 106 * @productversion Flex 3 107 */ 108public class BubbleChart extends CartesianChart 109{ 110 include "../core/Version.as"; 111 112 //-------------------------------------------------------------------------- 113 // 114 // Class initialization 115 // 116 //-------------------------------------------------------------------------- 117 118 119 //-------------------------------------------------------------------------- 120 // 121 // Constructor 122 // 123 //-------------------------------------------------------------------------- 124 125 /** 126 * Constructor. 127 * 128 * @langversion 3.0 129 * @playerversion Flash 9 130 * @playerversion AIR 1.1 131 * @productversion Flex 3 132 */ 133 public function BubbleChart() 134 { 135 super(); 136 137 var zAxis:LinearAxis = new LinearAxis(); 138 zAxis.autoAdjust = false; 139 zAxis.minimum = 0; 140 zAxis.interval = 1; 141 radiusAxis = zAxis; 142 } 143 144 //-------------------------------------------------------------------------- 145 // 146 // Variables 147 // 148 //-------------------------------------------------------------------------- 149 150 /** 151 * @private 152 */ 153 private var _moduleFactoryInitialized:Boolean = false; 154 155 //-------------------------------------------------------------------------- 156 // 157 // Properties 158 // 159 //-------------------------------------------------------------------------- 160 161 //---------------------------------- 162 // radiusAxis 163 //---------------------------------- 164 165 /** 166 * @private 167 * Storage for the radiusAxis property. 168 */ 169 private var _radiusAxis:IAxis; 170 171 [Inspectable(category="Data")] 172 173 /** 174 * The axis the bubble radius is mapped against 175 * Bubble charts treat the size of the individual bubbles 176 * as a third dimension of data which is transformed 177 * in a similar manner to how x and y position is transformed. 178 * By default, the <code>radiusAxis</code> is a LinearAxis 179 * with the <code>autoAdjust</code> property set to <code>false</code>. 180 * 181 * @langversion 3.0 182 * @playerversion Flash 9 183 * @playerversion AIR 1.1 184 * @productversion Flex 3 185 */ 186 public function get radiusAxis():IAxis 187 { 188 return _transforms[0].getAxis(BubbleSeries.RADIUS_AXIS); 189 } 190 191 /** 192 * @private 193 */ 194 public function set radiusAxis(value:IAxis):void 195 { 196 _radiusAxis = value; 197 _transforms[0].setAxis(BubbleSeries.RADIUS_AXIS, value); 198 199 invalidateData(); 200 } 201 202 //-------------------------------------------------------------------------- 203 // 204 // Overridden methods: UIComponent 205 // 206 //-------------------------------------------------------------------------- 207 208 /** 209 * @private 210 */ 211 private function initStyles():Boolean 212 { 213 HaloDefaults.init(styleManager); 214 215 var bubbleChartStyle:CSSStyleDeclaration = styleManager.getStyleDeclaration("mx.charts.BubbleChart"); 216 bubbleChartStyle.setStyle("chartSeriesStyles", HaloDefaults.chartBaseChartSeriesStyles); 217 bubbleChartStyle.setStyle("dataTipCalloutStroke", new SolidColorStroke(2,0)); 218 bubbleChartStyle.setStyle("fill", new SolidColor(0xFFFFFF, 0)); 219 bubbleChartStyle.setStyle("calloutStroke", new SolidColorStroke(0x888888,2)); 220 bubbleChartStyle.setStyle("horizontalAxisStyleNames", ["blockNumericAxis"]); 221 bubbleChartStyle.setStyle("verticalAxisStyleNames", ["blockNumericAxis"]); 222 223 return true; 224 } 225 226 /** 227 * A module factory is used as context for using embedded fonts and for finding the style manager that controls the styles for this component. 228 * 229 * @langversion 3.0 230 * @playerversion Flash 9 231 * @playerversion AIR 1.1 232 * @productversion Flex 3 233 */ 234 override public function set moduleFactory(factory:IFlexModuleFactory):void 235 { 236 super.moduleFactory = factory; 237 238 if (_moduleFactoryInitialized) 239 return; 240 241 _moduleFactoryInitialized = true; 242 243 // our style settings 244 initStyles(); 245 } 246 247 /** 248 * @private 249 */ 250 override public function styleChanged(styleProp:String):void 251 { 252 var series:Array /* of Series */; 253 var n:int; 254 var i:int; 255 256 if (styleProp == null || styleProp == "maxRadius") 257 { 258 var maxRadius:Number = getStyle("maxRadius"); 259 260 series = this.series; 261 n = series.length; 262 for (i = 0; i < n; i++) 263 { 264 if (series[i] is BubbleSeries) 265 { 266 series[i].maxRadius = maxRadius; 267 series[i].invalidateDisplayList(); 268 } 269 } 270 } 271 if (styleProp == null || styleProp == "minRadius") 272 { 273 var minRadius:Number = getStyle("minRadius"); 274 275 series = this.series; 276 n = series.length; 277 for (i = 0; i < n; i++) 278 { 279 if (series[i] is BubbleSeries) 280 { 281 series[i].minRadius = minRadius; 282 series[i].invalidateDisplayList(); 283 } 284 } 285 } 286 } 287 288 //-------------------------------------------------------------------------- 289 // 290 // Overridden methods: ChartBase 291 // 292 //-------------------------------------------------------------------------- 293 294 /** 295 * @private 296 */ 297 override protected function customizeSeries(seriesGlyph:Series, i:uint):void 298 { 299 var maxRadius:Number = getStyle("maxRadius"); 300 var minRadius:Number = getStyle("minRadius"); 301 302 if ((seriesGlyph is BubbleSeries) && !isNaN(maxRadius)) 303 BubbleSeries(seriesGlyph).maxRadius = maxRadius; 304 if ((seriesGlyph is BubbleSeries) && !isNaN(minRadius)) 305 BubbleSeries(seriesGlyph).minRadius = minRadius; 306 } 307} 308 309} 310