Iconize.js 2.5 KB

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