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

📄 defaultaxisrenderer.as

📁 拓扑图基于SNMP数据采集模块的设计和实现
💻 AS
📖 第 1 页 / 共 2 页
字号:
package com.yahoo.astra.fl.charts.axes{		import com.yahoo.astra.utils.DynamicRegistration;	import com.yahoo.astra.utils.GeomUtil;	import com.yahoo.astra.utils.NumberUtil;		import fl.core.InvalidationType;	import fl.core.UIComponent;		import flash.geom.Point;	import flash.geom.Rectangle;	import flash.text.TextField;	import flash.text.TextFieldAutoSize;	import flash.text.TextFormat;	import flash.text.TextFormatAlign;		//--------------------------------------	//  Styles	//--------------------------------------        //-- Axis    	/**	 * If false, the axis is not drawn. Titles, labels, ticks, and grid	 * lines may still be drawn, however, so you must specifically hide each	 * item if nothing should be drawn.	 * 	 * @default true	 */	[Style(name="showAxis", type="Boolean")]    	/**	 * The line weight, in pixels, for the axis.	 * 	 * @default 1	 */	[Style(name="axisWeight", type="int")]    	/**	 * The line color for the axis.	 * 	 * @default #888a85	 */	[Style(name="axisColor", type="uint")]        //-- Labels    	/**	 * If true, labels will be displayed on the axis.	 * 	 * @default true	 */	[Style(name="showLabels", type="Boolean")]    	/**	 * The distance, in pixels, between a label and the axis.	 * 	 * @default 2	 */	[Style(name="labelDistance", type="Number")]    	/** 	 * If true, labels that overlap previously drawn labels on the axis will be	 * hidden. The first and last labels on the axis will always be drawn.	 * 	 * @default true	 */	[Style(name="hideOverlappingLabels", type="Boolean")]    	/** 	 * The angle, in degrees, of the labels on the axis. May be a value	 * between <code>-90</code> and <code>90</code>. The font must be embedded	 * in the SWF and the <code>embedFonts</code> style on the chart must be set	 * to <code>true</code> before labels may be rotated. If these conditions	 * aren't met, the labels will not be rotated.	 * 	 * @default 0	 */	[Style(name="labelRotation", type="Number")]		//-- Ticks    	/**	 * If true, ticks will be displayed on the axis.	 * 	 * @default true	 */	[Style(name="showTicks", type="Boolean")]    	/**	 * The line weight, in pixels, for the ticks on the axis.	 * 	 * @default 1	 */	[Style(name="tickWeight", type="int")]    	/**	 * The line color for the ticks on the axis.	 * 	 * @default #888a85	 */	[Style(name="tickColor", type="uint")]    	/**	 * The length, in pixels, of the ticks on the axis.	 * 	 * @default 4	 */	[Style(name="tickLength", type="Number")]		/**	 * The position of the ticks on the axis.	 * 	 * @default "cross"	 * @see TickPosition	 */	[Style(name="tickPosition", type="String")]        //-- Minor ticks    	/**	 * If true, ticks will be displayed on the axis at minor positions.	 * 	 * @default true	 */	[Style(name="showMinorTicks", type="Boolean")]		/**	 * The line weight, in pixels, for the minor ticks on the axis.	 * 	 * @default 1	 */	[Style(name="minorTickWeight", type="int")]    	/**	 * The line color for the minor ticks on the axis.	 * 	 * @default #888a85	 */	[Style(name="minorTickColor", type="uint")]    	/**	 * The length of the minor ticks on the axis.	 * 	 * @default 3	 */	[Style(name="minorTickLength", type="Number")]		/**	 * The position of the minor ticks on the axis.	 * 	 * @default "outside"	 * @see com.yahoo.astra.fl.charts.TickPosition	 */	[Style(name="minorTickPosition", type="String")]		//-- Title		/**	 * If true, the axis title will be displayed.	 * 	 * @default 2	 */	[Style(name="showTitle", type="Boolean")]		/**	 * The TextFormat object to use to render the axis title label.     *     * @default TextFormat("_sans", 11, 0x000000, false, false, false, '', '', TextFormatAlign.LEFT, 0, 0, 0, 0)	 */	[Style(name="titleTextFormat", type="TextFormat")]	/**	 * The default axis renderer for a cartesian chart.	 * 	 * @see com.yahoo.astra.fl.charts.CartesianChart	 * @author Josh Tynjala	 */	public class DefaultAxisRenderer extends UIComponent implements ICartesianAxisRenderer	{			//--------------------------------------	//  Class Variables	//--------------------------------------				/**		 * @private		 */		private static var defaultStyles:Object = 		{			//axis			showAxis: true,			axisWeight: 1,			axisColor: 0x888a85,						//labels			showLabels: true,			labelDistance: 2,			embedFonts: false,			hideOverlappingLabels: true,			labelRotation: 0,						//ticks			showTicks: true,			tickWeight: 1,			tickColor: 0x888a85,			tickLength: 4,			tickPosition: TickPosition.CROSS,						//minor ticks			showMinorTicks: true,			minorTickWeight: 1,			minorTickColor: 0x888a85,			minorTickLength: 3,			minorTickPosition: TickPosition.OUTSIDE,						//title			showTitle: true,			titleTextFormat: new TextFormat("_sans", 11, 0x000000, false, false, false, "", "", TextFormatAlign.LEFT, 0, 0, 0, 0)		};			//--------------------------------------	//  Class Methods	//--------------------------------------			/**		 * @copy fl.core.UIComponent#getStyleDefinition()		 */		public static function getStyleDefinition():Object		{			return mergeStyles(defaultStyles, UIComponent.getStyleDefinition());		}			//--------------------------------------	//  Constructor	//--------------------------------------				/**		 * Constructor.		 */		public function DefaultAxisRenderer(orientation:String)		{			super();			this.orientation = orientation;		}			//--------------------------------------	//  Properties	//--------------------------------------				/**		 * @private		 * Storage for the TextFields used for labels on this axis.		 */		protected var labelTextFields:Array = [];				/**		 * @private		 * A cache to allow the reuse of TextFields when redrawing the renderer.		 */		private var _labelCache:Array;				/**		 * @private		 * The TextField used to display the axis title.		 */		protected var titleTextField:TextField;				/**		 * @inheritDoc		 */		public function get length():Number		{			if(this.orientation == AxisOrientation.VERTICAL)			{				return this.contentBounds.height;			}			return this.contentBounds.width;		}				/**		 * @private		 * Storage for the orientation property.		 */		private var _orientation:String = AxisOrientation.VERTICAL;				/**		 * @inheritDoc		 */		public function get orientation():String		{			return this._orientation;		}				/**		 * @private		 */		public function set orientation(value:String):void		{			if(this._orientation != value)			{				this._orientation = value;				this.invalidate();			}		}				/**		 * @private		 * Storage for the contentBounds property.		 */		protected var _contentBounds:Rectangle = new Rectangle();				/**		 * @inheritDoc		 */		public function get contentBounds():Rectangle		{			return this._contentBounds;		}				/**		 * @private		 * Storage for the ticks property.		 */		private var _ticks:Array = [];				/**		 * @inheritDoc		 */		public function get ticks():Array		{			return this._ticks;		}				/**		 * @private		 */		public function set ticks(value:Array):void		{			this._ticks = value;			this.invalidate(InvalidationType.DATA);		}				/**		 * @private		 * Storage for the minorTicks property.		 */		private var _minorTicks:Array = [];				/**		 * @inheritDoc		 */		public function get minorTicks():Array		{			return this._minorTicks;		}				/**		 * @private		 */		public function set minorTicks(value:Array):void		{			this._minorTicks = value;			this.invalidate(InvalidationType.DATA);		}				/**		 * @private		 * Storage for the title property.		 */		private var _title:String = "";				/**		 * @inheritDoc		 */		public function get title():String		{			return this._title;		}				/**		 * @private		 */		public function set title(value:String):void		{			if(this._title != value)			{				this._title = value ? value : "";				this.invalidate();			}		}			//--------------------------------------	//  Public Methods	//--------------------------------------			/**		 * @inheritDoc		 */		public function updateBounds():void		{			var showLabels:Boolean = this.getStyleValue("showLabels") as Boolean;			var labelDistance:Number = this.getStyleValue("labelDistance") as Number;			var textFormat:TextFormat = this.getStyleValue("textFormat") as TextFormat;			var labelRotation:Number = this.getStyleValue("labelRotation") as Number;			var embedFonts:Boolean = this.getStyleValue("embedFonts") as Boolean;			labelRotation = Math.max(-90, Math.min(labelRotation, 90));						this.createCache();			this.updateLabels(this.ticks, showLabels, textFormat, labelDistance, labelRotation, embedFonts);			this.clearCache();						this.updateTitle();						this.calculateContentBounds();		}			//--------------------------------------	//  Protected Methods	//--------------------------------------				/**		 * @private		 */		override protected function configUI():void		{			super.configUI();						if(!this.titleTextField)			{				this.titleTextField = new TextField();				this.titleTextField.autoSize = TextFieldAutoSize.LEFT;				this.addChild(this.titleTextField);			}		}				/**		 * @private		 */		override protected function draw():void		{			this.graphics.clear();						this.positionTitle();						var showTicks:Boolean = this.getStyleValue("showTicks") as Boolean;			var showMinorTicks:Boolean = this.getStyleValue("showMinorTicks") as Boolean;			var filteredMinorTicks:Array = this.minorTicks.concat();			if(showMinorTicks && showTicks)			{				//filter out minor ticks that appear at the same position				//as major ticks.				filteredMinorTicks = filteredMinorTicks.filter(function(item:AxisData, index:int, source:Array):Boolean				{					return !this.ticks.some(function(item2:AxisData, index2:int, source2:Array):Boolean					{						//using fuzzyEquals because we may encounter rounding errors						return NumberUtil.fuzzyEquals(item.position, item2.position, 10);					});				}, this);			}						this.drawAxis();						var showLabels:Boolean = this.getStyleValue("showLabels") as Boolean;			var labelDistance:Number = this.getStyleValue("labelDistance") as Number;			var textFormat:TextFormat = this.getStyleValue("textFormat") as TextFormat;			var labelRotation:Number = this.getStyleValue("labelRotation") as Number;			var embedFonts:Boolean = this.getStyleValue("embedFonts") as Boolean;			labelRotation = Math.max(-90, Math.min(labelRotation, 90));			this.positionLabels(this.ticks, showLabels, labelDistance, labelRotation, embedFonts);						var tickPosition:String = this.getStyleValue("tickPosition") as String;			var tickLength:Number = this.getStyleValue("tickLength") as Number;			var tickWeight:int = this.getStyleValue("tickWeight") as int;			var tickColor:uint = this.getStyleValue("tickColor") as uint;			this.drawTicks(this.ticks, showTicks, tickPosition, tickLength, tickWeight, tickColor);						var minorTickPosition:String = this.getStyleValue("minorTickPosition") as String;			var minorTickLength:Number = this.getStyleValue("minorTickLength") as Number;			var minorTickWeight:int = this.getStyleValue("minorTickWeight") as int;			var minorTickColor:uint = this.getStyleValue("minorTickColor") as uint;			this.drawTicks(filteredMinorTicks, showMinorTicks, minorTickPosition, minorTickLength, minorTickWeight, minorTickColor);						super.draw();			}				/**		 * @private		 * Updates the title text and styles.		 */		protected function updateTitle():void		{			var showTitle:Boolean = this.getStyleValue("showTitle") as Boolean;			if(!showTitle)			{				this.titleTextField.text = "";			}			else			{				var textFormat:TextFormat = this.getStyleValue("titleTextFormat") as TextFormat;				var embedFonts:Boolean = this.getStyleValue("embedFonts") as Boolean;				this.titleTextField.defaultTextFormat = textFormat;				this.titleTextField.embedFonts = embedFonts;				this.titleTextField.text = this.title;				if(this.orientation == AxisOrientation.VERTICAL && embedFonts)				{					this.titleTextField.rotation = 90;				}			}		}				/**		 * @private		 * Positions the title along the axis.		 */		protected function positionTitle():void		{			var showTitle:Boolean = this.getStyleValue("showTitle") as Boolean;			this.titleTextField.visible = showTitle;			if(showTitle)			{				if(this.orientation == AxisOrientation.VERTICAL)				{					if(this.titleTextField.rotation != 0)					{						this.titleTextField.x = this.titleTextField.width;					}					this.titleTextField.y = this.contentBounds.y + (this.contentBounds.height - this.titleTextField.height) / 2;				}				else //horizontal				{					this.titleTextField.x = this.contentBounds.x + (this.contentBounds.width - this.titleTextField.width) / 2;					this.titleTextField.y = this.height - this.titleTextField.height;

⌨️ 快捷键说明

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