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

Error when data are filled with zeros #14

Open
qtphan734 opened this issue Feb 25, 2019 · 1 comment · Fixed by charleseidsness/sparkline#1 · May be fixed by #25
Open

Error when data are filled with zeros #14

qtphan734 opened this issue Feb 25, 2019 · 1 comment · Fixed by charleseidsness/sparkline#1 · May be fixed by #25

Comments

@qtphan734
Copy link

In case where the data array are filled with all zeros, Expected Number error will occurred:

Error: <path> attribute d: Expected number, "M4 NaN L 4 NaN L 29…"

Base on looking at the source, the Y coord of each datapoint is determined by the max values of datapoints. If data arrays are all 0, then you will run into a divide by zero scenario resulting in the above error.

  // The maximum value. This is used to calculate the Y coord of
  // each sparkline datapoint.
  const max = Math.max(...values);
glaszig added a commit to glaszig/sparkline that referenced this issue Dec 3, 2022
calling getY() with 0 value would produce NaN which are invalid in svg where those end up.
in that case, the added condition returns the height in float to draw a data point at y=0.

releated fnando#13, closes fnando#24, fixes fnando#14
@glaszig glaszig linked a pull request Dec 3, 2022 that will close this issue
@tekhedd
Copy link

tekhedd commented Apr 20, 2023

Have reproduced the error. Can someone recommend a fork that has the patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants