source: Dev/branches/rest-dojo-ui/client/dojox/charting/action2d/Highlight.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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