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

Creating Contribution Graph with only one value returns error #425

Closed
sinuheshinbr opened this issue Oct 22, 2020 · 1 comment · Fixed by #543
Closed

Creating Contribution Graph with only one value returns error #425

sinuheshinbr opened this issue Oct 22, 2020 · 1 comment · Fixed by #543

Comments

@sinuheshinbr
Copy link

If you create a contribution graph with only one date it will return: "rgba(255,82,82, NaN) is not a valid color. Probably due to the fact that opacity is compared with other values to be determined. In this case, I think it is possible to default count to 0 if no other record is provided.

@Andrew-Chen-Wang
Copy link
Contributor

Andrew-Chen-Wang commented Aug 3, 2021

It's not just a single value. Using this data: const contributionData = [{"count": 2, "date": "2021-07-31"}, {"count": 2, "date": "2021-08-01"}]; with an end date of '2021-08-03' also does not work and produces NaN. Weird enough; if you do const contributionData = [{"count": 1, "date": "2021-07-31"}, {"count": 2, "date": "2021-08-01"}]; it works fine.

Anyone know how I could extend the current class to fix this issue temporarily? (Edit OK filed a PR, but here's a temp solution):

function mapValue(
  x: number,
  in_min: number,
  in_max: number,
  out_min: number,
  out_max: number
) {
  return ((x - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
}

class Blah extends ContributionGraph {
  getClassNameForIndex(index: number) {
    if (this.state.valueCache[index]) {
      if (this.state.valueCache[index].value) {
        const count = this.state.valueCache[index].value[this.props.accessor];

        if (count) {
          console.log(this.state.minValue,this.state.maxValue);
          const opacity = mapValue(
            count,
            this.state.maxValue === this.state.minValue ? 0: this.state.minValue,
            isNaN(this.state.maxValue) ? 1 : this.state.maxValue,
            0.15 + 0.05, // + 0.05 to make smaller values a bit more visible
            1
          );
          console.log(this.state.minValue, this.state.maxValue,  this.state.maxValue || this.state.minValue, opacity);

          return this.props.chartConfig.color(opacity);
        }
      }
    }

    return this.props.chartConfig.color(0.15);
  }
}

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

Successfully merging a pull request may close this issue.

2 participants