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