code: function drawGradient(legend, barGroup, y) {
    var id = "terriajs-legend-gradient" + ++gradientCount;
    var defs = addSvgElement(legend, "defs", {}); // apparently it's ok to have the defs anywhere in the doc
    var linearGradient = svgElement(legend, "linearGradient", {
      x1: "0",
      x2: "0",
      y1: "1",
      y2: "0",
      id: id
    });
    legend.gradientColorMap.forEach(function(c, i) {
      linearGradient.appendChild(
        svgElement(legend, "stop", {
          offset: c.offset,
          "stop-color": c.color
        })
      );
    });
    defs.appendChild(linearGradient);
  
    var gradientItems = legend.items.filter(function(item) {
      return !defined(item.color);
    });
  
    var totalSpacingAbove = gradientItems.reduce(function(prev, item) {
      return prev + (item.spacingAbove || 0);
    }, 0);
    var barHeight = Math.max(
      (legend.computedItemHeight + legend.itemSpacing) * gradientItems.length +
        totalSpacingAbove,
      legend.barHeightMin
    );
  
    addSvgElement(
      legend,
      "rect",
      {
        x: legend.barLeft,
        y: y,
        width: legend.itemWidth,
        height: barHeight,
        fill: "url(#" + id + ")"
      },
      "gradient-bar"
    );
  
    return barHeight;
  }
docs: /* The older, non-quantised, smooth gradient.