@@ -3,7 +3,7 @@ import Element from './core.element';
33import { _alignPixel , _measureText , renderText , clipArea , unclipArea } from '../helpers/helpers.canvas' ;
44import { callback as call , each , finiteOrDefault , isArray , isFinite , isNullOrUndef , isObject , valueOrDefault } from '../helpers/helpers.core' ;
55import { _factorize , toDegrees , toRadians , _int16Range , HALF_PI } from '../helpers/helpers.math' ;
6- import { toFont , resolve , toPadding } from '../helpers/helpers.options' ;
6+ import { toFont , toPadding } from '../helpers/helpers.options' ;
77import Ticks from './core.ticks' ;
88
99/**
@@ -34,9 +34,13 @@ defaults.set('scale', {
3434 drawOnChartArea : true ,
3535 drawTicks : true ,
3636 tickLength : 10 ,
37+ tickWidth : ( _ctx , options ) => options . lineWidth ,
38+ tickColor : ( _ctx , options ) => options . color ,
3739 offsetGridLines : false ,
3840 borderDash : [ ] ,
39- borderDashOffset : 0.0
41+ borderDashOffset : 0.0 ,
42+ borderColor : ( _ctx , options ) => options . color ,
43+ borderWidth : ( _ctx , options ) => options . lineWidth
4044 } ,
4145
4246 // scale label
@@ -80,15 +84,9 @@ defaults.route('scale.gridLines', 'color', '', 'borderColor');
8084defaults . route ( 'scale.scaleLabel' , 'color' , '' , 'color' ) ;
8185
8286defaults . describe ( 'scales' , {
83- _defaultId : ( ctx , options ) => options . axis === options . indexAxis ? '_index_' : '_value_' ,
8487 _fallback : 'scale' ,
85- _scriptable : ( name ) => ! name . startsWith ( 'before' ) && ! name . startsWith ( 'after' ) ,
86- ticks : {
87- _scriptable : ( name ) => name !== 'callback'
88- } ,
89- gridLines : {
90- _indexable : ( name ) => name !== 'borderDash' && name !== 'tickBorderDash'
91- }
88+ _scriptable : ( name ) => ! name . startsWith ( 'before' ) && ! name . startsWith ( 'after' ) && name !== 'callback' && name !== 'parser' ,
89+ _indexable : ( name ) => name !== 'borderDash' && name !== 'tickBorderDash' ,
9290} ) ;
9391
9492/**
@@ -408,7 +406,7 @@ export default class Scale extends Element {
408406 const me = this ;
409407 me . options = options ;
410408
411- me . axis = me . isHorizontal ( ) ? 'x' : 'y' ;
409+ me . axis = options . axis ;
412410
413411 // parse min/max value, so we can properly determine min/max for other scales
414412 me . _userMin = me . parse ( options . min ) ;
@@ -1218,8 +1216,8 @@ export default class Scale extends Element {
12181216 const tl = getTickMarkLength ( gridLines ) ;
12191217 const items = [ ] ;
12201218
1221- let context = this . getContext ( 0 ) ;
1222- const axisWidth = gridLines . drawBorder ? resolve ( [ gridLines . borderWidth , gridLines . lineWidth , 0 ] , context , 0 ) : 0 ;
1219+ const borderOpts = gridLines . setContext ( me . getContext ( 0 ) ) ;
1220+ const axisWidth = borderOpts . drawBorder ? borderOpts . borderWidth : 0 ;
12231221 const axisHalfWidth = axisWidth / 2 ;
12241222 const alignBorderValue = function ( pixel ) {
12251223 return _alignPixel ( chart , pixel , axisWidth ) ;
@@ -1280,17 +1278,17 @@ export default class Scale extends Element {
12801278 }
12811279
12821280 for ( i = 0 ; i < ticksLength ; ++ i ) {
1283- context = this . getContext ( i ) ;
1281+ const optsAtIndex = gridLines . setContext ( me . getContext ( i ) ) ;
12841282
1285- const lineWidth = resolve ( [ gridLines . lineWidth ] , context , i ) ;
1286- const lineColor = resolve ( [ gridLines . color ] , context , i ) ;
1283+ const lineWidth = optsAtIndex . lineWidth ;
1284+ const lineColor = optsAtIndex . color ;
12871285 const borderDash = gridLines . borderDash || [ ] ;
1288- const borderDashOffset = resolve ( [ gridLines . borderDashOffset ] , context , i ) ;
1286+ const borderDashOffset = optsAtIndex . borderDashOffset ;
12891287
1290- const tickWidth = resolve ( [ gridLines . tickWidth , lineWidth ] , context , i ) ;
1291- const tickColor = resolve ( [ gridLines . tickColor , lineColor ] , context , i ) ;
1292- const tickBorderDash = gridLines . tickBorderDash || borderDash ;
1293- const tickBorderDashOffset = resolve ( [ gridLines . tickBorderDashOffset , borderDashOffset ] , context , i ) ;
1288+ const tickWidth = optsAtIndex . tickWidth ;
1289+ const tickColor = optsAtIndex . tickColor ;
1290+ const tickBorderDash = optsAtIndex . tickBorderDash || [ ] ;
1291+ const tickBorderDashOffset = optsAtIndex . tickBorderDashOffset ;
12941292
12951293 lineValue = getPixelForGridLine ( me , i , offsetGridLines ) ;
12961294
@@ -1398,14 +1396,15 @@ export default class Scale extends Element {
13981396 tick = ticks [ i ] ;
13991397 label = tick . label ;
14001398
1399+ const optsAtIndex = optionTicks . setContext ( me . getContext ( i ) ) ;
14011400 pixel = me . getPixelForTick ( i ) + optionTicks . labelOffset ;
14021401 font = me . _resolveTickFontOptions ( i ) ;
14031402 lineHeight = font . lineHeight ;
14041403 lineCount = isArray ( label ) ? label . length : 1 ;
14051404 const halfCount = lineCount / 2 ;
1406- const color = resolve ( [ optionTicks . color ] , me . getContext ( i ) , i ) ;
1407- const strokeColor = resolve ( [ optionTicks . textStrokeColor ] , me . getContext ( i ) , i ) ;
1408- const strokeWidth = resolve ( [ optionTicks . textStrokeWidth ] , me . getContext ( i ) , i ) ;
1405+ const color = optsAtIndex . color ;
1406+ const strokeColor = optsAtIndex . textStrokeColor ;
1407+ const strokeWidth = optsAtIndex . textStrokeWidth ;
14091408
14101409 if ( isHorizontal ) {
14111410 x = pixel ;
@@ -1551,8 +1550,8 @@ export default class Scale extends Element {
15511550 const gridLines = me . options . gridLines ;
15521551 const ctx = me . ctx ;
15531552 const chart = me . chart ;
1554- let context = me . getContext ( 0 ) ;
1555- const axisWidth = gridLines . drawBorder ? resolve ( [ gridLines . borderWidth , gridLines . lineWidth , 0 ] , context , 0 ) : 0 ;
1553+ const borderOpts = gridLines . setContext ( me . getContext ( 0 ) ) ;
1554+ const axisWidth = gridLines . drawBorder ? borderOpts . borderWidth : 0 ;
15561555 const items = me . _gridLineItems || ( me . _gridLineItems = me . _computeGridLineItems ( chartArea ) ) ;
15571556 let i , ilen ;
15581557
@@ -1597,24 +1596,23 @@ export default class Scale extends Element {
15971596
15981597 if ( axisWidth ) {
15991598 // Draw the line at the edge of the axis
1600- const firstLineWidth = axisWidth ;
1601- context = me . getContext ( me . _ticksLength - 1 ) ;
1602- const lastLineWidth = resolve ( [ gridLines . lineWidth , 1 ] , context , me . _ticksLength - 1 ) ;
1599+ const edgeOpts = gridLines . setContext ( me . getContext ( me . _ticksLength - 1 ) ) ;
1600+ const lastLineWidth = edgeOpts . lineWidth ;
16031601 const borderValue = me . _borderValue ;
16041602 let x1 , x2 , y1 , y2 ;
16051603
16061604 if ( me . isHorizontal ( ) ) {
1607- x1 = _alignPixel ( chart , me . left , firstLineWidth ) - firstLineWidth / 2 ;
1605+ x1 = _alignPixel ( chart , me . left , axisWidth ) - axisWidth / 2 ;
16081606 x2 = _alignPixel ( chart , me . right , lastLineWidth ) + lastLineWidth / 2 ;
16091607 y1 = y2 = borderValue ;
16101608 } else {
1611- y1 = _alignPixel ( chart , me . top , firstLineWidth ) - firstLineWidth / 2 ;
1609+ y1 = _alignPixel ( chart , me . top , axisWidth ) - axisWidth / 2 ;
16121610 y2 = _alignPixel ( chart , me . bottom , lastLineWidth ) + lastLineWidth / 2 ;
16131611 x1 = x2 = borderValue ;
16141612 }
16151613
16161614 ctx . lineWidth = axisWidth ;
1617- ctx . strokeStyle = resolve ( [ gridLines . borderColor , gridLines . color ] , context , 0 ) ;
1615+ ctx . strokeStyle = edgeOpts . borderColor ;
16181616 ctx . beginPath ( ) ;
16191617 ctx . moveTo ( x1 , y1 ) ;
16201618 ctx . lineTo ( x2 , y2 ) ;
@@ -1800,11 +1798,8 @@ export default class Scale extends Element {
18001798 * @protected
18011799 */
18021800 _resolveTickFontOptions ( index ) {
1803- const me = this ;
1804- const chart = me . chart ;
1805- const options = me . options . ticks ;
1806- const context = me . getContext ( index ) ;
1807- return toFont ( resolve ( [ options . font ] , context ) , chart . options . font ) ;
1801+ const opts = this . options . ticks . setContext ( this . getContext ( index ) ) ;
1802+ return toFont ( opts . font ) ;
18081803 }
18091804}
18101805
0 commit comments