| 1 | /* */
|
|---|
| 2 |
|
|---|
| 3 | package elements.axis {
|
|---|
| 4 |
|
|---|
| 5 | import flash.display.Sprite;
|
|---|
| 6 | import flash.text.TextField;
|
|---|
| 7 | import flash.geom.Rectangle;
|
|---|
| 8 |
|
|---|
| 9 | public class AxisLabel extends TextField {
|
|---|
| 10 | public var xAdj:Number = 0;
|
|---|
| 11 | public var yAdj:Number = 0;
|
|---|
| 12 | public var leftOverhang:Number = 0;
|
|---|
| 13 | public var rightOverhang:Number = 0;
|
|---|
| 14 | public var xVal:Number = NaN;
|
|---|
| 15 | public var yVal:Number = NaN;
|
|---|
| 16 |
|
|---|
| 17 | public function AxisLabel() {}
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * Rotate the label and align it to the X Axis tick
|
|---|
| 21 | *
|
|---|
| 22 | * @param rotation
|
|---|
| 23 | */
|
|---|
| 24 | public function rotate_and_align( rotation:Number, align:String, parent:Sprite ): void
|
|---|
| 25 | {
|
|---|
| 26 | rotation = rotation % 360;
|
|---|
| 27 | if (rotation < 0) rotation += 360;
|
|---|
| 28 |
|
|---|
| 29 | var myright:Number = this.width * Math.cos(rotation * Math.PI / 180);
|
|---|
| 30 | var myleft:Number = this.height * Math.cos((90 - rotation) * Math.PI / 180);
|
|---|
| 31 | var mytop:Number = this.height * Math.sin((90 - rotation) * Math.PI / 180);
|
|---|
| 32 | var mybottom:Number = this.width * Math.sin(rotation * Math.PI / 180);
|
|---|
| 33 |
|
|---|
| 34 | if (((rotation % 90) == 0) || (align == "center"))
|
|---|
| 35 | {
|
|---|
| 36 | this.xAdj = (myleft - myright) / 2;
|
|---|
| 37 | }
|
|---|
| 38 | else
|
|---|
| 39 | {
|
|---|
| 40 | this.xAdj = (rotation < 180) ? myleft / 2 : -myright + (myleft / 2);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | if (rotation > 90) {
|
|---|
| 44 | this.yAdj = -mytop;
|
|---|
| 45 | }
|
|---|
| 46 | if (rotation > 180) {
|
|---|
| 47 | this.yAdj = -mytop - mybottom;
|
|---|
| 48 | }
|
|---|
| 49 | if (rotation > 270) {
|
|---|
| 50 | this.yAdj = - mybottom;
|
|---|
| 51 | }
|
|---|
| 52 | this.rotation = rotation;
|
|---|
| 53 |
|
|---|
| 54 | var titleRect:Rectangle = this.getBounds(parent);
|
|---|
| 55 | this.leftOverhang = Math.abs(titleRect.x + this.xAdj);
|
|---|
| 56 | this.rightOverhang = Math.abs(titleRect.x + titleRect.width + this.xAdj);
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|