Angle.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // wrapped by build app
  2. define("dojox/drawing/annotations/Angle", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.annotations.Angle");
  4. dojox.drawing.annotations.Angle = dojox.drawing.util.oo.declare(
  5. // summary:
  6. // When initiated, an HTML box will hover near the Stencil,
  7. // displaying it's angle while drawn or modified. Currently
  8. // only works with Vector, Line, Arrow, and Axes.
  9. // description:
  10. // Annotation is positioned with dojox.drawing.util.positioning.angle
  11. // That method should be overwritten for custom placement.
  12. // Called internally. To initiaize:
  13. // TODO: currently always on
  14. //
  15. function(/*Object*/options){
  16. // arguments:
  17. // options: Object
  18. // One key value: the stencil that called this.
  19. //
  20. this.stencil = options.stencil;
  21. this.util = options.stencil.util;
  22. this.mouse = options.stencil.mouse;
  23. this.stencil.connectMult([
  24. ["onDrag", this, "showAngle"],
  25. ["onUp", this, "hideAngle"],
  26. ["onTransformBegin", this, "showAngle"],
  27. ["onTransform", this, "showAngle"],
  28. ["onTransformEnd", this, "hideAngle"]
  29. ]);
  30. },
  31. {
  32. type:"dojox.drawing.tools.custom",
  33. angle:0,
  34. showAngle: function(){
  35. // summary:
  36. // Called to display angle
  37. //
  38. if(!this.stencil.selected && this.stencil.created){ return; }
  39. if(this.stencil.getRadius() < this.stencil.minimumSize){
  40. this.hideAngle();
  41. return;
  42. }
  43. var node = this.getAngleNode();
  44. var d = this.stencil.pointsToData();
  45. var pt = dojox.drawing.util.positioning.angle({x:d.x1,y:d.y1},{x:d.x2,y:d.y2});
  46. var sc = this.mouse.scrollOffset();
  47. var mx = this.stencil.getTransform();
  48. var dx = mx.dx / this.mouse.zoom;
  49. var dy = mx.dy / this.mouse.zoom;
  50. pt.x /= this.mouse.zoom;
  51. pt.y /= this.mouse.zoom;
  52. // adding _offX & _offY since this is HTML
  53. // and we are from the page corner, not
  54. // the canvas corner
  55. var x = this.stencil._offX + pt.x - sc.left + dx;
  56. var y = this.stencil._offY + pt.y - sc.top + dy;
  57. dojo.style(node, {
  58. left: x + "px",
  59. top: y + "px",
  60. align:pt.align
  61. });
  62. var angle=this.stencil.getAngle();
  63. if(this.stencil.style.zAxis && this.stencil.shortType=="vector"){
  64. node.innerHTML = this.stencil.data.cosphi > 0 ? "out of" : "into";
  65. }else if(this.stencil.shortType=="line"){
  66. node.innerHTML = this.stencil.style.zAxis?"out of":Math.ceil(angle%180);
  67. }else{
  68. node.innerHTML = Math.ceil(angle);
  69. }
  70. },
  71. getAngleNode: function(){
  72. // summary:
  73. // Gets or creates HTMLNode used for display
  74. if(!this._angleNode){
  75. this._angleNode = dojo.create("span", null, dojo.body());
  76. dojo.addClass(this._angleNode, "textAnnotation");
  77. dojo.style(this._angleNode, "opacity", 1);
  78. }
  79. return this._angleNode; //HTMLNode
  80. },
  81. hideAngle: function(){
  82. // summary:
  83. // Turns display off.
  84. //
  85. if(this._angleNode && dojo.style(this._angleNode, "opacity")>0.9){
  86. dojo.fadeOut({node:this._angleNode,
  87. duration:500,
  88. onEnd: function(node){
  89. dojo.destroy(node);
  90. }
  91. }).play();
  92. this._angleNode = null;
  93. }
  94. }
  95. }
  96. );
  97. });