@@ -99,6 +99,24 @@ function computeTextSize(context, tick, font) {
9999 context . measureText ( tick ) . width ;
100100}
101101
102+ function parseFontOptions ( options , nestedOpts ) {
103+ return helpers . extend ( helpers . options . _parseFont ( {
104+ fontFamily : valueOrDefault ( nestedOpts . fontFamily , options . fontFamily ) ,
105+ fontSize : valueOrDefault ( nestedOpts . fontSize , options . fontSize ) ,
106+ fontStyle : valueOrDefault ( nestedOpts . fontStyle , options . fontStyle ) ,
107+ lineHeight : valueOrDefault ( nestedOpts . lineHeight , options . lineHeight )
108+ } ) , {
109+ color : helpers . options . resolve ( [ nestedOpts . fontColor , options . fontColor , defaults . global . defaultFontColor ] )
110+ } ) ;
111+ }
112+
113+ function parseTickFontOptions ( options ) {
114+ var minor = parseFontOptions ( options , options . minor ) ;
115+ var major = options . major . enabled ? parseFontOptions ( options , options . major ) : minor ;
116+
117+ return { minor : minor , major : major } ;
118+ }
119+
102120module . exports = Element . extend ( {
103121 /**
104122 * Get the padding needed for the scale
@@ -128,29 +146,16 @@ module.exports = Element.extend({
128146 // Any function defined here is inherited by all scale types.
129147 // Any function can be extended by the scale type
130148
149+ /**
150+ * Provided for backward compatibility, not available anymore
151+ * @function Chart.Scale.mergeTicksOptions
152+ * @deprecated since version 2.8.0
153+ * @todo remove at version 3
154+ */
131155 mergeTicksOptions : function ( ) {
132- var ticks = this . options . ticks ;
133- if ( ticks . minor === false ) {
134- ticks . minor = {
135- display : false
136- } ;
137- }
138- if ( ticks . major === false ) {
139- ticks . major = {
140- display : false
141- } ;
142- }
143- for ( var key in ticks ) {
144- if ( key !== 'major' && key !== 'minor' ) {
145- if ( typeof ticks . minor [ key ] === 'undefined' ) {
146- ticks . minor [ key ] = ticks [ key ] ;
147- }
148- if ( typeof ticks . major [ key ] === 'undefined' ) {
149- ticks . major [ key ] = ticks [ key ] ;
150- }
151- }
152- }
156+ // noop
153157 } ,
158+
154159 beforeUpdate : function ( ) {
155160 helpers . callback ( this . options . beforeUpdate , [ this ] ) ;
156161 } ,
@@ -628,7 +633,7 @@ module.exports = Element.extend({
628633 _autoSkip : function ( ticks ) {
629634 var me = this ;
630635 var isHorizontal = me . isHorizontal ( ) ;
631- var optionTicks = me . options . ticks . minor ;
636+ var optionTicks = me . options . ticks ;
632637 var tickCount = ticks . length ;
633638 var skipRatio = false ;
634639 var maxTicks = optionTicks . maxTicksLimit ;
@@ -673,7 +678,7 @@ module.exports = Element.extend({
673678 _tickSize : function ( ) {
674679 var me = this ;
675680 var isHorizontal = me . isHorizontal ( ) ;
676- var optionTicks = me . options . ticks . minor ;
681+ var optionTicks = me . options . ticks ;
677682
678683 // Calculate space needed by label in axis direction.
679684 var rot = helpers . toRadians ( me . labelRotation ) ;
@@ -683,7 +688,7 @@ module.exports = Element.extend({
683688 var padding = optionTicks . autoSkipPadding || 0 ;
684689 var w = ( me . longestLabelWidth + padding ) || 0 ;
685690
686- var tickFont = helpers . options . _parseFont ( optionTicks ) ;
691+ var tickFont = parseTickFontOptions ( optionTicks ) . minor ;
687692 var h = ( me . _maxLabelLines * tickFont . lineHeight + padding ) || 0 ;
688693
689694 // Calculate space needed for 1 tick in axis direction.
@@ -732,10 +737,7 @@ module.exports = Element.extend({
732737
733738 var chart = me . chart ;
734739 var context = me . ctx ;
735- var globalDefaults = defaults . global ;
736- var defaultFontColor = globalDefaults . defaultFontColor ;
737- var optionTicks = options . ticks . minor ;
738- var optionMajorTicks = options . ticks . major || optionTicks ;
740+ var optionTicks = options . ticks ;
739741 var gridLines = options . gridLines ;
740742 var scaleLabel = options . scaleLabel ;
741743 var position = options . position ;
@@ -744,20 +746,15 @@ module.exports = Element.extend({
744746 var isMirrored = optionTicks . mirror ;
745747 var isHorizontal = me . isHorizontal ( ) ;
746748
747- var parseFont = helpers . options . _parseFont ;
748749 var ticks = optionTicks . display && optionTicks . autoSkip ? me . _autoSkip ( me . getTicks ( ) ) : me . getTicks ( ) ;
749- var tickFontColor = valueOrDefault ( optionTicks . fontColor , defaultFontColor ) ;
750- var tickFont = parseFont ( optionTicks ) ;
751- var lineHeight = tickFont . lineHeight ;
752- var majorTickFontColor = valueOrDefault ( optionMajorTicks . fontColor , defaultFontColor ) ;
753- var majorTickFont = parseFont ( optionMajorTicks ) ;
750+ var tickFonts = parseTickFontOptions ( optionTicks ) ;
754751 var tickPadding = optionTicks . padding ;
755752 var labelOffset = optionTicks . labelOffset ;
756753
757754 var tl = gridLines . drawTicks ? gridLines . tickMarkLength : 0 ;
758755
759- var scaleLabelFontColor = valueOrDefault ( scaleLabel . fontColor , defaultFontColor ) ;
760- var scaleLabelFont = parseFont ( scaleLabel ) ;
756+ var scaleLabelFontColor = valueOrDefault ( scaleLabel . fontColor , defaults . global . defaultFontColor ) ;
757+ var scaleLabelFont = helpers . options . _parseFont ( scaleLabel ) ;
761758 var scaleLabelPadding = helpers . options . toPadding ( scaleLabel . padding ) ;
762759 var labelRotationRadians = helpers . toRadians ( me . labelRotation ) ;
763760
@@ -794,6 +791,8 @@ module.exports = Element.extend({
794791 }
795792
796793 var label = tick . label ;
794+ var tickFont = tick . major ? tickFonts . major : tickFonts . minor ;
795+ var lineHeight = tickFont . lineHeight ;
797796 var lineWidth , lineColor , borderDash , borderDashOffset ;
798797 if ( index === me . zeroLineIndex && options . offset === gridLines . offsetGridLines ) {
799798 // Draw the first index specially
@@ -918,12 +917,14 @@ module.exports = Element.extend({
918917 }
919918
920919 if ( optionTicks . display ) {
920+ var tickFont = itemToDraw . major ? tickFonts . major : tickFonts . minor ;
921+
921922 // Make sure we draw text in the correct color and font
922923 context . save ( ) ;
923924 context . translate ( itemToDraw . labelX , itemToDraw . labelY ) ;
924925 context . rotate ( itemToDraw . rotation ) ;
925- context . font = itemToDraw . major ? majorTickFont . string : tickFont . string ;
926- context . fillStyle = itemToDraw . major ? majorTickFontColor : tickFontColor ;
926+ context . font = tickFont . string ;
927+ context . fillStyle = tickFont . color ;
927928 context . textBaseline = 'middle' ;
928929 context . textAlign = itemToDraw . textAlign ;
929930
@@ -933,7 +934,7 @@ module.exports = Element.extend({
933934 for ( var i = 0 ; i < label . length ; ++ i ) {
934935 // We just make sure the multiline element is a string here..
935936 context . fillText ( '' + label [ i ] , 0 , y ) ;
936- y += lineHeight ;
937+ y += tickFont . lineHeight ;
937938 }
938939 } else {
939940 context . fillText ( label , 0 , y ) ;
0 commit comments