Commit 7347230ec42b880c0ec6fa860714894771f5fdea
Committed by
GitHub
1 parent
fbc58d0e
Update knob control (#3501)
* Epdate knob control * Fix click function * Refactoring * Formatting * Change 'mouseup'
Showing
1 changed file
with
19 additions
and
13 deletions
... | ... | @@ -67,6 +67,7 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { |
67 | 67 | title = ''; |
68 | 68 | minValue: number; |
69 | 69 | maxValue: number; |
70 | + newValue = 0; | |
70 | 71 | |
71 | 72 | private startDeg = -1; |
72 | 73 | private currentDeg = 0; |
... | ... | @@ -175,16 +176,15 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { |
175 | 176 | |
176 | 177 | const offset = this.knob.offset(); |
177 | 178 | const center = { |
178 | - y : offset.top + this.knob.height()/2, | |
179 | - x: offset.left + this.knob.width()/2 | |
179 | + y: offset.top + this.knob.height() / 2, | |
180 | + x: offset.left + this.knob.width() / 2 | |
180 | 181 | }; |
181 | - const rad2deg = 180/Math.PI; | |
182 | + const rad2deg = 180 / Math.PI; | |
182 | 183 | const t: Touch = ((e.originalEvent as any).touches) ? (e.originalEvent as any).touches[0] : e; |
183 | - | |
184 | 184 | const a = center.y - t.pageY; |
185 | 185 | const b = center.x - t.pageX; |
186 | - let deg = Math.atan2(a,b)*rad2deg; | |
187 | - if(deg < 0){ | |
186 | + let deg = Math.atan2(a, b) * rad2deg; | |
187 | + if (deg < 0) { | |
188 | 188 | deg = 360 + deg; |
189 | 189 | } |
190 | 190 | if (deg > this.maxDeg) { |
... | ... | @@ -196,13 +196,17 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { |
196 | 196 | } |
197 | 197 | this.currentDeg = deg; |
198 | 198 | this.lastDeg = deg; |
199 | - this.knobTopPointerContainer.css('transform','rotate('+(this.currentDeg)+'deg)'); | |
199 | + this.knobTopPointerContainer.css('transform', 'rotate(' + (this.currentDeg) + 'deg)'); | |
200 | 200 | this.turn(this.degreeToRatio(this.currentDeg)); |
201 | 201 | this.rotation = this.currentDeg; |
202 | 202 | this.startDeg = -1; |
203 | + this.rpcUpdateValue(this.newValue); | |
203 | 204 | }); |
204 | 205 | |
206 | + | |
207 | + | |
205 | 208 | this.knob.on('mousedown touchstart', (e) => { |
209 | + this.moving = false; | |
206 | 210 | e.preventDefault(); |
207 | 211 | const offset = this.knob.offset(); |
208 | 212 | const center = { |
... | ... | @@ -211,7 +215,7 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { |
211 | 215 | }; |
212 | 216 | const rad2deg = 180/Math.PI; |
213 | 217 | |
214 | - this.knob.on('mousemove.rem touchmove.rem', (ev) => { | |
218 | + $(document).on('mousemove.rem touchmove.rem', (ev) => { | |
215 | 219 | this.moving = true; |
216 | 220 | const t: Touch = ((ev.originalEvent as any).touches) ? (ev.originalEvent as any).touches[0] : ev; |
217 | 221 | |
... | ... | @@ -262,6 +266,9 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { |
262 | 266 | }); |
263 | 267 | |
264 | 268 | $(document).on('mouseup.rem touchend.rem',() => { |
269 | + if(this.newValue !== this.rpcValue && this.moving) { | |
270 | + this.rpcUpdateValue(this.newValue); | |
271 | + } | |
265 | 272 | this.knob.off('.rem'); |
266 | 273 | $(document).off('.rem'); |
267 | 274 | this.rotation = this.currentDeg; |
... | ... | @@ -308,12 +315,12 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { |
308 | 315 | } |
309 | 316 | |
310 | 317 | private turn(ratio: number) { |
311 | - const value = Number((this.minValue + (this.maxValue - this.minValue)*ratio).toFixed(this.ctx.decimals)); | |
312 | - if (this.canvasBar.value !== value) { | |
313 | - this.canvasBar.value = value; | |
318 | + this.newValue = Number((this.minValue + (this.maxValue - this.minValue)*ratio).toFixed(this.ctx.decimals)); | |
319 | + if (this.canvasBar.value !== this.newValue) { | |
320 | + this.canvasBar.value = this.newValue; | |
314 | 321 | } |
315 | 322 | this.updateColor(this.canvasBar.getValueColor()); |
316 | - this.onValue(value); | |
323 | + this.onValue(this.newValue); | |
317 | 324 | } |
318 | 325 | |
319 | 326 | private resize() { |
... | ... | @@ -379,7 +386,6 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { |
379 | 386 | private onValue(value: number) { |
380 | 387 | this.value = this.formatValue(value); |
381 | 388 | this.checkValueSize(); |
382 | - this.rpcUpdateValue(value); | |
383 | 389 | this.ctx.detectChanges(); |
384 | 390 | } |
385 | 391 | ... | ... |