[rhmessaging-commits] rhmessaging commits: r4402 - in mgmt/trunk/cumin/open-flash-chart: charts and 7 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Oct 25 11:20:45 EDT 2010


Author: eallen
Date: 2010-10-25 11:20:44 -0400 (Mon, 25 Oct 2010)
New Revision: 4402

Modified:
   mgmt/trunk/cumin/open-flash-chart/charts/Area.as
   mgmt/trunk/cumin/open-flash-chart/charts/Base.as
   mgmt/trunk/cumin/open-flash-chart/charts/Line.as
   mgmt/trunk/cumin/open-flash-chart/charts/ObjectCollection.as
   mgmt/trunk/cumin/open-flash-chart/charts/Pie.as
   mgmt/trunk/cumin/open-flash-chart/charts/series/Element.as
   mgmt/trunk/cumin/open-flash-chart/charts/series/dots/PointDotBase.as
   mgmt/trunk/cumin/open-flash-chart/charts/series/pies/PieSlice.as
   mgmt/trunk/cumin/open-flash-chart/com/serialization/json/JSON.as
   mgmt/trunk/cumin/open-flash-chart/elements/Background.as
   mgmt/trunk/cumin/open-flash-chart/elements/control/Control.as
   mgmt/trunk/cumin/open-flash-chart/main.as
   mgmt/trunk/cumin/open-flash-chart/obj/open-flash-chartConfig.xml
Log:
Updates to the open source flash charts to support better incremental updates and json parsing improvements. 

Modified: mgmt/trunk/cumin/open-flash-chart/charts/Area.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/charts/Area.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/charts/Area.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -27,7 +27,14 @@
 				fill = "#3030d0";
 				
 			this.fill_colour = string.Utils.get_colour(fill);
-			this.fill_alpha = this.props.has('fill-alpha') ? this.props.get('fill-alpha') : 0.6;
+			var alpha:Number = 0.6;
+			if (this.props.has('fill-alpha')) {
+				alpha = this.props.get('fill-alpha');
+				if (alpha > 1.0) {
+					alpha = alpha / 10;
+				}
+			}
+			this.fill_alpha = alpha;
 				
 			
 			/*

Modified: mgmt/trunk/cumin/open-flash-chart/charts/Base.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/charts/Base.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/charts/Base.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -384,12 +384,13 @@
 			return null;
 		}
 		
-		public function shift_x_values( delta:Number ):void {
+		public function shift_x_values( delta:Number, duration:Number, tnow:Number, end_secs:Number ):void {
 			var killing:Boolean = false;
 			for ( var i:Number = this.numChildren - 1; i >=0; i-- ) {
 				if ( this.getChildAt(i) is Element ) {
 					var e:Element = this.getChildAt(i) as Element;
-					e._x -= delta;
+
+					e._x = Number(int(duration - (tnow - e.dt) + end_secs));
 					if (e._x < 0) {
 						if (killing) {
 							e.die();
@@ -400,12 +401,12 @@
 				}
 			}
 		}
-		protected function find_uid( uid:String ):Boolean {
+		protected function find_uid( dt:Number ):Boolean {
 			for ( var i:Number = 0; i < this.numChildren; i++ ) {
 				if ( this.getChildAt(i) is Element ) {
 					var e:Element = this.getChildAt(i) as Element;
-					if (e.uid)
-						if (e.uid == uid)
+					if (e.dt)
+						if (e.dt == dt)
 							return true;
 				}
 			}
@@ -425,7 +426,7 @@
 				if( val != null )
 				{
 					if ( !dups ) {
-						if ( this.find_uid( val['uid'] ) )
+						if ( this.find_uid( val['dt'] ) )
 							continue;
 					}
 					tmp = this.get_element( index, val );

Modified: mgmt/trunk/cumin/open-flash-chart/charts/Line.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/charts/Line.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/charts/Line.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -141,16 +141,16 @@
 		
 		protected function draw_line(): void {
 			
-			this.graphics.clear();
 			var width:Number = this.props.get_colour('width');
 			if (width > 0) {
-    			this.graphics.lineStyle( width, this.props.get_colour('colour') );
-    			
-    			if( this.line_style.style != 'solid' )
-    				this.dash_line();
-    			else
-                    this.solid_line();
-            }
+				this.graphics.clear();
+				this.graphics.lineStyle( width, this.props.get_colour('colour') );
+			
+				if( this.line_style.style != 'solid' )
+					this.dash_line();
+				else
+					this.solid_line();
+			}
 		}
 		
 		public function move_dots( sc:ScreenCoordsBase ): void {

Modified: mgmt/trunk/cumin/open-flash-chart/charts/ObjectCollection.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/charts/ObjectCollection.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/charts/ObjectCollection.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -268,13 +268,25 @@
 		// are we resizing a PIE chart?
 		//
 		public function has_pie():Boolean {
-			
 			if ( this.sets.length > 0 && ( this.sets[0] is Pie ) )
 				return true;
 			else
 				return false;
 		}
 		
+		public function set_pie_value( id:String, new_val:Object ): void {
+			if ( this.sets.length > 0 && ( this.sets[0] is Pie ) ) {
+				var pie:Pie = this.sets[0] as Pie;
+				pie.set_value ( id, new_val );
+			}
+		}
+
+		public function get_pie_element():Pie {
+			if ( this.sets.length > 0 && ( this.sets[0] is Pie ) )
+				return this.sets[0] as Pie;
+			else
+				return null;
+		}
 		/**
 		 * To stop memory leaks we explicitly kill all
 		 * our children

Modified: mgmt/trunk/cumin/open-flash-chart/charts/Pie.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/charts/Pie.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/charts/Pie.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -1,5 +1,6 @@
 package charts {
 	import charts.series.pies.PieLabel;
+	import charts.series.pies.PieSlice;
 	import flash.external.ExternalInterface;
 	import string.Utils;
 	import charts.series.Element;
@@ -178,7 +179,13 @@
 			return { Element:null, distance_x:0, distance_y:0 };
 		}
 
+		public function set_value ( id:String, new_val:Object ): void {
+			while ( this.numChildren > 0 )
+				this.removeChildAt(0);
 
+			this.values = new_val.values;
+			this.add_values();
+		}
 		public override function resize( sc:ScreenCoordsBase ): void {
 			var radius:Number = this.style.radius;
 			if (isNaN(radius)){

Modified: mgmt/trunk/cumin/open-flash-chart/charts/series/Element.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/charts/series/Element.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/charts/series/Element.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -20,7 +20,7 @@
 		//
 		public var _x:Number;
 		public var _y:Number;
-		public var uid:String;
+		public var dt:Number;
 		
 		public var index:Number;
 		protected var tooltip:String;

Modified: mgmt/trunk/cumin/open-flash-chart/charts/series/dots/PointDotBase.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/charts/series/dots/PointDotBase.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/charts/series/dots/PointDotBase.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -60,8 +60,8 @@
 				this._x = props.get('x');
 				this.index = Number.MIN_VALUE;
 			}
-			if ( props.has('uid') )
-				this.uid = props.get('uid');
+			if ( props.has('dt') )
+				this.dt = props.get('dt');
 			
 			this.radius = props.get('dot-size');
 			this.tooltip = this.replace_magic_values( props.get('tip') );

Modified: mgmt/trunk/cumin/open-flash-chart/charts/series/pies/PieSlice.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/charts/series/pies/PieSlice.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/charts/series/pies/PieSlice.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -233,5 +233,8 @@
 		public function get_colour(): Number {
 			return this.colour;
 		}
+		public function get_label(): String {
+			return this.label;
+		}
 	}
 }

Modified: mgmt/trunk/cumin/open-flash-chart/com/serialization/json/JSON.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/com/serialization/json/JSON.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/com/serialization/json/JSON.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -417,21 +417,21 @@
         _word = function ():* {
             switch (ch) {
                 case 't':
-                case 'T':
+				case 'T':
                     if (_next() == 'r' && _next() == 'u' && _next() == 'e') {
                         _next();
                         return true;
                     }
                     break;
                 case 'f':
-                case 'F':
+				case 'F':
                     if (_next() == 'a' && _next() == 'l' && _next() == 's' && _next() == 'e') {
                         _next();
                         return false;
                     }
                     break;
                 case 'n':
-                case 'N':
+				case 'N':
                     if (_next() == 'u' && _next() == 'l' && _next() == 'l') {
                         _next();
                         return null;

Modified: mgmt/trunk/cumin/open-flash-chart/elements/Background.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/elements/Background.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/elements/Background.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -137,9 +137,13 @@
       }
 
       public function resize():void {
-         this.graphics.beginFill( this.colour );
-         this.graphics.drawRect( 0, 0, this.stage.stageWidth, this.stage.stageHeight );
-      }
+		if (this.graphics) {
+			if (this.colour)
+				this.graphics.beginFill( this.colour );
+			if (this.stage)
+				this.graphics.drawRect( 0, 0, this.stage.stageWidth, this.stage.stageHeight );
+		}
+	  }
       
       public function die(): void {
    

Modified: mgmt/trunk/cumin/open-flash-chart/elements/control/Control.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/elements/control/Control.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/elements/control/Control.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -13,6 +13,8 @@
 	import flash.events.MouseEvent;
 	import com.serialization.json.JSON;
 	import string.Utils;
+	import flash.external.ExternalInterface;
+
    
 	public class Control extends Sprite {
   
@@ -44,7 +46,7 @@
 				this.current_min = json.slider_low.value;
 				this.low_colour = json.slider_low.colour;
 				this.high_colour = json.slider_high.colour;
-				tr.ace("low_colour = " + this.low_colour + " high=" + this.high_colour);
+				//tr.ace("low_colour = " + this.low_colour + " high=" + this.high_colour);
 				this.x_axis	= new XAxis( json, 0, 24 );
 				this.y_min = json.y_min;
 				this.y_max = json.y_max;
@@ -52,9 +54,25 @@
 				this.inter_rect = new Sprite();
 				this.addChild( this.inter_rect );
 				this.exists = true;
+
+				// calculate the x values
+				var tnow:Number = json.tnow;
+				var duration:Number = json.duration;
+				var end_secs:Number = json.end_secs;
+
+				var els:Array = json['elements'] as Array;
+				for ( var i:Number = 0; i < els.length; i++) {
+					var vals:Array = els[i]['values'] as Array;
+					for (var j:Number = 0; j < vals.length; j++) {
+						json.elements[i].values[j].x = Number(int(duration - (tnow - vals[j].dt) + end_secs));
+					}
+				}
+				
 				this.obs = Factory.MakeChart( json );
-				for each( var set:Sprite in this.obs.sets )
+				for each( var set:Sprite in this.obs.sets ) {
+					//ExternalInterface.call("ofc_debug", "Control - constructor set");
 					this.addChild( set );
+				}
 			}
 		}
 
@@ -71,6 +89,7 @@
 				}
 				this.slider_low.init( this.current_min );
 				this.slider_high.init( this.current_max );
+				//ExternalInterface.call("ofc_debug", "Control - init");
 			}
 		}
 
@@ -88,14 +107,6 @@
 			this.graphics.beginFill( 0xffffff );
 			this.graphics.drawRect( 0, 19, this.stage.stageWidth - right_pad, 1);
 			this.graphics.endFill();
-			/*
-			this.graphics.beginFill( 0x666666 );
-			this.graphics.drawRect( 0, 20, this.stage.stageWidth - right_pad, 1);
-			this.graphics.endFill();
-			this.graphics.beginFill( 0x000000 );
-			this.graphics.drawRect( 0, 21, this.stage.stageWidth - right_pad, 1);
-			this.graphics.endFill();
-*/
 			this.x = 0;
 			this.y = this.stage.stageHeight - 80;
 
@@ -124,6 +135,7 @@
 			this.slider_high.draw( right_pad );
 			
 			this.draw_chart_area();
+			//ExternalInterface.call("ofc_debug", "Control - draw_chart_area");
 		}
 
 		private function draw_chart_area():void {
@@ -198,6 +210,8 @@
 		}
 		
 		public function mouse_move( event:Event ):void {
+			if ( !this.exists )
+				return;
 			this.slider_low.mouseMove( event );
 			this.slider_high.mouseMove ( event );
 		}

Modified: mgmt/trunk/cumin/open-flash-chart/main.as
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/main.as	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/main.as	2010-10-25 15:20:44 UTC (rev 4402)
@@ -111,7 +111,8 @@
 					//var file:String = "../../data-files/test-bug.txt";
 					//var file:String = "../../data-files/radar-2.txt";
 					//var file:String = "../../data-files/jsontest1.txt";
-					var file:String = "../../data-files/testchart2.txt";
+					//var file:String = "../../data-files/testchart2.txt";
+					var file:String = "../../data-files/pietest1.txt";
 					this.load_external_file( file );
 
 					/*
@@ -123,13 +124,15 @@
 					*/
 				}
 				catch (e:Error) {
-					this.show_error( 'Loading test data\n'+file+'\n'+e.message );
+					//this.show_error( 'Loading test data\n'+file+'\n'+e.message );
 				}
 			}
 			
 			// inform javascript that it can call our reload method
 			ExternalInterface.addCallback("reload", reload); // mf 18nov08, line 110 of original 'main.as'
-		 
+
+			ExternalInterface.addCallback("setpieslice", setpieslice);
+			
 			// inform javascript that it can call our load method
 			ExternalInterface.addCallback("load", load);
 			
@@ -417,9 +420,9 @@
 			this.load_external_file( url );
 		}
 
-
 		private function load_external_file( file:String ):void {
 			
+			//ExternalInterface.call("ofc_debug", "I am load_external_file " + file );
 			this.URL = file;
 			//
 			// LOAD THE DATA
@@ -430,16 +433,18 @@
 			
 			var request:URLRequest = new URLRequest(file);
 			loader.load(request);
+			//ExternalInterface.call("ofc_debug", "end of load_external_file");
 		}
 		
 		private function ioError( e:IOErrorEvent ):void {
+			//ExternalInterface.call("ofc_debug", "ioError " + e.text);
 			
 			//return;
 			// remove the 'loading data...' msg:
 			this.removeChildAt(0);
-			var msg:ErrorMsg = new ErrorMsg( 'Open Flash Chart\nIO ERROR\nLoading test data\n' + e.text );
-			msg.add_html( 'This is the URL that I tried to open:<br><a href="'+this.URL+'">'+this.URL+'</a>' );
-			this.addChild( msg );
+			//var msg:ErrorMsg = new ErrorMsg( 'Open Flash Chart\nIO ERROR\nLoading test data\n' + e.text );
+			//msg.add_html( 'This is the URL that I tried to open:<br><a href="'+this.URL+'">'+this.URL+'</a>' );
+			//this.addChild( msg );
 		}
 		
 		private function show_error( msg:String ):void {
@@ -533,6 +538,19 @@
             this.resize();
         }
 		
+		public function setpieslice( id:String, new_vals:String):void {
+			var right:Number = this.stage.stageWidth - this.keys.get_right_width();
+			var top:Number = this.title.get_height() + this.keys.get_height();
+			// this object is used in the mouseMove method
+			this.sc = new ScreenCoords(
+				top, 0, right, this.stage.stageHeight,
+				null, null, null, 0, 0, false, this.stage.stageWidth);
+
+			var json:Object = JSON.deserialize( new_vals );
+			this.obs.set_pie_value( id, json );
+			this.obs.resize( sc );
+		}
+
 		//
 		// pie charts are simpler to resize, they don't
 		// have all the extras (X,Y axis, legends etc..)
@@ -629,7 +647,8 @@
 			this.addEventListener(MouseEvent.MOUSE_MOVE, this.mouseMove);
 	
 			// FlashConnect.trace("stageWidth: " + stage.stageWidth + " stageHeight: " + stage.stageHeight);
-			this.background.resize();
+			if (this.background)
+				this.background.resize();
 			this.title.resize();
 			
 			var left:Number   =  this.y_legend.get_width() /*+ this.y_labels.get_width()*/ + this.y_axis.get_width();
@@ -708,6 +727,7 @@
 		//
 		private function xmlLoaded(event:Event):void {
 			var loader:URLLoader = URLLoader(event.target);
+			//ExternalInterface.call("ofc_debug", "This is xmlLoaded");
 			this.parse_json( loader.data );
 		}
 		
@@ -722,6 +742,32 @@
 			this.json = json_string;
 			try {
 				var json:Object = JSON.deserialize( json_string );
+				// expand the element values, create a tooltip, and calculate the x value
+				var tnow:Number = json.tnow;
+				var duration:Number = json.duration;
+				var end_secs:Number = json.end_secs;
+				var snap_shot_date:Date = new Date(tnow * 1000);
+
+				var els:Array = json['elements'] as Array;
+				var mo:String, dd:String, yy:String, hh:String, mi:String, ss:String;
+				for ( var i:Number = 0; i < els.length; i++) {
+					var vals:Array = els[i]['values'] as Array;
+					for (var j:Number = 0; j < vals.length; j++) {
+						var sample_date:Date = new Date(vals[j].dt * 1000);
+						mo = zp(sample_date.getMonth() + 1);
+						dd = zp(sample_date.getDate());
+						yy = zp(sample_date.getFullYear());
+						hh = zp(sample_date.getHours());
+						mi = zp(sample_date.getMinutes());
+						ss = zp(sample_date.getSeconds());
+
+						var tt:String = "<br>" + els[i].text + ": #val#<br>" + mo + "/" + dd + "/" + yy + " " + hh + ":" + mi + ":" + ss;
+						json.elements[i].values[j].tip = tt;
+
+						json.elements[i].values[j].x = Number(int(duration - (tnow - vals[j].dt) + end_secs));
+						sample_date = null;
+						}
+				}
 				ok = true;
 			}
 			catch (e:Error) {
@@ -746,22 +792,32 @@
 			
 			json_string = '';
 		}
-		
+
+		private function zp( n:Number ) : String {
+			if (n < 10) {
+				return "0" + n.toString();
+			}
+			return n.toString();
+		}
 		private function build_chart( json:Object ):void {
 			
 //			tr.ace('----');
 //			tr.ace(JSON.serialize(json));
 //			tr.ace('----');
-			
+				
 			var append:Number = json['append'];
+			var els:Array;
+			var i:Number;
 			if ( append ) {
 				
-				var els:Array = json['elements'] as Array;
-				
-				for( var i:Number = 0; i < els.length; i++ ) {
+				els = json['elements'] as Array;
+				var duration:Number = json.duration;
+				var tnow:Number = json.tnow;
+				var end_secs:Number = json.end_secs;
+				for( i = 0; i < els.length; i++ ) {
 					var line:Base = this.obs.get_object_by_key( els[i]['text'] );
-					line.shift_x_values ( append );
 					line.add_values_2 ( els[i]['values'], false );
+					line.shift_x_values ( append, duration, tnow, end_secs );
 				}
 				this.ok = true;
 				this.resize();
@@ -825,6 +881,8 @@
 				this.menu = new Menu('99', json['menu']);
 				this.addChild(this.menu);
 			}
+
+			//ExternalInterface.call("ofc_debug", "creating control");
 			this.control    = new Control ( json.control );
 			this.addChild( this.control );
 			this.control.init();

Modified: mgmt/trunk/cumin/open-flash-chart/obj/open-flash-chartConfig.xml
===================================================================
--- mgmt/trunk/cumin/open-flash-chart/obj/open-flash-chartConfig.xml	2010-10-25 15:02:59 UTC (rev 4401)
+++ mgmt/trunk/cumin/open-flash-chart/obj/open-flash-chartConfig.xml	2010-10-25 15:20:44 UTC (rev 4402)
@@ -5,7 +5,7 @@
   <compiler>
     <source-path append="true">
       <path-element>C:\Users\Dad\OFC2Patches-DZ-Ichor\open-flash-chart\trunk</path-element>
-      <path-element>C:\Program Files\FlashDevelop\Library\AS3\classes</path-element>
+      <path-element>C:\Program Files (x86)\FlashDevelop\Library\AS3\classes</path-element>
     </source-path>
   </compiler>
   <file-specs>



More information about the rhmessaging-commits mailing list