@@ -376,11 +376,7 @@ var Chart = function(context){
376
376
graphMin : config . scaleStartValue ,
377
377
labels : [ ]
378
378
}
379
- for ( var i = 0 ; i < calculatedScale . steps ; i ++ ) {
380
- if ( labelTemplateString ) {
381
- calculatedScale . labels . push ( tmpl ( labelTemplateString , { value :( config . scaleStartValue + ( config . scaleStepWidth * i ) ) . toFixed ( getDecimalPlaces ( config . scaleStepWidth ) ) } ) ) ;
382
- }
383
- }
379
+ populateLabels ( labelTemplateString , calculatedScale . labels , calculatedScale . steps , config . scaleStartValue , config . scaleStepWidth ) ;
384
380
}
385
381
386
382
scaleHop = maxSize / ( calculatedScale . steps ) ;
@@ -516,11 +512,7 @@ var Chart = function(context){
516
512
graphMin : config . scaleStartValue ,
517
513
labels : [ ]
518
514
}
519
- for ( var i = 0 ; i < calculatedScale . steps ; i ++ ) {
520
- if ( labelTemplateString ) {
521
- calculatedScale . labels . push ( tmpl ( labelTemplateString , { value :( config . scaleStartValue + ( config . scaleStepWidth * i ) ) . toFixed ( getDecimalPlaces ( config . scaleStepWidth ) ) } ) ) ;
522
- }
523
- }
515
+ populateLabels ( labelTemplateString , calculatedScale . labels , calculatedScale . steps , config . scaleStartValue , config . scaleStepWidth ) ;
524
516
}
525
517
526
518
scaleHop = maxSize / ( calculatedScale . steps ) ;
@@ -813,11 +805,7 @@ var Chart = function(context){
813
805
graphMin : config . scaleStartValue ,
814
806
labels : [ ]
815
807
}
816
- for ( var i = 0 ; i < calculatedScale . steps ; i ++ ) {
817
- if ( labelTemplateString ) {
818
- calculatedScale . labels . push ( tmpl ( labelTemplateString , { value :( config . scaleStartValue + ( config . scaleStepWidth * i ) ) . toFixed ( getDecimalPlaces ( config . scaleStepWidth ) ) } ) ) ;
819
- }
820
- }
808
+ populateLabels ( labelTemplateString , calculatedScale . labels , calculatedScale . steps , config . scaleStartValue , config . scaleStepWidth ) ;
821
809
}
822
810
823
811
scaleHop = Math . floor ( scaleHeight / calculatedScale . steps ) ;
@@ -1049,11 +1037,7 @@ var Chart = function(context){
1049
1037
graphMin : config . scaleStartValue ,
1050
1038
labels : [ ]
1051
1039
}
1052
- for ( var i = 0 ; i < calculatedScale . steps ; i ++ ) {
1053
- if ( labelTemplateString ) {
1054
- calculatedScale . labels . push ( tmpl ( labelTemplateString , { value :( config . scaleStartValue + ( config . scaleStepWidth * i ) ) . toFixed ( getDecimalPlaces ( config . scaleStepWidth ) ) } ) ) ;
1055
- }
1056
- }
1040
+ populateLabels ( labelTemplateString , calculatedScale . labels , calculatedScale . steps , config . scaleStartValue , config . scaleStepWidth ) ;
1057
1041
}
1058
1042
1059
1043
scaleHop = Math . floor ( scaleHeight / calculatedScale . steps ) ;
@@ -1324,19 +1308,9 @@ var Chart = function(context){
1324
1308
numberOfSteps = Math . round ( graphRange / stepValue ) ;
1325
1309
}
1326
1310
} ;
1327
-
1328
1311
1329
-
1330
- //Create an array of all the labels by interpolating the string.
1331
-
1332
1312
var labels = [ ] ;
1333
-
1334
- if ( labelTemplateString ) {
1335
- //Fix floating point errors by setting to fixed the on the same decimal as the stepValue.
1336
- for ( var i = 1 ; i < numberOfSteps + 1 ; i ++ ) {
1337
- labels . push ( tmpl ( labelTemplateString , { value :( graphMin + ( stepValue * i ) ) . toFixed ( getDecimalPlaces ( stepValue ) ) } ) ) ;
1338
- }
1339
- }
1313
+ populateLabels ( labelTemplateString , labels , numberOfSteps , graphMin , stepValue ) ;
1340
1314
1341
1315
return {
1342
1316
steps : numberOfSteps ,
@@ -1352,6 +1326,16 @@ var Chart = function(context){
1352
1326
1353
1327
1354
1328
}
1329
+
1330
+ //Populate an array of all the labels by interpolating the string.
1331
+ function populateLabels ( labelTemplateString , labels , numberOfSteps , graphMin , stepValue ) {
1332
+ if ( labelTemplateString ) {
1333
+ //Fix floating point errors by setting to fixed the on the same decimal as the stepValue.
1334
+ for ( var i = 1 ; i < numberOfSteps + 1 ; i ++ ) {
1335
+ labels . push ( tmpl ( labelTemplateString , { value : ( graphMin + ( stepValue * i ) ) . toFixed ( getDecimalPlaces ( stepValue ) ) } ) ) ;
1336
+ }
1337
+ }
1338
+ }
1355
1339
1356
1340
//Max value from array
1357
1341
function Max ( array ) {
@@ -1440,4 +1424,3 @@ var Chart = function(context){
1440
1424
}
1441
1425
1442
1426
1443
-
0 commit comments