Line.js 2.5 KB

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