[7849] | 1 | package elements.axis {
|
---|
| 2 | import flash.text.TextField;
|
---|
| 3 | import flash.display.Sprite;
|
---|
| 4 | import flash.text.TextFormat;
|
---|
| 5 | import string.Utils;
|
---|
| 6 |
|
---|
| 7 | public class RadarAxisLabels extends Sprite{
|
---|
| 8 |
|
---|
| 9 | private var style:Object;
|
---|
| 10 | public var labels:Array;
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | public function RadarAxisLabels( json:Object ) {
|
---|
| 14 |
|
---|
| 15 | // default values
|
---|
| 16 | this.style = {
|
---|
| 17 | colour: '#784016',
|
---|
| 18 | steps: 1
|
---|
| 19 | };
|
---|
| 20 |
|
---|
| 21 | if( json != null )
|
---|
| 22 | object_helper.merge_2( json, this.style );
|
---|
| 23 |
|
---|
| 24 | this.style.colour = Utils.get_colour( this.style.colour );
|
---|
| 25 |
|
---|
| 26 | // cache the text for tooltips
|
---|
| 27 | this.labels = new Array();
|
---|
| 28 | var values:Array;
|
---|
| 29 | var ok:Boolean = false;
|
---|
| 30 |
|
---|
| 31 | if( ( this.style.labels is Array ) && ( this.style.labels.length > 0 ) )
|
---|
| 32 | {
|
---|
| 33 |
|
---|
| 34 | for each( var s:Object in this.style.labels )
|
---|
| 35 | this.add( s, this.style );
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public function add( label:Object, style:Object ) : void
|
---|
| 41 | {
|
---|
| 42 | var label_style:Object = {
|
---|
| 43 | colour: style.colour,
|
---|
| 44 | text: '',
|
---|
| 45 | size: style.size,
|
---|
| 46 | visible: true
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | if( label is String )
|
---|
| 50 | label_style.text = label as String;
|
---|
| 51 | else {
|
---|
| 52 | object_helper.merge_2( label, label_style );
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | // our parent colour is a number, but
|
---|
| 56 | // we may have our own colour:
|
---|
| 57 | if( label_style.colour is String )
|
---|
| 58 | label_style.colour = Utils.get_colour( label_style.colour );
|
---|
| 59 |
|
---|
| 60 | this.labels.push( label_style.text );
|
---|
| 61 |
|
---|
| 62 | //
|
---|
| 63 | // inheriting the 'visible' attribute
|
---|
| 64 | // is complext due to the 'steps' value
|
---|
| 65 | // only some labels will be visible
|
---|
| 66 | //
|
---|
| 67 | if( label_style.visible == null )
|
---|
| 68 | {
|
---|
| 69 | //
|
---|
| 70 | // some labels will be invisible due to our parents step value
|
---|
| 71 | //
|
---|
| 72 | if ( ( (this.labels.length - 1) % style.steps ) == 0 )
|
---|
| 73 | label_style.visible = true;
|
---|
| 74 | else
|
---|
| 75 | label_style.visible = false;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | var l:TextField = this.make_label( label_style );
|
---|
| 79 | this.addChild( l );
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | public function make_label( label_style:Object ):TextField {
|
---|
| 83 |
|
---|
| 84 | // we create the text in its own movie clip
|
---|
| 85 |
|
---|
| 86 | var tf:TextField = new TextField();
|
---|
| 87 | tf.x = 0;
|
---|
| 88 | tf.y = 0;
|
---|
| 89 | tf.text = label_style.text;
|
---|
| 90 |
|
---|
| 91 | var fmt:TextFormat = new TextFormat();
|
---|
| 92 | fmt.color = label_style.colour;
|
---|
| 93 | fmt.font = "Verdana";
|
---|
| 94 | fmt.size = label_style.size;
|
---|
| 95 | fmt.align = "right";
|
---|
| 96 | tf.setTextFormat(fmt);
|
---|
| 97 |
|
---|
| 98 | tf.autoSize = "left";
|
---|
| 99 | tf.visible = label_style.visible;
|
---|
| 100 | return tf;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | // move y axis labels to the correct x pos
|
---|
| 104 | public function resize( sc:ScreenCoordsRadar ):void {
|
---|
| 105 |
|
---|
| 106 | var i:Number;
|
---|
| 107 | var tf:TextField;
|
---|
| 108 | var center:Number = sc.get_center_x();
|
---|
| 109 |
|
---|
| 110 | for( i=0; i<this.numChildren; i++ ) {
|
---|
| 111 | // right align
|
---|
| 112 | tf = this.getChildAt(i) as TextField;
|
---|
| 113 | tf.x = center - tf.width;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | // now move it to the correct Y, vertical center align
|
---|
| 117 | for ( i = 0; i < this.numChildren; i++ ) {
|
---|
| 118 |
|
---|
| 119 | tf = this.getChildAt(i) as TextField;
|
---|
| 120 | tf.y = ( sc.get_y_from_val( i, false ) - (tf.height / 2) );
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | public function die(): void {
|
---|
| 125 |
|
---|
| 126 | this.style = null;
|
---|
| 127 | this.labels = null;
|
---|
| 128 |
|
---|
| 129 | this.graphics.clear();
|
---|
| 130 | while ( this.numChildren > 0 )
|
---|
| 131 | this.removeChildAt(0);
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 | }
|
---|