@@ -8,6 +8,7 @@ import {autoSkip} from './core.scale.autoskip.js';
88
99const reverseAlign = ( align ) => align === 'left' ? 'right' : align === 'right' ? 'left' : align ;
1010const offsetFromEdge = ( scale , edge , offset ) => edge === 'top' || edge === 'left' ? scale [ edge ] + offset : scale [ edge ] - offset ;
11+ const getTicksLimit = ( ticksLength , maxTicksLimit ) => Math . min ( maxTicksLimit || ticksLength , ticksLength ) ;
1112
1213/**
1314 * @typedef { import('./core.controller.js').default } Chart
@@ -585,7 +586,7 @@ export default class Scale extends Element {
585586 calculateLabelRotation ( ) {
586587 const options = this . options ;
587588 const tickOpts = options . ticks ;
588- const numTicks = this . ticks . length ;
589+ const numTicks = getTicksLimit ( this . ticks . length , options . ticks . maxTicksLimit ) ;
589590 const minRotation = tickOpts . minRotation || 0 ;
590591 const maxRotation = tickOpts . maxRotation ;
591592 let labelRotation = minRotation ;
@@ -803,7 +804,7 @@ export default class Scale extends Element {
803804 ticks = sample ( ticks , sampleSize ) ;
804805 }
805806
806- this . _labelSizes = labelSizes = this . _computeLabelSizes ( ticks , ticks . length ) ;
807+ this . _labelSizes = labelSizes = this . _computeLabelSizes ( ticks , ticks . length , this . options . ticks . maxTicksLimit ) ;
807808 }
808809
809810 return labelSizes ;
@@ -815,15 +816,16 @@ export default class Scale extends Element {
815816 * @return {{ first: object, last: object, widest: object, highest: object, widths: Array, heights: array } }
816817 * @private
817818 */
818- _computeLabelSizes ( ticks , length ) {
819+ _computeLabelSizes ( ticks , length , maxTicksLimit ) {
819820 const { ctx, _longestTextCache : caches } = this ;
820821 const widths = [ ] ;
821822 const heights = [ ] ;
823+ const increment = Math . floor ( length / getTicksLimit ( length , maxTicksLimit ) ) ;
822824 let widestLabelSize = 0 ;
823825 let highestLabelSize = 0 ;
824826 let i , j , jlen , label , tickFont , fontString , cache , lineHeight , width , height , nestedLabel ;
825827
826- for ( i = 0 ; i < length ; ++ i ) {
828+ for ( i = 0 ; i < length ; i += increment ) {
827829 label = ticks [ i ] . label ;
828830 tickFont = this . _resolveTickFontOptions ( i ) ;
829831 ctx . font = fontString = tickFont . string ;
0 commit comments