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

Added custom colorScale #703

Merged
merged 1 commit into from
Oct 19, 2019

Conversation

jashanbhullar
Copy link
Contributor

NEED HELP

I needed a custom color on the calendar heatmap based on my scale so I added this functionality. I have made it successfully work in my codebase.
I need more clarity on what needs to be changed and if there's a better way to do this rather than what I have currently done.

It also needs an update in the documentation.

Resolves #693

image

@plouc
Copy link
Owner

plouc commented Oct 19, 2019

That's a useful feature, thank you for your contribution @jashanbhullar!

@plouc plouc merged commit 484d308 into plouc:master Oct 19, 2019
@jashanbhullar
Copy link
Contributor Author

@plouc when will this show up on the npm package?

@jashanbhullar
Copy link
Contributor Author

@plouc still awaiting the update on the version number.

@jashanbhullar jashanbhullar deleted the calendar/custom-colorScale branch April 27, 2020 13:41
@ghost
Copy link

ghost commented Apr 19, 2022

Is there any example how this works? Or what the custom colorScale function is supposed to look like? I cannot figure it out.

@koders
Copy link

koders commented Jul 18, 2022

@gdevrs I figured it out, you have to have a function, which returns a color, and also have a tick array under the function.

const colors = [
    "#ff0000",
    "rgba(255, 255, 255, 0.5)",
    "#003300",
    "#005500",
    "#007700",
    "#009900",
    "#00bb00",
    "#00ff00",
  ];

  const ticks = ["Loss", 0, 200, 400, 600, 800, 1000];
  const colorScaleFn = (value) => {
    if (value < 0 || value === "Loss") {
      return colors[0];
    }
    if (value == 0) {
      return colors[1];
    }
    for (let i = 2; i < ticks.length; i++) {
      if (value < ticks[i]) {
        return colors[i];
      }
    }
    return colors[colors.length - 1];
  };

  colorScaleFn.ticks = () => ticks;

and then <ResponsiveTimeRange colorScale={colorScaleFn} />

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 this pull request may close these issues.

Dynamic Colors in Calendar (Custom colorScale fn)
3 participants