How to use the vega-util.isNumber function in vega-util

To help you get started, we’ve selected a few vega-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vega / vega-lite / src / datetime.ts View on Github external
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));
  }
github vega / vega-lite / build / src / compile / mark / bar.js View on Github external
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(
github vega / vega-lite / build / src / compile / scale / range.js View on Github external
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));
}
/**
github vega / vega-scenegraph / src / util / equal.js View on Github external
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);
}
github vega / vega / packages / vega-geo / src / Isocontour.js View on Github external
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));
}
github vega / vega-lite / src / compile / scale / range.ts View on Github external
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;
github vega / vega-lite / build / src / compile / scale / range.js View on Github external
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;