<commit_before>import * as transforms from '../transforms/index';

import {
  parse,
  context
} from 'vega-runtime';

import {
  rgb,
  lab,
  hcl,
  hsl
} from 'd3-color';

var encode = {
  rgb: rgb,
  lab: lab,
  hcl: hcl,
  hsl: hsl
};

export default function(dataflow, spec) {
  return parse(spec, context(dataflow, transforms, encode));
}<commit_msg>Add expression functions.<commit_after>import * as transforms from '../transforms/index';

import {
  parse,
  context
} from 'vega-runtime';

import {
  rgb,
  lab,
  hcl,
  hsl
} from 'd3-color';

function functions(fn, ctx) {
  fn.rgb = rgb;
  fn.lab = lab;
  fn.hcl = hcl;
  fn.hsl = hsl;

  fn.scale = function(name, value) {
    var s = ctx.scales[name];
    return s ? s.value(value) : undefined;
  };

  fn.scaleInvert = function(name, value) {
    var s = ctx.scales[name];
    return s ? s.value.invert(value) : undefined;
  };

  fn.scaleCopy = function(source, target) {
    var s = ctx.scales[source],
        t = ctx.scales[target];
    return (s && t)
      ? null // TODO: perform copy
      : undefined;
  };

  fn.indata = function(name, field, value) {
    var index = ctx.data['index:' + field];
    return index ? !!index.value.get(value) : undefined;
  };

  return ctx;
}

export default function(view, spec) {
  var fn = {},
      ctx = context(view, transforms, fn);
  return parse(spec, functions(fn, ctx));
}
{'fraction_non_alphanumeric': 0.15301724137931033, 'fraction_numerical': 0.0014367816091954023, 'mean_word_length': 2.9686609686609686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178885', 'n_tokens_mistral': 518, 'n_tokens_neox': 498, 'n_words': 130}