Bug description
I wanted to add an annotation to my area chart to indicate the max value. But I noticed that it only works until the value of 1 * 10^15 (which is 1 petabyte). I wanted to draw the line at 2 * 10^15, which is the maximum storage we have available, but the graph disappears from the moment I exceed 1* 10^15
is it possible to fix this?
How to reproduce the bug
- make an area chart
- go to 'Data' tab - Annotation and Layers
- Add Anotation layer
- choose annotation layer type = Formula
- fill in formula: 110^15 (this will work) - 1.110^15 (this will remove the graph, no error shown)
Screenshots/recordings
Superset version
4.0.2
Python version
I don't know
Node version
I don't know
Browser
Chrome
Additional context
No response
Checklist
- [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Comment From: dosubot[bot]
Hey there, @AnnelyseBe! I'm a bot here to help you with any bugs, questions, or contributions you have for Superset. Let's tackle this issue together!
Yes, it is possible to fix the issue where the annotation formula on a chart does not work for values above 1*10^15 in Superset version 4.0.2. The issue is likely due to the limitations of JavaScript's Number
type, which can cause precision errors for very large numbers.
To address this, you can use the BigInt
type for handling large integers. However, BigInt
does not support floating-point numbers. If you need to handle large floating-point numbers, you might need to use a library like decimal.js
or big.js
.
Here is an example of how you can modify the evalExpression
function to use BigInt
for large integers:
function evalExpression(expression, x) {
// Check if x is greater than 1*10^15 and convert to BigInt if necessary
const xValue = x > 1e15 ? BigInt(x) : x;
// Use Function constructor to evaluate the expression
const func = new Function('x', `return ${expression}`);
return func(xValue);
}
This modification ensures that the x
value is converted to BigInt
if it exceeds 1*10^15, which should help in handling large values without precision errors [1].
To continue talking to Dosu, mention @dosu.
Comment From: rusackas
I think @justinpark was working on some "bigint" related efforts recently. @AnnelyseBe are you still able to reproduce this in 4.1.2 or 5.0.0rc2? I'm assuming this is an edge case that has not been addressed. We'd welcome a PR if anyone is interested, but this is otherwise at risk of being closed as stale/not-planned.
Comment From: rusackas
Seems nobody has corroborated this issue or volunteered to work on it in the last several months, so I'll go ahead and close this as not-planned, but we would still welcome any investigation/PRs, or we can reopen it if others encounter it too.