Skip to content

Commit

Permalink
- supporto opzione "valueThreshold" per pie chart
Browse files Browse the repository at this point in the history
- fix pie slice di 360 gradi
- migliorie in anchorManager per gestione bind su elementi (fix in caso di transizioni)
- fix manager tooltip
  • Loading branch information
eric.goth committed Sep 8, 2010
1 parent 005271a commit ef6ee8a
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 35 deletions.
44 changes: 30 additions & 14 deletions dist/elycharts.js
Expand Up @@ -384,6 +384,8 @@ $.elycharts.templates = {
startAngle : 0,
// Disegna la torta con le fette in senso orario (invece dell'orientamento standard per gradi, in senso antiorario)
clockwise : false,
// Soglia (rapporto sul totale) entro la quale una fetta non viene visualizzata
valueThresold : 0.006,

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

if (!$section.plotProps)
$section.plotProps = {};
if ($section.type == 'line') {
if ($section.type == 'line' || ($options.type == 'line' && !$section.type)) {
if ($section.plotProps && !$section.plotProps.stroke)
$section.plotProps.stroke = color;
} else {
Expand All @@ -613,7 +615,7 @@ function _normalizeOptionsColor($options, $section) {
if ($section.legend.dotProps && !$section.legend.dotProps.fill)
$section.legend.dotProps.fill = color;

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

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

path = this.linepathRevert(path);
//path = this.linepathRevert(path);

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

if (!env.opt.anchors)
return;

if (!env.anchorBinds)
env.anchorBinds = [];

while (env.anchorBinds.length) {
var b = env.anchorBinds.pop();
$(b[0]).unbind(b[1], b[2]);
}

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

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

var f1 = function() { caller.anchorMouseOver(env, mouseAreaData); };
var f2 = function() { caller.anchorMouseOut(env, mouseAreaData); };
if (!env.mouseAreas[i].props.anchor.useMouseEnter) {
$(anc).mouseover(function() { caller.anchorMouseOver(env, mouseAreaData); });
$(anc).mouseout(function() { caller.anchorMouseOut(env, mouseAreaData); });
env.anchorBinds.push([anc, 'mouseover', f1]);
env.anchorBinds.push([anc, 'mouseout', f2]);
$(anc).mouseover(f1);
$(anc).mouseout(f2);
} else {
$(anc).mouseenter(function() { caller.anchorMouseOver(env, mouseAreaData); });
$(anc).mouseleave(function() { caller.anchorMouseOut(env, mouseAreaData); });
env.anchorBinds.push([anc, 'mouseenter', f1]);
env.anchorBinds.push([anc, 'mouseleave', f2]);
$(anc).mouseenter(f1);
$(anc).mouseleave(f2);
}
})(env, env.mouseAreas[i], anc, this);
}
Expand Down Expand Up @@ -2989,7 +3006,7 @@ $.elycharts.tooltipmanager = {
return;

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

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

Expand All @@ -3010,7 +3027,7 @@ $.elycharts.tooltipmanager = {
return;

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

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

Expand Down Expand Up @@ -3490,7 +3507,6 @@ $.elycharts.line = {
pieces.push({ section : 'Series', serie : serie, subSection : 'Dot', path : false, attr : false });
}
}

featuresmanager.beforeShow(env, pieces);
common.show(env, pieces);
featuresmanager.afterShow(env, pieces);
Expand Down Expand Up @@ -3716,7 +3732,7 @@ $.elycharts.pie = {
plot.total += plot.values[i];
}
for (var i = 0; i < ii; i++)
if (plot.values[i] < plot.total * 0.006) {
if (plot.values[i] < plot.total * opt.valueThresold) {
plot.total = plot.total - plot.values[i];
plot.values[i] = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/elycharts.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/changelog.txt
Expand Up @@ -110,3 +110,6 @@ v2.1.1
- script per riunificazione e minimizzazione codice da distribuire
- fix errore rendering
- fix highlight con path nascosti
- fix gestione colori in line chart
- supporto opzione "valueThreshold" per pie chart
- fix pie slice di 360 gradi
22 changes: 16 additions & 6 deletions docs/demo.html
Expand Up @@ -156,12 +156,22 @@
shadowOffset : [ 2, 2]
});
getChartCanvas("holder4").lineChart( labels, data, tooltips, {
*/
$("#holder4").chart( {
type : 'line',
labels: labels, values: data, tooltips: tooltips,
margins: [0,0,0,0],
gridNX: 0, gridNY: 0,
defaultPlotProps: { rounded: 1, dotProps: false, tooltipProps: false, lineProps : {"stroke-width": 1} }
features : {
grid : { nx: 0, ny: 0 }
},
defaultSeries: { rounded: 1, dot: false, fill: true, tooltipProps: false, plotProps : {"stroke-width": 1} },
series : [
{axis : 'r', color : 'blue' },
{axis : 'r', color : 'green', stacked: true },
{axis : 'l' , color : 'red'},
{axis : 'l', color : 'gray' }
],
});
*/

});
</script>
Expand Down Expand Up @@ -194,9 +204,9 @@
<div id="holder1"></div>
<div id="holder2"></div>
<div id="t" style="clear:both"></div>
<div id="holder3"></div>
<!-- <div id="holder3"></div>
<div id="holder6"></div>
<div id="t" style="clear:both"></div>
<div id="t" style="clear:both"></div>-->
<div id="holder5"></div>
<div id="holder4"></div>
<div id="log" style="clear:both"></div>
Expand Down
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -8,5 +8,6 @@ <h1>ElyCharts</h1>
<p><a href="docs/demo.html">Demo</a></p>
<p><a href="docs/demo_2.html">Demo 2</a></p>
<p><a href="docs/changelog.txt">Changelog</a></p>
<p><a href="http://code.google.com/p/elycharts/">Google Code Project</a></p>
</body>
</html>
1 change: 0 additions & 1 deletion src/elycharts_chart_line.js
Expand Up @@ -250,7 +250,6 @@ $.elycharts.line = {
pieces.push({ section : 'Series', serie : serie, subSection : 'Dot', path : false, attr : false });
}
}

featuresmanager.beforeShow(env, pieces);
common.show(env, pieces);
featuresmanager.afterShow(env, pieces);
Expand Down
2 changes: 1 addition & 1 deletion src/elycharts_chart_pie.js
Expand Up @@ -45,7 +45,7 @@ $.elycharts.pie = {
plot.total += plot.values[i];
}
for (var i = 0; i < ii; i++)
if (plot.values[i] < plot.total * 0.006) {
if (plot.values[i] < plot.total * opt.valueThresold) {
plot.total = plot.total - plot.values[i];
plot.values[i] = 0;
}
Expand Down
9 changes: 6 additions & 3 deletions src/elycharts_core.js
Expand Up @@ -172,7 +172,7 @@ function _normalizeOptionsColor($options, $section) {

if (!$section.plotProps)
$section.plotProps = {};
if ($section.type == 'line') {
if ($section.type == 'line' || ($options.type == 'line' && !$section.type)) {
if ($section.plotProps && !$section.plotProps.stroke)
$section.plotProps.stroke = color;
} else {
Expand All @@ -194,7 +194,7 @@ function _normalizeOptionsColor($options, $section) {
if ($section.legend.dotProps && !$section.legend.dotProps.fill)
$section.legend.dotProps.fill = color;

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

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

path = this.linepathRevert(path);
//path = this.linepathRevert(path);

} else {
var path = [];
Expand Down
2 changes: 2 additions & 0 deletions src/elycharts_defaults.js
Expand Up @@ -384,6 +384,8 @@ $.elycharts.templates = {
startAngle : 0,
// Disegna la torta con le fette in senso orario (invece dell'orientamento standard per gradi, in senso antiorario)
clockwise : false,
// Soglia (rapporto sul totale) entro la quale una fetta non viene visualizzata
valueThresold : 0.006,

defaultSeries : {
// r: .5, raggio usato solo per questo spicchio, se <=1 e' in rapporto al raggio generale
Expand Down
26 changes: 19 additions & 7 deletions src/elycharts_manager_anchor.js
Expand Up @@ -19,10 +19,18 @@ $.elycharts.anchormanager = {
afterShow : function(env, pieces) {
// Prendo le aree gestite da mouseAreas, e metto i miei listener
// Non c'e' bisogno di gestire il clean per una chiamata successiva, lo fa gia' il mouseareamanager
// TODO Pero' l'unbind precedente andrebbe fatto, e come fa ora fa l'unbind anche di funzioni non nostre
// Tranne per i bind degli eventi jquery

if (!env.opt.anchors)
return;

if (!env.anchorBinds)
env.anchorBinds = [];

while (env.anchorBinds.length) {
var b = env.anchorBinds.pop();
$(b[0]).unbind(b[1], b[2]);
}

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

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

var f1 = function() { caller.anchorMouseOver(env, mouseAreaData); };
var f2 = function() { caller.anchorMouseOut(env, mouseAreaData); };
if (!env.mouseAreas[i].props.anchor.useMouseEnter) {
$(anc).mouseover(function() { caller.anchorMouseOver(env, mouseAreaData); });
$(anc).mouseout(function() { caller.anchorMouseOut(env, mouseAreaData); });
env.anchorBinds.push([anc, 'mouseover', f1]);
env.anchorBinds.push([anc, 'mouseout', f2]);
$(anc).mouseover(f1);
$(anc).mouseout(f2);
} else {
$(anc).mouseenter(function() { caller.anchorMouseOver(env, mouseAreaData); });
$(anc).mouseleave(function() { caller.anchorMouseOut(env, mouseAreaData); });
env.anchorBinds.push([anc, 'mouseenter', f1]);
env.anchorBinds.push([anc, 'mouseleave', f2]);
$(anc).mouseenter(f1);
$(anc).mouseleave(f2);
}
})(env, env.mouseAreas[i], anc, this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/elycharts_manager_tooltip.js
Expand Up @@ -122,7 +122,7 @@ $.elycharts.tooltipmanager = {
return;

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

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

Expand All @@ -143,7 +143,7 @@ $.elycharts.tooltipmanager = {
return;

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

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

Expand Down

0 comments on commit ef6ee8a

Please sign in to comment.