Iconize.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // wrapped by build app
  2. define("dojox/drawing/plugins/tools/Iconize", ["dijit","dojo","dojox","dojo/require!dojox/drawing/plugins/_Plugin"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.plugins.tools.Iconize");
  4. dojo.require("dojox.drawing.plugins._Plugin");
  5. dojox.drawing.plugins.tools.Iconize = dojox.drawing.util.oo.declare(
  6. // summary:
  7. // Somewhat of internal use...
  8. // Outputs a path to be used as an icon. Will end up being a
  9. // sub-icon under Export options
  10. dojox.drawing.plugins._Plugin,
  11. function(options){
  12. },
  13. {
  14. onClick: function(){
  15. var item;
  16. for(var nm in this.stencils.stencils){
  17. console.log(" stanceil item:", this.stencils.stencils[nm].id, this.stencils.stencils[nm])
  18. if(this.stencils.stencils[nm].shortType=="path"){
  19. item = this.stencils.stencils[nm];
  20. break;
  21. }
  22. }
  23. if(item){
  24. console.log("click Iconize plugin", item.points);
  25. this.makeIcon(item.points);
  26. }
  27. },
  28. makeIcon: function(/*Array*/p){
  29. var rnd = function(n){
  30. return Number(n.toFixed(1));
  31. }
  32. var x = 10000;
  33. var y = 10000;
  34. p.forEach(function(pt){
  35. if(pt.x!==undefined && !isNaN(pt.x)){
  36. x = Math.min(x, pt.x);
  37. y = Math.min(y, pt.y);
  38. }
  39. });
  40. var xmax = 0;
  41. var ymax = 0;
  42. p.forEach(function(pt){
  43. if(pt.x!==undefined && !isNaN(pt.x)){
  44. pt.x = rnd(pt.x - x);
  45. //console.log("Y:", pt.y, y, pt.y - y)
  46. pt.y = rnd(pt.y - y);
  47. xmax = Math.max(xmax, pt.x);
  48. ymax = Math.max(ymax, pt.y);
  49. }
  50. });
  51. console.log("xmax:", xmax, "ymax:", ymax)
  52. var s = 60
  53. var m = 20
  54. p.forEach(function(pt){
  55. pt.x = rnd(pt.x / xmax) * s + m;
  56. pt.y = rnd(pt.y / ymax) * s + m;
  57. });
  58. var txt = "[\n";
  59. dojo.forEach(p, function(pt, i){
  60. txt += "{\t"
  61. if(pt.t){
  62. txt += "t:'"+pt.t+"'"
  63. }
  64. if(pt.x!==undefined && !isNaN(pt.x)){
  65. if(pt.t){
  66. txt += ", ";
  67. }
  68. txt += "x:"+pt.x+",\t\ty:"+pt.y;
  69. }
  70. txt += "\t}";
  71. if(i!=p.length-1){
  72. txt += ","
  73. }
  74. txt += "\n"
  75. });
  76. txt+="]"
  77. console.log(txt)
  78. var n = dojo.byId("data");
  79. if(n){
  80. n.value = txt;
  81. }
  82. }
  83. }
  84. );
  85. dojox.drawing.plugins.tools.Iconize.setup = {
  86. name:"dojox.drawing.plugins.tools.Iconize",
  87. tooltip:"Iconize Tool",
  88. iconClass:"iconPan"
  89. };
  90. dojox.drawing.register(dojox.drawing.plugins.tools.Iconize.setup, "plugin");
  91. });