Rect.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // wrapped by build app
  2. define("dojox/drawing/stencil/Rect", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.stencil.Rect");
  4. dojox.drawing.stencil.Rect = dojox.drawing.util.oo.declare(
  5. // summary:
  6. // Creates a dojox.gfx rectangle based on data or points provided.
  7. //
  8. dojox.drawing.stencil._Base,
  9. function(options){
  10. // summary:
  11. // constructor
  12. if(this.points.length){
  13. //this.render();
  14. }
  15. },
  16. {
  17. type:"dojox.drawing.stencil.Rect",
  18. anchorType: "group",
  19. baseRender:true,
  20. dataToPoints: function(/*Object*/d){
  21. //summary:
  22. // Converts data to points.
  23. d = d || this.data;
  24. this.points = [
  25. {x:d.x, y:d.y}, // TL
  26. {x:d.x + d.width, y:d.y}, // TR
  27. {x:d.x + d.width, y:d.y + d.height}, // BR
  28. {x:d.x, y:d.y + d.height} // BL
  29. ];
  30. return this.points;
  31. },
  32. pointsToData: function(/*Array*/p){
  33. // summary:
  34. // Converts points to data
  35. p = p || this.points;
  36. var s = p[0];
  37. var e = p[2];
  38. this.data = {
  39. x: s.x,
  40. y: s.y,
  41. width: e.x-s.x,
  42. height: e.y-s.y,
  43. r:this.data.r || 0
  44. };
  45. return this.data;
  46. },
  47. _create: function(/*String*/shp, /*StencilData*/d, /*Object*/sty){
  48. // summary:
  49. // Creates a dojox.gfx.shape based on passed arguments.
  50. // Can be called many times by implementation to create
  51. // multiple shapes in one stencil.
  52. //
  53. //console.log("render rect", d)
  54. //console.log("rect sty:", sty)
  55. this.remove(this[shp]);
  56. this[shp] = this.container.createRect(d)
  57. .setStroke(sty)
  58. .setFill(sty.fill);
  59. this._setNodeAtts(this[shp]);
  60. },
  61. render: function(){
  62. // summary:
  63. // Renders the 'hit' object (the shape used for an expanded
  64. // hit area and for highlighting) and the'shape' (the actual
  65. // display object).
  66. //
  67. this.onBeforeRender(this);
  68. this.renderHit && this._create("hit", this.data, this.style.currentHit);
  69. this._create("shape", this.data, this.style.current);
  70. }
  71. }
  72. );
  73. dojox.drawing.register({
  74. name:"dojox.drawing.stencil.Rect"
  75. }, "stencil");
  76. });