Commit 7347230ec42b880c0ec6fa860714894771f5fdea

Authored by kalutkaz
Committed by GitHub
1 parent fbc58d0e

Update knob control (#3501)

* Epdate knob control

* Fix click function

* Refactoring

* Formatting

* Change 'mouseup'
@@ -67,6 +67,7 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { @@ -67,6 +67,7 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy {
67 title = ''; 67 title = '';
68 minValue: number; 68 minValue: number;
69 maxValue: number; 69 maxValue: number;
  70 + newValue = 0;
70 71
71 private startDeg = -1; 72 private startDeg = -1;
72 private currentDeg = 0; 73 private currentDeg = 0;
@@ -175,16 +176,15 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { @@ -175,16 +176,15 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy {
175 176
176 const offset = this.knob.offset(); 177 const offset = this.knob.offset();
177 const center = { 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 const t: Touch = ((e.originalEvent as any).touches) ? (e.originalEvent as any).touches[0] : e; 183 const t: Touch = ((e.originalEvent as any).touches) ? (e.originalEvent as any).touches[0] : e;
183 -  
184 const a = center.y - t.pageY; 184 const a = center.y - t.pageY;
185 const b = center.x - t.pageX; 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 deg = 360 + deg; 188 deg = 360 + deg;
189 } 189 }
190 if (deg > this.maxDeg) { 190 if (deg > this.maxDeg) {
@@ -196,13 +196,17 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { @@ -196,13 +196,17 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy {
196 } 196 }
197 this.currentDeg = deg; 197 this.currentDeg = deg;
198 this.lastDeg = deg; 198 this.lastDeg = deg;
199 - this.knobTopPointerContainer.css('transform','rotate('+(this.currentDeg)+'deg)'); 199 + this.knobTopPointerContainer.css('transform', 'rotate(' + (this.currentDeg) + 'deg)');
200 this.turn(this.degreeToRatio(this.currentDeg)); 200 this.turn(this.degreeToRatio(this.currentDeg));
201 this.rotation = this.currentDeg; 201 this.rotation = this.currentDeg;
202 this.startDeg = -1; 202 this.startDeg = -1;
  203 + this.rpcUpdateValue(this.newValue);
203 }); 204 });
204 205
  206 +
  207 +
205 this.knob.on('mousedown touchstart', (e) => { 208 this.knob.on('mousedown touchstart', (e) => {
  209 + this.moving = false;
206 e.preventDefault(); 210 e.preventDefault();
207 const offset = this.knob.offset(); 211 const offset = this.knob.offset();
208 const center = { 212 const center = {
@@ -211,7 +215,7 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { @@ -211,7 +215,7 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy {
211 }; 215 };
212 const rad2deg = 180/Math.PI; 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 this.moving = true; 219 this.moving = true;
216 const t: Touch = ((ev.originalEvent as any).touches) ? (ev.originalEvent as any).touches[0] : ev; 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,6 +266,9 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy {
262 }); 266 });
263 267
264 $(document).on('mouseup.rem touchend.rem',() => { 268 $(document).on('mouseup.rem touchend.rem',() => {
  269 + if(this.newValue !== this.rpcValue && this.moving) {
  270 + this.rpcUpdateValue(this.newValue);
  271 + }
265 this.knob.off('.rem'); 272 this.knob.off('.rem');
266 $(document).off('.rem'); 273 $(document).off('.rem');
267 this.rotation = this.currentDeg; 274 this.rotation = this.currentDeg;
@@ -308,12 +315,12 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { @@ -308,12 +315,12 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy {
308 } 315 }
309 316
310 private turn(ratio: number) { 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 this.updateColor(this.canvasBar.getValueColor()); 322 this.updateColor(this.canvasBar.getValueColor());
316 - this.onValue(value); 323 + this.onValue(this.newValue);
317 } 324 }
318 325
319 private resize() { 326 private resize() {
@@ -379,7 +386,6 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy { @@ -379,7 +386,6 @@ export class KnobComponent extends PageComponent implements OnInit, OnDestroy {
379 private onValue(value: number) { 386 private onValue(value: number) {
380 this.value = this.formatValue(value); 387 this.value = this.formatValue(value);
381 this.checkValueSize(); 388 this.checkValueSize();
382 - this.rpcUpdateValue(value);  
383 this.ctx.detectChanges(); 389 this.ctx.detectChanges();
384 } 390 }
385 391