(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-dataflow'), require('vega-util')) : typeof define === 'function' && define.amd ? define(['exports', 'vega-dataflow', 'vega-util'], factory) : (global = global || self, factory(global.vega = {}, global.vega, global.vega)); }(this, function (exports, vegaDataflow, vegaUtil) { 'use strict'; /** * Parse an expression given the argument signature and body code. */ function expression(args, code, ctx) { // wrap code in return statement if expression does not terminate if (code[code.length-1] !== ';') { code = 'return(' + code + ');'; } var fn = Function.apply(null, args.concat(code)); return ctx && ctx.functions ? fn.bind(ctx.functions) : fn; } /** * Parse an expression used to update an operator value. */ function operatorExpression(code, ctx) { return expression(['_'], code, ctx); } /** * Parse an expression provided as an operator parameter value. */ function parameterExpression(code, ctx) { return expression(['datum', '_'], code, ctx); } /** * Parse an expression applied to an event stream. */ function eventExpression(code, ctx) { return expression(['event'], code, ctx); } /** * Parse an expression used to handle an event-driven operator update. */ function handlerExpression(code, ctx) { return expression(['_', 'event'], code, ctx); } /** * Parse an expression that performs visual encoding. */ function encodeExpression(code, ctx) { return expression(['item', '_'], code, ctx); } /** * Parse a set of operator parameters. */ function parseParameters(spec, ctx, params) { params = params || {}; var key, value; for (key in spec) { value = spec[key]; params[key] = vegaUtil.isArray(value) ? value.map(function(v) { return parseParameter(v, ctx, params); }) : parseParameter(value, ctx, params); } return params; } /** * Parse a single parameter. */ function parseParameter(spec, ctx, params) { if (!spec || !vegaUtil.isObject(spec)) return spec; for (var i=0, n=PARSERS.length, p; i