How to use the d3-scale-chromatic.interpolateCool function in d3-scale-chromatic

To help you get started, we’ve selected a few d3-scale-chromatic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chanzuckerberg / cellxgene / client / src / middleware / updateCellColors.js View on Github external
}

  if (action.type === "color by expression") {
    const { gene, data } = action;
    const expression = data[gene]; // Float32Array
    const colorBins = 100;
    const [min, max] = finiteExtent(expression);
    colorScale = d3
      .scaleQuantile()
      .domain([min, max])
      .range(_.range(colorBins - 1, -1, -1));

    /* pre-create colors - much faster than doing it for each obs */
    const colors = new Array(colorBins);
    for (let i = 0; i < colorBins; i += 1) {
      colors[i] = parseRGB(interpolateCool(i / colorBins));
    }
    const nonFiniteColor = parseRGB(globals.nonFiniteCellColor);

    for (let i = 0, len = expression.length; i < len; i += 1) {
      const e = expression[i];
      if (Number.isFinite(e)) {
        const c = colorScale(e);
        colorsByRGB[i] = colors[c];
      } else {
        colorsByRGB[i] = nonFiniteColor;
      }
    }
  }

  /*
  append the result of all the filters to the action the user just triggered
github chanzuckerberg / cellxgene / client / src / util / stateManager / colorHelpers.js View on Github external
function createColorsByExpression(world, accessor) {
  const expression = world.varData.col(accessor).asArray();
  const colorBins = 100;
  const [min, max] = finiteExtent(expression);
  const scale = d3
    .scaleQuantile()
    .domain([min, max])
    .range(range(colorBins - 1, -1, -1));

  /* pre-create colors - much faster than doing it for each obs */
  const colors = new Array(colorBins);
  for (let i = 0; i < colorBins; i += 1) {
    colors[i] = parseRGB(interpolateCool(i / colorBins));
  }
  const nonFiniteColor = parseRGB(globals.nonFiniteCellColor);

  const rgb = new Array(world.nObs);
  for (let i = 0, len = expression.length; i < len; i += 1) {
    const e = expression[i];
    if (Number.isFinite(e)) {
      const c = scale(e);
      rgb[i] = colors[c];
    } else {
      rgb[i] = nonFiniteColor;
    }
  }
  return { rgb, scale };
}
github chanzuckerberg / cellxgene / client / src / util / stateManager / colorHelpers.js View on Github external
function createColorsByContinuousMetadata(world, accessor) {
  const colorBins = 100;
  const col = world.obsAnnotations.col(accessor);
  const { min, max } = col.summarize();
  const scale = d3
    .scaleQuantile()
    .domain([min, max])
    .range(range(colorBins - 1, -1, -1));

  /* pre-create colors - much faster than doing it for each obs */
  const colors = new Array(colorBins);
  for (let i = 0; i < colorBins; i += 1) {
    colors[i] = parseRGB(interpolateCool(i / colorBins));
  }

  const nonFiniteColor = parseRGB(globals.nonFiniteCellColor);
  const rgb = new Array(world.nObs);
  const data = col.asArray();
  for (let i = 0, len = world.obsAnnotations.length; i < len; i += 1) {
    const val = data[i];
    if (Number.isFinite(val)) {
      const c = scale(val);
      rgb[i] = colors[c];
    } else {
      rgb[i] = nonFiniteColor;
    }
  }
  return { rgb, scale };
}
github rolyatmax / sketches / sketches / 2019.07.08-18.46.39.js View on Github external
function getColors (mesh) {
  let j = 0
  const colors = new Float32Array(mesh.cells.length * 3 * 3)
  const colorsByPosition = []
  for (let cell of mesh.cells) {
    for (let i of cell) {
      let color = colorsByPosition[i]
      if (!color) {
        const t = rand.noise3D(
          mesh.positions[i][0] * settings.colorNoiseMultiplier,
          mesh.positions[i][1] * settings.colorNoiseMultiplier,
          mesh.positions[i][2] * settings.colorNoiseMultiplier
        )
        const { r, g, b } = rgb(interpolateCool(t * 0.5 + 0.5))
        color = colorsByPosition[i] = [r / 255, g / 255, b / 255]
      }
      colors[j++] = color[0]
      colors[j++] = color[1]
      colors[j++] = color[2]
    }
  }
  return colors
}