Line.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.stencil.Line"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.drawing.stencil.Line"] = true;
  8. dojo.provide("dojox.drawing.stencil.Line");
  9. dojox.drawing.stencil.Line = dojox.drawing.util.oo.declare(
  10. // summary:
  11. // Creates a dojox.gfx Line based on data or points provided.
  12. //
  13. dojox.drawing.stencil._Base,
  14. function(options){
  15. // summary:
  16. // constructor
  17. },
  18. {
  19. type:"dojox.drawing.stencil.Line",
  20. anchorType: "single",
  21. baseRender:true,
  22. /*=====
  23. StencilData: {
  24. // summary:
  25. // The data used to create the dojox.gfx Shape
  26. // x1: Number
  27. // First point x
  28. // y1: Number
  29. // First point y
  30. // x2: Number
  31. // Second point x
  32. // y2: Number
  33. // Second point y
  34. // ALTERNATIVE:
  35. // x: Number
  36. // First point x
  37. // y: Number
  38. // First point y
  39. // angle: Number
  40. // angle of line
  41. // radius: Number
  42. // length of line
  43. },
  44. StencilPoints: [
  45. // summary:
  46. // An Array of dojox.__StencilPoint objects that describe the Stencil
  47. // 0: Object
  48. // First point
  49. // 1: Object
  50. // Second point
  51. ],
  52. =====*/
  53. dataToPoints: function(o){
  54. //summary:
  55. // Converts data to points.
  56. o = o || this.data;
  57. if(o.radius || o.angle){
  58. // instead of using x1,x2,y1,y1,
  59. // it's been set as x,y,angle,radius
  60. var pt = this.util.pointOnCircle(o.x,o.y,o.radius,o.angle);
  61. //console.log(" ---- pts:", pt.x, pt.y);
  62. this.data = o = {
  63. x1:o.x,
  64. y1:o.y,
  65. x2:pt.x,
  66. y2:pt.y
  67. }
  68. }
  69. this.points = [
  70. {x:o.x1, y:o.y1},
  71. {x:o.x2, y:o.y2}
  72. ];
  73. return this.points;
  74. },
  75. pointsToData: function(p){
  76. // summary:
  77. // Converts points to data
  78. p = p || this.points;
  79. this.data = {
  80. x1: p[0].x,
  81. y1: p[0].y,
  82. x2: p[1].x,
  83. y2: p[1].y
  84. };
  85. return this.data;
  86. },
  87. _create: function(/*String*/shp, /*StencilData*/d, /*Object*/sty){
  88. // summary:
  89. // Creates a dojox.gfx.shape based on passed arguments.
  90. // Can be called many times by implementation to create
  91. // multiple shapes in one stencil.
  92. //
  93. this.remove(this[shp]);
  94. this[shp] = this.container.createLine(d)
  95. .setStroke(sty);
  96. this._setNodeAtts(this[shp]);
  97. },
  98. render: function(){
  99. // summary:
  100. // Renders the 'hit' object (the shape used for an expanded
  101. // hit area and for highlighting) and the'shape' (the actual
  102. // display object).
  103. //
  104. this.onBeforeRender(this);
  105. this.renderHit && this._create("hit", this.data, this.style.currentHit);
  106. this._create("shape", this.data, this.style.current);
  107. }
  108. }
  109. );
  110. dojox.drawing.register({
  111. name:"dojox.drawing.stencil.Line"
  112. }, "stencil");
  113. }