Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove trailing whitespace

  • Loading branch information...
commit 238844b76faee08ac74112c6a4274855162096e5 1 parent 2475d55
@brumm authored
Showing with 210 additions and 210 deletions.
  1. +210 −210 Chart.js
View
420 Chart.js
@@ -10,10 +10,10 @@
//Define the global Chart Variable as a class.
window.Chart = function(context, options){
var chart = this;
-
+
//Easing functions adapted from Robert Penner's easing equations
//http://www.robertpenner.com/easing/
-
+
var animationOptions = {
linear : function (t){
return t;
@@ -121,7 +121,7 @@ window.Chart = function(context, options){
return 1*((t=t/1-1)*t*((s+1)*t + s) + 1);
},
easeInOutBack: function (t) {
- var s = 1.70158;
+ var s = 1.70158;
if ((t/=1/2) < 1) return 1/2*(t*t*(((s*=(1.525))+1)*t - s));
return 1/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2);
},
@@ -311,7 +311,7 @@ window.Chart = function(context, options){
}
return { x: xPosition, y: yPosition };
}
-
+
function tooltipEventHandler(e) {
if(chart.tooltips.length > 0) {
chart.savedState = chart.savedState == null ? context.getImageData(0,0,context.canvas.width,context.canvas.height) : chart.savedState;
@@ -364,7 +364,7 @@ window.Chart = function(context, options){
}
this.PolarArea = function(data,options){
-
+
chart.PolarArea.defaults = {
scaleOverlay : true,
scaleOverride : false,
@@ -395,14 +395,14 @@ window.Chart = function(context, options){
onAnimationComplete : null,
showTooltips : true
};
-
+
var config = (options)? mergeChartConfig(chart.PolarArea.defaults,options) : chart.PolarArea.defaults;
-
+
return new PolarArea(data,config,context);
};
this.Radar = function(data,options){
-
+
chart.Radar.defaults = {
scaleOverlay : false,
scaleOverride : false,
@@ -424,7 +424,7 @@ window.Chart = function(context, options){
scaleBackdropPaddingX : 2,
angleShowLineOut : true,
angleLineColor : "rgba(0,0,0,.1)",
- angleLineWidth : 1,
+ angleLineWidth : 1,
pointLabelFontFamily : "'Arial'",
pointLabelFontStyle : "normal",
pointLabelFontSize : 12,
@@ -441,12 +441,12 @@ window.Chart = function(context, options){
onAnimationComplete : null,
showTooltips : true
};
-
+
var config = (options)? mergeChartConfig(chart.Radar.defaults,options) : chart.Radar.defaults;
return new Radar(data,config,context);
};
-
+
this.Pie = function(data,options){
chart.Pie.defaults = {
segmentShowStroke : true,
@@ -464,15 +464,15 @@ window.Chart = function(context, options){
labelFontColor : "#666",
labelAlign : 'right',
showTooltips : true
- };
+ };
var config = (options)? mergeChartConfig(chart.Pie.defaults,options) : chart.Pie.defaults;
-
- return new Pie(data,config,context);
+
+ return new Pie(data,config,context);
};
-
+
this.Doughnut = function(data,options){
-
+
chart.Doughnut.defaults = {
segmentShowStroke : true,
segmentStrokeColor : "#fff",
@@ -485,16 +485,16 @@ window.Chart = function(context, options){
animateScale : false,
onAnimationComplete : null,
showTooltips : true
- };
+ };
var config = (options)? mergeChartConfig(chart.Doughnut.defaults,options) : chart.Doughnut.defaults;
-
- return new Doughnut(data,config,context);
-
+
+ return new Doughnut(data,config,context);
+
};
this.Line = function(data,options){
-
+
chart.Line.defaults = {
scaleOverlay : false,
scaleOverride : false,
@@ -524,12 +524,12 @@ window.Chart = function(context, options){
animationEasing : "easeOutQuart",
onAnimationComplete : null,
showTooltips : true
- };
+ };
var config = (options) ? mergeChartConfig(chart.Line.defaults,options) : chart.Line.defaults;
-
+
return new Line(data,config,context);
}
-
+
this.Bar = function(data,options){
chart.Bar.defaults = {
scaleOverlay : false,
@@ -557,29 +557,29 @@ window.Chart = function(context, options){
animationEasing : "easeOutQuart",
onAnimationComplete : null,
showTooltips : true
- };
+ };
var config = (options) ? mergeChartConfig(chart.Bar.defaults,options) : chart.Bar.defaults;
-
- return new Bar(data,config,context);
+
+ return new Bar(data,config,context);
}
-
+
var clear = function(c){
c.clearRect(0, 0, width, height);
};
var PolarArea = function(data,config,ctx){
- var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString;
-
-
+ var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString;
+
+
calculateDrawingSizes();
-
+
valueBounds = getValueBounds();
labelTemplateString = (config.scaleShowLabels)? config.scaleLabel : null;
//Check and set the scale
if (!config.scaleOverride){
-
+
calculatedScale = calculateScale(scaleHeight,valueBounds.maxSteps,valueBounds.minSteps,valueBounds.maxValue,valueBounds.minValue,labelTemplateString);
}
else {
@@ -591,7 +591,7 @@ window.Chart = function(context, options){
}
populateLabels(labelTemplateString, calculatedScale.labels,calculatedScale.steps,config.scaleStartValue,config.scaleStepWidth);
}
-
+
scaleHop = maxSize/(calculatedScale.steps);
//Wrap in an animation loop wrapper
@@ -600,16 +600,16 @@ window.Chart = function(context, options){
function calculateDrawingSizes(){
maxSize = (Min([width,height])/2);
//Remove whatever is larger - the font size or line width.
-
+
maxSize -= Max([config.scaleFontSize*0.5,config.scaleLineWidth*0.5]);
-
+
labelHeight = config.scaleFontSize*2;
//If we're drawing the backdrop - add the Y padding to the label height and remove from drawing region.
if (config.scaleShowLabelBackdrop){
labelHeight += (2 * config.scaleBackdropPaddingY);
maxSize -= config.scaleBackdropPaddingY*1.5;
}
-
+
scaleHeight = maxSize;
//If the label height is less than 5, set it to 5 so we don't have lines on top of each other.
labelHeight = Default(labelHeight,5);
@@ -700,24 +700,24 @@ window.Chart = function(context, options){
var maxSteps = Math.floor((scaleHeight / (labelHeight*0.66)));
var minSteps = Math.floor((scaleHeight / labelHeight*0.5));
-
+
return {
maxValue : upperValue,
minValue : lowerValue,
maxSteps : maxSteps,
minSteps : minSteps
};
-
+
}
}
var Radar = function (data,config,ctx) {
- var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString;
-
+ var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString;
+
//If no labels are defined set to an empty array, so referencing length for looping doesn't blow up.
if (!data.labels) data.labels = [];
-
+
calculateDrawingSizes();
var valueBounds = getValueBounds();
@@ -726,7 +726,7 @@ window.Chart = function(context, options){
//Check and set the scale
if (!config.scaleOverride){
-
+
calculatedScale = calculateScale(scaleHeight,valueBounds.maxSteps,valueBounds.minSteps,valueBounds.maxValue,valueBounds.minValue,labelTemplateString);
}
else {
@@ -738,11 +738,11 @@ window.Chart = function(context, options){
}
populateLabels(labelTemplateString, calculatedScale.labels,calculatedScale.steps,config.scaleStartValue,config.scaleStepWidth);
}
-
+
scaleHop = maxSize/(calculatedScale.steps);
-
+
animationLoop(config,drawScale,drawAllDataPoints,ctx);
-
+
//Radar specific functions.
function drawAllDataPoints(animationDecimal){
var rotationDegree = (2*Math.PI)/data.datasets[0].data.length;
@@ -775,15 +775,15 @@ window.Chart = function(context, options){
}
}
ctx.closePath();
-
-
+
+
ctx.fillStyle = data.datasets[i].fillColor;
ctx.strokeStyle = data.datasets[i].strokeColor;
ctx.lineWidth = config.datasetStrokeWidth;
ctx.fill();
ctx.stroke();
-
-
+
+
if (config.pointDot){
ctx.fillStyle = data.datasets[i].pointColor;
ctx.strokeStyle = data.datasets[i].pointStrokeColor;
@@ -794,25 +794,25 @@ window.Chart = function(context, options){
ctx.arc(0,animationDecimal*(-1*calculateOffset(data.datasets[i].data[k],calculatedScale,scaleHop)),config.pointDotRadius,2*Math.PI,false);
ctx.fill();
ctx.stroke();
- }
-
+ }
+
}
ctx.rotate(rotationDegree);
}
ctx.restore();
-
-
+
+
}
function drawScale(){
var rotationDegree = (2*Math.PI)/data.datasets[0].data.length;
ctx.save();
- ctx.translate(width / 2, height / 2);
-
+ ctx.translate(width / 2, height / 2);
+
if (config.angleShowLineOut){
- ctx.strokeStyle = config.angleLineColor;
+ ctx.strokeStyle = config.angleLineColor;
ctx.lineWidth = config.angleLineWidth;
for (var h=0; h<data.datasets[0].data.length; h++){
-
+
ctx.rotate(rotationDegree);
ctx.beginPath();
ctx.moveTo(0,0);
@@ -823,25 +823,25 @@ window.Chart = function(context, options){
for (var i=0; i<calculatedScale.steps; i++){
ctx.beginPath();
-
+
if(config.scaleShowLine){
ctx.strokeStyle = config.scaleLineColor;
ctx.lineWidth = config.scaleLineWidth;
- ctx.moveTo(0,-scaleHop * (i+1));
+ ctx.moveTo(0,-scaleHop * (i+1));
for (var j=0; j<data.datasets[0].data.length; j++){
ctx.rotate(rotationDegree);
ctx.lineTo(0,-scaleHop * (i+1));
}
ctx.closePath();
- ctx.stroke();
-
+ ctx.stroke();
+
}
-
- if (config.scaleShowLabels){
+
+ if (config.scaleShowLabels){
ctx.textAlign = 'center';
- ctx.font = config.scaleFontStyle + " " + config.scaleFontSize+"px " + config.scaleFontFamily;
+ ctx.font = config.scaleFontStyle + " " + config.scaleFontSize+"px " + config.scaleFontFamily;
ctx.textBaseline = "middle";
-
+
if (config.scaleShowLabelBackdrop){
var textWidth = ctx.measureText(calculatedScale.labels[i]).width;
ctx.fillStyle = config.scaleBackdropColor;
@@ -853,18 +853,18 @@ window.Chart = function(context, options){
Math.round(config.scaleFontSize + (config.scaleBackdropPaddingY*2)) //Height
);
ctx.fill();
- }
+ }
ctx.fillStyle = config.scaleFontColor;
ctx.fillText(calculatedScale.labels[i],0,-scaleHop*(i+1));
}
}
- for (var k=0; k<data.labels.length; k++){
+ for (var k=0; k<data.labels.length; k++){
ctx.font = config.pointLabelFontStyle + " " + config.pointLabelFontSize+"px " + config.pointLabelFontFamily;
ctx.fillStyle = config.pointLabelFontColor;
var opposite = Math.sin(rotationDegree*k) * (maxSize + config.pointLabelFontSize);
var adjacent = Math.cos(rotationDegree*k) * (maxSize + config.pointLabelFontSize);
-
+
if(rotationDegree*k == Math.PI || rotationDegree*k == 0){
ctx.textAlign = "center";
}
@@ -874,11 +874,11 @@ window.Chart = function(context, options){
else{
ctx.textAlign = "left";
}
-
+
ctx.textBaseline = "middle";
-
+
ctx.fillText(data.labels[k],opposite,-adjacent);
-
+
}
ctx.restore();
};
@@ -886,17 +886,17 @@ window.Chart = function(context, options){
maxSize = (Min([width,height])/2);
labelHeight = config.scaleFontSize*2;
-
+
var labelLength = 0;
for (var i=0; i<data.labels.length; i++){
ctx.font = config.pointLabelFontStyle + " " + config.pointLabelFontSize+"px " + config.pointLabelFontFamily;
var textMeasurement = ctx.measureText(data.labels[i]).width;
if(textMeasurement>labelLength) labelLength = textMeasurement;
}
-
+
//Figure out whats the largest - the height of the text or the width of what's there, and minus it from the maximum usable size.
- maxSize -= Max([labelLength,((config.pointLabelFontSize/2)*1.5)]);
-
+ maxSize -= Max([labelLength,((config.pointLabelFontSize/2)*1.5)]);
+
maxSize -= config.pointLabelFontSize;
maxSize = CapValue(maxSize, null, 0);
scaleHeight = maxSize;
@@ -906,7 +906,7 @@ window.Chart = function(context, options){
function getValueBounds() {
var upperValue = Number.MIN_VALUE;
var lowerValue = Number.MAX_VALUE;
-
+
for (var i=0; i<data.datasets.length; i++){
for (var j=0; j<data.datasets[i].data.length; j++){
if (data.datasets[i].data[j] > upperValue){upperValue = data.datasets[i].data[j]}
@@ -916,32 +916,32 @@ window.Chart = function(context, options){
var maxSteps = Math.floor((scaleHeight / (labelHeight*0.66)));
var minSteps = Math.floor((scaleHeight / labelHeight*0.5));
-
+
return {
maxValue : upperValue,
minValue : lowerValue,
maxSteps : maxSteps,
minSteps : minSteps
};
-
+
}
}
var Pie = function(data,config,ctx){
var segmentTotal = 0;
-
+
//In case we have a canvas that is not a square. Minus 5 pixels as padding round the edge.
var pieRadius = Min([height/2,width/2]) - 5;
-
+
for (var i=0; i<data.length; i++){
segmentTotal += data[i].value;
}
ctx.fillStyle = 'black';
ctx.textBaseline = 'base';
-
+
animationLoop(config,null,drawPieSegments,ctx);
-
+
function drawPieSegments (animationDecimal){
var cumulativeAngle = -Math.PI/2,
scaleAnimation = 1,
@@ -976,7 +976,7 @@ window.Chart = function(context, options){
}
return -10;
}
-
+
function reversePieLabelAlign(align) {
switch(align) {
case 'left': return 'right'; break;
@@ -984,9 +984,9 @@ window.Chart = function(context, options){
case 'center': return align; break;
}
}
-
+
var fontSize = data[i].labelFontSize || config.labelFontSize+'px';
-
+
if(fontSize.match(/^[0-9]+$/g) != null) {
fontSize = fontSize+'px';
}
@@ -1010,7 +1010,7 @@ window.Chart = function(context, options){
ctx.rotate(textRotation);
ctx.translate(-tX, -tY);
}
-
+
if(animationDecimal >= 1 && config.showTooltips) {
var points = [{x:width/2,y:height/2}],
pAmount = 50;
@@ -1020,33 +1020,33 @@ window.Chart = function(context, options){
}
registerTooltip(ctx,{type:'shape',points:points},{label:data[i].label,value:data[i].value},'Pie');
}
-
+
if(config.segmentShowStroke){
ctx.lineWidth = config.segmentStrokeWidth;
ctx.strokeStyle = config.segmentStrokeColor;
ctx.stroke();
}
cumulativeAngle += segmentAngle;
- }
- }
+ }
+ }
}
var Doughnut = function(data,config,ctx){
var segmentTotal = 0;
-
+
//In case we have a canvas that is not a square. Minus 5 pixels as padding round the edge.
var doughnutRadius = Min([height/2,width/2]) - 5;
-
+
var cutoutRadius = doughnutRadius * (config.percentageInnerCutout/100);
-
+
for (var i=0; i<data.length; i++){
segmentTotal += data[i].value;
}
-
-
+
+
animationLoop(config,null,drawPieSegments,ctx);
-
-
+
+
function drawPieSegments (animationDecimal){
var cumulativeAngle = -Math.PI/2,
scaleAnimation = 1,
@@ -1081,30 +1081,30 @@ window.Chart = function(context, options){
}
registerTooltip(ctx,{type:'shape',points:points},{label:data[i].label,value:data[i].value},'Doughnut');
}
-
+
if(config.segmentShowStroke){
ctx.lineWidth = config.segmentStrokeWidth;
ctx.strokeStyle = config.segmentStrokeColor;
ctx.stroke();
}
cumulativeAngle += segmentAngle;
- }
- }
-
-
-
+ }
+ }
+
+
+
}
var Line = function(data,config,ctx){
var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString, valueHop,widestXLabel, xAxisLength,yAxisPosX,xAxisPosY, rotateLabels = 0;
-
+
calculateDrawingSizes();
-
+
valueBounds = getValueBounds();
//Check and set the scale
labelTemplateString = (config.scaleShowLabels)? config.scaleLabel : "";
if (!config.scaleOverride){
-
+
calculatedScale = calculateScale(scaleHeight,valueBounds.maxSteps,valueBounds.minSteps,valueBounds.maxValue,valueBounds.minValue,labelTemplateString);
}
else {
@@ -1116,11 +1116,11 @@ window.Chart = function(context, options){
}
populateLabels(labelTemplateString, calculatedScale.labels,calculatedScale.steps,config.scaleStartValue,config.scaleStepWidth);
}
-
+
scaleHop = Math.floor(scaleHeight/calculatedScale.steps);
calculateXAxisSize();
animationLoop(config,drawScale,drawLines,ctx);
-
+
function drawLines(animPc){
for (var i=0; i<data.datasets.length; i++){
ctx.strokeStyle = data.datasets[i].strokeColor;
@@ -1166,9 +1166,9 @@ window.Chart = function(context, options){
}
}
}
-
+
function yPos(dataSet,iteration){
- return xAxisPosY - animPc*(calculateOffset(data.datasets[dataSet].data[iteration],calculatedScale,scaleHop));
+ return xAxisPosY - animPc*(calculateOffset(data.datasets[dataSet].data[iteration],calculatedScale,scaleHop));
}
function xPos(iteration){
return yAxisPosX + (valueHop * iteration);
@@ -1182,8 +1182,8 @@ window.Chart = function(context, options){
ctx.moveTo(width-widestXLabel/2+5,xAxisPosY);
ctx.lineTo(width-(widestXLabel/2)-xAxisLength-5,xAxisPosY);
ctx.stroke();
-
-
+
+
if (rotateLabels > 0){
ctx.save();
ctx.textAlign = "right";
@@ -1200,26 +1200,26 @@ window.Chart = function(context, options){
ctx.fillText(data.labels[i], 0,0);
ctx.restore();
}
-
+
else{
- ctx.fillText(data.labels[i], yAxisPosX + i*valueHop,xAxisPosY + config.scaleFontSize+3);
+ ctx.fillText(data.labels[i], yAxisPosX + i*valueHop,xAxisPosY + config.scaleFontSize+3);
}
ctx.beginPath();
ctx.moveTo(yAxisPosX + i * valueHop, xAxisPosY+3);
-
+
//Check i isnt 0, so we dont go over the Y axis twice.
if(config.scaleShowGridLines && i>0){
ctx.lineWidth = config.scaleGridLineWidth;
- ctx.strokeStyle = config.scaleGridLineColor;
+ ctx.strokeStyle = config.scaleGridLineColor;
ctx.lineTo(yAxisPosX + i * valueHop, 5);
}
else{
- ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY+3);
+ ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY+3);
}
ctx.stroke();
}
-
+
//Y axis
ctx.lineWidth = config.scaleLineWidth;
ctx.strokeStyle = config.scaleLineColor;
@@ -1227,7 +1227,7 @@ window.Chart = function(context, options){
ctx.moveTo(yAxisPosX,xAxisPosY+5);
ctx.lineTo(yAxisPosX,5);
ctx.stroke();
-
+
ctx.textAlign = "right";
ctx.textBaseline = "middle";
for (var j=0; j<calculatedScale.steps; j++){
@@ -1236,20 +1236,20 @@ window.Chart = function(context, options){
if (config.scaleShowGridLines){
ctx.lineWidth = config.scaleGridLineWidth;
ctx.strokeStyle = config.scaleGridLineColor;
- ctx.lineTo(yAxisPosX + xAxisLength + 5,xAxisPosY - ((j+1) * scaleHop));
+ ctx.lineTo(yAxisPosX + xAxisLength + 5,xAxisPosY - ((j+1) * scaleHop));
}
else{
ctx.lineTo(yAxisPosX-0.5,xAxisPosY - ((j+1) * scaleHop));
}
-
+
ctx.stroke();
-
+
if (config.scaleShowLabels){
ctx.fillText(calculatedScale.labels[j],yAxisPosX-8,xAxisPosY - ((j+1) * scaleHop));
}
}
-
-
+
+
}
function calculateXAxisSize(){
var longestText = 1;
@@ -1264,11 +1264,11 @@ window.Chart = function(context, options){
longestText +=10;
}
xAxisLength = width - longestText - widestXLabel;
- valueHop = Math.floor(xAxisLength/(data.labels.length-1));
-
+ valueHop = Math.floor(xAxisLength/(data.labels.length-1));
+
yAxisPosX = width-widestXLabel/2-xAxisLength;
- xAxisPosY = scaleHeight + config.scaleFontSize/2;
- }
+ xAxisPosY = scaleHeight + config.scaleFontSize/2;
+ }
function calculateDrawingSizes(){
maxSize = height;
@@ -1284,7 +1284,7 @@ window.Chart = function(context, options){
rotateLabels = 45;
if (width/data.labels.length < Math.cos(rotateLabels) * widestXLabel){
rotateLabels = 90;
- maxSize -= widestXLabel;
+ maxSize -= widestXLabel;
}
else{
maxSize -= Math.sin(rotateLabels) * widestXLabel;
@@ -1293,21 +1293,21 @@ window.Chart = function(context, options){
else{
maxSize -= config.scaleFontSize;
}
-
+
//Add a little padding between the x line and the text
maxSize -= 5;
-
-
+
+
labelHeight = config.scaleFontSize;
-
+
maxSize -= labelHeight;
//Set 5 pixels greater than the font size to allow for a little padding from the X axis.
-
+
scaleHeight = maxSize;
-
+
//Then get the area above we can safely draw on.
-
- }
+
+ }
function getValueBounds() {
var upperValue = Number.MIN_VALUE;
var lowerValue = Number.MAX_VALUE;
@@ -1317,33 +1317,33 @@ window.Chart = function(context, options){
if ( data.datasets[i].data[j] < lowerValue) { lowerValue = data.datasets[i].data[j] };
}
};
-
+
var maxSteps = Math.floor((scaleHeight / (labelHeight*0.66)));
var minSteps = Math.floor((scaleHeight / labelHeight*0.5));
-
+
return {
maxValue : upperValue,
minValue : lowerValue,
maxSteps : maxSteps,
minSteps : minSteps
};
-
-
+
+
}
-
+
}
-
+
var Bar = function(data,config,ctx){
var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString, valueHop,widestXLabel, xAxisLength,yAxisPosX,xAxisPosY,barWidth, rotateLabels = 0;
-
+
calculateDrawingSizes();
-
+
valueBounds = getValueBounds();
//Check and set the scale
labelTemplateString = (config.scaleShowLabels)? config.scaleLabel : "";
if (!config.scaleOverride){
-
+
calculatedScale = calculateScale(scaleHeight,valueBounds.maxSteps,valueBounds.minSteps,valueBounds.maxValue,valueBounds.minValue,labelTemplateString);
}
else {
@@ -1355,11 +1355,11 @@ window.Chart = function(context, options){
}
populateLabels(labelTemplateString, calculatedScale.labels,calculatedScale.steps,config.scaleStartValue,config.scaleStepWidth);
}
-
+
scaleHop = Math.floor(scaleHeight/calculatedScale.steps);
calculateXAxisSize();
- animationLoop(config,drawScale,drawBars,ctx);
-
+ animationLoop(config,drawScale,drawBars,ctx);
+
function drawBars(animPc){
ctx.lineWidth = config.barStrokeWidth;
for (var i=0; i<data.datasets.length; i++){
@@ -1367,7 +1367,7 @@ window.Chart = function(context, options){
ctx.strokeStyle = data.datasets[i].strokeColor;
for (var j=0; j<data.datasets[i].data.length; j++){
var barOffset = yAxisPosX + config.barValueSpacing + valueHop*j + barWidth*i + config.barDatasetSpacing*i + config.barStrokeWidth*i;
-
+
ctx.beginPath();
ctx.moveTo(barOffset, xAxisPosY);
ctx.lineTo(barOffset, xAxisPosY - animPc*calculateOffset(data.datasets[i].data[j],calculatedScale,scaleHop)+(config.barStrokeWidth/2));
@@ -1389,7 +1389,7 @@ window.Chart = function(context, options){
}
}
}
-
+
}
function drawScale(){
//X axis line
@@ -1399,8 +1399,8 @@ window.Chart = function(context, options){
ctx.moveTo(width-widestXLabel/2+5,xAxisPosY);
ctx.lineTo(width-(widestXLabel/2)-xAxisLength-5,xAxisPosY);
ctx.stroke();
-
-
+
+
if (rotateLabels > 0){
ctx.save();
ctx.textAlign = "right";
@@ -1417,21 +1417,21 @@ window.Chart = function(context, options){
ctx.fillText(data.labels[i], 0,0);
ctx.restore();
}
-
+
else{
- ctx.fillText(data.labels[i], yAxisPosX + i*valueHop + valueHop/2,xAxisPosY + config.scaleFontSize+3);
+ ctx.fillText(data.labels[i], yAxisPosX + i*valueHop + valueHop/2,xAxisPosY + config.scaleFontSize+3);
}
ctx.beginPath();
ctx.moveTo(yAxisPosX + (i+1) * valueHop, xAxisPosY+3);
-
+
//Check i isnt 0, so we dont go over the Y axis twice.
ctx.lineWidth = config.scaleGridLineWidth;
- ctx.strokeStyle = config.scaleGridLineColor;
+ ctx.strokeStyle = config.scaleGridLineColor;
ctx.lineTo(yAxisPosX + (i+1) * valueHop, 5);
ctx.stroke();
}
-
+
//Y axis
ctx.lineWidth = config.scaleLineWidth;
ctx.strokeStyle = config.scaleLineColor;
@@ -1439,7 +1439,7 @@ window.Chart = function(context, options){
ctx.moveTo(yAxisPosX,xAxisPosY+5);
ctx.lineTo(yAxisPosX,5);
ctx.stroke();
-
+
ctx.textAlign = "right";
ctx.textBaseline = "middle";
for (var j=0; j<calculatedScale.steps; j++){
@@ -1448,19 +1448,19 @@ window.Chart = function(context, options){
if (config.scaleShowGridLines){
ctx.lineWidth = config.scaleGridLineWidth;
ctx.strokeStyle = config.scaleGridLineColor;
- ctx.lineTo(yAxisPosX + xAxisLength + 5,xAxisPosY - ((j+1) * scaleHop));
+ ctx.lineTo(yAxisPosX + xAxisLength + 5,xAxisPosY - ((j+1) * scaleHop));
}
else{
ctx.lineTo(yAxisPosX-0.5,xAxisPosY - ((j+1) * scaleHop));
}
-
+
ctx.stroke();
if (config.scaleShowLabels){
ctx.fillText(calculatedScale.labels[j],yAxisPosX-8,xAxisPosY - ((j+1) * scaleHop));
}
}
-
-
+
+
}
function calculateXAxisSize(){
var longestText = 1;
@@ -1475,13 +1475,13 @@ window.Chart = function(context, options){
longestText +=10;
}
xAxisLength = width - longestText - widestXLabel;
- valueHop = Math.floor(xAxisLength/(data.labels.length));
-
+ valueHop = Math.floor(xAxisLength/(data.labels.length));
+
barWidth = (valueHop - config.scaleGridLineWidth*2 - (config.barValueSpacing*2) - (config.barDatasetSpacing*data.datasets.length-1) - ((config.barStrokeWidth/2)*data.datasets.length-1))/data.datasets.length;
-
+
yAxisPosX = width-widestXLabel/2-xAxisLength;
- xAxisPosY = scaleHeight + config.scaleFontSize/2;
- }
+ xAxisPosY = scaleHeight + config.scaleFontSize/2;
+ }
function calculateDrawingSizes(){
maxSize = height;
@@ -1497,7 +1497,7 @@ window.Chart = function(context, options){
rotateLabels = 45;
if (width/data.labels.length < Math.cos(rotateLabels) * widestXLabel){
rotateLabels = 90;
- maxSize -= widestXLabel;
+ maxSize -= widestXLabel;
}
else{
maxSize -= Math.sin(rotateLabels) * widestXLabel;
@@ -1506,21 +1506,21 @@ window.Chart = function(context, options){
else{
maxSize -= config.scaleFontSize;
}
-
+
//Add a little padding between the x line and the text
maxSize -= 5;
-
-
+
+
labelHeight = config.scaleFontSize;
-
+
maxSize -= labelHeight;
//Set 5 pixels greater than the font size to allow for a little padding from the X axis.
-
+
scaleHeight = maxSize;
-
+
//Then get the area above we can safely draw on.
-
- }
+
+ }
function getValueBounds() {
var upperValue = Number.MIN_VALUE;
var lowerValue = Number.MAX_VALUE;
@@ -1530,39 +1530,39 @@ window.Chart = function(context, options){
if ( data.datasets[i].data[j] < lowerValue) { lowerValue = data.datasets[i].data[j] };
}
};
-
+
var maxSteps = Math.floor((scaleHeight / (labelHeight*0.66)));
var minSteps = Math.floor((scaleHeight / labelHeight*0.5));
-
+
return {
maxValue : upperValue,
minValue : lowerValue,
maxSteps : maxSteps,
minSteps : minSteps
};
-
-
+
+
}
}
-
+
function calculateOffset(val,calculatedScale,scaleHop){
var outerValue = calculatedScale.steps * calculatedScale.stepValue;
var adjustedValue = val - calculatedScale.graphMin;
var scalingFactor = CapValue(adjustedValue/outerValue,1,0);
return (scaleHop*calculatedScale.steps) * scalingFactor;
}
-
+
function animationLoop(config,drawScale,drawData,ctx){
var animFrameAmount = (config.animation)? 1/CapValue(config.animationSteps,Number.MAX_VALUE,1) : 1,
easingFunction = animationOptions[config.animationEasing],
percentAnimComplete =(config.animation)? 0 : 1;
-
-
-
+
+
+
if (typeof drawScale !== "function") drawScale = function(){};
-
+
requestAnimFrame(animLoop);
-
+
function animateFrame(){
var easeAdjustedAnimationPercent =(config.animation)? CapValue(easingFunction(percentAnimComplete),null,0) : 1;
clear(ctx);
@@ -1572,12 +1572,12 @@ window.Chart = function(context, options){
} else {
drawScale();
drawData(easeAdjustedAnimationPercent);
- }
+ }
}
function animLoop(){
//We need to check if the animation is incomplete (less than 1), or complete (1).
percentAnimComplete += animFrameAmount;
- animateFrame();
+ animateFrame();
//Stop the loop continuing forever
if (percentAnimComplete <= 1){
requestAnimFrame(animLoop);
@@ -1585,14 +1585,14 @@ window.Chart = function(context, options){
else{
if (typeof config.onAnimationComplete == "function") config.onAnimationComplete();
}
-
- }
-
+
+ }
+
}
//Declare global functions to be called within this namespace here.
-
-
+
+
// shim layer with setTimeout fallback
var requestAnimFrame = (function(){
return window.requestAnimationFrame ||
@@ -1609,13 +1609,13 @@ window.Chart = function(context, options){
var graphMin,graphMax,graphRange,stepValue,numberOfSteps,valueRange,rangeOrderOfMagnitude,decimalNum;
valueRange = maxValue - minValue;
rangeOrderOfMagnitude = calculateOrderOfMagnitude(valueRange);
- graphMin = Math.floor(minValue / (1 * Math.pow(10, rangeOrderOfMagnitude))) * Math.pow(10, rangeOrderOfMagnitude);
+ graphMin = Math.floor(minValue / (1 * Math.pow(10, rangeOrderOfMagnitude))) * Math.pow(10, rangeOrderOfMagnitude);
graphMax = Math.ceil(maxValue / (1 * Math.pow(10, rangeOrderOfMagnitude))) * Math.pow(10, rangeOrderOfMagnitude);
graphRange = graphMax - graphMin;
stepValue = Math.pow(10, rangeOrderOfMagnitude);
numberOfSteps = Math.round(graphRange / stepValue);
-
- //Compare number of steps to the max and min for that size graph, and add in half steps if need be.
+
+ //Compare number of steps to the max and min for that size graph, and add in half steps if need be.
while(numberOfSteps < minSteps || numberOfSteps > maxSteps) {
if (numberOfSteps < minSteps){
stepValue /= 2;
@@ -1634,9 +1634,9 @@ window.Chart = function(context, options){
steps : numberOfSteps,
stepValue : stepValue,
graphMin : graphMin,
- labels : labels
+ labels : labels
}
-
+
function calculateOrderOfMagnitude(val){
return Math.floor(Math.log(val) / Math.LN10);
}
@@ -1651,7 +1651,7 @@ window.Chart = function(context, options){
}
}
}
-
+
//Max value from array
function Max( array ){
return Math.max.apply( Math, array );
@@ -1694,9 +1694,9 @@ window.Chart = function(context, options){
else{
return 0;
}
-
- }
-
+
+ }
+
function mergeChartConfig(defaults,userDefined){
var returnObj = {};
for (var attrname in defaults) { returnObj[attrname] = defaults[attrname]; }
@@ -1709,25 +1709,25 @@ window.Chart = function(context, options){
}
return returnObj;
}
-
+
//Javascript micro templating by John Resig - source at http://ejohn.org/blog/javascript-micro-templating/
var cache = {};
-
+
function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
-
+
// Generate a reusable function that will serve as a template
// generator (and which will be cached).
new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +
-
+
// Introduce the data as local variables using with(){}
"with(obj){p.push('" +
-
+
// Convert the template into pure JavaScript
str
.replace(/[\r\t\n]/g, " ")
@@ -1738,7 +1738,7 @@ window.Chart = function(context, options){
.split("%>").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');");
-
+
// Provide some basic currying to the user
return data ? fn( data ) : fn;
};

0 comments on commit 238844b

Please sign in to comment.
Something went wrong with that request. Please try again.