Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function normalizeMonth(m: string | number) {
if (isNumber(m)) {
// We accept 1-based month, so need to readjust to 0-based month
return (m - 1).toString();
} else {
const lowerM = m.toLowerCase();
const monthIndex = MONTHS.indexOf(lowerM);
if (monthIndex !== -1) {
return monthIndex + ''; // 0 for january, ...
}
const shortM = lowerM.substr(0, 3);
const shortMonthIndex = SHORT_MONTHS.indexOf(shortM);
if (shortMonthIndex !== -1) {
return shortMonthIndex + '';
}
// Invalid month
throw new Error(log.message.invalidTimeUnit('month', m));
}
function defaultSizeRef(markDef, sizeChannel, scaleName, scale, config) {
const markPropOrConfig = getFirstDefined(markDef[sizeChannel], markDef.size, getMarkConfig('size', markDef, config, { vgChannel: sizeChannel }));
if (markPropOrConfig !== undefined) {
return { value: markPropOrConfig };
}
if (scale) {
const scaleType = scale.get('type');
if (scaleType === 'point' || scaleType === 'band') {
if (config.bar.discreteBandSize !== undefined) {
return { value: config.bar.discreteBandSize };
}
if (scaleType === ScaleType.POINT) {
const scaleRange = scale.get('range');
if (isVgRangeStep(scaleRange) && isNumber(scaleRange.step)) {
return { value: scaleRange.step - 1 };
}
log.warn(log.message.BAR_WITH_POINT_SCALE_AND_RANGESTEP_NULL);
}
else {
// BAND
return ref.bandRef(scaleName);
}
}
else {
// continuous scale
return { value: config.bar.continuousBandSize };
}
}
// No Scale
const value = getFirstDefined(
return new SignalRefWrapper(() => `${min.signal} - 1`);
}
case 'line':
case 'trail':
case 'rule':
return config.scale.maxStrokeWidth;
case 'text':
return config.scale.maxFontSize;
case 'point':
case 'square':
case 'circle':
if (config.scale.maxSize) {
return config.scale.maxSize;
}
const pointStep = minXYRangeStep(xyRangeSteps, scaleConfig);
if (isNumber(pointStep)) {
return Math.pow(MAX_SIZE_RANGE_STEP_RATIO * pointStep, 2);
}
else {
return new SignalRefWrapper(() => `pow(${MAX_SIZE_RANGE_STEP_RATIO} * ${pointStep.signal}, 2)`);
}
}
/* istanbul ignore next: should never reach here */
// sizeRangeMax not implemented for the mark
throw new Error(log.message.incompatibleChannel('size', mark));
}
/**
export function sceneEqual(a, b, key) {
return (a === b) ? true
: (key === 'path') ? pathEqual(a, b)
: (a instanceof Date && b instanceof Date) ? +a === +b
: (isNumber(a) && isNumber(b)) ? Math.abs(a - b) <= TOLERANCE
: (!a || !b || !isObject(a) && !isObject(b)) ? a == b
: (a == null || b == null) ? false
: objectEqual(a, b);
}
function transformPaths(paths, grid, datum, _) {
let s = _.scale || grid.scale,
t = _.translate || grid.translate;
if (isFunction(s)) s = s(datum, _);
if (isFunction(t)) t = t(datum, _);
if ((s === 1 || s == null) && !t) return;
const sx = (isNumber(s) ? s : s[0]) || 1,
sy = (isNumber(s) ? s : s[1]) || 1,
tx = t && t[0] || 0,
ty = t && t[1] || 0;
paths.forEach(transform(grid, sx, sy, tx, ty));
}
function sizeRangeMax(mark: Mark, size: LayoutSizeMixins, model: UnitModel, config: Config): number | SignalRef {
const xyStepSignals = {
x: getBinStepSignal(model, 'x'),
y: getBinStepSignal(model, 'y')
};
switch (mark) {
case 'bar':
case 'tick': {
if (config.scale.maxBandSize !== undefined) {
return config.scale.maxBandSize;
}
const min = minXYStep(size, xyStepSignals, config.view);
if (isNumber(min)) {
return min - 1;
} else {
return new SignalRefWrapper(() => `${min.signal} - 1`);
}
}
case 'line':
case 'trail':
case 'rule':
return config.scale.maxStrokeWidth;
case 'text':
return config.scale.maxFontSize;
case 'point':
case 'square':
case 'circle': {
if (config.scale.maxSize) {
return config.scale.maxSize;
function sizeRangeMax(mark, xyRangeSteps, config) {
const scaleConfig = config.scale;
switch (mark) {
case 'bar':
case 'tick':
if (config.scale.maxBandSize !== undefined) {
return config.scale.maxBandSize;
}
const min = minXYRangeStep(xyRangeSteps, config.scale);
if (isNumber(min)) {
return min - 1;
}
else {
return new SignalRefWrapper(() => `${min.signal} - 1`);
}
case 'line':
case 'trail':
case 'rule':
return config.scale.maxStrokeWidth;
case 'text':
return config.scale.maxFontSize;
case 'point':
case 'square':
case 'circle':
if (config.scale.maxSize) {
return config.scale.maxSize;