apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
62.62k stars 13.81k forks source link

Annotation formula on chart does not work for values above 1*10^15 (peta) #30209

Open AnnelyseBe opened 1 month ago

AnnelyseBe commented 1 month ago

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

  1. make an area chart
  2. go to 'Data' tab - Annotation and Layers
  3. Add Anotation layer
  4. choose annotation layer type = Formula
  5. fill in formula: 110^15 (this will work) - 1.110^15 (this will remove the graph, no error shown)

Screenshots/recordings

annotation value too big annotation value max

Superset version

4.0.2

Python version

I don't know

Node version

I don't know

Browser

Chrome

Additional context

No response

Checklist

dosubot[bot] commented 1 month ago

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.