99 HostBinding ,
1010 ElementRef
1111} from '@angular/core'
12-
12+ import * as uuid from 'uuid/v4'
1313import { UtilitiesService } from '../../services/utilities.service'
1414
1515export interface KnobValueChangedEvent {
@@ -24,7 +24,7 @@ export interface KnobValueChangedEvent {
2424export class KnobComponent implements OnInit {
2525 @Input ( ) size : 'large' | 'medium' | 'small' = 'medium'
2626 @Input ( ) showScale = true
27-
27+ id = uuid ( )
2828 private _min = - 1
2929 @Input ( ) set min ( newMin ) { this . _min = newMin ; this . calculateMiddleValue ( ) }
3030 get min ( ) { return this . _min }
@@ -44,7 +44,6 @@ export class KnobComponent implements OnInit {
4444 @Output ( ) stickedToMiddle = new EventEmitter ( )
4545
4646 private dragging = false
47- private padding = 5
4847 private setDraggingFalseTimeout : any = null
4948 private continueAnimation = false
5049 private dragStartDegr = 0
@@ -77,7 +76,6 @@ export class KnobComponent implements OnInit {
7776 }
7877 this . _value = this . clampValue ( value )
7978 this . valueChange . emit ( this . _value )
80- this . setKnobImage ( this . _value )
8179 }
8280 get value ( ) {
8381 return this . _value
@@ -93,7 +91,6 @@ export class KnobComponent implements OnInit {
9391
9492 async ngOnInit ( ) {
9593 this . container = this . containerRef . nativeElement
96- this . setKnobImage ( this . _value )
9794 }
9895
9996 mouseWheel ( event ) {
@@ -143,7 +140,7 @@ export class KnobComponent implements OnInit {
143140 if ( this . dragging ) {
144141 this . continueAnimation = false
145142 const distanceFromCenter = this . getDistanceFromCenterOfElementAndEvent ( event )
146- const unaffectedRadius = ( this . container . clientWidth + this . padding * 2 ) / 7
143+ const unaffectedRadius = ( this . container . clientWidth ) / 7
147144 if ( distanceFromCenter < unaffectedRadius ) {
148145 return
149146 }
@@ -184,28 +181,35 @@ export class KnobComponent implements OnInit {
184181 }
185182 }
186183
187- largeCapMaxAngle = 130
188- getLargeCapClipPathStyle ( ) {
184+ largeCapMaxAngle = 135
185+ get largeCapClipPathStyle ( ) {
189186 return {
190- transform : `rotate(${ this . utils . mapValue ( this . value , this . min , this . max , - this . largeCapMaxAngle , this . largeCapMaxAngle ) } deg)`
187+ transform : `rotate(${ this . utils . mapValue ( this . value , this . min , this . max , - this . largeCapMaxAngle , this . largeCapMaxAngle ) } deg)` ,
188+ 'transform-origin' : '50% 50%'
191189 }
192190 }
193191
194- getLargeCapIndicatorStyle ( ) {
192+ get largeCapIndicatorStyle ( ) {
195193 return {
196194 transform : `translate(-50%, -50%) rotate(${ this . utils . mapValue ( this . value , this . min , this . max , - this . largeCapMaxAngle , this . largeCapMaxAngle ) } deg)`
197195 }
198196 }
199197
198+ get largeCapBodyStyle ( ) {
199+ return {
200+ 'clip-path' : `url(#large-knob-cap-clip-path-${ this . id } )`
201+ }
202+ }
203+
200204 mediumCapMaxAngle = 135
201- getMediumCapIndicatorStyle ( ) {
205+ get mediumCapIndicatorStyle ( ) {
202206 return {
203207 transform : `translate(-50%, -50%) rotate(${ this . utils . mapValue ( this . value , this . min , this . max , - this . mediumCapMaxAngle , this . mediumCapMaxAngle ) } deg)`
204208 }
205209 }
206210
207211 smallCapMaxAngle = 135
208- getSmallCapIndicatorStyle ( ) {
212+ get smallCapIndicatorStyle ( ) {
209213 return {
210214 transform : `translate(-50%, -50%) rotate(${ this . utils . mapValue ( this . value , this . min , this . max , - this . smallCapMaxAngle , this . smallCapMaxAngle ) } deg)`
211215 }
@@ -235,17 +239,17 @@ export class KnobComponent implements OnInit {
235239 }
236240
237241 private getDegreesFromEvent ( event ) {
238- const coords = this . utils . getCoordinatesInsideElementFromEvent ( event )
239- const knobCenterX = ( this . container . clientWidth + this . padding * 2 ) / 2
240- const knobCenterY = ( this . container . clientHeight + this . padding * 2 ) / 2
242+ const coords = this . utils . getCoordinatesInsideElementFromEvent ( event , this . container )
243+ const knobCenterX = ( this . container . clientWidth ) / 2
244+ const knobCenterY = ( this . container . clientHeight ) / 2
241245 const rads = Math . atan2 ( coords . x - knobCenterX , coords . y - knobCenterY )
242246 return rads * 100
243247 }
244248
245249 private getDistanceFromCenterOfElementAndEvent ( event ) {
246- const coords = this . utils . getCoordinatesInsideElementFromEvent ( event )
247- const knobCenterX = ( this . container . clientWidth + this . padding * 2 ) / 2
248- const knobCenterY = ( this . container . clientHeight + this . padding * 2 ) / 2
250+ const coords = this . utils . getCoordinatesInsideElementFromEvent ( event , this . container )
251+ const knobCenterX = ( this . container . clientWidth ) / 2
252+ const knobCenterY = ( this . container . clientHeight ) / 2
249253 const w = coords . x - knobCenterX
250254 const h = coords . y - knobCenterY
251255 return Math . sqrt ( w * w + h * h )
@@ -262,9 +266,4 @@ export class KnobComponent implements OnInit {
262266
263267 return value
264268 }
265-
266- private setKnobImage ( value : number ) {
267-
268- }
269-
270269}
0 commit comments