package { import flash.display.MovieClip; import flash.display.Graphics; import flash.display.Sprite; import flash.geom.Matrix; import flash.text.TextFormat; import flash.text.TextField; public class SHZHabitabilityPlot extends MovieClip { public var plotWidth:Number = 100; public var plotHeight:Number = 30; public const coldColor:uint = 0x9cadeb; public const hotColor:uint = 0xfad2ac; public const cursorThickness:Number = 2; public const cursorColor:uint = 0xe03030; public const cursorAlpha:Number = 0.5; protected var _backgroundSP:Sprite; protected var _curveSP:Sprite; protected var _curveMaskSP:Sprite; protected var _shadingSP:Sprite; protected var _labelsSP:Sprite; protected var _coldLabel:TextField; protected var _hotLabel:TextField; protected var _borderSP:Sprite; protected var _destroyedSP:Sprite; protected var _cursorSP:Sprite; public function SHZHabitabilityPlot(w:Number, h:Number) { _backgroundSP = new Sprite(); addChild(_backgroundSP); _curveSP = new Sprite(); addChild(_curveSP); _curveMaskSP = new Sprite(); addChild(_curveMaskSP); _shadingSP = new Sprite(); addChild(_shadingSP); _labelsSP = new Sprite(); addChild(_labelsSP); _destroyedSP = new Sprite(); addChild(_destroyedSP); _borderSP = new Sprite(); addChild(_borderSP); _cursorSP = new Sprite(); addChild(_cursorSP); var tf:TextFormat = new TextFormat("Verdana", 10, 0x000000, false, true); _curveMaskSP.visible = false; _curveSP.mask = _curveMaskSP; _coldLabel = new TextField(); tf.color = 0x658ADE; _coldLabel.defaultTextFormat = tf; _coldLabel.selectable = false; _coldLabel.embedFonts = true; _coldLabel.width = 0; _coldLabel.height = 0; _coldLabel.autoSize = "left"; _coldLabel.text = "too cold"; _hotLabel = new TextField(); tf.color = 0xF19538; _hotLabel.defaultTextFormat = tf; _hotLabel.selectable = false; _hotLabel.embedFonts = true; _hotLabel.width = 0; _hotLabel.height = 0; _hotLabel.autoSize = "left"; _hotLabel.text = "too hot"; _labelsSP.addChild(_coldLabel); _labelsSP.addChild(_hotLabel); plotWidth = w; plotHeight = h; drawStaticContent(); } public function setCursorTime(time:Number, timespan:Number):void { _cursorSP.x = time*plotWidth/timespan; } public function plotDataTable(dT:Array, timespan:Number, timeDestroyed:Number):void { var g:Graphics = _curveSP.graphics; g.clear(); g.lineStyle(1, 0x505050); var xScale:Number = plotWidth/timespan; var yScale:Number = -(plotHeight - 2*shadingExtent); var yOffset:Number = plotHeight - shadingExtent; var i:int; var nx:Number; var ny:Number; var npos:int; var lx:Number; var ly:Number; var lpos:int; lx = xScale*dT[0].time; ly = yScale*dT[0].shzTemp + yOffset; if (ly<0) lpos = 1; else if (ly>plotHeight) lpos = -1; else lpos = 0; var topLimit:Number = -10; var bottomLimit:Number = plotHeight + 10; if (lybottomLimit) ly = bottomLimit; if (lpos==0) g.moveTo(lx, ly); for (i=1; iplotHeight) npos = -1; else npos = 0; if (nybottomLimit) ny = bottomLimit; if (lpos==0) { // the last point was in bounds, so we need to draw the segment (no moveTo needed) g.lineTo(nx, ny); } else if (lpos!=npos) { // the last point was out of bounds and the current point is either in bounds, or it // is out of bounds in the other out of bounds region; either way, we do a moveTo and lineTo g.moveTo(lx, ly); g.lineTo(nx, ny); } lx = nx; ly = ny; lpos = npos; } g = _destroyedSP.graphics; g.clear(); var xDestroyed:Number = xScale*timeDestroyed; if (xDestroyed