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

📄 timeaxis.as

📁 拓扑图基于SNMP数据采集模块的设计和实现
💻 AS
📖 第 1 页 / 共 2 页
字号:
package com.yahoo.astra.fl.charts.axes{	import com.yahoo.astra.fl.charts.series.ISeries;	import com.yahoo.astra.utils.DateUtil;	import com.yahoo.astra.utils.TimeUnit;	/**	 * An axis type representing a date and time range from minimum to maximum	 * with major and minor divisions.	 * 	 * @author Josh Tynjala	 */	public class TimeAxis extends BaseAxis implements IAxis, IStackingAxis	{			//--------------------------------------	//  Static Properties	//--------------------------------------			/**		 * A magic number specifying an ideal minimum number of		 * pixels between each tick/line/label on a major unit.		 * Used to calculate the major unit if it is not set by		 * the developer. 		 */		private static const IDEAL_PIXELS_BETWEEN_MAJOR_POSITIONS:Number = 75;				/**		 * A magic number specifying an ideal minimum number of		 * pixels between each tick/line/label on a minor unit.		 * Used to calculate the minor unit if it is not set by		 * the developer. 		 */		private static const IDEAL_PIXELS_BETWEEN_MINOR_POSITIONS:Number = 30;				/**		 * @private		 */		private static const TIME_UNITS:Array = [TimeUnit.MILLISECONDS, TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAY, TimeUnit.MONTH, TimeUnit.YEAR];				//--------------------------------------	//  Constructor	//--------------------------------------			/**		 * Constructor.		 */		public function TimeAxis()		{			super();		}			//--------------------------------------	//  Properties	//--------------------------------------			protected var positionMultiplier:Number = 0;			/**		 * @private		 * Storage for the minimum value.		 */		private var _minimum:Date;				/**		 * @private		 * Indicates whether the minimum bound is user-defined or generated by the axis.		 */		private var _minimumSetByUser:Boolean = false;				/**		 * The minimum value displayed on the axis.		 */		public function get minimum():Date		{			return this._minimum;		}				/**		 * @private		 */		public function set minimum(value:Date):void		{			this._minimum = value;			this._minimumSetByUser = value != null;		}			/**		 * @private		 * Storage for the maximum value.		 */		private var _maximum:Date;				/**		 * @private		 * Indicates whether the maximum bound is user-defined or generated by the axis.		 */		private var _maximumSetByUser:Boolean = false;				/**		 * The maximum value displayed on the axis.		 */		public function get maximum():Date		{			return this._maximum;		}				/**		 * @private		 */		public function set maximum(value:Date):void		{			this._maximum = value;			this._maximumSetByUser = value != null;		}		//-- Units			/**		 * @private		 * Storage for the major unit.		 */		private var _majorUnit:int = 1;				/**		 * @private		 * Indicates whether the major unit is user-defined or generated by the axis.		 */		private var _majorUnitSetByUser:Boolean = false;				/**		 * The major unit at which new lines are drawn.		 */		public function get majorUnit():Number		{			return this._majorUnit;		}				/**		 * @private		 */		public function set majorUnit(value:Number):void		{			this._majorUnit = value;			this._majorUnitSetByUser = !isNaN(value);		}			/**		 * @private		 * Storage for the majorTimeUnit property.		 */		private var _majorTimeUnit:String = TimeUnit.MONTH;				/**		 * @private		 * Indicates whether the major time unit is user-defined or generated by the axis.		 */		private var _majorTimeUnitSetByUser:Boolean = false;				/**		 * Combined with majorUnit, determines the amount of time between major ticks and labels.		 * 		 * @see com.yahoo.astra.fl.charts.TimeUnit;		 */		public function get majorTimeUnit():String		{			return this._majorTimeUnit;		}				/**		 * @private		 */		public function set majorTimeUnit(value:String):void		{			this._majorTimeUnit = value;			this._majorTimeUnitSetByUser = value != null;		}			/**		 * @private		 * Storage for the minor unit.		 */		private var _minorUnit:int = 1;				/**		 * @private		 * Indicates whether the minor unit is user-defined or generated by the axis.		 */		private var _minorUnitSetByUser:Boolean = false;				/**		 * The minor unit at which new lines are drawn.		 */		public function get minorUnit():Number		{			return this._minorUnit;		}				/**		 * @private		 */		public function set minorUnit(value:Number):void		{			this._minorUnit = value;			this._minorUnitSetByUser = !isNaN(value);		}			/**		 * @private		 * Storage for the minorTimeUnit property.		 */		private var _minorTimeUnit:String = TimeUnit.MONTH;				/**		 * @private		 * Indicates whether the minor time unit is user-defined or generated by the axis.		 */		private var _minorTimeUnitSetByUser:Boolean = false;				/**		 * Combined with minorUnit, determines the amount of time between minor ticks.		 * 		 * @see com.yahoo.astra.fl.charts.TimeUnit;		 */		public function get minorTimeUnit():String		{			return this._minorTimeUnit;		}				/**		 * @private		 */		public function set minorTimeUnit(value:String):void		{			this._minorTimeUnit = value;			this._minorTimeUnitSetByUser = value != null;		}				/**		 * @private		 * Storage for the stackingEnabled property.		 */		private var _stackingEnabled:Boolean = false;				/**		 * @inheritDoc		 */		public function get stackingEnabled():Boolean		{			return this._stackingEnabled;		}				/**		 * @private		 */		public function set stackingEnabled(value:Boolean):void		{			this._stackingEnabled = value;		}			/**		 * @private		 * Storage for the snapToUnits property.		 */		private var _snapToUnits:Boolean = true;				/**		 * If true, the labels, ticks, gridlines, and other objects will snap to		 * the nearest major or minor unit. If false, their position will be based		 * on the minimum value.		 */		public function get snapToUnits():Boolean		{			return this._snapToUnits;		}				/**		 * @private		 */		public function set snapToUnits(value:Boolean):void		{			this._snapToUnits = value;		}				/**		 * @private		 */		private var _dataMinimum:Date;				/**		 * @private		 */		private var _dataMaximum:Date;			//--------------------------------------	//  Public Methods	//--------------------------------------			/**		 * @inheritDoc		 */		public function stack(top:Object, ...rest:Array):Object		{			var value:Number = this.valueToNumber(top);			var restCount:int = rest.length;			for(var i:int = 0; i < restCount; i++)			{				value += this.valueToNumber(rest[i]);			}			return value;		}			/**		 * @inheritDoc		 */		public function updateScale(data:Array):void		{			var seriesCount:int = data.length;			var min:Number = NaN;			var max:Number = NaN;			for(var i:int = 0; i < seriesCount; i++)			{				var series:ISeries = ISeries(data[i]);				var seriesLength:int = series.length;				for(var j:int = 0; j < seriesLength; j++)				{					var item:Object = series.dataProvider[j];					var value:Object = this.chart.itemToAxisValue(series, j, this);					var numericValue:Number = this.valueToNumber(value);										if(isNaN(min))					{						min = numericValue;					}					else					{						min = Math.min(min, numericValue);					}					if(isNaN(max))					{						max = numericValue;					}					else					{						max = Math.max(max, numericValue);					}				}			}						//bad data. show yesterday through today.			if(isNaN(min) || isNaN(max))			{				var today:Date = new Date();				max = today.valueOf();				today.setDate(today.getDate() - 1);				min = today.valueOf();			}						this._dataMinimum = new Date(min);			this._dataMaximum = new Date(max);						this.resetScale();			this.calculatePositionMultiplier();						this.renderer.ticks = this.createAxisData(this.majorUnit, this.majorTimeUnit);			this.renderer.minorTicks = this.createAxisData(this.minorUnit, this.minorTimeUnit);		}				/**		 * @inheritDoc		 */		public function valueToLocal(value:Object):Number		{			var numericValue:Number = this.valueToNumber(value);						var position:Number = (numericValue - this.minimum.valueOf()) * this.positionMultiplier;			if(this.reverse)			{				position = this.renderer.length - position;			}							return position;		}			/**		 * @inheritDoc		 */		override public function valueToLabel(value:Object):String		{			var text:String = value.toString();			if(this.labelFunction != null)			{				var numericValue:Number = this.valueToNumber(value);				text = this.labelFunction(new Date(numericValue), this.majorTimeUnit);			}						if(text == null)			{				text = "";			}			return text;		}			//--------------------------------------	//  Protected Methods	//--------------------------------------				/**		 * @private		 * Converts one of the accepted values to a Number that can be		 * used for position calculation.		 */		protected function valueToNumber(value:Object):Number		{			var convertedValue:Number = 0;			if(value is Date)			{				convertedValue = (value as Date).valueOf();			}			else if(!(value is Number))			{				convertedValue = new Date(value.toString()).valueOf();			}			else			{				convertedValue = value as Number;			}			return convertedValue;		}				/**		 * @private		 * Calculates the best scale.		 */		protected function resetScale():void		{			if(!this._minimumSetByUser)			{				this._minimum = new Date(this._dataMinimum.valueOf());			}							if(!this._maximumSetByUser)			{				this._maximum = new Date(this._dataMaximum.valueOf());			}

⌨️ 快捷键说明

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