@@ -33,6 +33,7 @@ export class FlatSliderComponent {
3333 public sanitizer : DomSanitizer
3434 ) { }
3535
36+ @Input ( ) scale : 'logarithmic' | 'linear' = 'linear'
3637 @Input ( ) doubleClickToAnimateToMiddle = true
3738 @Input ( ) showMiddleNotch = true
3839 @Input ( ) min : number = 0
@@ -96,7 +97,13 @@ export class FlatSliderComponent {
9697 if ( diffFromMiddle < 0 ) {
9798 diffFromMiddle *= - 1
9899 }
99- const percFromMiddle = this . utils . mapValue ( diffFromMiddle , 0 , this . max - middleValue , 0 , 100 )
100+ const percFromMiddle = this . mapValue ( {
101+ value : diffFromMiddle ,
102+ inMin : 0 ,
103+ inMax : this . max - middleValue ,
104+ outMin : 0 ,
105+ outMax : 100
106+ } )
100107 if ( ( this . _value ) . toFixed ( 2 ) === ( middleValue ) . toFixed ( 2 ) && percFromMiddle < 5 ) {
101108 value = middleValue
102109 } else if ( ( this . _value < middleValue && newValue > this . _value ) || ( this . _value > middleValue && newValue < this . _value ) ) {
@@ -139,7 +146,16 @@ export class FlatSliderComponent {
139146 public getValueFromMouseEvent ( event : MouseEvent ) {
140147 const coords = this . utils . getCoordinatesInsideElementFromEvent ( event , this . elem . nativeElement )
141148 const progress = this . orientation === 'vertical' ? coords . y : coords . x
142- const value = this . utils . mapValue ( progress , this . knobRadius , ( this . orientation === 'vertical' ? this . height : this . width ) - this . knobRadius , this . min , this . max )
149+ const value = ( ( ) => {
150+ const inMin = this . knobRadius
151+ const inMax = ( this . orientation === 'vertical' ? this . height : this . width ) - this . knobRadius
152+ return this . mapValue ( {
153+ value : progress ,
154+ inMin, inMax,
155+ outMin : this . min ,
156+ outMax : this . max
157+ } )
158+ } ) ( )
143159 return value
144160 }
145161
@@ -211,7 +227,13 @@ export class FlatSliderComponent {
211227 }
212228
213229 get progress ( ) {
214- return this . utils . mapValue ( this . value , this . min , this . max , 0 , 1 )
230+ return this . mapValue ( {
231+ value : this . value ,
232+ inMin : this . min ,
233+ inMax : this . max ,
234+ outMin : 0 ,
235+ outMax : 1
236+ } )
215237 }
216238
217239 get containerStyle ( ) {
@@ -276,6 +298,15 @@ export class FlatSliderComponent {
276298 return style
277299 }
278300
301+ private mapValue ( { value, inMin, inMax, outMin, outMax } : {
302+ [ param in 'value' | 'inMin' | 'inMax' | 'outMin' | 'outMax' ] : number
303+ } ) {
304+ switch ( this . scale ) {
305+ case 'linear' : return this . utils . mapValue ( value , inMin , inMax , outMin , outMax )
306+ case 'logarithmic' : return this . utils . logMapValue ( { value, inMin, inMax, outMin, outMax } )
307+ }
308+ }
309+
279310 get thumbStyle ( ) {
280311 const style : { [ style : string ] : number | string } = { }
281312 style . width = `${ this . knobRadius * 2 } px`
@@ -285,9 +316,21 @@ export class FlatSliderComponent {
285316
286317 style . borderRadius = '100%'
287318 if ( this . orientation === 'horizontal' ) {
288- style . left = `${ this . utils . mapValue ( this . value , this . min , this . max , 0 , this . width - this . knobRadius * 2 ) } px`
319+ style . left = `${ this . mapValue ( {
320+ value : this . value ,
321+ inMin : this . min ,
322+ inMax : this . max ,
323+ outMin : 0 ,
324+ outMax : this . width - this . knobRadius * 2
325+ } ) } px`
289326 } else {
290- style . bottom = `${ this . utils . mapValue ( this . value , this . min , this . max , 0 , this . height - this . knobRadius * 2 ) } px`
327+ style . bottom = `${ this . mapValue ( {
328+ value : this . value ,
329+ inMin : this . min ,
330+ inMax : this . max ,
331+ outMin : 0 ,
332+ outMax : this . height - this . knobRadius * 2
333+ } ) } px`
291334 }
292335 return style
293336 }
0 commit comments