Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Item, GroupItem} from 'vega-scenegraph';
import {inherits} from 'vega-util';
/**
* Bind scenegraph items to a scenegraph mark instance.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {object} params.markdef - The mark definition for creating the mark.
* This is an object of legal scenegraph mark properties which *must* include
* the 'marktype' property.
*/
export default function Mark(params) {
Transform.call(this, null, params);
}
var prototype = inherits(Mark, Transform);
prototype.transform = function(_, pulse) {
var mark = this.value;
// acquire mark on first invocation, bind context and group
if (!mark) {
mark = pulse.dataflow.scenegraph().mark(_.markdef, lookup(_), _.index);
mark.group.context = _.context;
if (!_.context.group) _.context.group = mark.group;
mark.source = this.source; // point to upstream collector
mark.clip = _.clip;
mark.interactive = _.interactive;
this.value = mark;
}
// initialize entering items
* @param {function(object): *} params.key - The key field to facet by.
*/
export default function Facet(params) {
Transform.call(this, {}, params);
this._keys = fastmap(); // cache previously calculated key values
// keep track of active subflows, use as targets array for listeners
// this allows us to limit propagation to only updated subflows
var a = this._targets = [];
a.active = 0;
a.forEach = function(f) {
for (var i=0, n=a.active; i
/**
* Generates data tuples using a provided generator function.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {function(Parameters): object} params.generator - A tuple generator
* function. This function is given the operator parameters as input.
* Changes to any additional parameters will not trigger re-calculation
* of previously generated tuples. Only future tuples are affected.
* @param {number} params.size - The number of tuples to produce.
*/
export default function Generate(params) {
Transform.call(this, [], params);
}
var prototype = inherits(Generate, Transform);
prototype.transform = function(_, pulse) {
var data = this.value,
out = pulse.fork(pulse.ALL),
num = _.size - data.length,
gen = _.generator,
add, rem, t;
if (num > 0) {
// need more tuples, generate and add
for (add=[]; --num >= 0;) {
add.push(t = ingest(gen(_)));
data.push(t);
}
out.add = out.add.length
? out.materialize(out.ADD).add.concat(add)
Transform.call(this, Bitmaps(), params);
this._indices = null;
this._dims = null;
}
CrossFilter.Definition = {
"type": "CrossFilter",
"metadata": {},
"params": [
{ "name": "fields", "type": "field", "array": true, "required": true },
{ "name": "query", "type": "array", "array": true, "required": true,
"content": {"type": "number", "array": true, "length": 2} }
]
};
var prototype = inherits(CrossFilter, Transform);
prototype.transform = function(_, pulse) {
if (!this._dims) {
return this.init(_, pulse);
} else {
var init = _.modified('fields')
|| _.fields.some(function(f) { return pulse.modified(f.fields); });
return init
? this.reinit(_, pulse)
: this.eval(_, pulse);
}
};
prototype.init = function(_, pulse) {
var fields = _.fields,
import Operator from '../Operator';
import {inherits, key} from 'vega-util';
/**
* Generates a key function.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {Array} params.fields - The field name(s) for the key function.
*/
export default function Key(params) {
Operator.call(this, null, update, params);
}
inherits(Key, Operator);
function update(_) {
return (this.value && !_.modified()) ? this.value : key(_.fields);
}
"params": [
{ "name": "size", "type": "number", "array": true, "length": 2 },
{ "name": "font", "type": "string", "expr": true, "default": "sans-serif" },
{ "name": "fontStyle", "type": "string", "expr": true, "default": "normal" },
{ "name": "fontWeight", "type": "string", "expr": true, "default": "normal" },
{ "name": "fontSize", "type": "number", "expr": true, "default": 14 },
{ "name": "fontSizeRange", "type": "number", "array": "nullable", "default": [10, 50] },
{ "name": "rotate", "type": "number", "expr": true, "default": 0 },
{ "name": "text", "type": "field" },
{ "name": "spiral", "type": "string", "values": ["archimedean", "rectangular"] },
{ "name": "padding", "type": "number", "expr": true },
{ "name": "as", "type": "string", "array": true, "length": 7, "default": Output }
]
};
var prototype = inherits(Wordcloud, Transform);
prototype.transform = function(_, pulse) {
if (_.size && !(_.size[0] && _.size[1])) {
error('Wordcloud size dimensions must be non-zero.');
}
function modp(param) {
var p = _[param];
return isFunction(p) && pulse.modified(p.fields);
}
var mod = _.modified();
if (!(mod || pulse.changed(pulse.ADD_REM) || Params.some(modp))) return;
var data = pulse.materialize(pulse.SOURCE).source,
layout = this.value,
/**
* Extracts an array of values. Assumes the source data has already been
* reduced as needed (e.g., by an upstream Aggregate transform).
* @constructor
* @param {object} params - The parameters for this operator.
* @param {function(object): *} params.field - The domain field to extract.
* @param {function(*,*): number} [params.sort] - An optional
* comparator function for sorting the values. The comparator will be
* applied to backing tuples prior to value extraction.
*/
export default function Values(params) {
Transform.call(this, null, params);
}
var prototype = inherits(Values, Transform);
prototype.transform = function(_, pulse) {
var run = !this.value
|| _.modified('field')
|| _.modified('sort')
|| pulse.changed()
|| (_.sort && pulse.modified(_.sort.fields));
if (run) {
this.value = (_.sort
? pulse.source.slice().sort(stableCompare(_.sort))
: pulse.source).map(_.field);
}
};
import {accessorName, error, inherits} from 'vega-util';
/**
* Extend tuples by joining them with values from a lookup table.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {Map} params.index - The lookup table map.
* @param {Array} params.as - Output field names for each lookup value.
* @param {*} [params.default] - A default value to use if lookup fails.
*/
export default function Lookup(params) {
Transform.call(this, {}, params);
}
var prototype = inherits(Lookup, Transform);
prototype.transform = function(_, pulse) {
var out = pulse,
as = _.as,
keys = _.fields,
index = _.index,
values = _.values,
defaultValue = _.default==null ? null : _.default,
reset = _.modified(),
flag = reset ? pulse.SOURCE : pulse.ADD,
n = keys.length,
set, m, mods;
if (values) {
m = values.length;
/**
* Extracts an array of values. Assumes the source data has already been
* reduced as needed (e.g., by an upstream Aggregate transform).
* @constructor
* @param {object} params - The parameters for this operator.
* @param {function(object): *} params.field - The domain field to extract.
* @param {function(*,*): number} [params.sort] - An optional
* comparator function for sorting the values. The comparator will be
* applied to backing tuples prior to value extraction.
*/
export default function Values(params) {
Transform.call(this, null, params);
}
var prototype = inherits(Values, Transform);
prototype.transform = function(_, pulse) {
var run = !this.value
|| _.modified('field')
|| _.modified('sort')
|| pulse.changed()
|| (_.sort && pulse.modified(_.sort.fields));
if (run) {
this.value = (_.sort
? pulse.source.slice().sort(_.sort)
: pulse.source).map(_.field);
}
};
}
Partition.Definition = {
"type": "Partition",
"metadata": {"tree": true, "modifies": true},
"params": [
{ "name": "field", "type": "field" },
{ "name": "sort", "type": "compare" },
{ "name": "padding", "type": "number", "default": 0 },
{ "name": "round", "type": "boolean", "default": false },
{ "name": "size", "type": "number", "array": true, "length": 2 },
{ "name": "as", "type": "string", "array": true, "length": Output.length, "default": Output }
]
};
var prototype = inherits(Partition, HierarchyLayout);
prototype.layout = partition;
prototype.params = ['size', 'round', 'padding'];
prototype.fields = Output;