Highlight.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. define("dojox/charting/action2d/Highlight", ["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/declare", "dojo/_base/Color", "dojo/_base/connect", "dojox/color/_base",
  2. "./PlotAction", "dojo/fx/easing", "dojox/gfx/fx"],
  3. function(dojo, lang, declare, Color, hub, c, PlotAction, dfe, dgf){
  4. /*=====
  5. dojo.declare("dojox.charting.action2d.__HighlightCtorArgs", dojox.charting.action2d.__PlotActionCtorArgs, {
  6. // summary:
  7. // Additional arguments for highlighting actions.
  8. // highlight: String|dojo.Color|Function?
  9. // Either a color or a function that creates a color when highlighting happens.
  10. highlight: null
  11. });
  12. var PlotAction = dojox.charting.action2d.PlotAction;
  13. =====*/
  14. var DEFAULT_SATURATION = 100, // %
  15. DEFAULT_LUMINOSITY1 = 75, // %
  16. DEFAULT_LUMINOSITY2 = 50, // %
  17. cc = function(color){
  18. return function(){ return color; };
  19. },
  20. hl = function(color){
  21. var a = new c.Color(color),
  22. x = a.toHsl();
  23. if(x.s == 0){
  24. x.l = x.l < 50 ? 100 : 0;
  25. }else{
  26. x.s = DEFAULT_SATURATION;
  27. if(x.l < DEFAULT_LUMINOSITY2){
  28. x.l = DEFAULT_LUMINOSITY1;
  29. }else if(x.l > DEFAULT_LUMINOSITY1){
  30. x.l = DEFAULT_LUMINOSITY2;
  31. }else{
  32. x.l = x.l - DEFAULT_LUMINOSITY2 > DEFAULT_LUMINOSITY1 - x.l ?
  33. DEFAULT_LUMINOSITY2 : DEFAULT_LUMINOSITY1;
  34. }
  35. }
  36. return c.fromHsl(x);
  37. };
  38. return declare("dojox.charting.action2d.Highlight", PlotAction, {
  39. // summary:
  40. // Creates a highlighting action on a plot, where an element on that plot
  41. // has a highlight on it.
  42. // the data description block for the widget parser
  43. defaultParams: {
  44. duration: 400, // duration of the action in ms
  45. easing: dfe.backOut // easing for the action
  46. },
  47. optionalParams: {
  48. highlight: "red" // name for the highlight color
  49. // programmatic instantiation can use functions and color objects
  50. },
  51. constructor: function(chart, plot, kwArgs){
  52. // summary:
  53. // Create the highlighting action and connect it to the plot.
  54. // chart: dojox.charting.Chart
  55. // The chart this action belongs to.
  56. // plot: String?
  57. // The plot this action is attached to. If not passed, "default" is assumed.
  58. // kwArgs: charting.action2d.__HighlightCtorArgs?
  59. // Optional keyword arguments object for setting parameters.
  60. var a = kwArgs && kwArgs.highlight;
  61. this.colorFun = a ? (lang.isFunction(a) ? a : cc(a)) : hl;
  62. this.connect();
  63. },
  64. process: function(o){
  65. // summary:
  66. // Process the action on the given object.
  67. // o: dojox.gfx.Shape
  68. // The object on which to process the highlighting action.
  69. if(!o.shape || !(o.type in this.overOutEvents)){ return; }
  70. var runName = o.run.name, index = o.index, anim, startFill, endFill;
  71. if(runName in this.anim){
  72. anim = this.anim[runName][index];
  73. }else{
  74. this.anim[runName] = {};
  75. }
  76. if(anim){
  77. anim.action.stop(true);
  78. }else{
  79. var color = o.shape.getFill();
  80. if(!color || !(color instanceof Color)){
  81. return;
  82. }
  83. this.anim[runName][index] = anim = {
  84. start: color,
  85. end: this.colorFun(color)
  86. };
  87. }
  88. var start = anim.start, end = anim.end;
  89. if(o.type == "onmouseout"){
  90. // swap colors
  91. var t = start;
  92. start = end;
  93. end = t;
  94. }
  95. anim.action = dgf.animateFill({
  96. shape: o.shape,
  97. duration: this.duration,
  98. easing: this.easing,
  99. color: {start: start, end: end}
  100. });
  101. if(o.type == "onmouseout"){
  102. hub.connect(anim.action, "onEnd", this, function(){
  103. if(this.anim[runName]){
  104. delete this.anim[runName][index];
  105. }
  106. });
  107. }
  108. anim.action.play();
  109. }
  110. });
  111. });