<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:twaver="http://www.servasoftware.com/2009/twaver/flex" paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom="0" creationComplete="init();">
<mx:Script> <![CDATA[ import mx.collections.*;
import twaver.*;
[Bindable] private var memoryUsages:ArrayCollection = new ArrayCollection(); [Bindable] private var timeUsages:ArrayCollection = new ArrayCollection();
private var box:ElementBox = null; private var currentStep:int = 0;
private function init():void{ box = network.elementBox; }
private function test():void{ currentStep++; var nodeCount:int = int(txtNodeCount.text) * currentStep; var linkCount:int = this.withLink.selected ? nodeCount/5 : 0; var result:Object = loadNode(box, nodeCount, linkCount, withImage.selected, 1000, 1000); var item:Object = new Object(); item.Count = nodeCount; item.Memory = result[1]; memoryUsages.addItem(item);
item = new Object(); item.Count = nodeCount; item.Time = result[0]; timeUsages.addItem(item);
trace(numberFormatter.format(result[0]) + 'ms,' + numberFormatter.format(result[1]) + 'KB'); }
private function reset():void{ box.clear(); System.gc(); }
private static function loadNode(box:ElementBox, nodeCount:int, linkCount:int, useIcon:Boolean, xLimit:int, yLimit:int):Object{ Styles.setStyle(Styles.CONTENT_TYPE, useIcon ? Consts.CONTENT_TYPE_DEFAULT : Consts.CONTENT_TYPE_VECTOR); Styles.setStyle(Styles.VECTOR_SHAPE, Consts.SHAPE_CIRCLE); Styles.setStyle(Styles.VECTOR_FILL, true); Styles.setStyle(Styles.VECTOR_FILL_COLOR, 0x00FF00); Styles.setStyle(Styles.VECTOR_OUTLINE_WIDTH, 1); Styles.setStyle(Styles.VECTOR_OUTLINE_COLOR, 0xFFFFFF); Styles.setStyle(Styles.VECTOR_GRADIENT, Consts.GRADIENT_RADIAL_NORTHWEST);
var memoryUsage:int = System.totalMemory / 1024; var time:Number = new Date().getTime(); for (var nodeIndex:int = 0; nodeIndex < nodeCount; nodeIndex++) { var node:Node = new Node(); if (!useIcon) { node.setSize(12, 12); }
node.setLocation(Utils.randomInt(xLimit), Utils.randomInt(yLimit)); box.add(node); }
var allNodes:ICollection = box.datas; var links:Collection = new Collection(); for (var linkIndex:int = 0; linkIndex < linkCount; linkIndex++) { var node1:Node = allNodes.getItemAt(Utils.randomInt(nodeCount)); var node2:Node = allNodes.getItemAt(Utils.randomInt(nodeCount));
var link:Link = new Link(node1, node2); link.setStyle(Styles.LINK_WIDTH, 0); link.setStyle(Styles.LINK_COLOR, 0xFFFF00); link.setStyle(Styles.OUTER_WIDTH, 0); link.setStyle(Styles.OUTER_COLOR, 0xFFFFFF); links.addItem(link); } links.forEach(function(link:Link):void{box.add(link);}); return [new Date().getTime() - time, System.totalMemory / 1024 - memoryUsage]; } ]]> </mx:Script>
<mx:NumberFormatter id="numberFormatter"/>
<mx:Stroke id = "s1" color="blue" weight="2"/> <mx:Stroke id = "s2" color="red" weight="2"/>
<mx:VBox width="100%" height="100%" verticalGap="0" horizontalGap="0"> <mx:HBox id="toolbar" top="0" left="0" horizontalGap="0"> <mx:Label id="totalMemory" text="{'Memory:' + numberFormatter.format(System.totalMemory / 1024) + 'KB'}" render="totalMemory.text = 'Memory:' + numberFormatter.format(System.totalMemory / 1024) + 'KB'"/>
<mx:Label text="Node Count:"/> <mx:TextInput id="txtNodeCount" width="50" text="500"/>
<mx:Label text="With Image:"/> <mx:CheckBox id="withImage" selected="true"/>
<mx:Label text="With Link:"/> <mx:CheckBox id="withLink"/>
<mx:Button id="btnClear" label="Reset" click="reset()"/>
<mx:Button id="btnTest" label="Start Test" click="test()"/> </mx:HBox>
<mx:HBox width="100%" height="90%" verticalGap="0" horizontalGap="0"> <twaver:Network id="network" width="50%" height="100%"/>
<mx:VBox width="50%" height="100%" verticalGap="0" horizontalGap="0"> <mx:LineChart id="memoryChart" height="50%" width="100%" paddingLeft="0" paddingRight="10" showDataTips="true" dataProvider="{memoryUsages}">
<mx:horizontalAxis> <mx:CategoryAxis categoryField="Count" title="Memory Usage (KB)"/> </mx:horizontalAxis>
<mx:series> <mx:LineSeries yField="Memory" form="curve" displayName="Memory Usage (KB)" lineStroke="{s1}"/> </mx:series> </mx:LineChart>
<mx:LineChart id="timeChart" height="50%" width="100%" paddingLeft="0" paddingRight="10" showDataTips="true" dataProvider="{timeUsages}">
<mx:horizontalAxis> <mx:CategoryAxis categoryField="Count" title="Time Usage (ms)"/> </mx:horizontalAxis>
<mx:series> <mx:LineSeries yField="Time" form="curve" displayName="Time Usage (ms)" lineStroke="{s2}"/> </mx:series> </mx:LineChart> </mx:VBox> </mx:HBox> </mx:VBox>
</mx:Application> |