Magnify.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.charting.action2d.Magnify"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.charting.action2d.Magnify"] = true;
  8. dojo.provide("dojox.charting.action2d.Magnify");
  9. dojo.require("dojox.charting.action2d.Base");
  10. dojo.require("dojox.gfx.matrix");
  11. dojo.require("dojo.fx");
  12. /*=====
  13. dojo.declare("dojox.charting.action2d.__MagnifyCtorArgs", dojox.charting.action2d.__BaseCtorArgs, {
  14. // summary:
  15. // Additional arguments for highlighting actions.
  16. // scale: Number?
  17. // The amount to magnify the given object to. Default is 2.
  18. scale: 2
  19. });
  20. =====*/
  21. (function(){
  22. var DEFAULT_SCALE = 2,
  23. m = dojox.gfx.matrix,
  24. gf = dojox.gfx.fx;
  25. dojo.declare("dojox.charting.action2d.Magnify", dojox.charting.action2d.Base, {
  26. // summary:
  27. // Create an action that magnifies the object the action is applied to.
  28. // the data description block for the widget parser
  29. defaultParams: {
  30. duration: 400, // duration of the action in ms
  31. easing: dojo.fx.easing.backOut, // easing for the action
  32. scale: DEFAULT_SCALE // scale of magnification
  33. },
  34. optionalParams: {}, // no optional parameters
  35. constructor: function(chart, plot, kwArgs){
  36. // summary:
  37. // Create the magnifying action.
  38. // chart: dojox.charting.Chart2D
  39. // The chart this action belongs to.
  40. // plot: String?
  41. // The plot to apply the action to. If not passed, "default" is assumed.
  42. // kwArgs: dojox.charting.action2d.__MagnifyCtorArgs?
  43. // Optional keyword arguments for this action.
  44. // process optional named parameters
  45. this.scale = kwArgs && typeof kwArgs.scale == "number" ? kwArgs.scale : DEFAULT_SCALE;
  46. this.connect();
  47. },
  48. process: function(o){
  49. // summary:
  50. // Process the action on the given object.
  51. // o: dojox.gfx.Shape
  52. // The object on which to process the magnifying action.
  53. if(!o.shape || !(o.type in this.overOutEvents) ||
  54. !("cx" in o) || !("cy" in o)){ return; }
  55. var runName = o.run.name, index = o.index, vector = [], anim, init, scale;
  56. if(runName in this.anim){
  57. anim = this.anim[runName][index];
  58. }else{
  59. this.anim[runName] = {};
  60. }
  61. if(anim){
  62. anim.action.stop(true);
  63. }else{
  64. this.anim[runName][index] = anim = {};
  65. }
  66. if(o.type == "onmouseover"){
  67. init = m.identity;
  68. scale = this.scale;
  69. }else{
  70. init = m.scaleAt(this.scale, o.cx, o.cy);
  71. scale = 1 / this.scale;
  72. }
  73. var kwArgs = {
  74. shape: o.shape,
  75. duration: this.duration,
  76. easing: this.easing,
  77. transform: [
  78. {name: "scaleAt", start: [1, o.cx, o.cy], end: [scale, o.cx, o.cy]},
  79. init
  80. ]
  81. };
  82. if(o.shape){
  83. vector.push(gf.animateTransform(kwArgs));
  84. }
  85. if(o.oultine){
  86. kwArgs.shape = o.outline;
  87. vector.push(gf.animateTransform(kwArgs));
  88. }
  89. if(o.shadow){
  90. kwArgs.shape = o.shadow;
  91. vector.push(gf.animateTransform(kwArgs));
  92. }
  93. if(!vector.length){
  94. delete this.anim[runName][index];
  95. return;
  96. }
  97. anim.action = dojo.fx.combine(vector);
  98. if(o.type == "onmouseout"){
  99. dojo.connect(anim.action, "onEnd", this, function(){
  100. if(this.anim[runName]){
  101. delete this.anim[runName][index];
  102. }
  103. });
  104. }
  105. anim.action.play();
  106. }
  107. });
  108. })();
  109. }