Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function(channel, rules, scope, params, fields) {
var code = '';
rules.forEach(function(rule) {
var value = entry(channel, rule, scope, params, fields);
code += rule.test
? expression(rule.test, scope, params, fields) + '?' + value + ':'
: value;
});
// if no else clause, terminate with null (vega/vega#1366)
if (peek(code) === ':') {
code += 'null';
}
return set('o', channel, code);
}
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)
});
});
}
else {
size = values.length - 1;
fraction = labelFraction(scale);
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)
});
});
}
else {
size = values.length - 1;
fraction = labelFraction(scale);
export function selectionVisitor(name, args, scope, params) {
if (args[0].type !== Literal) error('First argument to selection functions must be a string literal.');
const data = args[0].value,
op = args.length >= 2 && peek(args).value,
field = 'unit',
indexName = IndexPrefix + field,
dataName = DataPrefix + data;
// eslint-disable-next-line no-prototype-builtins
if (op === Intersect && !hasOwnProperty(params, indexName)) {
params[indexName] = scope.getData(data).indataRef(scope, field);
}
// eslint-disable-next-line no-prototype-builtins
if (!hasOwnProperty(params, dataName)) {
params[dataName] = scope.getData(data).tuplesRef();
}
}
export function validTicks(scale, ticks, count) {
var range = scale.range(),
lo = Math.floor(range[0]),
hi = Math.ceil(peek(range));
if (lo > hi) {
range = hi;
hi = lo;
lo = range;
}
ticks = ticks.filter(function(v) {
v = scale(v);
return lo <= v && v <= hi;
});
if (count > 0 && ticks.length > 1) {
var endpoints = [ticks[0], peek(ticks)];
while (ticks.length > count && ticks.length >= 3) {
ticks = ticks.filter(function(_, i) { return !(i % 2); });
lo = Math.floor(range[0]),
hi = Math.ceil(peek(range));
if (lo > hi) {
range = hi;
hi = lo;
lo = range;
}
ticks = ticks.filter(function(v) {
v = scale(v);
return lo <= v && v <= hi;
});
if (count > 0 && ticks.length > 1) {
var endpoints = [ticks[0], peek(ticks)];
while (ticks.length > count && ticks.length >= 3) {
ticks = ticks.filter(function(_, i) { return !(i % 2); });
}
if (ticks.length < 3) {
ticks = endpoints;
}
}
return ticks;
}
scale.tickFormat = function(count, specifier) {
return tickFormat(domain[0], peek(domain), count == null ? 10 : count, specifier);
};
export function labelFraction(scale) {
var domain = scale.domain(),
count = domain.length - 1,
lo = +domain[0],
hi = +peek(domain),
span = hi - lo;
if (scale.type === Threshold) {
var adjust = count ? span / count : 0.1;
lo -= adjust;
hi += adjust;
span = hi - lo;
}
return function(value) {
return (value - lo) / span;
};
}
prototype.lookup = function() {
return peek(this._lookup);
};