Skip to content

Commit b4306ab

Browse files
committed
- supporto opzione "valueThreshold" per pie chart
- fix pie slice di 360 gradi - migliorie in anchorManager per gestione bind su elementi (fix in caso di transizioni) - fix manager tooltip git-svn-id: http://elycharts.googlecode.com/svn/trunk@4 d12c1f63-3eea-9699-2b47-88fa03d2d012
1 parent 5f7976f commit b4306ab

11 files changed

+81
-35
lines changed

dist/elycharts.js

+30-14
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ $.elycharts.templates = {
384384
startAngle : 0,
385385
// Disegna la torta con le fette in senso orario (invece dell'orientamento standard per gradi, in senso antiorario)
386386
clockwise : false,
387+
// Soglia (rapporto sul totale) entro la quale una fetta non viene visualizzata
388+
valueThresold : 0.006,
387389

388390
defaultSeries : {
389391
// r: .5, raggio usato solo per questo spicchio, se <=1 e' in rapporto al raggio generale
@@ -591,7 +593,7 @@ function _normalizeOptionsColor($options, $section) {
591593

592594
if (!$section.plotProps)
593595
$section.plotProps = {};
594-
if ($section.type == 'line') {
596+
if ($section.type == 'line' || ($options.type == 'line' && !$section.type)) {
595597
if ($section.plotProps && !$section.plotProps.stroke)
596598
$section.plotProps.stroke = color;
597599
} else {
@@ -613,7 +615,7 @@ function _normalizeOptionsColor($options, $section) {
613615
if ($section.legend.dotProps && !$section.legend.dotProps.fill)
614616
$section.legend.dotProps.fill = color;
615617

616-
if ($options.type == 'line' && $section.type == 'line') {
618+
if ($options.type == 'line' && ($section.type == 'line' || !$section.type)) {
617619
if (!$section.dotProps)
618620
$section.dotProps = {};
619621
if ($section.dotProps && !$section.dotProps.fill)
@@ -688,6 +690,9 @@ $.elycharts.common = {
688690
var flag = (a2 - a1) > 180;
689691
a1 = (a1 % 360) * Math.PI / 180;
690692
a2 = (a2 % 360) * Math.PI / 180;
693+
// Se i due angoli risultano uguali ma inizialmente erano diversi significa che c'e' un giro intero (es: 0-360), che va rappresentato
694+
if (a1 == a2 && aa1 != aa2)
695+
a2 += 359.99 * Math.PI / 180;
691696

692697
return { path : rint ? [
693698
["M", cx + r * Math.cos(a1), cy + r * Math.sin(a1)],
@@ -910,7 +915,7 @@ $.elycharts.common = {
910915
}
911916
path.push([ "C", anc[0], anc[1], points[jj][0], points[jj][1], points[jj][0], points[jj][1] ]);
912917

913-
path = this.linepathRevert(path);
918+
//path = this.linepathRevert(path);
914919

915920
} else {
916921
var path = [];
@@ -1606,10 +1611,18 @@ $.elycharts.anchormanager = {
16061611
afterShow : function(env, pieces) {
16071612
// Prendo le aree gestite da mouseAreas, e metto i miei listener
16081613
// Non c'e' bisogno di gestire il clean per una chiamata successiva, lo fa gia' il mouseareamanager
1609-
// TODO Pero' l'unbind precedente andrebbe fatto, e come fa ora fa l'unbind anche di funzioni non nostre
1614+
// Tranne per i bind degli eventi jquery
16101615

16111616
if (!env.opt.anchors)
16121617
return;
1618+
1619+
if (!env.anchorBinds)
1620+
env.anchorBinds = [];
1621+
1622+
while (env.anchorBinds.length) {
1623+
var b = env.anchorBinds.pop();
1624+
$(b[0]).unbind(b[1], b[2]);
1625+
}
16131626

16141627
for (var i = 0; i < env.mouseAreas.length; i++) {
16151628
var serie = env.mouseAreas[i].piece ? env.mouseAreas[i].piece.serie : false;
@@ -1621,15 +1634,19 @@ $.elycharts.anchormanager = {
16211634
if (anc && env.mouseAreas[i].props.anchor && env.mouseAreas[i].props.anchor.highlight) {
16221635

16231636
(function(env, mouseAreaData, anc, caller) {
1624-
// TODO Dovrebbe fare l'unbind solo delle sue funzioni
1625-
$(anc).unbind();
16261637

1638+
var f1 = function() { caller.anchorMouseOver(env, mouseAreaData); };
1639+
var f2 = function() { caller.anchorMouseOut(env, mouseAreaData); };
16271640
if (!env.mouseAreas[i].props.anchor.useMouseEnter) {
1628-
$(anc).mouseover(function() { caller.anchorMouseOver(env, mouseAreaData); });
1629-
$(anc).mouseout(function() { caller.anchorMouseOut(env, mouseAreaData); });
1641+
env.anchorBinds.push([anc, 'mouseover', f1]);
1642+
env.anchorBinds.push([anc, 'mouseout', f2]);
1643+
$(anc).mouseover(f1);
1644+
$(anc).mouseout(f2);
16301645
} else {
1631-
$(anc).mouseenter(function() { caller.anchorMouseOver(env, mouseAreaData); });
1632-
$(anc).mouseleave(function() { caller.anchorMouseOut(env, mouseAreaData); });
1646+
env.anchorBinds.push([anc, 'mouseenter', f1]);
1647+
env.anchorBinds.push([anc, 'mouseleave', f2]);
1648+
$(anc).mouseenter(f1);
1649+
$(anc).mouseleave(f2);
16331650
}
16341651
})(env, env.mouseAreas[i], anc, this);
16351652
}
@@ -2989,7 +3006,7 @@ $.elycharts.tooltipmanager = {
29893006
return;
29903007

29913008
if (!env.opt.tooltips || (serie && (!env.opt.tooltips[serie] || !env.opt.tooltips[serie][index])) || (!serie && !env.opt.tooltips[index]))
2992-
return this.hide(env, serie, index, mouseAreaData, props);
3009+
return this.onMouseExit(env, serie, index, mouseAreaData);
29933010

29943011
var tip = serie ? env.opt.tooltips[serie][index] : env.opt.tooltips[index];
29953012

@@ -3010,7 +3027,7 @@ $.elycharts.tooltipmanager = {
30103027
return;
30113028

30123029
if (!env.opt.tooltips || (serie && (!env.opt.tooltips[serie] || !env.opt.tooltips[serie][index])) || (!serie && !env.opt.tooltips[index]))
3013-
return this.hide(env, serie, index, mouseAreaData, props);
3030+
return this.onMouseExit(env, serie, index, mouseAreaData);
30143031

30153032
var tip = serie ? env.opt.tooltips[serie][index] : env.opt.tooltips[index];
30163033

@@ -3490,7 +3507,6 @@ $.elycharts.line = {
34903507
pieces.push({ section : 'Series', serie : serie, subSection : 'Dot', path : false, attr : false });
34913508
}
34923509
}
3493-
34943510
featuresmanager.beforeShow(env, pieces);
34953511
common.show(env, pieces);
34963512
featuresmanager.afterShow(env, pieces);
@@ -3716,7 +3732,7 @@ $.elycharts.pie = {
37163732
plot.total += plot.values[i];
37173733
}
37183734
for (var i = 0; i < ii; i++)
3719-
if (plot.values[i] < plot.total * 0.006) {
3735+
if (plot.values[i] < plot.total * opt.valueThresold) {
37203736
plot.total = plot.total - plot.values[i];
37213737
plot.values[i] = 0;
37223738
}

dist/elycharts.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/changelog.txt

+3
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ v2.1.1
110110
- script per riunificazione e minimizzazione codice da distribuire
111111
- fix errore rendering
112112
- fix highlight con path nascosti
113+
- fix gestione colori in line chart
114+
- supporto opzione "valueThreshold" per pie chart
115+
- fix pie slice di 360 gradi

docs/demo.html

+16-6
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,22 @@
156156
shadowOffset : [ 2, 2]
157157
});
158158
159-
getChartCanvas("holder4").lineChart( labels, data, tooltips, {
159+
*/
160+
$("#holder4").chart( {
161+
type : 'line',
162+
labels: labels, values: data, tooltips: tooltips,
160163
margins: [0,0,0,0],
161-
gridNX: 0, gridNY: 0,
162-
defaultPlotProps: { rounded: 1, dotProps: false, tooltipProps: false, lineProps : {"stroke-width": 1} }
164+
features : {
165+
grid : { nx: 0, ny: 0 }
166+
},
167+
defaultSeries: { rounded: 1, dot: false, fill: true, tooltipProps: false, plotProps : {"stroke-width": 1} },
168+
series : [
169+
{axis : 'r', color : 'blue' },
170+
{axis : 'r', color : 'green', stacked: true },
171+
{axis : 'l' , color : 'red'},
172+
{axis : 'l', color : 'gray' }
173+
],
163174
});
164-
*/
165175

166176
});
167177
</script>
@@ -194,9 +204,9 @@
194204
<div id="holder1"></div>
195205
<div id="holder2"></div>
196206
<div id="t" style="clear:both"></div>
197-
<div id="holder3"></div>
207+
<!-- <div id="holder3"></div>
198208
<div id="holder6"></div>
199-
<div id="t" style="clear:both"></div>
209+
<div id="t" style="clear:both"></div>-->
200210
<div id="holder5"></div>
201211
<div id="holder4"></div>
202212
<div id="log" style="clear:both"></div>

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ <h1>ElyCharts</h1>
88
<p><a href="docs/demo.html">Demo</a></p>
99
<p><a href="docs/demo_2.html">Demo 2</a></p>
1010
<p><a href="docs/changelog.txt">Changelog</a></p>
11+
<p><a href="http://code.google.com/p/elycharts/">Google Code Project</a></p>
1112
</body>
1213
</html>

src/elycharts_chart_line.js

-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ $.elycharts.line = {
250250
pieces.push({ section : 'Series', serie : serie, subSection : 'Dot', path : false, attr : false });
251251
}
252252
}
253-
254253
featuresmanager.beforeShow(env, pieces);
255254
common.show(env, pieces);
256255
featuresmanager.afterShow(env, pieces);

src/elycharts_chart_pie.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ $.elycharts.pie = {
4545
plot.total += plot.values[i];
4646
}
4747
for (var i = 0; i < ii; i++)
48-
if (plot.values[i] < plot.total * 0.006) {
48+
if (plot.values[i] < plot.total * opt.valueThresold) {
4949
plot.total = plot.total - plot.values[i];
5050
plot.values[i] = 0;
5151
}

src/elycharts_core.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function _normalizeOptionsColor($options, $section) {
172172

173173
if (!$section.plotProps)
174174
$section.plotProps = {};
175-
if ($section.type == 'line') {
175+
if ($section.type == 'line' || ($options.type == 'line' && !$section.type)) {
176176
if ($section.plotProps && !$section.plotProps.stroke)
177177
$section.plotProps.stroke = color;
178178
} else {
@@ -194,7 +194,7 @@ function _normalizeOptionsColor($options, $section) {
194194
if ($section.legend.dotProps && !$section.legend.dotProps.fill)
195195
$section.legend.dotProps.fill = color;
196196

197-
if ($options.type == 'line' && $section.type == 'line') {
197+
if ($options.type == 'line' && ($section.type == 'line' || !$section.type)) {
198198
if (!$section.dotProps)
199199
$section.dotProps = {};
200200
if ($section.dotProps && !$section.dotProps.fill)
@@ -269,6 +269,9 @@ $.elycharts.common = {
269269
var flag = (a2 - a1) > 180;
270270
a1 = (a1 % 360) * Math.PI / 180;
271271
a2 = (a2 % 360) * Math.PI / 180;
272+
// Se i due angoli risultano uguali ma inizialmente erano diversi significa che c'e' un giro intero (es: 0-360), che va rappresentato
273+
if (a1 == a2 && aa1 != aa2)
274+
a2 += 359.99 * Math.PI / 180;
272275

273276
return { path : rint ? [
274277
["M", cx + r * Math.cos(a1), cy + r * Math.sin(a1)],
@@ -491,7 +494,7 @@ $.elycharts.common = {
491494
}
492495
path.push([ "C", anc[0], anc[1], points[jj][0], points[jj][1], points[jj][0], points[jj][1] ]);
493496

494-
path = this.linepathRevert(path);
497+
//path = this.linepathRevert(path);
495498

496499
} else {
497500
var path = [];

src/elycharts_defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ $.elycharts.templates = {
384384
startAngle : 0,
385385
// Disegna la torta con le fette in senso orario (invece dell'orientamento standard per gradi, in senso antiorario)
386386
clockwise : false,
387+
// Soglia (rapporto sul totale) entro la quale una fetta non viene visualizzata
388+
valueThresold : 0.006,
387389

388390
defaultSeries : {
389391
// r: .5, raggio usato solo per questo spicchio, se <=1 e' in rapporto al raggio generale

src/elycharts_manager_anchor.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ $.elycharts.anchormanager = {
1919
afterShow : function(env, pieces) {
2020
// Prendo le aree gestite da mouseAreas, e metto i miei listener
2121
// Non c'e' bisogno di gestire il clean per una chiamata successiva, lo fa gia' il mouseareamanager
22-
// TODO Pero' l'unbind precedente andrebbe fatto, e come fa ora fa l'unbind anche di funzioni non nostre
22+
// Tranne per i bind degli eventi jquery
2323

2424
if (!env.opt.anchors)
2525
return;
26+
27+
if (!env.anchorBinds)
28+
env.anchorBinds = [];
29+
30+
while (env.anchorBinds.length) {
31+
var b = env.anchorBinds.pop();
32+
$(b[0]).unbind(b[1], b[2]);
33+
}
2634

2735
for (var i = 0; i < env.mouseAreas.length; i++) {
2836
var serie = env.mouseAreas[i].piece ? env.mouseAreas[i].piece.serie : false;
@@ -34,15 +42,19 @@ $.elycharts.anchormanager = {
3442
if (anc && env.mouseAreas[i].props.anchor && env.mouseAreas[i].props.anchor.highlight) {
3543

3644
(function(env, mouseAreaData, anc, caller) {
37-
// TODO Dovrebbe fare l'unbind solo delle sue funzioni
38-
$(anc).unbind();
3945

46+
var f1 = function() { caller.anchorMouseOver(env, mouseAreaData); };
47+
var f2 = function() { caller.anchorMouseOut(env, mouseAreaData); };
4048
if (!env.mouseAreas[i].props.anchor.useMouseEnter) {
41-
$(anc).mouseover(function() { caller.anchorMouseOver(env, mouseAreaData); });
42-
$(anc).mouseout(function() { caller.anchorMouseOut(env, mouseAreaData); });
49+
env.anchorBinds.push([anc, 'mouseover', f1]);
50+
env.anchorBinds.push([anc, 'mouseout', f2]);
51+
$(anc).mouseover(f1);
52+
$(anc).mouseout(f2);
4353
} else {
44-
$(anc).mouseenter(function() { caller.anchorMouseOver(env, mouseAreaData); });
45-
$(anc).mouseleave(function() { caller.anchorMouseOut(env, mouseAreaData); });
54+
env.anchorBinds.push([anc, 'mouseenter', f1]);
55+
env.anchorBinds.push([anc, 'mouseleave', f2]);
56+
$(anc).mouseenter(f1);
57+
$(anc).mouseleave(f2);
4658
}
4759
})(env, env.mouseAreas[i], anc, this);
4860
}

src/elycharts_manager_tooltip.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ $.elycharts.tooltipmanager = {
122122
return;
123123

124124
if (!env.opt.tooltips || (serie && (!env.opt.tooltips[serie] || !env.opt.tooltips[serie][index])) || (!serie && !env.opt.tooltips[index]))
125-
return this.hide(env, serie, index, mouseAreaData, props);
125+
return this.onMouseExit(env, serie, index, mouseAreaData);
126126

127127
var tip = serie ? env.opt.tooltips[serie][index] : env.opt.tooltips[index];
128128

@@ -143,7 +143,7 @@ $.elycharts.tooltipmanager = {
143143
return;
144144

145145
if (!env.opt.tooltips || (serie && (!env.opt.tooltips[serie] || !env.opt.tooltips[serie][index])) || (!serie && !env.opt.tooltips[index]))
146-
return this.hide(env, serie, index, mouseAreaData, props);
146+
return this.onMouseExit(env, serie, index, mouseAreaData);
147147

148148
var tip = serie ? env.opt.tooltips[serie][index] : env.opt.tooltips[index];
149149

0 commit comments

Comments
 (0)