@@ -93,7 +93,7 @@ function fitWithPointLabels(scale) {
9393 const labelSizes = [ ] ;
9494 const padding = [ ] ;
9595
96- const valueCount = scale . chart . data . labels . length ;
96+ const valueCount = scale . getLabels ( ) . length ;
9797 for ( i = 0 ; i < valueCount ; i ++ ) {
9898 const opts = scale . options . pointLabels . setContext ( scale . getContext ( i ) ) ;
9999 padding [ i ] = opts . padding ;
@@ -196,17 +196,11 @@ function adjustPointPositionForLabelHeight(angle, textSize, position) {
196196 }
197197}
198198
199- function drawPointLabels ( scale ) {
200- const ctx = scale . ctx ;
201- const opts = scale . options ;
202- const pointLabelOpts = opts . pointLabels ;
203-
204- ctx . save ( ) ;
205-
206- ctx . textBaseline = 'middle' ;
199+ function drawPointLabels ( scale , labelCount ) {
200+ const { ctx, options : { pointLabels} } = scale ;
207201
208- for ( let i = scale . chart . data . labels . length - 1 ; i >= 0 ; i -- ) {
209- const optsAtIndex = pointLabelOpts . setContext ( scale . getContext ( i ) ) ;
202+ for ( let i = labelCount - 1 ; i >= 0 ; i -- ) {
203+ const optsAtIndex = pointLabels . setContext ( scale . getContext ( i ) ) ;
210204 const plFont = toFont ( optsAtIndex . font ) ;
211205 const { x, y, textAlign} = scale . _pointLabelItems [ i ] ;
212206 renderText (
@@ -218,45 +212,47 @@ function drawPointLabels(scale) {
218212 {
219213 color : optsAtIndex . color ,
220214 textAlign : textAlign ,
215+ textBaseline : 'middle'
221216 }
222217 ) ;
223218 }
224- ctx . restore ( ) ;
225219}
226220
227- function drawRadiusLine ( scale , gridLineOpts , radius ) {
221+ function pathRadiusLine ( scale , radius , circular , labelCount ) {
222+ const { ctx} = scale ;
223+ if ( circular ) {
224+ // Draw circular arcs between the points
225+ ctx . arc ( scale . xCenter , scale . yCenter , radius , 0 , TAU ) ;
226+ } else {
227+ // Draw straight lines connecting each index
228+ let pointPosition = scale . getPointPosition ( 0 , radius ) ;
229+ ctx . moveTo ( pointPosition . x , pointPosition . y ) ;
230+
231+ for ( let i = 1 ; i < labelCount ; i ++ ) {
232+ pointPosition = scale . getPointPosition ( i , radius ) ;
233+ ctx . lineTo ( pointPosition . x , pointPosition . y ) ;
234+ }
235+ }
236+ }
237+
238+ function drawRadiusLine ( scale , gridLineOpts , radius , labelCount ) {
228239 const ctx = scale . ctx ;
229240 const circular = gridLineOpts . circular ;
230- const valueCount = scale . chart . data . labels . length ;
231241
232- const lineColor = gridLineOpts . color ;
233- const lineWidth = gridLineOpts . lineWidth ;
234- let pointPosition ;
242+ const { color, lineWidth} = gridLineOpts ;
235243
236- if ( ( ! circular && ! valueCount ) || ! lineColor || ! lineWidth || radius < 0 ) {
244+ if ( ( ! circular && ! labelCount ) || ! color || ! lineWidth || radius < 0 ) {
237245 return ;
238246 }
239247
240248 ctx . save ( ) ;
241- ctx . strokeStyle = lineColor ;
249+ ctx . strokeStyle = color ;
242250 ctx . lineWidth = lineWidth ;
243251 ctx . setLineDash ( gridLineOpts . borderDash ) ;
244252 ctx . lineDashOffset = gridLineOpts . borderDashOffset ;
245253
246254 ctx . beginPath ( ) ;
247- if ( circular ) {
248- // Draw circular arcs between the points
249- ctx . arc ( scale . xCenter , scale . yCenter , radius , 0 , TAU ) ;
250- } else {
251- // Draw straight lines connecting each index
252- pointPosition = scale . getPointPosition ( 0 , radius ) ;
253- ctx . moveTo ( pointPosition . x , pointPosition . y ) ;
254-
255- for ( let i = 1 ; i < valueCount ; i ++ ) {
256- pointPosition = scale . getPointPosition ( i , radius ) ;
257- ctx . lineTo ( pointPosition . x , pointPosition . y ) ;
258- }
259- }
255+ pathRadiusLine ( scale , radius , circular , labelCount ) ;
260256 ctx . closePath ( ) ;
261257 ctx . stroke ( ) ;
262258 ctx . restore ( ) ;
@@ -319,7 +315,7 @@ export default class RadialLinearScale extends LinearScaleBase {
319315 LinearScaleBase . prototype . generateTickLabels . call ( me , ticks ) ;
320316
321317 // Point labels
322- me . _pointLabels = me . chart . data . labels . map ( ( value , index ) => {
318+ me . _pointLabels = me . getLabels ( ) . map ( ( value , index ) => {
323319 const label = callCallback ( me . options . pointLabels . callback , [ value , index ] , me ) ;
324320 return label || label === 0 ? label : '' ;
325321 } ) ;
@@ -428,38 +424,56 @@ export default class RadialLinearScale extends LinearScaleBase {
428424 } ;
429425 }
430426
427+ /**
428+ * @protected
429+ */
430+ drawBackground ( ) {
431+ const me = this ;
432+ const { backgroundColor, gridLines : { circular} } = me . options ;
433+ if ( backgroundColor ) {
434+ const ctx = me . ctx ;
435+ ctx . save ( ) ;
436+ ctx . beginPath ( ) ;
437+ pathRadiusLine ( me , me . getDistanceFromCenterForValue ( me . _endValue ) , circular , me . getLabels ( ) . length ) ;
438+ ctx . closePath ( ) ;
439+ ctx . fillStyle = backgroundColor ;
440+ ctx . fill ( ) ;
441+ ctx . restore ( ) ;
442+ }
443+ }
444+
431445 /**
432446 * @protected
433447 */
434448 drawGrid ( ) {
435449 const me = this ;
436450 const ctx = me . ctx ;
437451 const opts = me . options ;
438- const gridLineOpts = opts . gridLines ;
439- const angleLineOpts = opts . angleLines ;
452+ const { angleLines, gridLines} = opts ;
453+ const labelCount = me . getLabels ( ) . length ;
454+
440455 let i , offset , position ;
441456
442457 if ( opts . pointLabels . display ) {
443- drawPointLabels ( me ) ;
458+ drawPointLabels ( me , labelCount ) ;
444459 }
445460
446- if ( gridLineOpts . display ) {
461+ if ( gridLines . display ) {
447462 me . ticks . forEach ( ( tick , index ) => {
448463 if ( index !== 0 ) {
449- offset = me . getDistanceFromCenterForValue ( me . ticks [ index ] . value ) ;
450- const optsAtIndex = gridLineOpts . setContext ( me . getContext ( index - 1 ) ) ;
451- drawRadiusLine ( me , optsAtIndex , offset ) ;
464+ offset = me . getDistanceFromCenterForValue ( tick . value ) ;
465+ const optsAtIndex = gridLines . setContext ( me . getContext ( index - 1 ) ) ;
466+ drawRadiusLine ( me , optsAtIndex , offset , labelCount ) ;
452467 }
453468 } ) ;
454469 }
455470
456- if ( angleLineOpts . display ) {
471+ if ( angleLines . display ) {
457472 ctx . save ( ) ;
458473
459- for ( i = me . chart . data . labels . length - 1 ; i >= 0 ; i -- ) {
460- const optsAtIndex = angleLineOpts . setContext ( me . getContext ( i ) ) ;
461- const lineWidth = optsAtIndex . lineWidth ;
462- const color = optsAtIndex . color ;
474+ for ( i = me . getLabels ( ) . length - 1 ; i >= 0 ; i -- ) {
475+ const optsAtIndex = angleLines . setContext ( me . getContext ( i ) ) ;
476+ const { color, lineWidth} = optsAtIndex ;
463477
464478 if ( ! lineWidth || ! color ) {
465479 continue ;
@@ -518,11 +532,12 @@ export default class RadialLinearScale extends LinearScaleBase {
518532 width = ctx . measureText ( tick . label ) . width ;
519533 ctx . fillStyle = optsAtIndex . backdropColor ;
520534
535+ const { backdropPaddingX, backdropPaddingY} = optsAtIndex ;
521536 ctx . fillRect (
522- - width / 2 - optsAtIndex . backdropPaddingX ,
523- - offset - tickFont . size / 2 - optsAtIndex . backdropPaddingY ,
524- width + optsAtIndex . backdropPaddingX * 2 ,
525- tickFont . size + optsAtIndex . backdropPaddingY * 2
537+ - width / 2 - backdropPaddingX ,
538+ - offset - tickFont . size / 2 - backdropPaddingY ,
539+ width + backdropPaddingX * 2 ,
540+ tickFont . size + backdropPaddingY * 2
526541 ) ;
527542 }
528543
0 commit comments