Skip to content

Commit 7800db7

Browse files
committed
- Highlight: improvement in stepAnimation management and overlayprops
git-svn-id: http://elycharts.googlecode.com/svn/trunk@36 d12c1f63-3eea-9699-2b47-88fa03d2d012
1 parent 16a8930 commit 7800db7

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

src/elycharts_manager_highlight.js

+43-29
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,47 @@ var common = $.elycharts.common;
1313

1414
/***********************************************************************
1515
* FEATURE: HIGHLIGHT
16-
*
16+
*
1717
* Permette di evidenziare in vari modi l'area in cui si passa con il
1818
* mouse.
1919
**********************************************************************/
2020

2121
$.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+
2335
afterShow : function(env, pieces) {
36+
if (env.highlighted && env.highlighted.length > 0)
37+
this.removeHighlighted(env, false);
2438
env.highlighted = [];
2539
},
26-
40+
2741
onMouseOver : function(env, serie, index, mouseAreaData) {
2842
var path, element;
2943
// TODO Se non e' attivo l'overlay (per la serie o per tutto) e' inutile fare il resto
30-
44+
3145
// Cerco i piece da evidenziare (tutti quelli che sono costituiti da path multipli)
3246
for (var i = 0; i < mouseAreaData.pieces.length; i++)
33-
47+
3448
// 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)
3751
&& mouseAreaData.pieces[i].paths[index] && mouseAreaData.pieces[i].paths[index].element) {
3852
var piece = mouseAreaData.pieces[i].paths[index];
3953
element = piece.element;
4054
path = piece.path;
4155
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
4257
var props = serie ? mouseAreaData.props : common.areaProps(env, mouseAreaData.pieces[i].section, mouseAreaData.pieces[i].serie);
4358
var pelement, ppiece, ppath;
4459
if (path && props.highlight) {
@@ -55,7 +70,8 @@ $.elycharts.highlightmanager = {
5570
}
5671
else if (path[0][0] == 'CIRCLE') {
5772
// 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);
5975
}
6076
else if (path[0][0] == 'SLICE') {
6177
// Per lo slice x e' il raggio, y e' l'angolo
@@ -64,11 +80,11 @@ $.elycharts.highlightmanager = {
6480
d = 90;
6581
path = [ [ 'SLICE', path[0][1], path[0][1], path[0][3] * scale[0], path[0][4], path[0][5] - d, path[0][6] + d ] ];
6682
common.animationStackPush(env, piece, element, common.getSVGProps(common.preparePathShow(env, path)), props.highlight.scaleSpeed, props.highlight.scaleEasing);
67-
83+
6884
} else if (env.opt.type == 'funnel') {
6985
var dx = (piece.rect[2] - piece.rect[0]) * (scale[0] - 1) / 2;
7086
var dy = (piece.rect[3] - piece.rect[1]) * (scale[1] - 1) / 2;
71-
87+
7288
// Specifico di un settore del funnel
7389
common.animationStackStart(env);
7490
path = [ common.movePath(env, [ path[0]], [-dx, -dy])[0],
@@ -77,7 +93,7 @@ $.elycharts.highlightmanager = {
7793
common.movePath(env, [ path[3]], [-dx, +dy])[0],
7894
path[4] ];
7995
common.animationStackPush(env, piece, element, common.getSVGProps(common.preparePathShow(env, path)), props.highlight.scaleSpeed, props.highlight.scaleEasing, 0, true);
80-
96+
8197
// Se c'e' un piece precedente lo usa, altrimenti cerca un topSector per la riduzione
8298
pelement = false;
8399
if (index > 0) {
@@ -101,7 +117,7 @@ $.elycharts.highlightmanager = {
101117
common.animationStackPush(env, ppiece, pelement, common.getSVGProps(common.preparePathShow(env, ppath)), props.highlight.scaleSpeed, props.highlight.scaleEasing, 0, true);
102118
env.highlighted.push({piece : ppiece, cfg : props.highlight});
103119
}
104-
120+
105121
// Se c'e' un piece successivo lo usa, altrimenti cerca un bottomSector per la riduzione
106122
pelement = false;
107123
if (index < mouseAreaData.pieces[i].paths.length - 1) {
@@ -125,11 +141,11 @@ $.elycharts.highlightmanager = {
125141
common.animationStackPush(env, ppiece, pelement, common.getSVGProps(common.preparePathShow(env, ppath)), props.highlight.scaleSpeed, props.highlight.scaleEasing, 0, true);
126142
env.highlighted.push({piece : ppiece, cfg : props.highlight});
127143
}
128-
144+
129145
common.animationStackEnd(env);
130146
}
131147
/* Con scale non va bene
132-
if (!attr.scale)
148+
if (!attr.scale)
133149
attr.scale = [1, 1];
134150
element.attr({scale : [scale[0], scale[1]]}); */
135151
}
@@ -144,13 +160,17 @@ $.elycharts.highlightmanager = {
144160
path = common.movePath(env, path, offset);
145161
common.animationStackPush(env, piece, element, common.getSVGProps(common.preparePathShow(env, path)), props.highlight.moveSpeed, props.highlight.moveEasing);
146162
}
147-
163+
148164
//env.highlighted.push({element : element, attr : attr});
149165
env.highlighted.push({piece : piece, cfg : props.highlight});
150-
166+
151167
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
152169
//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);
154174
//BIND: $(element.node).unbind().mouseover(mouseAreaData.mouseover).mouseout(mouseAreaData.mouseout);
155175
// Se metto immediatamente il mouseAreaData.listenerDisabled poi va comunque un mouseout dalla vecchia area e va
156176
// in loop. TODO Rivedere e sistemare anche per tooltip
@@ -160,7 +180,7 @@ $.elycharts.highlightmanager = {
160180
}
161181
}
162182
}
163-
183+
164184
if (env.opt.features.highlight.indexHighlight && env.opt.type == 'line') {
165185
var t = env.opt.features.highlight.indexHighlight;
166186
if (t == 'auto')
@@ -169,13 +189,13 @@ $.elycharts.highlightmanager = {
169189
var delta1 = (env.opt.width - env.opt.margins[3] - env.opt.margins[1]) / (env.opt.labels.length > 0 ? env.opt.labels.length : 1);
170190
var delta2 = (env.opt.width - env.opt.margins[3] - env.opt.margins[1]) / (env.opt.labels.length > 1 ? env.opt.labels.length - 1 : 1);
171191
var lineCenter = true;
172-
192+
173193
switch (t) {
174194
case 'bar':
175195
path = [ ['RECT', env.opt.margins[3] + index * delta1, env.opt.margins[0] ,
176196
env.opt.margins[3] + (index + 1) * delta1, env.opt.height - env.opt.margins[2] ] ];
177197
break;
178-
198+
179199
case 'line':
180200
lineCenter = false;
181201
case 'barline':
@@ -191,18 +211,12 @@ $.elycharts.highlightmanager = {
191211
}
192212
}
193213
},
194-
214+
195215
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);
203217
}
204218

205-
}
219+
};
206220

207221
$.elycharts.featuresmanager.register($.elycharts.highlightmanager, 21);
208222

0 commit comments

Comments
 (0)