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

Crashes by react-native-svg invalid number formating character #3049

Open
2 tasks done
Rob-latticetraining opened this issue Feb 20, 2025 · 0 comments
Open
2 tasks done
Labels
Type: Bug 🐛 Oh no! A bug or unintentional behavior

Comments

@Rob-latticetraining
Copy link

Rob-latticetraining commented Feb 20, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Victory version

36.9.2

Code Sandbox link

No response

Bug report

Svg invalid number error when trying to draw bar chart with corner radius causes crash. This seemed to only happen under some very specific circumstances with data and screen sizes.

Fatal Exception: java.lang.Error Invalid number formating character 'N'

Found that in function solveX in these two files was returning NaN in the case where cornerRadius = 4

  • victory-bar/es/geometry-helper-methods.js b/node_modules/victory-bar/es/geometry-helper-methods.js
  • victory-bar/src/geometry-helper-methods.ts b/node_modules/victory-bar/src/geometry-helper-methods.ts

This was due to a floating point error when calculating the powers within this function

  solveX: function (y) {
    var sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2));
    return [this.center.x - sqrt, this.center.x + sqrt];
  },

Resulting in it trying to calculate Math.sqrt(0 - 0.000000000000146)
We ended up patching this function to check if the value is less than 0

solveX(y: number) {
    const diff = Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2);
    const sqrt = diff >= 0 ? Math.sqrt(diff) : 0;

    return [this.center.x - sqrt, this.center.x + sqrt];
  }

Potentially related to this issue which mentions rounded cornerRadius as a potential fix: #2654

@Rob-latticetraining Rob-latticetraining added the Type: Bug 🐛 Oh no! A bug or unintentional behavior label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug 🐛 Oh no! A bug or unintentional behavior
Projects
None yet
Development

No branches or pull requests

1 participant