[483] | 1 | define(["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(lang, declare, Color, hub, c, PlotAction, dfe, dgf){ |
---|
| 4 | |
---|
| 5 | /*===== |
---|
| 6 | var __HighlightCtorArgs = { |
---|
| 7 | // summary: |
---|
| 8 | // Additional arguments for highlighting actions. |
---|
| 9 | // duration: Number? |
---|
| 10 | // The amount of time in milliseconds for an animation to last. Default is 400. |
---|
| 11 | // easing: dojo/fx/easing/*? |
---|
| 12 | // An easing object (see dojo.fx.easing) for use in an animation. The |
---|
| 13 | // default is dojo.fx.easing.backOut. |
---|
| 14 | // highlight: String|dojo/_base/Color|Function? |
---|
| 15 | // Either a color or a function that creates a color when highlighting happens. |
---|
| 16 | }; |
---|
| 17 | =====*/ |
---|
| 18 | |
---|
| 19 | var DEFAULT_SATURATION = 100, // % |
---|
| 20 | DEFAULT_LUMINOSITY1 = 75, // % |
---|
| 21 | DEFAULT_LUMINOSITY2 = 50, // % |
---|
| 22 | cc = function(color){ |
---|
| 23 | return function(){ return color; }; |
---|
| 24 | }, |
---|
| 25 | |
---|
| 26 | hl = function(color){ |
---|
| 27 | var a = new c.Color(color), |
---|
| 28 | x = a.toHsl(); |
---|
| 29 | if(x.s == 0){ |
---|
| 30 | x.l = x.l < 50 ? 100 : 0; |
---|
| 31 | }else{ |
---|
| 32 | x.s = DEFAULT_SATURATION; |
---|
| 33 | if(x.l < DEFAULT_LUMINOSITY2){ |
---|
| 34 | x.l = DEFAULT_LUMINOSITY1; |
---|
| 35 | }else if(x.l > DEFAULT_LUMINOSITY1){ |
---|
| 36 | x.l = DEFAULT_LUMINOSITY2; |
---|
| 37 | }else{ |
---|
| 38 | x.l = x.l - DEFAULT_LUMINOSITY2 > DEFAULT_LUMINOSITY1 - x.l ? |
---|
| 39 | DEFAULT_LUMINOSITY2 : DEFAULT_LUMINOSITY1; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | var rcolor = c.fromHsl(x); |
---|
| 43 | rcolor.a = a.a; |
---|
| 44 | return rcolor; |
---|
| 45 | }, |
---|
| 46 | |
---|
| 47 | spiderhl = function(color){ |
---|
| 48 | var r = hl(color); |
---|
| 49 | r.a = 0.7; |
---|
| 50 | return r; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | return declare("dojox.charting.action2d.Highlight", PlotAction, { |
---|
| 54 | // summary: |
---|
| 55 | // Creates a highlighting action on a plot, where an element on that plot |
---|
| 56 | // has a highlight on it. |
---|
| 57 | |
---|
| 58 | // the data description block for the widget parser |
---|
| 59 | defaultParams: { |
---|
| 60 | duration: 400, // duration of the action in ms |
---|
| 61 | easing: dfe.backOut // easing for the action |
---|
| 62 | }, |
---|
| 63 | optionalParams: { |
---|
| 64 | highlight: "red" // name for the highlight color |
---|
| 65 | // programmatic instantiation can use functions and color objects |
---|
| 66 | }, |
---|
| 67 | |
---|
| 68 | constructor: function(chart, plot, kwArgs){ |
---|
| 69 | // summary: |
---|
| 70 | // Create the highlighting action and connect it to the plot. |
---|
| 71 | // chart: dojox/charting/Chart |
---|
| 72 | // The chart this action belongs to. |
---|
| 73 | // plot: String? |
---|
| 74 | // The plot this action is attached to. If not passed, "default" is assumed. |
---|
| 75 | // kwArgs: __HighlightCtorArgs? |
---|
| 76 | // Optional keyword arguments object for setting parameters. |
---|
| 77 | var a = kwArgs && kwArgs.highlight; |
---|
| 78 | this.colorFunc = a ? (lang.isFunction(a) ? a : cc(a)) : hl; |
---|
| 79 | this.connect(); |
---|
| 80 | }, |
---|
| 81 | |
---|
| 82 | process: function(o){ |
---|
| 83 | // summary: |
---|
| 84 | // Process the action on the given object. |
---|
| 85 | // o: dojox/gfx/shape.Shape |
---|
| 86 | // The object on which to process the highlighting action. |
---|
| 87 | if(!o.shape || !(o.type in this.overOutEvents)){ return; } |
---|
| 88 | |
---|
| 89 | // if spider let's deal only with poly |
---|
| 90 | if(o.element == "spider_circle" || o.element == "spider_plot"){ |
---|
| 91 | return; |
---|
| 92 | }else if(o.element == "spider_poly" && this.colorFunc == hl){ |
---|
| 93 | // hardcode alpha for compatibility reasons |
---|
| 94 | // TODO to remove in 2.0 |
---|
| 95 | this.colorFunc = spiderhl; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | var runName = o.run.name, index = o.index, anim; |
---|
| 99 | |
---|
| 100 | if(runName in this.anim){ |
---|
| 101 | anim = this.anim[runName][index]; |
---|
| 102 | }else{ |
---|
| 103 | this.anim[runName] = {}; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | if(anim){ |
---|
| 107 | anim.action.stop(true); |
---|
| 108 | }else{ |
---|
| 109 | var color = o.shape.getFill(); |
---|
| 110 | if(!color || !(color instanceof Color)){ |
---|
| 111 | return; |
---|
| 112 | } |
---|
| 113 | this.anim[runName][index] = anim = { |
---|
| 114 | start: color, |
---|
| 115 | end: this.colorFunc(color) |
---|
| 116 | }; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | var start = anim.start, end = anim.end; |
---|
| 120 | if(o.type == "onmouseout"){ |
---|
| 121 | // swap colors |
---|
| 122 | var t = start; |
---|
| 123 | start = end; |
---|
| 124 | end = t; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | anim.action = dgf.animateFill({ |
---|
| 128 | shape: o.shape, |
---|
| 129 | duration: this.duration, |
---|
| 130 | easing: this.easing, |
---|
| 131 | color: {start: start, end: end} |
---|
| 132 | }); |
---|
| 133 | if(o.type == "onmouseout"){ |
---|
| 134 | hub.connect(anim.action, "onEnd", this, function(){ |
---|
| 135 | if(this.anim[runName]){ |
---|
| 136 | delete this.anim[runName][index]; |
---|
| 137 | } |
---|
| 138 | }); |
---|
| 139 | } |
---|
| 140 | anim.action.play(); |
---|
| 141 | } |
---|
| 142 | }); |
---|
| 143 | |
---|
| 144 | }); |
---|