colormap but with 2 values, one has positive and negative value (positive value = blue, negative value = red) and pvalue (the color graduates) in javascript

You can create a custom colormap with 2 values using d3-scale-chromatic library in JavaScript. Here's an example function that takes in a value (val) and returns a color based on whether it's positive or negative:

index.tsx
const colorScale = d3.scaleSequential()
  .domain([-1, 1]) // input domain for values, assuming they range from -1 to 1
  .interpolator(d3.interpolateRedBlue); // color interpolator for pvalues

function getColor(val) {
  // if value is positive, return blue color
  // if value is negative, return red color
  // otherwise, return white color
  return val > 0 ? colorScale(val) : val < 0 ? colorScale(val) : '#fff';
}
419 chars
11 lines

You can then use this getColor function to color your data points or areas based on their values.

gistlibby LogSnag