import {Gradient} from 'vega-scenegraph';
import {scaleFraction} from 'vega-scale';

export default function(scale, p0, p1, count) {
  var gradient = Gradient(p0, p1),
      stops = scale.domain(),
      min = stops[0],
      max = stops[stops.length-1],
      fraction = scaleFraction(scale, min, max);

  if (scale.ticks) {
    stops = scale.ticks(+count || 15);
    if (min !== stops[0]) stops.unshift(min);
    if (max !== stops[stops.length-1]) stops.push(max);
  }

  for (var i=0, n=stops.length; i<n; ++i) {
    gradient.stop(fraction(stops[i]), scale(stops[i]));
  }

  return gradient;
}

@@ -1,16 +1,50 @@
+import %7BgetScale%7D from './scale';%0A
 import %7BGradient
@@ -156,19 +156,79 @@
 1, count
-) %7B
+, group) %7B%0A  scale = getScale(scale, (group %7C%7C this).context);%0A
 %0A  var g

Fix scale lookup for gradient expr function. (vega/vega#1143)