@@ -247,19 +247,31 @@ export class MdSlider implements AfterContentInit {
247247 * separation constant.
248248 */
249249 private _updateAutoTickSeparation ( ) {
250- let width = this . _sliderDimensions . width ;
250+ // We're looking for the multiple of step for which the separation between is greater than the
251+ // minimum tick separation.
252+ let sliderWidth = this . _sliderDimensions . width ;
251253
252- // This calculates which step is far enough away from the beginning of the slider to draw a tick
253- // at. This value will then be used to draw ticks at every tickStep steps.
254- let tickStep =
255- Math . ceil ( MIN_AUTO_TICK_SEPARATION * ( this . max - this . min ) / ( width * this . step ) ) ;
254+ // This is the total "width" of the slider in terms of values.
255+ let valueWidth = this . max - this . min ;
256256
257- // The percentage of the slider where the first tick should go.
258- let tickPercentage = this . calculatePercentage ( ( this . step * tickStep ) + this . min ) ;
257+ // Calculate how many values exist within 1px on the slider.
258+ let valuePerPixel = valueWidth / sliderWidth ;
259+
260+ // Calculate how many values exist in the minimum tick separation (px).
261+ let valuePerSeparation = valuePerPixel * MIN_AUTO_TICK_SEPARATION ;
262+
263+ // Calculate how many steps exist in this separation. This will be the lowest value you can
264+ // multiply step by to get a separation that is greater than or equal to the minimum tick
265+ // separation.
266+ let stepsPerSeparation = Math . ceil ( valuePerSeparation / this . step ) ;
267+
268+ // Get the percentage of the slider for which this tick would be located so we can then draw
269+ // it on the slider.
270+ let tickPercentage = this . calculatePercentage ( ( this . step * stepsPerSeparation ) + this . min ) ;
259271
260272 // The pixel value of the tick is the percentage * the width of the slider. Use this to draw
261273 // the ticks on the slider.
262- this . _renderer . drawTicks ( width * tickPercentage ) ;
274+ this . _renderer . drawTicks ( sliderWidth * tickPercentage ) ;
263275 }
264276
265277 /**
0 commit comments