Skip to content

Commit

Permalink
0.2 Update
Browse files Browse the repository at this point in the history
- Fixes hard coded scales now longer not one step out of sync
  • Loading branch information
nnnick committed Apr 12, 2013
1 parent 75f4d21 commit 7a55a16
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 71 deletions.
47 changes: 15 additions & 32 deletions Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,7 @@ var Chart = function(context){
graphMin : config.scaleStartValue,
labels : []
}
for (var i=0; i<calculatedScale.steps; i++){
if(labelTemplateString){
calculatedScale.labels.push(tmpl(labelTemplateString,{value:(config.scaleStartValue + (config.scaleStepWidth * i)).toFixed(getDecimalPlaces (config.scaleStepWidth))}));
}
}
populateLabels(labelTemplateString, calculatedScale.labels,calculatedScale.steps,config.scaleStartValue,config.scaleStepWidth);
}

scaleHop = maxSize/(calculatedScale.steps);
Expand Down Expand Up @@ -516,11 +512,7 @@ var Chart = function(context){
graphMin : config.scaleStartValue,
labels : []
}
for (var i=0; i<calculatedScale.steps; i++){
if(labelTemplateString){
calculatedScale.labels.push(tmpl(labelTemplateString,{value:(config.scaleStartValue + (config.scaleStepWidth * i)).toFixed(getDecimalPlaces (config.scaleStepWidth))}));
}
}
populateLabels(labelTemplateString, calculatedScale.labels,calculatedScale.steps,config.scaleStartValue,config.scaleStepWidth);
}

scaleHop = maxSize/(calculatedScale.steps);
Expand Down Expand Up @@ -813,11 +805,7 @@ var Chart = function(context){
graphMin : config.scaleStartValue,
labels : []
}
for (var i=0; i<calculatedScale.steps; i++){
if(labelTemplateString){
calculatedScale.labels.push(tmpl(labelTemplateString,{value:(config.scaleStartValue + (config.scaleStepWidth * i)).toFixed(getDecimalPlaces (config.scaleStepWidth))}));
}
}
populateLabels(labelTemplateString, calculatedScale.labels,calculatedScale.steps,config.scaleStartValue,config.scaleStepWidth);
}

scaleHop = Math.floor(scaleHeight/calculatedScale.steps);
Expand Down Expand Up @@ -1049,11 +1037,7 @@ var Chart = function(context){
graphMin : config.scaleStartValue,
labels : []
}
for (var i=0; i<calculatedScale.steps; i++){
if(labelTemplateString){
calculatedScale.labels.push(tmpl(labelTemplateString,{value:(config.scaleStartValue + (config.scaleStepWidth * i)).toFixed(getDecimalPlaces (config.scaleStepWidth))}));
}
}
populateLabels(labelTemplateString, calculatedScale.labels,calculatedScale.steps,config.scaleStartValue,config.scaleStepWidth);
}

scaleHop = Math.floor(scaleHeight/calculatedScale.steps);
Expand Down Expand Up @@ -1324,19 +1308,9 @@ var Chart = function(context){
numberOfSteps = Math.round(graphRange/stepValue);
}
};



//Create an array of all the labels by interpolating the string.

var labels = [];

if(labelTemplateString){
//Fix floating point errors by setting to fixed the on the same decimal as the stepValue.
for (var i=1; i<numberOfSteps+1; i++){
labels.push(tmpl(labelTemplateString,{value:(graphMin + (stepValue*i)).toFixed(getDecimalPlaces (stepValue))}));
}
}
populateLabels(labelTemplateString, labels, numberOfSteps, graphMin, stepValue);

return {
steps : numberOfSteps,
Expand All @@ -1352,6 +1326,16 @@ var Chart = function(context){


}

//Populate an array of all the labels by interpolating the string.
function populateLabels(labelTemplateString, labels, numberOfSteps, graphMin, stepValue) {
if (labelTemplateString) {
//Fix floating point errors by setting to fixed the on the same decimal as the stepValue.
for (var i = 1; i < numberOfSteps + 1; i++) {
labels.push(tmpl(labelTemplateString, {value: (graphMin + (stepValue * i)).toFixed(getDecimalPlaces(stepValue))}));
}
}
}

//Max value from array
function Max( array ){
Expand Down Expand Up @@ -1440,4 +1424,3 @@ var Chart = function(context){
}



Loading

0 comments on commit 7a55a16

Please sign in to comment.