[moodle] / contrib / plugins / grade / report / visual / flare_visualization / flare_visualization.as Repository:

Diff of /contrib/plugins/grade/report/visual/flare_visualization/flare_visualization.as

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2, Tue Jul 15 03:27:17 2008 WST revision 1.3, Thu Jul 24 15:31:44 2008 WST

By dservos:

CONTRIB-497 *Added new visualization, Grade Distribution *Fixed some minor bugs *Made abstract visualization class for creating visualizations by making classes witch extend it. *Made visual_settings.php witch takes a visualization class and truns it in to XML witch flex can read in. *Made flex visualization application read in XML formated settings as well as tab formated data from moodle and combind them to make a custom visualization. *Made flex visualization application read and use langue strings from moodle. *Added printer firendly tab TODO: *Add more visualizations *Refactor some of the flex/actionscript code *More douctenation *More UI functions for the flex application

# Line 40  Line 40 
40      import flare.vis.legend.Legend;      import flare.vis.legend.Legend;
41      import flare.vis.legend.LegendItem;      import flare.vis.legend.LegendItem;
42      import flare.vis.operator.encoder.ColorEncoder;      import flare.vis.operator.encoder.ColorEncoder;
43        import flare.vis.operator.encoder.Encoder;
44      import flare.vis.operator.encoder.ShapeEncoder;      import flare.vis.operator.encoder.ShapeEncoder;
45        import flare.vis.operator.encoder.SizeEncoder;
46      import flare.vis.operator.layout.AxisLayout;      import flare.vis.operator.layout.AxisLayout;
47      import flare.vis.scale.ScaleType;      import flare.vis.operator.layout.CircleLayout;
48        import flare.vis.operator.layout.DendrogramLayout;
49        import flare.vis.operator.layout.ForceDirectedLayout;
50        import flare.vis.operator.layout.IndentedTreeLayout;
51        import flare.vis.operator.layout.Layout;
52        import flare.vis.operator.layout.NodeLinkTreeLayout;
53        import flare.vis.operator.layout.PieLayout;
54        import flare.vis.operator.layout.RadialTreeLayout;
55        import flare.vis.operator.layout.RandomLayout;
56        import flare.vis.operator.layout.StackedAreaLayout;
57        import flare.vis.operator.layout.TreeMapLayout;
58        import flare.vis.scale.Scale;
59      import flare.vis.util.Filters;      import flare.vis.util.Filters;
60    
61      import flash.display.DisplayObject;      import flash.display.DisplayObject;
62      import flash.display.DisplayObjectContainer;      import flash.display.DisplayObjectContainer;
63      import flash.display.Sprite;      import flash.display.Sprite;
64        import flash.errors.IOError;
65      import flash.events.Event;      import flash.events.Event;
66        import flash.events.IOErrorEvent;
67      import flash.events.MouseEvent;      import flash.events.MouseEvent;
68      import flash.filters.GlowFilter;      import flash.filters.GlowFilter;
69      import flash.geom.Rectangle;      import flash.geom.Rectangle;
70      import flash.net.URLLoader;      import flash.net.URLLoader;
71        import flash.net.URLRequest;
72        import flash.text.TextField;
73      import flash.text.TextFormat;      import flash.text.TextFormat;
74    
75      [SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="30")]      [SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="30")]
# Line 79  Line 96 
96          private var lastBoxData:DataSprite = null;          private var lastBoxData:DataSprite = null;
97    
98          /**          /**
          * The data feild the X axis is based on.  
          * @default data.student  
          */  
         private var axisX:String = "data.student";  
   
         /**  
          * The data field the Y axis is based on.  
          * @default data.grade  
          */  
         private var axisY:String = "data.grade";  
   
         /**  
99           * A container for the legends witch will be displayed on the righ hand           * A container for the legends witch will be displayed on the righ hand
100           * side.           * side.
101           */           */
# Line 101  Line 106 
106           */           */
107          private var boxhc:HoverControl = new HoverControl();          private var boxhc:HoverControl = new HoverControl();
108    
109            private var settings:XML = new XML();
110    
111            private var dataURL:String;
112    
113            private var settingsURL:String;
114    
115            private var loadingMessage:TextSprite;
116    
117          /**          /**
118           * The constucter for the flare_visualization class.           * The constucter for the flare_visualization class.
119           * Calls on harvest_data and sets up the varibles from the flashvars.           * Calls on harvest_data and sets up the varibles from the flashvars.
120           */           */
121          public function flare_visualization()          public function flare_visualization()
122          {          {
123                    loadingMessage = new TextSprite("Loading....", new TextFormat("monospace", 20, 0x0000FF, true));
124                    addChild(loadingMessage);
125    
126                  // Call harvest_data, loading needed visualization data from moodle.                  // Call harvest_data, loading needed visualization data from moodle.
127                  // The Moodle wwwroot, course id, users sessionid, users session cookie                  // The Moodle wwwroot, course id, users sessionid, users session cookie
128                  // and session test data are needed to get the data from moodle are                  // and session test data are needed to get the data from moodle are
129                  // loaded threw flashvars.                  // loaded threw flashvars.
130                  harvest_data(loaderInfo.parameters['wwwroot'] + '/grade/report/visual/data.php?id=' +   escape(loaderInfo.parameters['courseid']) + '&sessioncookie=' +  escape(loaderInfo.parameters['sessioncookie']) + '&sessionid=' +  escape(loaderInfo.parameters['sessionid']) + '&sessiontest=' + escape(loaderInfo.parameters['sessiontest']));                  loaderInfo.addEventListener(Event.COMPLETE, function(evt:Event):void {
131                  //harvest_data('http://localhost/moodle/grade/report/visual/data.php?id=3&sessioncookie=&sessionid=ebb79f5984c0fa4c9b0d85814c573a81&sessiontest=jHKFJhsOPf');                          dataURL = loaderInfo.parameters['wwwroot'] + '/grade/report/visual/data.php?id=' + escape(loaderInfo.parameters['courseid']) + '&sessioncookie=' +  escape(loaderInfo.parameters['sessioncookie']) + '&sessionid=' +  escape(loaderInfo.parameters['sessionid']) + '&sessiontest=' + escape(loaderInfo.parameters['sessiontest']) + '&visid=' + escape(loaderInfo.parameters['visid']);
132                            settingsURL = loaderInfo.parameters['wwwroot'] + '/grade/report/visual/visual_settings.php?id=' + escape(loaderInfo.parameters['courseid']) + '&visid=' + escape(loaderInfo.parameters['visid']);
133    
134                            //dataURL = 'http://localhost/moodle/grade/report/visual/data.php?id=3&sessioncookie=&sessionid=ec7b77fa297d0454fa45367b42761d07&sessiontest=iqw4nC9hc7&visid=grade_distribution';
135                            //settingsURL = 'http://localhost/moodle/grade/report/visual/visual_settings.php?id=3&visid=grade_distribution';
136    
137                            harvest_data();
138                    });
139          }          }
140    
141          /**          /**
# Line 121  Line 144 
144          * TODO: Add a loading bar and more feed back about the loading process.          * TODO: Add a loading bar and more feed back about the loading process.
145          * @param url The url from witch to load the tab formated data for the visualization.          * @param url The url from witch to load the tab formated data for the visualization.
146          */          */
147          public function harvest_data(url:String):void          public function harvest_data():void
148          {          {
149                  var ds:DataSource = new DataSource(url, "tab");                          loadingMessage.text ="Loading Settings....";
150              var loader:URLLoader = ds.load();                          loadingMessage.x = loaderInfo.width/2 - loadingMessage.width/2;
151              loader.addEventListener(Event.COMPLETE, function(evt:Event):void {                          loadingMessage.y = loaderInfo.height/2 - loadingMessage.height/2;
152                  var ds:DataSet = loader.data as DataSet;  
153                  buildVis(Data.fromDataSet(ds));  
154                            try{
155                                    var ds:DataSource = new DataSource(dataURL, "tab");
156                                    var settingsRequest:URLRequest = new URLRequest(settingsURL);
157                                            var settingsLoader:URLLoader = new URLLoader(settingsRequest);
158    
159                              settingsLoader.addEventListener(IOErrorEvent.IO_ERROR, function(evt:IOErrorEvent):void {
160                                    error("Loading", evt.text);
161              });              });
162    
163                              settingsLoader.addEventListener(Event.COMPLETE, function(evt:Event):void {
164                                    try{
165                                            settings = XML(settingsLoader.data);
166                                            loadingMessage.text = "Loading Data....";
167    
168                                            var dataLoader:URLLoader = ds.load();
169    
170                                            dataLoader.addEventListener(IOErrorEvent.IO_ERROR, function(evt:IOErrorEvent):void {
171                                            error("Loading", evt.text);
172                                    });
173    
174                                    dataLoader.addEventListener(Event.COMPLETE, function(evt:Event):void {
175                                            removeChild(addChild(loadingMessage));
176                                            var data:DataSet = dataLoader.data as DataSet;
177                                            buildVis(Data.fromDataSet(data));
178                                    });
179                                    } catch(e:Error) {
180                                            error("", e.message);
181                                    }
182                              });
183                            } catch(e:IOError) {
184                                    error("IO", e.message);
185                            } catch(e:Error) {
186                                    error("", e.message)
187                            }
188                    }
189    
190            private function error(type:String = "", text:String = ""):void {
191                    trace(type + " Error: " + text);
192    
193                    var textfield:TextField = new TextSprite(type + " Error: " + text, new TextFormat("monospace", 12, 0xFF0000, true)).textField;
194                    textfield.wordWrap = true;
195    
196                    addChild(textfield);
197          }          }
198    
199          /**          /**
# Line 199  Line 264 
264              return max;              return max;
265          }          }
266    
267            private function nullify(o:*):* {
268                    if(isnull(o)) {
269                            return null;
270                    } else {
271                            return o;
272                    }
273            }
274    
275            private function isnull(o:*):Boolean {
276                    if(o == null || o.length == 0 || String(o).length == 0) {
277                            return true;
278                    } else {
279                            return false;
280                    }
281            }
282    
283            private function booleanify(o:*):* {
284                    var ob:Object = nullify(o);
285    
286                    if(String(ob).toLocaleLowerCase() == "false") {
287                            return false;
288                    } else if (String(ob).toLocaleLowerCase() == "true") {
289                            return true;
290                    }
291    
292                    return ob;
293            }
294    
295            private function passSettings(theClass:Class, XMLSettings:XMLList, ... args):* {
296                    var params:Array = new Array();
297    
298                    for each(var arg:* in args) {
299                            params.push(arg);
300                    }
301    
302                    for each(var param:* in XMLSettings) {
303                            var cleanParam:* = booleanify(param);
304                            if(cleanParam != null) {
305                                    params.push(cleanParam);
306                            }
307                    }
308    
309                    switch(params.length) {
310                            case 1: return new theClass(params[0]);
311                            case 2: return new theClass(params[0], params[1]);
312                            case 3: return new theClass(params[0], params[1], params[2]);
313                            case 4: return new theClass(params[0], params[1], params[2], params[3]);
314                            case 5: return new theClass(params[0], params[1], params[2], params[3], params[4]);
315                            case 6: return new theClass(params[0], params[1], params[2], params[3], params[4], params[5]);
316                            case 7: return new theClass(params[0], params[1], params[2], params[3], params[4], params[5], params[6]);
317                            case 8: return new theClass(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7]);
318                            case 9: return new theClass(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8]);
319                            case 10: return new theClass(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9]);
320                            default: return new theClass();
321                    }
322            }
323    
324            private function toStringArray(xmllist:XMLList):Object {
325                    if(xmllist.length() > 1) {
326                            var array:Array = new Array;
327    
328                            for each(var element:XML in xmllist) {
329                                    array.push(String(element));
330                            }
331    
332                            return array;
333                    } else {
334                            return String(xmllist);
335                    }
336            }
337    
338            private function toNumberArray(xmllist:XMLList):Object {
339                    if(xmllist.length() > 1) {
340                            var array:Array = new Array;
341    
342                            for each(var element:XML in xmllist) {
343                                    array.push(Number(element));
344                            }
345    
346                            return array;
347                    } else {
348                            return Number(xmllist);
349                    }
350            }
351    
352          /**          /**
353           * Builds the visualization based on the loaded data.           * Builds the visualization based on the loaded data.
354           * Also sets up the legends, buttons and controls.           * Also sets up the legends, buttons and controls.
# Line 206  Line 356 
356           */           */
357          private function buildVis(data:Data):void          private function buildVis(data:Data):void
358          {          {
359                if(!isnull(settings.edge)) {
360                    for each(var edge:XML in settings.edge) {
361                            data.createEdges(toStringArray(edge.sortby), toStringArray(edge.groupby));
362                    }
363                }
364    
365              vis = new Visualization(data);              vis = new Visualization(data);
366              legends = new Sprite();              legends = new Sprite();
367    
# Line 213  Line 369 
369              boxhc.onRollOver = boxRollOver;              boxhc.onRollOver = boxRollOver;
370                          boxhc.onRollOut = boxRollOut;                          boxhc.onRollOut = boxRollOut;
371    
372                          // Set up the encoders and layout                          // Set up the layout
373                          var colorEncoder:ColorEncoder = new ColorEncoder("data.item", Data.NODES, "lineColor", ScaleType.CATEGORIES);                          var layout:Layout = new AxisLayout(settings.layout.xaxis.field, settings.layout.yaxis.field);
374                          var shapeEncoder:ShapeEncoder = new ShapeEncoder("data.group");                          switch(int(settings.layout.type)) {
375                          var al:AxisLayout = new AxisLayout(axisX, axisY);                                  case 1: layout = passSettings(AxisLayout, settings.layout.setting, settings.layout.xaxis.field, settings.layout.yaxis.field);
376                                                    break;
377                          // Add the encoders and layout to the visualization.                                  case 2: layout = passSettings(CircleLayout, settings.layout.setting);
378                          vis.operators.add(al);                                                  break;
379              vis.operators.add(colorEncoder);                                  case 3: layout = passSettings(DendrogramLayout, settings.layout.setting);
380              vis.operators.add(shapeEncoder);                                                  break;
381                                    case 4: layout = passSettings(ForceDirectedLayout, settings.layout.setting);
382                                                    break;
383                                    case 5: layout = passSettings(IndentedTreeLayout, settings.layout.setting);
384                                                    break;
385                                    case 6: layout = passSettings(NodeLinkTreeLayout, settings.layout.setting);
386                                                    break;
387                                    case 7: layout = passSettings(PieLayout, settings.layout.setting);
388                                                    break;
389                                    case 8: layout = passSettings(RadialTreeLayout, settings.layout.setting);
390                                                    break;
391                                    case 9: layout = new RandomLayout();
392                                                    break;
393                                    case 10: layout = passSettings(StackedAreaLayout, settings.layout.setting);
394                                                    break;
395                                    case 11: layout = new TreeMapLayout();
396                                                    break;
397                                    default: layout = passSettings(AxisLayout, settings.layout.setting, settings.layout.xaxis.field, settings.layout.yaxis.field);
398                                                    break;
399                            }
400                            vis.operators.add(layout);
401    
402                            // Set up the encoders
403                            var encoders:Array = new Array(settings.encoder.length);
404                            for each(var encoder:XML in settings.encoder) {
405                                    var e:Encoder;
406    
407                                    switch(int(encoder.type)) {
408                                            case 1: e = passSettings(ColorEncoder, encoder.setting, encoder.datafield);
409                                                            break;
410                                            case 2: e = passSettings(ShapeEncoder, encoder.setting, encoder.datafield);
411                                                            break;
412                                            case 3: e = passSettings(SizeEncoder, encoder.setting, encoder.datafield);
413                                                            break;
414                                            default: e = passSettings(ColorEncoder, encoder.setting, encoder.datafield);
415                                                            break;
416                                    }
417    
418                                    encoders[encoder.id] = e;
419                                    vis.operators.add(e);
420                            }
421    
422              // Set up the layout of the axes.              // Set up the layout of the axes.
423              vis.xyAxes.xAxis.horizontalAnchor = TextSprite.LEFT;              vis.xyAxes.xAxis.horizontalAnchor = TextSprite.LEFT;
# Line 230  Line 426 
426                          vis.xyAxes.xAxis.fixLabelOverlap = false;                          vis.xyAxes.xAxis.fixLabelOverlap = false;
427                          vis.xyAxes.yAxis.fixLabelOverlap = false;                          vis.xyAxes.yAxis.fixLabelOverlap = false;
428    
429                            if(!isnull(settings.layout.yaxis.labelformat)) {
430                                    vis.xyAxes.yAxis.labelFormat = settings.layout.yaxis.labelformat;
431                            } else {
432                                    vis.xyAxes.yAxis.labelFormat = "0";
433                            }
434    
435                            if(!isnull(settings.layout.xaxis.labelformat)) {
436                                    vis.xyAxes.xAxis.labelFormat = settings.layout.xaxis.labelformat;
437                            } else {
438                                    vis.xyAxes.xAxis.labelFormat = "0";
439                            }
440    
441                            if(!isnull(settings.layout.xaxis.min)) {
442                                    vis.xyAxes.xAxis.axisScale.min = settings.layout.xaxis.min;
443                                    vis.xyAxes.xAxis.axisScale.flush = true;
444                            }
445    
446                            if(!isnull(settings.layout.xaxis.max)) {
447                                    vis.xyAxes.xAxis.axisScale.max = settings.layout.xaxis.max;
448                                    vis.xyAxes.xAxis.axisScale.flush = true;
449                            }
450    
451                            if(!isnull(settings.layout.yaxis.min)) {
452                                    vis.xyAxes.yAxis.axisScale.min = settings.layout.yaxis.min;
453                            }
454    
455                            if(!isnull(settings.layout.yaxis.max)) {
456                                    vis.xyAxes.yAxis.axisScale.max = settings.layout.yaxis.max;
457                            }
458    
459                            if(!isnull(settings.layout.yaxis.yoffset)) {
460                                    vis.xyAxes.yAxis.labelOffsetY = settings.layout.yaxis.yoffset;
461                            }
462    
463                            if(!isnull(settings.layout.yaxis.xoffset)) {
464                                    vis.xyAxes.yAxis.labelOffsetX = settings.layout.yaxis.xoffset;
465                            }
466    
467                            if(!isnull(settings.layout.xaxis.yoffset)) {
468                                    vis.xyAxes.xAxis.labelOffsetY = settings.layout.xaxis.yoffset;
469                            }
470    
471                            if(!isnull(settings.layout.xaxis.xoffset)) {
472                                    vis.xyAxes.xAxis.labelOffsetX = settings.layout.xaxis.xoffset;
473                            }
474    
475    
476              // Update the visualization so the widths and other values are correct.              // Update the visualization so the widths and other values are correct.
477              vis.update();              vis.update();
478    
479                          // Initalize the X and Y axis labels and the visualizations title.                          // Initalize the X and Y axis labels and the visualizations title.
480                          var labelX:TextSprite = new TextSprite("Student", new TextFormat("mono", 20));                          var labelX:TextSprite = new TextSprite(settings.labels.xaxis, new TextFormat(settings.style.text.font, settings.style.text.size));
481                          var labelY:TextSprite = new TextSprite("Grade", new TextFormat("mono", 20));                          var labelY:TextSprite = new TextSprite(settings.labels.yaxis, new TextFormat(settings.style.text.font, settings.style.text.size));
482                          var title:TextSprite = new TextSprite("Normalized Grades vs Students", new TextFormat("mono", 25));                          var title:TextSprite = new TextSprite(settings.labels.title, new TextFormat(settings.style.text.font, int(settings.style.text.size) + 5));
483    
484                          // Find the largest width out of the X axis labels so it can used for positing sprites.                          // Find the largest width out of the X axis labels so it can used for positing sprites.
485                  var xLabelsHeight:int = getMaxHeight(vis.xyAxes.xAxis.labels);                  var xLabelsHeight:int = getMaxHeight(vis.xyAxes.xAxis.labels);
# Line 247  Line 490 
490              vis.x = labelY.height + -vis.xyAxes.yAxis.labelOffsetX + yLabelsWidth;              vis.x = labelY.height + -vis.xyAxes.yAxis.labelOffsetX + yLabelsWidth;
491    
492                          // Set up the legends.                          // Set up the legends.
493                          var itemLegend:Legend = new Legend("data.item", colorEncoder.scale, colorEncoder.colors, null, null);                          var nextLegendY:int = 0;
494              var groupLegend:Legend = new Legend("data.group", shapeEncoder.scale, null, shapeEncoder.shapes, null);                          for each(var legend:XML in settings.legend) {
495                                    var en:Encoder = encoders[legend.encoderid];
496                                    var l:Legend;
497    
498                                    switch(int(settings.encoder.(id == int(legend.encoderid)).type)) {
499                                            case 1: l = new Legend(en.source, en.scale, ColorEncoder(en).colors);
500                                                            break;
501                                            case 2: l = new Legend(en.source, en.scale, null, ShapeEncoder(en).shapes);
502                                                            break;
503                                            case 3: l = new Legend(en.source, en.scale, null, null, SizeEncoder(en).sizes);
504                                                            break;
505                                            default: l = new Legend(en.source, en.scale, ColorEncoder(en).colors);
506                                                            break;
507                                    }
508    
509                                    l.x = 0;
510                                    l.y = nextLegendY;
511                                    nextLegendY += l.height;
512    
513                                    l.items.addEventListener(MouseEvent.CLICK, legendClick);
514    
515                                    var lhc:HoverControl = new HoverControl(l.items);
516                    lhc.onRollOver = legendRollOver;
517                                    lhc.onRollOut = legendRollOut;
518    
519                                    legends.addChild(l);
520                            }
521    
522              // Set the bounds of the visualization based on the hieght and width of the flash application,              // Set the bounds of the visualization based on the hieght and width of the flash application,
523              // and the other components so the visualization is takes up the unused space.              // and the other components so the visualization is takes up the unused space.
524              vis.bounds = new Rectangle(0, 0, loaderInfo.width - (max(itemLegend.width, groupLegend.width) + 15 + vis.x), loaderInfo.height - (vis.y + xLabelsHeight + labelX.height + vis.xyAxes.xAxis.labelOffsetY));              vis.bounds = new Rectangle(0, 0, loaderInfo.width - (legends.width + 15 + vis.x), loaderInfo.height - (vis.y + xLabelsHeight + labelX.height + vis.xyAxes.xAxis.labelOffsetY));
525    
526              // Add the visualization to the main sprite.              // Add the visualization to the main sprite.
527              addChild(vis);              addChild(vis);
528    
529              // Set up the properitys of the data sprites and add a eventlistener to check for              // Set up the properitys of the data sprites and add a eventlistener to check for
530              // clicks on them.              // clicks on them.
531              vis.data.visit(function(d:DataSprite):void {              vis.data.nodes.visit(function(d:DataSprite):void {
532                    if(!isnull(settings.style.nodeshape)) {
533                            d.shape = settings.style.nodeshape;
534                    }
535                                  d.fillColor = 0x018888ff;                                  d.fillColor = 0x018888ff;
536                                  d.fillAlpha = 0.2;                                  d.fillAlpha = 0.2;
537                                  d.lineWidth = 2;                                  d.lineWidth = 2;
538                                  d.addEventListener(MouseEvent.CLICK, mouseClicked);                                  d.addEventListener(MouseEvent.CLICK, mouseClicked);
539    
540                            });
541    
542                            vis.data.edges.visit(function(d:DataSprite):void {
543                                    if(!isnull(settings.style.edgeshape)) {
544                                            d.shape = settings.style.edgeshape;
545                                    }
546                                    d.lineWidth = 2;
547                                    d.fillAlpha = 1;
548                          });                          });
549    
550              // Position the legends.              // Position the legends.
551              legends.x = vis.bounds.width + 10;              legends.x = vis.bounds.width + 10;
             itemLegend.x = 0;  
             itemLegend.y = 0;  
             groupLegend.x = 0;  
             groupLegend.y = itemLegend.y + itemLegend.height;  
   
             // Add a listener for mouse clicks on the legends.  
             itemLegend.items.addEventListener(MouseEvent.CLICK, legendClick);  
             groupLegend.items.addEventListener(MouseEvent.CLICK, legendClick);  
   
             // Add the legends to the legends container.  
             legends.addChild(itemLegend);  
             legends.addChild(groupLegend);  
   
             // Set up and add a hover control to each legend.  
             var itemHC:HoverControl = new HoverControl(itemLegend.items);  
             itemHC.onRollOver = legendRollOver;  
                         itemHC.onRollOut = legendRollOut;  
             var groupHC:HoverControl = new HoverControl(groupLegend.items);  
             groupHC.onRollOver = legendRollOver;  
                         groupHC.onRollOut = legendRollOut;  
   
552    
553              // Position and add the labels and title to the axes.              // Position and add the labels and title to the axes.
554                          labelX.x = vis.bounds.width/2 - labelX.width/2;                          labelX.x = vis.bounds.width/2 - labelX.width/2;
555                          labelX.y = vis.bounds.height + vis.xyAxes.xAxis.labelOffsetY + xLabelsHeight;                          labelX.y = vis.bounds.height + vis.xyAxes.xAxis.labelOffsetY + xLabelsHeight;
556              vis.xyAxes.xAxis.addChild(labelX);              vis.xyAxes.xAxis.addChild(labelX);
557    
                         labelY.x = -vis.x;  
                         labelY.y = vis.bounds.height/2 - labelY.width/2;  
558                          labelY.rotation = -90;                          labelY.rotation = -90;
559                            labelY.x = -vis.x;
560                            labelY.y = (vis.bounds.height/2) + (labelY.height/2);
561                          vis.xyAxes.yAxis.addChild(labelY);                          vis.xyAxes.yAxis.addChild(labelY);
562    
563                          title.x = vis.bounds.width/2 - title.width/2;                          title.x = vis.bounds.width/2 - title.width/2;
# Line 314  Line 574 
574    
575                          // Set up the buttons and a container for them.                          // Set up the buttons and a container for them.
576                          var controls:Sprite = new Sprite();                          var controls:Sprite = new Sprite();
577                          var bInvert:Button = new Button("Invert Axes");                          var bInvert:Button = new Button(settings.lang.invertaxes, settings.style.button);
578                          var bHideAxis:Button = new Button("Hide Axes");                          var bHideAxis:Button = new Button(settings.lang.hide + " " + settings.lang.axes, settings.style.button);
579                          var bHideXLabel:Button = new Button("Hide X Labels");                          var bHideXLabel:Button = new Button(settings.lang.hide + " " + settings.lang.xlabels, settings.style.button);
580                          var bHideYLabel:Button = new Button("Hide Y Labels");                          var bHideYLabel:Button = new Button(settings.lang.hide + " " + settings.lang.ylabels, settings.style.button);
581    
582                          var hideXLabelTransitioner:Transitioner = new Transitioner(2);                          var hideXLabelTransitioner:Transitioner = new Transitioner(2);
583                            hideXLabelTransitioner.onEnd = updateMarkVisiblity;
584                            hideXLabelTransitioner.onStart = updateMarkVisiblity;
585    
586                          bHideXLabel.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void {                          bHideXLabel.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void {
587                                  if(!hideXLabelTransitioner.running) {                                  if(!hideXLabelTransitioner.running) {
588                                          hideXLabelTransitioner.reset();                                          hideXLabelTransitioner.reset();
589    
590                                          if(bHideXLabel.text == "Show X Labels") {                                          if(bHideXLabel.text == settings.lang.show + " " +  settings.lang.xlabels) {
591                                                  bHideXLabel.text = "Hide X Labels";                                                  bHideXLabel.text = settings.lang.hide + " " + settings.lang.xlabels;
592                                                  vis.xyAxes.xAxis.showLabels = true;                                                  vis.xyAxes.xAxis.showLabels = true;
593                                                  vis.bounds = new Rectangle(0, 0, loaderInfo.width - (legends.width + 15 + vis.x), loaderInfo.height - (vis.y + xLabelsHeight + labelX.height + vis.xyAxes.xAxis.labelOffsetY));                                                  vis.bounds = new Rectangle(0, 0, loaderInfo.width - (legends.width + 15 + vis.x), loaderInfo.height - (vis.y + xLabelsHeight + labelX.height + vis.xyAxes.xAxis.labelOffsetY));
594                                          } else {                                          } else {
595                                                  bHideXLabel.text = "Show X Labels";                                                  bHideXLabel.text = settings.lang.show + " " +  settings.lang.xlabels;
596                                                  vis.xyAxes.xAxis.showLabels = false;                                                  vis.xyAxes.xAxis.showLabels = false;
597                                                  vis.bounds = new Rectangle(0, 0, loaderInfo.width - (legends.width + 15 + vis.x), loaderInfo.height - (vis.y + labelX.height));                                                  vis.bounds = new Rectangle(0, 0, loaderInfo.width - (legends.width + 15 + vis.x), loaderInfo.height - (vis.y + labelX.height));
598                                          }                                          }
# Line 342  Line 605 
605                          });                          });
606    
607                          var hideYLabelTransitioner:Transitioner = new Transitioner(2);                          var hideYLabelTransitioner:Transitioner = new Transitioner(2);
608                            hideYLabelTransitioner.onEnd = updateMarkVisiblity;
609                            hideYLabelTransitioner.onStart = updateMarkVisiblity;
610    
611                          bHideYLabel.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void {                          bHideYLabel.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void {
612                                  if(!hideYLabelTransitioner.running) {                                  if(!hideYLabelTransitioner.running) {
613                                          var t:Transitioner = new Transitioner(2);                                          var t:Transitioner = new Transitioner(2);
# Line 349  Line 615 
615    
616                                          hideYLabelTransitioner.reset();                                          hideYLabelTransitioner.reset();
617    
618                                          if(bHideYLabel.text == "Show Y Labels") {                                          if(bHideYLabel.text == settings.lang.show + " " +  settings.lang.ylabels) {
619                                                  bHideYLabel.text = "Hide Y Labels";                                                  bHideYLabel.text = settings.lang.hide + " " +  settings.lang.ylabels;
620                                                  vis.xyAxes.yAxis.showLabels = true;                                                  vis.xyAxes.yAxis.showLabels = true;
621                                                  newX = labelY.width + -vis.xyAxes.yAxis.labelOffsetX + yLabelsWidth;                                                  newX = labelY.width + -vis.xyAxes.yAxis.labelOffsetX + yLabelsWidth;
622                                          } else {                                          } else {
623                                                  bHideYLabel.text = "Show Y Labels";                                                  bHideYLabel.text = settings.lang.show + " " +  settings.lang.ylabels;
624                                                  vis.xyAxes.yAxis.showLabels = false;                                                  vis.xyAxes.yAxis.showLabels = false;
625                                                  newX = labelY.width;                                                  newX = labelY.width;
626                                          }                                          }
# Line 398  Line 664 
664                                          var tempText:String = labelX.text;                                          var tempText:String = labelX.text;
665                                          var tempOffset:int = vis.xyAxes.xAxis.labelOffsetX;                                          var tempOffset:int = vis.xyAxes.xAxis.labelOffsetX;
666                                          var tempWidth:uint = vis.bounds.width;                                          var tempWidth:uint = vis.bounds.width;
667                                            var tempLabelFormat:String = vis.xyAxes.xAxis.labelFormat;
668                                          var tempLabels:int = xLabelsHeight;                                          var tempLabels:int = xLabelsHeight;
669                                            var tempScale:Scale = vis.xyAxes.xAxis.axisScale;
670                                            var tempLabelOffsetY:Number = vis.xyAxes.xAxis.labelOffsetY;
671                                            var tempLabelOffsetX:Number = vis.xyAxes.xAxis.labelOffsetX;
672                                          var currentXLabelsHeight:int = getMaxWidth(vis.xyAxes.yAxis.labels);                                          var currentXLabelsHeight:int = getMaxWidth(vis.xyAxes.yAxis.labels);
673    
674                                          var tempShowLabels:Boolean = vis.xyAxes.xAxis.showLabels;                                          var tempShowLabels:Boolean = vis.xyAxes.xAxis.showLabels;
# Line 407  Line 676 
676                                          // Rest the transitioner for a clean transition.                                          // Rest the transitioner for a clean transition.
677                                          updateTransitioner.reset();                                          updateTransitioner.reset();
678    
679                                            vis.xyAxes.xAxis.axisScale = vis.xyAxes.yAxis.axisScale;
680                                            vis.xyAxes.yAxis.axisScale = tempScale;
681                                            vis.xyAxes.yAxis.axisScale.flush = true;
682                                            vis.xyAxes.xAxis.axisScale.flush = true
683    
684                                          // Flip the axis feilds.                                          // Flip the axis feilds.
685                                          al.xField = axisY;                                          if(settings.layout.type == 1) {
686                                          al.yField = axisX;                                                  AxisLayout(layout).xField = settings.layout.yaxis.field;
687                                          axisX = al.xField;                                                  AxisLayout(layout).yField = settings.layout.xaxis.field;
688                                          axisY = al.yField;                                                  settings.layout.xaxis.field = AxisLayout(layout).xField;
689                                                    settings.layout.yaxis.field = AxisLayout(layout).yField;
690    
691                                                    var tempStack:Boolean = AxisLayout(layout).xStacked;
692                                                    AxisLayout(layout).xStacked = AxisLayout(layout).yStacked;
693                                                    AxisLayout(layout).yStacked = tempStack;
694                                            }
695    
696                                            vis.xyAxes.xAxis.labelFormat = vis.xyAxes.yAxis.labelFormat;
697                                            vis.xyAxes.yAxis.labelFormat = tempLabelFormat;
698    
699    
700                                            vis.xyAxes.xAxis.labelOffsetX = vis.xyAxes.yAxis.labelOffsetY * -1;
701                                            vis.xyAxes.yAxis.labelOffsetY = tempLabelOffsetX * -1;
702                                            vis.xyAxes.xAxis.labelOffsetY = vis.xyAxes.yAxis.labelOffsetX * -1;
703                                            vis.xyAxes.yAxis.labelOffsetX = tempLabelOffsetY * -1;
704    
705    
706                                          xLabelsHeight = yLabelsWidth;                                          xLabelsHeight = yLabelsWidth;
707                                          yLabelsWidth = tempLabels;                                          yLabelsWidth = tempLabels;
708    
709    
710                                          vis.xyAxes.xAxis.showLabels = vis.xyAxes.yAxis.showLabels;                                          vis.xyAxes.xAxis.showLabels = vis.xyAxes.yAxis.showLabels;
711                                          vis.xyAxes.yAxis.showLabels = tempShowLabels;                                          vis.xyAxes.yAxis.showLabels = tempShowLabels;
712    
713                                          if(vis.xyAxes.yAxis.showLabels) {                                          if(vis.xyAxes.yAxis.showLabels) {
714                                                  bHideYLabel.text = "Hide Y Labels";                                                  bHideYLabel.text = settings.lang.hide + " " +  settings.lang.ylabels;
715                                          } else {                                          } else {
716                                                  bHideYLabel.text = "Show Y Labels";                                                  bHideYLabel.text = settings.lang.show + " " +  settings.lang.ylabels;
717                                          }                                          }
718    
719                                          if(vis.xyAxes.xAxis.showLabels) {                                          if(vis.xyAxes.xAxis.showLabels) {
720                                                  bHideXLabel.text = "Hide X Labels";                                                  bHideXLabel.text = settings.lang.hide + " " +  settings.lang.xlabels;
721                                          } else {                                          } else {
722                                                  bHideXLabel.text = "Show X Labels";                                                  bHideXLabel.text = settings.lang.show + " " +  settings.lang.xlabels;
723                                          }                                          }
724    
   
725                                          // Flip the labels                                          // Flip the labels
726                                          labelX.text = labelY.text;                                          labelX.text = labelY.text;
727                                          labelY.text = tempText;                                          labelY.text = tempText;
# Line 448  Line 738 
738                                          t.$(labelX).x = vis.bounds.width/2 - labelX.width/2;                                          t.$(labelX).x = vis.bounds.width/2 - labelX.width/2;
739                                          t.$(labelX).y = vis.bounds.height + vis.xyAxes.xAxis.labelOffsetY + currentXLabelsHeight;                                          t.$(labelX).y = vis.bounds.height + vis.xyAxes.xAxis.labelOffsetY + currentXLabelsHeight;
740                                          t.$(labelY).x = -newX;                                          t.$(labelY).x = -newX;
741                                          t.$(labelY).y = vis.bounds.height/2 - labelY.width/2;                                          t.$(labelY).y = vis.bounds.height/2 + labelY.height/2;
742    
743                                          // Keep the legends in there place.                                          // Keep the legends in there place.
744                                          t.$(legends).x = vis.bounds.width + 10;                                          t.$(legends).x = vis.bounds.width + 10;
# Line 470  Line 760 
760                                          hideAxisTrans.reset();                                          hideAxisTrans.reset();
761    
762                                          // Hide or show the axes.                                          // Hide or show the axes.
763                                          if(bHideAxis.text == "Show Axes") {                                          if(bHideAxis.text == settings.lang.show + " " + settings.lang.axes) {
764                                                  hideAxisTrans.$(bHideAxis).text = "Hide Axes";                                                  hideAxisTrans.$(bHideAxis).text = settings.lang.hide + " " + settings.lang.axes;
765                                                  al.showAxes(hideAxisTrans).play();                                                  layout.showAxes(hideAxisTrans).play();
766                                          } else {                                          } else {
767                                                  hideAxisTrans.$(bHideAxis).text = "Show Axes";                                                  hideAxisTrans.$(bHideAxis).text = settings.lang.show + " " + settings.lang.axes;
768                                                  al.hideAxes(hideAxisTrans).play();                                                  layout.hideAxes(hideAxisTrans).play();
769                                          }                                          }
770                                  }                                  }
771                          });                          });
# Line 617  Line 907 
907                  var box:Sprite = new Sprite;                  var box:Sprite = new Sprite;
908    
909                  var backGround:Sprite = new Sprite;                  var backGround:Sprite = new Sprite;
910                  backGround.graphics.beginFill(0x7777ff, 0.60);                  backGround.graphics.beginFill(parseInt(settings.style.popup.bgcolor, 16), settings.style.popup.alpha);
911                  backGround.graphics.lineStyle(3, 0x0000ff, 0.3);                  backGround.graphics.lineStyle(settings.style.popup.line.size, parseInt(settings.style.popup.line.color, 16), settings.style.popup.line.alpha);
912    
913                  var text:Sprite = new Sprite;                  var text:Sprite = new Sprite;
914                  var x:int = 5;                  var x:int = 5;
915                  var y:int = 0;                  var y:int = 0;
916    
917                  for(var property:Object in data.data) {                  for(var property:Object in data.data) {
918                          var temp:TextSprite = new TextSprite(property.toString() + ": " + data.data[property], new TextFormat("mono", 12, null, true));                          var temp:TextSprite = new TextSprite(property.toString() + ": " + data.data[property], new TextFormat(settings.style.popup.text.font, settings.style.popup.text.size, null, true));
919                          temp.x = x;                          temp.x = x;
920                          temp.y = y;                          temp.y = y;
921                          text.addChild(temp);                          text.addChild(temp);
922                          y += temp.height;                          y += temp.height;
923                  }                  }
924    
                 /*var name:TextSprite = new TextSprite(data.data.student, new TextFormat("mono", 20, null, true));  
                 var item:TextSprite = new TextSprite("Item: " + data.data.item, new TextFormat("mono", 12, null, true));  
                 var grade:TextSprite = new TextSprite("Grade: " + data.data.grade + "%", new TextFormat("mono", 12, null, true));  
                 var group:TextSprite = new TextSprite("Group: " + data.data.group, new TextFormat("mono", 12, null, true));  
                 text.addChild(name);  
                 text.addChild(item);  
                 text.addChild(group);  
                 text.addChild(grade);  
   
                 name.x = text.width/2 - name.width/2;  
                 item.x = 5;  
                 grade.x = 5;  
                 group.x = 5;  
   
                 name.y = 0;  
                 item.y = name.y + name.height;  
                 group.y = item.y + item.height;  
                 grade.y = group.y + group.height;*/  
   
925                  backGround.graphics.drawRoundRect(0, 0, text.width + 10, text.height, 30, 30);                  backGround.graphics.drawRoundRect(0, 0, text.width + 10, text.height, 30, 30);
926    
927                  box.addChild(backGround);                  box.addChild(backGround);
# Line 741  Line 1012 
1012                  }                  }
1013    
1014                  updateMarkVisiblity(item);                  updateMarkVisiblity(item);
1015                    vis.update();
1016          }          }
1017    
1018          /**          /**

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

Moodle CVS Admin
ViewVC Help
Powered by ViewVC 1.0.7