Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function assignField(i) {
// If all fields are assigned, save
if (i === fieldDefs.length) {
// at the minimal all chart should have x, y, geo, text or arc
if (rule.encoding(tmpEncoding, stats, opt)) {
encodings.push(duplicate(tmpEncoding));
}
return;
}
// Otherwise, assign i-th field
var fieldDef = fieldDefs[i];
for (var j in opt.channelList) {
var channel = opt.channelList[j],
isDim = isDimension(fieldDef);
const supportedRole = getSupportedRole(channel);
// TODO: support "multiple" assignment
if (
// encoding not used
!(channel in tmpEncoding) &&
// channel support the assigned role
((isDim && supportedRole.dimension) || (!isDim && supportedRole.measure)) &&
// the field satisfies the channel's rule
rule.channel[channel](tmpEncoding, fieldDef, stats, opt)
) {
tmpEncoding[channel] = fieldDef;
assignField(i + 1);
delete tmpEncoding[channel];
}
export function tick(encoding: Encoding, stats, opt: SpecOption) {
// jshint unused:false
if (encoding.x || encoding.y) {
if(isAggregate(encoding)) return false;
var xIsDim = isDimension(encoding.x),
yIsDim = isDimension(encoding.y);
return (!xIsDim && (!encoding.y || yIsDim)) ||
(!yIsDim && (!encoding.x || xIsDim));
}
return false;
}
function xyPlotRules(encoding: Encoding, stats, opt: SpecOption) {
if (encoding.row || encoding.column) { // have facet(s)
if (opt.omitNonTextAggrWithAllDimsOnFacets) {
// remove all aggregated charts with all dims on facets (row, column)
if (isAggrWithAllDimOnFacets(encoding)) { return false; }
}
}
var isDimX = isDimension(encoding.x),
isDimY = isDimension(encoding.y);
// If both x and y are dimension, and the plot is not aggregated,
// there might be occlusion.
if (opt.omitRawWithXYBothDimension && isDimX && isDimY && !isAggregate(encoding)) {
// FIXME actually check if there would be occlusion #90
return false;
}
if (opt.omitTranspose) {
if (isDimX !== isDimY) { // dim x mea
// create horizontal histogram for ordinal
if ((encoding.y.type === Type.NOMINAL || encoding.y.type === Type.ORDINAL) && isMeasure(encoding.x)) {
return true;
}
// vertical histogram for binned Q and T
export function point(encoding: Encoding, stats, opt: SpecOption) {
if(!facetsRule(encoding, stats, opt)) return false;
if (encoding.x && encoding.y) {
// have both x & y ==> scatter plot / bubble plot
var xIsDim = isDimension(encoding.x),
yIsDim = isDimension(encoding.y);
// For OxO
if (xIsDim && yIsDim) {
// TODO: revise if we need his
// shape doesn't work with both x, y as ordinal
if (encoding.shape) {
return false;
}
// TODO(kanitw): check that there is quant at least ...
if (encoding.color && isDimension(encoding.color)) {
return false;
}
}
export function point(encoding: Encoding, stats, opt: SpecOption) {
if(!facetsRule(encoding, stats, opt)) return false;
if (encoding.x && encoding.y) {
// have both x & y ==> scatter plot / bubble plot
var xIsDim = isDimension(encoding.x),
yIsDim = isDimension(encoding.y);
// For OxO
if (xIsDim && yIsDim) {
// TODO: revise if we need his
// shape doesn't work with both x, y as ordinal
if (encoding.shape) {
return false;
}
// TODO(kanitw): check that there is quant at least ...
if (encoding.color && isDimension(encoding.color)) {
return false;
}
}
} else { // plot with one axis = dot plot
tf.forEach(function(f) {
if (vlFieldDef.isDimension(f)) {
hasDimension = true;
} else {
hasMeasure = true;
if (!f.aggregate) { hasRaw = true; }
}
});
// Constraint: Omit Aggregate Plot with measure only
}
// FIXME actually check if there would be occlusion #90
// need to aggregate on either x or y
var aggEitherXorY =
(!encoding.x || encoding.x.aggregate === undefined) !== // xor
(!encoding.y || encoding.y.aggregate === undefined);
if (aggEitherXorY) {
var eitherXorYisDimOrNull =
(!encoding.x || isDimension(encoding.x)) !== // xor
(!encoding.y || isDimension(encoding.y));
if (eitherXorYisDimOrNull) {
var aggregate = encoding.x.aggregate || encoding.y.aggregate;
// TODO: revise
return !(opt.omitStackedAverage && aggregate ==='mean' && encoding.color);
}
}
return false;
}
scores = mappings.map(function(m) {
var roleScore = vlFieldDef.isDimension(m.fieldDef) ?
dimensionScore : measureScore;
var score = roleScore(m.fieldDef, m.channel, spec.mark, stats, opt);
return !selected || selected[m.fieldDef.field] ? score : Math.pow(score, 0.125);
});
function isAggrWithAllDimOnFacets(encoding) {
var hasAggr = false, hasOtherO = false;
for (var c in encoding) {
const channel: Channel = c as any;
var fieldDef = encoding[channel];
if (fieldDef.aggregate) {
hasAggr = true;
}
if (isDimension(fieldDef) && (channel !== ROW && channel !== COLUMN)) {
hasOtherO = true;
}
if (hasAggr && hasOtherO) { break; }
}
return hasAggr && !hasOtherO;
};