code: function renderColorScaleToCanvas(name, canvas) {
    /* eslint-disable no-param-reassign */
    const csDef = colorscales[name];
    canvas.height = 1;
    const ctx = canvas.getContext('2d');
  
    if (Object.prototype.toString.call(csDef) === '[object Object]') {
      canvas.width = 256;
      const gradient = ctx.createLinearGradient(0, 0, 256, 1);
  
      for (let i = 0; i < csDef.colors.length; ++i) {
        gradient.addColorStop(csDef.positions[i], csDef.colors[i]);
      }
      ctx.fillStyle = gradient;
      ctx.fillRect(0, 0, 256, 1);
    } else if (Object.prototype.toString.call(csDef) === '[object Uint8Array]') {
      canvas.width = 256;
      const imgData = ctx.createImageData(256, 1);
      imgData.data.set(csDef);
      ctx.putImageData(imgData, 0, 0);
    } else {
      throw new Error('Color scale not defined.');
    }
    /* eslint-enable no-param-reassign */
  }
docs: Render the colorscale to the specified canvas.
  @memberof module:plotty
  @param {String} name the name of the color scale to render
  @param {HTMLCanvasElement} canvas the canvas to render to