Arrow.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // wrapped by build app
  2. define("dojox/drawing/tools/Arrow", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.tools.Arrow");
  4. dojox.drawing.tools.Arrow = dojox.drawing.util.oo.declare(
  5. // summary:
  6. // Extends stencil.Line and adds an arrow head
  7. // to the end and or start.
  8. //
  9. dojox.drawing.tools.Line,
  10. function(options){
  11. // summary: constructor
  12. if(this.arrowStart){
  13. this.begArrow = new dojox.drawing.annotations.Arrow({stencil:this, idx1:0, idx2:1});
  14. }
  15. if(this.arrowEnd){
  16. this.endArrow = new dojox.drawing.annotations.Arrow({stencil:this, idx1:1, idx2:0});
  17. }
  18. if(this.points.length){
  19. // This is protecting against cases when there are no points
  20. // not sure how that would ever happen
  21. // Render & label here instead of in base because of Arrow annotation
  22. this.render();
  23. options.label && this.setLabel(options.label);
  24. }
  25. },
  26. {
  27. draws:true,
  28. type:"dojox.drawing.tools.Arrow",
  29. baseRender:false,
  30. // arrowStart: Boolean
  31. // Whether or not to place an arrow on start.
  32. arrowStart:false,
  33. //
  34. // arrowEnd: Boolean
  35. // Whether or not to place an arrow on end.
  36. arrowEnd:true,
  37. labelPosition: function(){
  38. // summary:
  39. // The custom position used for the label
  40. //
  41. var d = this.data;
  42. var pt = dojox.drawing.util.positioning.label({x:d.x1,y:d.y1},{x:d.x2,y:d.y2});
  43. return {
  44. x:pt.x,
  45. y:pt.y
  46. }
  47. },
  48. onUp: function(/*EventObject*/obj){
  49. // summary: See stencil._Base.onUp
  50. //
  51. if(this.created || !this.shape){ return; }
  52. // if too small, need to reset
  53. var p = this.points;
  54. var len = this.util.distance(p[0].x,p[0].y,p[1].x,p[1].y);
  55. if(len<this.minimumSize){
  56. this.remove(this.shape, this.hit);
  57. return;
  58. }
  59. var pt = this.util.snapAngle(obj, this.angleSnap/180);
  60. this.setPoints([
  61. {x:p[0].x, y:p[0].y},
  62. {x:pt.x, y:pt.y}
  63. ]);
  64. this.renderedOnce = true;
  65. this.onRender(this);
  66. }
  67. }
  68. );
  69. dojox.drawing.tools.Arrow.setup = {
  70. // summary: See stencil._Base ToolsSetup
  71. //
  72. name:"dojox.drawing.tools.Arrow",
  73. tooltip:"Arrow Tool",
  74. iconClass:"iconArrow"
  75. };
  76. dojox.drawing.register(dojox.drawing.tools.Arrow.setup, "tool");
  77. });