Rect.js 2.3 KB

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