Magnify.js 3.0 KB

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