How to use the vega-scale.scaleFraction function in vega-scale

To help you get started, we’ve selected a few vega-scale 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 vega / vega / packages / vega-encode / src / LegendEntries.js View on Github external
if (ellipsis) {
      ellipsis = values[items.length];
      items.push(ingest({
        index:    items.length,
        label:    `\u2026${values.length-items.length} entries`,
        value:    ellipsis,
        offset:   offset,
        size:     size(ellipsis, _)
      }));
    }
  }

  else if (type === Gradient) {
    domain = scale.domain(),
    fraction = scaleFraction(scale, domain[0], peek(domain));

    // if automatic label generation produces 2 or fewer values,
    // use the domain end points instead (fixes vega/vega#1364)
    if (values.length < 3 && !_.values && domain[0] !== peek(domain)) {
      values = [domain[0], peek(domain)];
    }

    items = values.map(function(value, index) {
      return ingest({
        index: index,
        label: format(value, index, values),
        value: value,
        perc:  fraction(value)
      });
    });
  }
github vega / vega / packages / vega-functions / src / scale-gradient.js View on Github external
const gradient = Gradient(p0, p1);

  let stops = scale.domain(),
      min = stops[0],
      max = peek(stops),
      fraction = identity

  if (!(max - min)) {
    // expand scale if domain has zero span, fix #1479
    scale = (scale.interpolator
      ? get('sequential')().interpolator(scale.interpolator())
      : get('linear')().interpolate(scale.interpolate()).range(scale.range())
    ).domain([min=0, max=1]);
  } else {
    fraction = scaleFraction(scale, min, max);
  }

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

  stops.forEach(_ => gradient.stop(fraction(_), scale(_)));

  return gradient;
}