Skip to content

Commit

Permalink
fix(potentiometer): improve knob accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Apr 7, 2020
1 parent 7b64379 commit 0ca74a1
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/potentiometer-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ export class PotentiometerElement extends LitElement {
stroke-width=".30"
/>
<rect x="5.4" y=".70" width="9.1" height="1.9" fill="#ccdae3" stroke-width=".15" />
<ellipse cx="9.91" cy="8.18" rx="7.27" ry="7.43" fill="#e4e8eb" stroke-width=".15" />
<ellipse
id="knob"
cx="9.91"
cy="8.18"
rx="7.27"
ry="7.43"
fill="#e4e8eb"
stroke-width=".15"
/>
<rect
x="6.6"
y="17"
Expand Down Expand Up @@ -134,12 +142,14 @@ export class PotentiometerElement extends LitElement {
event.stopPropagation();
event.preventDefault();

const potentiometerRect = this.getBoundingClientRect();
const potentiometerRect = this.shadowRoot?.querySelector('#knob')?.getBoundingClientRect();

this.center = {
x: window.scrollX + potentiometerRect.left + potentiometerRect.width / 2,
y: window.scrollY + potentiometerRect.top + potentiometerRect.height / 2,
};
if (potentiometerRect) {
this.center = {
x: window.scrollX + potentiometerRect.left + potentiometerRect.width / 2,
y: window.scrollY + potentiometerRect.top + potentiometerRect.height / 2,
};
}
}

private rotateHandler(event: MouseEvent | TouchEvent) {
Expand Down

0 comments on commit 0ca74a1

Please sign in to comment.