⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pieseries.as

📁 拓扑图基于SNMP数据采集模块的设计和实现
💻 AS
📖 第 1 页 / 共 2 页
字号:
			super.removeAllMarkers();			var markerCount:int = this.markerMasks.length;			for(var i:int = 0; i < markerCount; i++)			{				var mask:Shape = this.markerMasks.pop() as Shape;				this.removeChild(mask);			}		}				/**		 * @private		 * Add or remove markers as needed. current markers will be reused.		 */		override protected function refreshMarkers():void		{			super.refreshMarkers();						var itemCount:int = this.length;			var difference:int = itemCount - this.markerMasks.length;			if(difference > 0)			{				for(var i:int = 0; i < difference; i++)				{					var mask:Shape = new Shape();					this.addChild(mask);					this.markerMasks.push(mask);										var marker:Sprite = this.markers[i] as Sprite;					marker.mask = mask;				}			}			else if(difference < 0)			{				difference = Math.abs(difference);				for(i = 0; i < difference; i++)				{					mask = this.markerMasks.pop() as Shape;					this.removeChild(mask);				}			}		}				/**		 * @private		 * The default function called to initialize the text on the marker		 * labels.		 */		protected function defaultLabelFunction(item:Object):String		{			var percentage:Number = this.itemToPercentage(item);			return (percentage < 0.01 ? "< 0.01" : NumberUtil.roundToNearest(percentage, 0.01)) + "%";		}				/**		 * @private		 * Draws the markers in this series.		 */		protected function drawMarkers(stylesInvalid:Boolean, sizeInvalid:Boolean):void		{			var markerCount:int = this.markers.length;			for(var i:int = 0; i < markerCount; i++)			{				var marker:UIComponent = UIComponent(this.markers[i]);								if(stylesInvalid)				{					this.copyStylesToRenderer(ISeriesItemRenderer(marker), RENDERER_STYLES);				}								if(sizeInvalid)				{					marker.width = this.width;					marker.height = this.height;				}				//not really required, but we should validate anyway.				this.validateMarker(ISeriesItemRenderer(marker));			}		}				/**		 * @private		 * Either creates a new label TextField or retrieves one from the		 * cache.		 */		protected function getLabel():TextField		{			var label:TextField;			if(this.labelsCache.length > 0)			{				label = TextField(this.labelsCache.shift());			}			else			{				label = new TextField();				label.autoSize = TextFieldAutoSize.LEFT;				label.selectable = false;				label.mouseEnabled = false;				this.addChild(label);			}			label.visible = true;			return label;		}				/**		 * @private		 * Updates the label text and positions the labels.		 */		protected function drawLabels():void		{				var textFormat:TextFormat = this.getStyleValue("textFormat") as TextFormat;			var embedFonts:Boolean = this.getStyleValue("embedFonts") as Boolean;			var hideOverlappingLabels:Boolean = this.getStyleValue("hideOverlappingLabels") as Boolean;						var angle:Number = 0;			var valueSum:Number = 0;			var totalValue:Number = this.calculateTotalValue();			var markerCount:int = this.markers.length;			for(var i:int = 0; i < markerCount; i++)			{				var label:TextField = this.getLabel();				this.labels.push(label);				label.defaultTextFormat = textFormat;				label.embedFonts = embedFonts;				label.text = this.labelFunction(this.dataProvider[i]);								var value:Number = this.itemToData(this.dataProvider[i]);				if(totalValue == 0)				{					angle = 360 / this.length;				}				else				{					angle = 360 * ((valueSum + value / 2) / totalValue);				}				valueSum += value;				var halfWidth:Number = this.width / 2;				var halfHeight:Number = this.height / 2;				var radius:Number = Math.min(halfWidth, halfHeight);				var position:Point = Point.polar(2 * radius / 3, -GeomUtil.degreesToRadians(angle));				label.x = halfWidth + position.x - label.width / 2;				label.y = halfHeight + position.y - label.height / 2;								if(hideOverlappingLabels)				{					for(var j:int = 0; j < i; j++)					{						var previousLabel:TextField = TextField(this.labels[j]);						if(previousLabel.hitTestObject(label))						{							label.visible = false;						}					}				}			}		}				/**		 * Copies a styles from the series to a child through a style map.		 * 		 * @see copyStylesToChild()		 */		protected function copyStylesToRenderer(child:ISeriesItemRenderer, styleMap:Object):void		{			var index:int = this.markers.indexOf(child);			var childComponent:UIComponent = child as UIComponent;			for(var n:String in styleMap)			{				var styleValues:Array = this.getStyleValue(styleMap[n]) as Array;				//if it doesn't exist, ignore it and go with the defaults for this series				if(!styleValues) continue;				childComponent.setStyle(n, styleValues[index % styleValues.length])			}		}			//--------------------------------------	//  Private Methods	//--------------------------------------			/**		 * @private		 * Sets up the animation for the markers.		 */		private function beginAnimation():void		{			var itemCount:int = this.length;			if(!this._previousData || this._previousData.length != this.length)			{				this._previousData = [];				for(var i:int = 0; i < itemCount; i++)				{					this._previousData.push(0);				}			}						//handle animating all the markers in one fell swoop.			if(this._animation)			{				if(this._animation.active)				{					this._animation.pause();				}				this._animation.removeEventListener(AnimationEvent.UPDATE, tweenUpdateHandler);				this._animation.removeEventListener(AnimationEvent.PAUSE, tweenPauseHandler);				this._animation.removeEventListener(AnimationEvent.COMPLETE, tweenCompleteHandler);				this._animation = null;			}						var data:Array = this.dataProviderToArrayOfNumbers();						//don't animate on livepreview!			if(this.isLivePreview || !this.getStyleValue("animationEnabled"))			{				this.renderMarkerMasks(data);			}			else			{				var animationDuration:int = this.getStyleValue("animationDuration") as int;				var animationEasingFunction:Function = this.getStyleValue("animationEasingFunction") as Function;								this._animation = new Animation(animationDuration, this._previousData, data);				this._animation.addEventListener(AnimationEvent.UPDATE, tweenUpdateHandler);				this._animation.addEventListener(AnimationEvent.PAUSE, tweenPauseHandler);				this._animation.addEventListener(AnimationEvent.COMPLETE, tweenCompleteHandler);				this._animation.easingFunction = animationEasingFunction;				this.renderMarkerMasks(this._previousData);			}		}			/**		 * @private		 * Determines the total sum of all values in the data provider.		 */		private function calculateTotalValue():Number		{			var totalValue:Number = 0;			var itemCount:int = this.length;			for(var i:int = 0; i < itemCount; i++)			{				var currentItem:Object = this.dataProvider[i];				var value:Number = this.itemToData(currentItem);								if(!isNaN(value))				{					totalValue += value;				}			}			return totalValue;		}			/**		 * @private		 * Retreives all the numeric values from the data provider		 * and places them into an Array so that they may be used		 * in an animation.		 */		private function dataProviderToArrayOfNumbers():Array		{			var output:Array = [];						var itemCount:int = this.length;			for(var i:int = 0; i < itemCount; i++)			{				var item:Object = this.dataProvider[i];				var value:Number = 0;				if(item != null)				{					value = this.itemToData(item);				}				output.push(value);			}			return output;		}			/**		 * @private		 */		private function tweenUpdateHandler(event:AnimationEvent):void		{			this.renderMarkerMasks(event.parameters as Array);		}				/**		 * @private		 */		private function tweenCompleteHandler(event:AnimationEvent):void		{			this.tweenUpdateHandler(event);			this.tweenPauseHandler(event);		}				/**		 * @private		 */		private function tweenPauseHandler(event:AnimationEvent):void		{			this._previousData = (event.parameters as Array).concat();		}			/**		 * @private		 */		private function renderMarkerMasks(data:Array):void		{			var values:Array = [];			var totalValue:Number = 0;			var itemCount:int = data.length;			for(var i:int = 0; i < itemCount; i++)			{				var value:Number = Number(data[i]);								values.push(value);				if(!isNaN(value))				{					totalValue += value;				}			}						var totalAngle:Number = 0;			var halfWidth:Number = this.width / 2;			var halfHeight:Number = this.height / 2;			var radius:Number = Math.min(halfWidth, halfHeight);			var fillColors:Array = this.getStyleValue("fillColors") as Array;						var angle:Number = 0;			for(i = 0; i < itemCount; i++)			{				value = Number(data[i]);				if(totalValue == 0)				{					angle = 360 / data.length;				}				else				{					angle = 360 * (value / totalValue);				}								var mask:Shape = this.markerMasks[i] as Shape;				mask.graphics.clear();				mask.graphics.beginFill(0xff0000);				GraphicsUtil.drawWedge(mask.graphics, halfWidth, halfHeight, totalAngle, angle, radius);				mask.graphics.endFill();				totalAngle += angle;								var marker:UIComponent = UIComponent(this.markers[i]);				marker.drawNow();			}		}				/**		 * @private		 * Places all the existing labels in a cache so that they may be reused		 * when we redraw the series.		 */		private function createLabelCache():void		{			this.labelsCache = this.labels.concat();			this.labels = [];		}				/**		 * @private		 * If any labels are left in the cache after we've redrawn, they can be		 * removed from the display list.		 */		private function clearLabelCache():void		{			var cacheLength:int = this.labelsCache.length;			for(var i:int = 0; i < cacheLength; i++)			{				var label:TextField = TextField(this.labelsCache.shift());				this.removeChild(label);			}		}			}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -