AxisLabel.as 1.5 KB

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