@@ -13,32 +13,47 @@ var common = $.elycharts.common;
13
13
14
14
/***********************************************************************
15
15
* FEATURE: HIGHLIGHT
16
- *
16
+ *
17
17
* Permette di evidenziare in vari modi l'area in cui si passa con il
18
18
* mouse.
19
19
**********************************************************************/
20
20
21
21
$ . elycharts . highlightmanager = {
22
-
22
+
23
+ removeHighlighted : function ( env , full ) {
24
+ if ( env . highlighted )
25
+ while ( env . highlighted . length > 0 ) {
26
+ var o = env . highlighted . pop ( ) ;
27
+ if ( o . piece ) {
28
+ if ( full )
29
+ common . animationStackPush ( env , o . piece , o . piece . element , common . getPieceFullAttr ( env , o . piece ) , o . cfg . restoreSpeed , o . cfg . restoreEasing , 0 , true ) ;
30
+ } else
31
+ o . element . remove ( ) ;
32
+ }
33
+ } ,
34
+
23
35
afterShow : function ( env , pieces ) {
36
+ if ( env . highlighted && env . highlighted . length > 0 )
37
+ this . removeHighlighted ( env , false ) ;
24
38
env . highlighted = [ ] ;
25
39
} ,
26
-
40
+
27
41
onMouseOver : function ( env , serie , index , mouseAreaData ) {
28
42
var path , element ;
29
43
// TODO Se non e' attivo l'overlay (per la serie o per tutto) e' inutile fare il resto
30
-
44
+
31
45
// Cerco i piece da evidenziare (tutti quelli che sono costituiti da path multipli)
32
46
for ( var i = 0 ; i < mouseAreaData . pieces . length ; i ++ )
33
-
47
+
34
48
// Il loop sotto estrae solo i pieces con array di path (quindi non i line o i fill del linechart ... ma il resto si)
35
- if ( mouseAreaData . pieces [ i ] . section == 'Series' && mouseAreaData . pieces [ i ] . paths
36
- && ( ! serie || mouseAreaData . pieces [ i ] . serie == serie )
49
+ if ( mouseAreaData . pieces [ i ] . section == 'Series' && mouseAreaData . pieces [ i ] . paths
50
+ && ( ! serie || mouseAreaData . pieces [ i ] . serie == serie )
37
51
&& mouseAreaData . pieces [ i ] . paths [ index ] && mouseAreaData . pieces [ i ] . paths [ index ] . element ) {
38
52
var piece = mouseAreaData . pieces [ i ] . paths [ index ] ;
39
53
element = piece . element ;
40
54
path = piece . path ;
41
55
var attr = common . getElementOriginalAttrs ( element ) ;
56
+ var newattr = false ; // In caso la geometria dell'oggetto è modificata mediante attr (es: per circle) qui memorizza i nuovi attributi
42
57
var props = serie ? mouseAreaData . props : common . areaProps ( env , mouseAreaData . pieces [ i ] . section , mouseAreaData . pieces [ i ] . serie ) ;
43
58
var pelement , ppiece , ppath ;
44
59
if ( path && props . highlight ) {
@@ -55,7 +70,8 @@ $.elycharts.highlightmanager = {
55
70
}
56
71
else if ( path [ 0 ] [ 0 ] == 'CIRCLE' ) {
57
72
// I pass directly new radius
58
- common . animationStackPush ( env , piece , element , { r : path [ 0 ] [ 3 ] * scale [ 0 ] } , props . highlight . scaleSpeed , props . highlight . scaleEasing ) ;
73
+ newattr = { r : path [ 0 ] [ 3 ] * scale [ 0 ] } ;
74
+ common . animationStackPush ( env , piece , element , newattr , props . highlight . scaleSpeed , props . highlight . scaleEasing ) ;
59
75
}
60
76
else if ( path [ 0 ] [ 0 ] == 'SLICE' ) {
61
77
// Per lo slice x e' il raggio, y e' l'angolo
@@ -64,11 +80,11 @@ $.elycharts.highlightmanager = {
64
80
d = 90 ;
65
81
path = [ [ 'SLICE' , path [ 0 ] [ 1 ] , path [ 0 ] [ 1 ] , path [ 0 ] [ 3 ] * scale [ 0 ] , path [ 0 ] [ 4 ] , path [ 0 ] [ 5 ] - d , path [ 0 ] [ 6 ] + d ] ] ;
66
82
common . animationStackPush ( env , piece , element , common . getSVGProps ( common . preparePathShow ( env , path ) ) , props . highlight . scaleSpeed , props . highlight . scaleEasing ) ;
67
-
83
+
68
84
} else if ( env . opt . type == 'funnel' ) {
69
85
var dx = ( piece . rect [ 2 ] - piece . rect [ 0 ] ) * ( scale [ 0 ] - 1 ) / 2 ;
70
86
var dy = ( piece . rect [ 3 ] - piece . rect [ 1 ] ) * ( scale [ 1 ] - 1 ) / 2 ;
71
-
87
+
72
88
// Specifico di un settore del funnel
73
89
common . animationStackStart ( env ) ;
74
90
path = [ common . movePath ( env , [ path [ 0 ] ] , [ - dx , - dy ] ) [ 0 ] ,
@@ -77,7 +93,7 @@ $.elycharts.highlightmanager = {
77
93
common . movePath ( env , [ path [ 3 ] ] , [ - dx , + dy ] ) [ 0 ] ,
78
94
path [ 4 ] ] ;
79
95
common . animationStackPush ( env , piece , element , common . getSVGProps ( common . preparePathShow ( env , path ) ) , props . highlight . scaleSpeed , props . highlight . scaleEasing , 0 , true ) ;
80
-
96
+
81
97
// Se c'e' un piece precedente lo usa, altrimenti cerca un topSector per la riduzione
82
98
pelement = false ;
83
99
if ( index > 0 ) {
@@ -101,7 +117,7 @@ $.elycharts.highlightmanager = {
101
117
common . animationStackPush ( env , ppiece , pelement , common . getSVGProps ( common . preparePathShow ( env , ppath ) ) , props . highlight . scaleSpeed , props . highlight . scaleEasing , 0 , true ) ;
102
118
env . highlighted . push ( { piece : ppiece , cfg : props . highlight } ) ;
103
119
}
104
-
120
+
105
121
// Se c'e' un piece successivo lo usa, altrimenti cerca un bottomSector per la riduzione
106
122
pelement = false ;
107
123
if ( index < mouseAreaData . pieces [ i ] . paths . length - 1 ) {
@@ -125,11 +141,11 @@ $.elycharts.highlightmanager = {
125
141
common . animationStackPush ( env , ppiece , pelement , common . getSVGProps ( common . preparePathShow ( env , ppath ) ) , props . highlight . scaleSpeed , props . highlight . scaleEasing , 0 , true ) ;
126
142
env . highlighted . push ( { piece : ppiece , cfg : props . highlight } ) ;
127
143
}
128
-
144
+
129
145
common . animationStackEnd ( env ) ;
130
146
}
131
147
/* Con scale non va bene
132
- if (!attr.scale)
148
+ if (!attr.scale)
133
149
attr.scale = [1, 1];
134
150
element.attr({scale : [scale[0], scale[1]]}); */
135
151
}
@@ -144,13 +160,17 @@ $.elycharts.highlightmanager = {
144
160
path = common . movePath ( env , path , offset ) ;
145
161
common . animationStackPush ( env , piece , element , common . getSVGProps ( common . preparePathShow ( env , path ) ) , props . highlight . moveSpeed , props . highlight . moveEasing ) ;
146
162
}
147
-
163
+
148
164
//env.highlighted.push({element : element, attr : attr});
149
165
env . highlighted . push ( { piece : piece , cfg : props . highlight } ) ;
150
-
166
+
151
167
if ( props . highlight . overlayProps ) {
168
+ // NOTA: path e' il path modificato dai precedenti (cosi' l'overlay tiene conto della cosa), deve guardare anche a newattr
152
169
//BIND: mouseAreaData.listenerDisabled = true;
153
- element = common . showPath ( env , path ) . attr ( props . highlight . overlayProps ) ;
170
+ element = common . showPath ( env , path ) ;
171
+ if ( newattr )
172
+ element . attr ( newattr ) ;
173
+ element . attr ( props . highlight . overlayProps ) ;
154
174
//BIND: $(element.node).unbind().mouseover(mouseAreaData.mouseover).mouseout(mouseAreaData.mouseout);
155
175
// Se metto immediatamente il mouseAreaData.listenerDisabled poi va comunque un mouseout dalla vecchia area e va
156
176
// in loop. TODO Rivedere e sistemare anche per tooltip
@@ -160,7 +180,7 @@ $.elycharts.highlightmanager = {
160
180
}
161
181
}
162
182
}
163
-
183
+
164
184
if ( env . opt . features . highlight . indexHighlight && env . opt . type == 'line' ) {
165
185
var t = env . opt . features . highlight . indexHighlight ;
166
186
if ( t == 'auto' )
@@ -169,13 +189,13 @@ $.elycharts.highlightmanager = {
169
189
var delta1 = ( env . opt . width - env . opt . margins [ 3 ] - env . opt . margins [ 1 ] ) / ( env . opt . labels . length > 0 ? env . opt . labels . length : 1 ) ;
170
190
var delta2 = ( env . opt . width - env . opt . margins [ 3 ] - env . opt . margins [ 1 ] ) / ( env . opt . labels . length > 1 ? env . opt . labels . length - 1 : 1 ) ;
171
191
var lineCenter = true ;
172
-
192
+
173
193
switch ( t ) {
174
194
case 'bar' :
175
195
path = [ [ 'RECT' , env . opt . margins [ 3 ] + index * delta1 , env . opt . margins [ 0 ] ,
176
196
env . opt . margins [ 3 ] + ( index + 1 ) * delta1 , env . opt . height - env . opt . margins [ 2 ] ] ] ;
177
197
break ;
178
-
198
+
179
199
case 'line' :
180
200
lineCenter = false ;
181
201
case 'barline' :
@@ -191,18 +211,12 @@ $.elycharts.highlightmanager = {
191
211
}
192
212
}
193
213
} ,
194
-
214
+
195
215
onMouseOut : function ( env , serie , index , mouseAreaData ) {
196
- while ( env . highlighted . length > 0 ) {
197
- var o = env . highlighted . pop ( ) ;
198
- if ( o . piece )
199
- common . animationStackPush ( env , o . piece , o . piece . element , common . getPieceFullAttr ( env , o . piece ) , o . cfg . restoreSpeed , o . cfg . restoreEasing , 0 , true ) ;
200
- else
201
- o . element . remove ( ) ;
202
- }
216
+ this . removeHighlighted ( env , true ) ;
203
217
}
204
218
205
- }
219
+ } ;
206
220
207
221
$ . elycharts . featuresmanager . register ( $ . elycharts . highlightmanager , 21 ) ;
208
222
0 commit comments