@@ -29,6 +29,9 @@ export default class Scales {
2929 axisCnf = w . config . yaxis [ index ]
3030 maxTicks = Math . max ( ( gl . svgHeight - 100 ) / 15 , 2 )
3131 }
32+ if ( ! Utils . isNumber ( maxTicks ) ) {
33+ maxTicks = 10
34+ }
3235 gotMin = axisCnf . min !== undefined && axisCnf . min !== null
3336 gotMax = axisCnf . max !== undefined && axisCnf . min !== null
3437 let gotStepSize =
@@ -37,8 +40,6 @@ export default class Scales {
3740 axisCnf . tickAmount !== undefined && axisCnf . tickAmount !== null
3841 let ticks = gotTickAmount
3942 ? axisCnf . tickAmount
40- : ! axisCnf . forceNiceScale
41- ? 10
4243 : gl . niceScaleDefaultTicks [
4344 Math . min (
4445 Math . round ( maxTicks / 2 ) ,
@@ -100,19 +101,17 @@ export default class Scales {
100101 // Determine Range
101102 let range = Math . abs ( yMax - yMin )
102103
103- if ( axisCnf . forceNiceScale ) {
104- // Snap min or max to zero if close
105- let proximityRatio = 0.15
106- if ( ! gotMin && yMin > 0 && yMin / range < proximityRatio ) {
107- yMin = 0
108- gotMin = true
109- }
110- if ( ! gotMax && yMax < 0 && - yMax / range < proximityRatio ) {
111- yMax = 0
112- gotMax = true
113- }
114- range = Math . abs ( yMax - yMin )
104+ // Snap min or max to zero if close
105+ let proximityRatio = 0.15
106+ if ( ! gotMin && yMin > 0 && yMin / range < proximityRatio ) {
107+ yMin = 0
108+ gotMin = true
109+ }
110+ if ( ! gotMax && yMax < 0 && - yMax / range < proximityRatio ) {
111+ yMax = 0
112+ gotMax = true
115113 }
114+ range = Math . abs ( yMax - yMin )
116115
117116 // Calculate a pretty step value based on ticks
118117
@@ -231,18 +230,25 @@ export default class Scales {
231230 } else {
232231 // Snap range to ticks
233232 if ( ! gotMin && ! gotMax ) {
234- if ( gotTickAmount ) {
235- // Allow a half-stepSize shift if series doesn't cross the X axis
236- // to ensure graph doesn't clip. Not if it does cross, in order
237- // to keep the 0 aligned with a grid line in multi axis charts.
238- let shift = stepSize / ( yMax - yMin > yMax ? 1 : 2 )
239- let tMin = shift * Math . floor ( yMin / shift )
240- if ( Math . abs ( tMin - yMin ) <= shift / 2 ) {
241- yMin = tMin
242- yMax = yMin + stepSize * tiks
243- } else {
244- yMax = shift * Math . ceil ( yMax / shift )
245- yMin = yMax - stepSize * tiks
233+ if ( gl . isMultipleYAxis && gotTickAmount ) {
234+ // Ensure graph doesn't clip.
235+ let tMin = stepSize * Math . floor ( yMin / stepSize )
236+ let tMax = tMin + stepSize * tiks
237+ if ( tMax < yMax ) {
238+ stepSize *= 2
239+ }
240+ yMin = tMin
241+ tMax = yMax
242+ yMax = yMin + stepSize * tiks
243+ // Snap min or max to zero if possible
244+ range = Math . abs ( yMax - yMin )
245+ if ( yMin > 0 && yMin < Math . abs ( tMax - yMax ) ) {
246+ yMin = 0
247+ yMax = stepSize * tiks
248+ }
249+ if ( yMax < 0 && - yMax < Math . abs ( tMin - yMin ) ) {
250+ yMax = 0
251+ yMin = - stepSize * tiks
246252 }
247253 } else {
248254 yMin = stepSize * Math . floor ( yMin / stepSize )
@@ -297,9 +303,9 @@ export default class Scales {
297303 }
298304
299305 // Prune tiks down to range if series is all integers. Since tiks > range,
300- // range is very low (< 10 or so). Skip this step if tickAmount is true
301- // because, either the user set it, or the chart is multiscale and this
302- // axis is not determining the number of grid lines.
306+ // range is very low (< 10 or so). Skip this step if gotTickAmount is true
307+ // because either the user set tickAmount or the chart is multiscale and
308+ // this axis is not determining the number of grid lines.
303309 if (
304310 ! gotTickAmount &&
305311 axisCnf . forceNiceScale &&
0 commit comments