Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KnobVisualHelpers uses vbox.width to calculate centerY #49

Open
Ascalion opened this issue Jun 2, 2022 · 0 comments
Open

KnobVisualHelpers uses vbox.width to calculate centerY #49

Ascalion opened this issue Jun 2, 2022 · 0 comments

Comments

@Ascalion
Copy link

Ascalion commented Jun 2, 2022

KnobVisualHelpers uses vbox.width to calculate centerY and it offsets the graphic of the helper for non-square knobs.

Change from:

static getDerivedStateFromProps(props: KnobVisualHelpersProps, state: KnobVisualHelpersState) {
    //Calculate position
    const vbox = props.svgRef.getBoundingClientRect();
    const halfWidth = vbox.width / 2;

    //Calculate current angle segment end point
    //Note: Not sure why we need to substract 90 here
    const valueMarkerX =
      props.radius * Math.cos(utils.toRadians(props.valueAngle - 90));
    const valueMarkerY =
      props.radius * Math.sin(utils.toRadians(props.valueAngle - 90));

    return {
      ...state,
      centerX: vbox.left + halfWidth,
      centerY: vbox.top + halfWidth,
      valueMarkerX,
      valueMarkerY
    };
  }

to:

static getDerivedStateFromProps(props: KnobVisualHelpersProps, state: KnobVisualHelpersState) {
    //Calculate position
    const vbox = props.svgRef.getBoundingClientRect();
    const halfWidth = vbox.width / 2;
    const halfHeight = vbox.height / 2;

    //Calculate current angle segment end point
    //Note: Not sure why we need to substract 90 here
    const valueMarkerX =
      props.radius * Math.cos(utils.toRadians(props.valueAngle - 90));
    const valueMarkerY =
      props.radius * Math.sin(utils.toRadians(props.valueAngle - 90));

    return {
      ...state,
      centerX: vbox.left + halfWidth,
      centerY: vbox.top + halfHeight,
      valueMarkerX,
      valueMarkerY
    };
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant