Arrow.js 2.0 KB

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