[7849] | 1 | package elements.labels {
|
---|
| 2 | import charts.Base;
|
---|
| 3 | import charts.ObjectCollection;
|
---|
| 4 | import flash.display.Sprite;
|
---|
| 5 | import flash.text.TextField;
|
---|
| 6 | import flash.text.TextFormat;
|
---|
| 7 | import org.flashdevelop.utils.FlashConnect;
|
---|
| 8 |
|
---|
| 9 | public class Keys extends Sprite {
|
---|
| 10 | private var _height:Number = 0;
|
---|
| 11 | private var count:Number = 0;
|
---|
| 12 | public var colours:Array;
|
---|
| 13 |
|
---|
| 14 | public function Keys( stuff:ObjectCollection )
|
---|
| 15 | {
|
---|
| 16 | this.colours = new Array();
|
---|
| 17 |
|
---|
| 18 | var key:Number = 0;
|
---|
| 19 | for each( var b:Base in stuff.sets )
|
---|
| 20 | {
|
---|
| 21 | for each( var o:Object in b.get_keys() ) {
|
---|
| 22 |
|
---|
| 23 | this.make_key( o.text, o['font-size'], o.colour );
|
---|
| 24 | this.colours.push( o.colour );
|
---|
| 25 | key++;
|
---|
| 26 |
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | this.count = key;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | // each key is a MovieClip with text on it
|
---|
| 34 | private function make_key( text:String, font_size:Number, colour:Number ) : void
|
---|
| 35 | {
|
---|
| 36 |
|
---|
| 37 | var tf:TextField = new TextField();
|
---|
| 38 |
|
---|
| 39 | tf.text = text;
|
---|
| 40 | var fmt:TextFormat = new TextFormat();
|
---|
| 41 | fmt.color = colour;
|
---|
| 42 | fmt.font = "Verdana";
|
---|
| 43 | fmt.size = font_size;
|
---|
| 44 | fmt.align = "left";
|
---|
| 45 |
|
---|
| 46 | tf.setTextFormat(fmt);
|
---|
| 47 | tf.autoSize="left";
|
---|
| 48 |
|
---|
| 49 | this.addChild(tf);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | //
|
---|
| 53 | // draw the colour block for the data set
|
---|
| 54 | //
|
---|
| 55 | private function draw_line( x:Number, y:Number, height:Number, colour:Number ):Number {
|
---|
| 56 | y += (height / 2);
|
---|
| 57 | this.graphics.beginFill( colour, 100 );
|
---|
| 58 | this.graphics.drawRect( x, y - 1, 10, 2 );
|
---|
| 59 | this.graphics.endFill();
|
---|
| 60 | return x+12;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | // shuffle the keys into place, keeping note of the total
|
---|
| 64 | // height the key block has taken up
|
---|
| 65 | public function resize( x:Number, y:Number ):void {
|
---|
| 66 | if( this.count == 0 )
|
---|
| 67 | return;
|
---|
| 68 |
|
---|
| 69 | this.x = x;
|
---|
| 70 | this.y = y;
|
---|
| 71 |
|
---|
| 72 | var height:Number = 0;
|
---|
| 73 | var x:Number = 0;
|
---|
| 74 | var y:Number = 0;
|
---|
| 75 |
|
---|
| 76 | this.graphics.clear();
|
---|
| 77 |
|
---|
| 78 | for( var i:Number=0; i<this.numChildren; i++ )
|
---|
| 79 | {
|
---|
| 80 | var width:Number = this.getChildAt(i).width;
|
---|
| 81 |
|
---|
| 82 | if( ( this.x + x + width + 12 ) > this.stage.stageWidth )
|
---|
| 83 | {
|
---|
| 84 | // it is past the edge of the stage, so move it down a line
|
---|
| 85 | x = 0;
|
---|
| 86 | y += this.getChildAt(i).height;
|
---|
| 87 | height += this.getChildAt(i).height;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | this.draw_line( x, y, this.getChildAt(i).height, this.colours[i] );
|
---|
| 91 | x += 12;
|
---|
| 92 |
|
---|
| 93 | this.getChildAt(i).x = x;
|
---|
| 94 | this.getChildAt(i).y = y;
|
---|
| 95 |
|
---|
| 96 | // move next key to the left + some padding between keys
|
---|
| 97 | x += width + 10;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | // Ugly code:
|
---|
| 101 | height += this.getChildAt(0).height;
|
---|
| 102 | this._height = height;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public function get_height() : Number {
|
---|
| 106 | return this._height;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | public function die(): void {
|
---|
| 110 |
|
---|
| 111 | this.colours = null;
|
---|
| 112 |
|
---|
| 113 | this.graphics.clear();
|
---|
| 114 | while ( this.numChildren > 0 )
|
---|
| 115 | this.removeChildAt(0);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | }
|
---|
| 119 | }
|
---|