Arrow.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // wrapped by build app
  2. define("dojox/drawing/annotations/Arrow", ["dijit","dojo","dojox","dojo/require!dojox/drawing/stencil/Path"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.annotations.Arrow");
  4. dojo.require("dojox.drawing.stencil.Path");
  5. dojox.drawing.annotations.Arrow = dojox.drawing.util.oo.declare(
  6. // summary:
  7. // An annotation called internally to put an arrowhead
  8. // on ether end of a Line. Initiated in Arrow (and Vector)
  9. // with the optional params: arrowStart and arrowEnd. Both
  10. // default true for Axes.
  11. //
  12. dojox.drawing.stencil.Path,
  13. function(/* dojox.__stencilArgs */options){
  14. // arguments: See stencil._Base
  15. this.stencil.connectMult([
  16. [this.stencil, "select", this, "select"],
  17. [this.stencil, "deselect", this, "deselect"],
  18. [this.stencil, "render", this, "render"],
  19. [this.stencil, "onDelete", this, "destroy"]
  20. ]);
  21. this.connect("onBeforeRender", this, function(){
  22. var o = this.stencil.points[this.idx1];
  23. var c = this.stencil.points[this.idx2];
  24. if(this.stencil.getRadius() >= this.minimumSize){
  25. this.points = this.arrowHead(c.x, c.y, o.x, o.y, this.style);
  26. }else{
  27. this.points = [];
  28. }
  29. });
  30. },
  31. {
  32. idx1:0,
  33. idx2:1,
  34. subShape:true,
  35. minimumSize:30,
  36. //annotation:true, NOT!
  37. arrowHead: function(x1, y1, x2, y2, style){
  38. // summary:
  39. // Creates data used to draw arrow head.
  40. //
  41. var obj = {
  42. start:{
  43. x:x1,
  44. y:y1
  45. },
  46. x:x2,
  47. y:y2
  48. }
  49. var angle = this.util.angle(obj);
  50. var lineLength = this.util.length(obj);
  51. var al = style.arrows.length;
  52. var aw = style.arrows.width/2;
  53. if(lineLength<al){
  54. al = lineLength/2;
  55. }
  56. var p1 = this.util.pointOnCircle(x2, y2, -al, angle-aw);
  57. var p2 = this.util.pointOnCircle(x2, y2, -al, angle+aw);
  58. return [
  59. {x:x2, y:y2},
  60. p1,
  61. p2
  62. ];
  63. }
  64. }
  65. );
  66. });