Skip to content

Commit

Permalink
Merge pull request #505 from FVANCOP/issue502
Browse files Browse the repository at this point in the history
Issue502
  • Loading branch information
Francois Vancoppenolle authored Mar 5, 2017
2 parents 7b19262 + 6f7b092 commit 615f863
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ChartNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -3282,9 +3282,10 @@ function init_and_start(ctx,data,config) {
fixAngle[j]=0;
firstAngle[j]=statData[i][j].firstAngle;
cumulativeAngle[j] = (((-config.startAngle * (Math.PI / 180) + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI) ;
if(1*config.animationStartWithData>1 && 1*config.animationStartWithData-1 < data.datasets.length) {
}
}
}

statData[i][j].inRadius=0;
statData[i][j].outRadius=0;

if(setOptionValue(false,true,1,"DISPLAYDATA",ctx,data,statData,data.datasets[i].displayData,config.displayData,"displayData",i,j,{nullvalue : null} )== false) continue;
if(setOptionValue(false,true,1,"DISPLAYDATA",ctx,data,statData,data.displayData,config.displayData,"displayData",-1,j,{nullvalue : null} )== false) continue;
Expand All @@ -3309,6 +3310,9 @@ function init_and_start(ctx,data,config) {
dataCutoutRadius=rdataCutoutRadius;
dataDoughnutRadius=rdataDoughnutRadius;

statData[i][j].inRadius=dataCutoutRadius;
statData[i][j].outRadius=dataDoughnutRadius;

if (config.animation) {
if (config.animateScale) {
scaleAnimation = animationDecimal;
Expand Down Expand Up @@ -7356,14 +7360,14 @@ function calculateOrderOfMagnitude(val) {
// ----------------------------------------------------
// highLight : false, highLightMouseFunction : "mousemove",
// ----------------------------------------------------
// - mouse sortir ou entrer dans une pièce => Pas d'influence sur une action de souris. C'est lié à l'action de annotateFunction
// - mouse sortir ou entrer dans une piece => Pas d'influence sur une action de souris. C'est lie a l'action de annotateFunction
// annotateFunctionIn : inBar,
// annotateFunctionOut : outBar,
// ----------------------------------------------------
// - mouseDownRight mouseDownLeft: null mouseDownMiddle: null
// - mouseMove: null mouseWheel : null mouseOut: null (lorsque la souris sort du canvas)
// ----------------------------------------------------
// mouse sur texte : detectMouseOnText => Pas d'influence sur une action de souris. C'est lié à une autre action;
// mouse sur texte : detectMouseOnText => Pas d'influence sur une action de souris. C'est lie a une autre action;
// ----------------------------------------------------

function setAction(ctx,action){
Expand Down Expand Up @@ -7458,7 +7462,7 @@ function calculateOrderOfMagnitude(val) {
};
}

// initialiser les variables nécessaires pour l'action doMouseAction;
// initialiser les variables necessaires pour l'action doMouseAction;
inMouseAction[ctx.ChartNewId]=false;
mouseActionData[ctx.ChartNewId]={ data : data, config: config, prevShow : -1 };
};
Expand Down
158 changes: 158 additions & 0 deletions Samples/inGraphData_around_slices.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<!doctype html>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">

<!--[if lte IE 8]><SCRIPT src='source/excanvas.js'></script><![endif]-->
<SCRIPT src='../ChartNew.js'></script>
<SCRIPT src='../Add-ins/shapesInChart.js'></script>


<SCRIPT>



var charJSPersonnalDefaultOptions = { decimalSeparator : "," , thousandSeparator : ".", roundNumber : "none", graphTitleFontSize: 2 };

defCanvasWidth=1200;
defCanvasHeight=600;

var mydata1 = {
labels : ["2015","2016"],
datasets : [
{
data : [0,10],
fillColor : "rgba(220,0,220,0.2)",
title : "data1",
},
{
data : [10,0],
fillColor : "rgba(220,0,220,0.2)",
title : "data2",
},
{
data : [90,0],
fillColor : "rgba(0,0,220,0.2)",
title : "label for data3",
},
{
data : [0,50],
fillColor : "rgba(220,0,220,0.2)",
title : "data4",
},
{
data : [10,10],
fillColor : "rgba(220,0,220,0.2)",
title : "data5",
},
{
data : [24,80],
fillColor : "rgba(220,0,0,0.2)",
title : "data6",
},
{
data : [58,20],
fillColor : "rgba(0,220,220,0.2)",
title : "data7",
},
{
data : [18,0],
fillColor : "rgba(0,220,0,0.2)",
title : "data8",
},
{
data : [8,25],
fillColor : "rgba(50,100,150,0.2)",
title : "data9",
}
]
};

var opt1 = {
endDrawDataFunction: drawShapes
};



// add text around;

function setXPos(typVal,i,j,k,txt,startAngle,endAngle,fontSize,position,truncLabel,inradius,outradius) {

var nbcharRound=(inradius+position*(outradius-inradius))*2*Math.PI/(fontSize/2);
var degPerChar=Math.ceil(10*360/nbcharRound)/10;
var availableAngle=(180/Math.PI)*(endAngle-startAngle);
var newText=txt;
if(availableAngle<degPerChar*txt.length){
if(truncLabel==false) {
if (typVal=="TEXT")return("");
else return(i);
} else {
newText=txt.substring(0,Math.floor(availableAngle/degPerChar));
if(k>=newText.length) {
if (typVal=="TEXT")return("");
else return(i);
}
}
}
if(typVal=="TEXT")return(txt.substring(k,k+1));
var addAngle=(availableAngle-degPerChar*newText.length)/2+k*degPerChar+degPerChar/2;
if(typVal=="X1") return(i-0.5+addAngle/availableAngle);
if(typVal=="ROTATE")return ((180/Math.PI)*(startAngle)+addAngle+90);
} ;

function addRoundText(data,fontSize,position,truncLabel) {
if(typeof data.shapesInChart!=="object")data.shapesInChart=[];
for(i=0;i<data.datasets.length;i++) {
for(j=0;j<data.labels.length;j++) {
tt=typeof (1*data.datasets[i].data[j]) ;
if(tt!="number")continue;
for(k=0;k<data.datasets[i].title.length;k++){
data.shapesInChart[data.shapesInChart.length]={
shape: "TEXT",
iter : "last",
text: "%eval(setXPos('TEXT',"+i+","+j+","+k+",'"+data.datasets[i].title+"',statData["+i+"]["+j+"].startAngle,statData["+i+"]["+j+"].endAngle,"+fontSize+","+position+","+truncLabel+",statData["+i+"]["+j+"].inRadius,statData["+i+"]["+j+"].outRadius);",
fontSize : fontSize,
textAlign : "center",
textBaseline : "bottom",
fontColor : "black",
animate : false,
x1: "%eval(setXPos('X1',"+i+","+j+","+k+",'"+data.datasets[i].title+"',statData["+i+"]["+j+"].startAngle,statData["+i+"]["+j+"].endAngle,"+fontSize+","+position+","+truncLabel+",statData["+i+"]["+j+"].inRadius,statData["+i+"]["+j+"].outRadius);",
y1: position,
posj: j,
rotate: "%eval(setXPos('ROTATE',"+i+","+j+","+k+",'"+data.datasets[i].title+"',statData["+i+"]["+j+"].startAngle,statData["+i+"]["+j+"].endAngle,"+fontSize+","+position+","+truncLabel+",statData["+i+"]["+j+"].inRadius,statData["+i+"]["+j+"].outRadius);",
paddingX1 : 0,
paddingY1 : 0
}
}
}
}
};



var truncLabel=false; // -> true or false;
position=0.70; // -> value between 0 and 1;

addRoundText(mydata1,30,position,truncLabel);


</SCRIPT>


<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<head>
<title>Demo ChartNew.js</title>
</head>
<body>

<center>
<FONT SIZE=6><B>Demo of ChartNew.js !</B></FONT> <BR>

<script>

document.write("<canvas id=\"canvas_Line\" height=\""+defCanvasHeight+"\" width=\""+defCanvasWidth+"\"></canvas>");
window.onload = function() {
var myLine = new Chart(document.getElementById("canvas_Line").getContext("2d")).Pie(mydata1,opt1);
}
</script>
</body>
</html>

0 comments on commit 615f863

Please sign in to comment.