How to use the vega-lite.spec function in vega-lite

To help you get started, we’ve selected a few vega-lite 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-tooltip / src / supplementField.ts View on Github external
options.fields.forEach(function (fieldOption: FieldOption) {
        // get the fieldDef in vlSpec that matches the fieldOption
        const fieldDef = getFieldDef(vl.spec.fieldDefs(vlSpec), fieldOption);

        // supplement the fieldOption with fieldDef and config
        const supplementedFieldOption = supplementFieldOption(fieldOption, fieldDef, vlSpec.config, normalizedVlSpec);

        supplementedFields.push(supplementedFieldOption);
      });
    }
github vega / vega-tooltip / src / vg-tooltip.ts View on Github external
vl.fieldDef.field(fieldDef) : fieldOption.field;

  // If a fieldDef is a (TIMEUNIT)T, we check if the original T is present in the vlSpec.
  // If only (TIMEUNIT)T is present in vlSpec, we set `removeOriginalTemporalField` to T,
  // which will cause function removeDuplicateTimeFields() to remove T and only keep (TIMEUNIT)T
  // in item data.
  // If both (TIMEUNIT)T and T are in vlSpec, we set `removeOriginalTemporalField` to undefined,
  // which will leave both T and (TIMEUNIT)T in item data.
  // Note: user should never have to provide this boolean in options
  if (fieldDef.type === TEMPORAL && fieldDef.timeUnit) {
    // in most cases, if it's a (TIMEUNIT)T, we remove original T
    var originalTemporalField = fieldDef.field;
    supplementedFieldOption.removeOriginalTemporalField = originalTemporalField;

    // handle corner case: if T is present in vlSpec, then we keep both T and (TIMEUNIT)T
    var fieldDefs = vl.spec.fieldDefs(vlSpec);
    for (var i = 0; i < fieldDefs.length; i++) {
      if (fieldDefs[i].field === originalTemporalField && !fieldDefs[i].timeUnit) {
        supplementedFieldOption.removeOriginalTemporalField = undefined;
        break;
      }
    }

  }

  // supplement title
  if (!config.countTitle) config.countTitle = vl.config.defaultConfig.countTitle; // use vl default countTitle
  supplementedFieldOption.title = fieldOption.title ?
    fieldOption.title : vl.fieldDef.title(fieldDef, config);

  // supplement formatType
  supplementedFieldOption.formatType = fieldOption.formatType ?
github vega / vega-tooltip / src / supplementField.ts View on Github external
supplementedFieldOption.field = vl.fieldDef.vgField(fieldDef) || fieldOption.field;

  // If a fieldDef is a (TIMEUNIT)T, we check if the original T is present in the vlSpec.
  // If only (TIMEUNIT)T is present in vlSpec, we set `removeOriginalTemporalField` to T,
  // which will cause function removeDuplicateTimeFields() to remove T and only keep (TIMEUNIT)T
  // in item data.
  // If both (TIMEUNIT)T and T are in vlSpec, we set `removeOriginalTemporalField` to undefined,
  // which will leave both T and (TIMEUNIT)T in item data.
  // Note: user should never have to provide this boolean in options
  if (fieldDef.type === TEMPORAL && fieldDef.timeUnit) {
    // in most cases, if it's a (TIMEUNIT)T, we remove original T
    const originalTemporalField = fieldDef.field;
    supplementedFieldOption.removeOriginalTemporalField = originalTemporalField;

    // handle corner case: if T is present in vlSpec, then we keep both T and (TIMEUNIT)T
    const fieldDefs = vl.spec.fieldDefs(vlSpec);
    for (const items of fieldDefs) {
      if (items.field === originalTemporalField && !items.timeUnit) {
        supplementedFieldOption.removeOriginalTemporalField = undefined;
        break;
      }
    }
  }

  // supplement title
  if (!config.countTitle) {
    config.countTitle = vl.config.defaultConfig.countTitle; // use vl default countTitle
  }
  let defaultTitle = vl.fieldDef.title(fieldDef, config);
  if (isPositionFieldDef(fieldDef)) {
    if (fieldDef.axis && fieldDef.axis.title) {
      defaultTitle = fieldDef.axis.title;
github vega / vega-tooltip / src / vg-tooltip.ts View on Github external
options.fields.forEach(function (fieldOption) {
        // get the fieldDef in vlSpec that matches the fieldOption
        var fieldDef = getFieldDef(vl.spec.fieldDefs(vlSpec), fieldOption);

        // supplement the fieldOption with fieldDef and config
        var supplementedFieldOption = supplementFieldOption(fieldOption, fieldDef, vlSpec);

        supplementedFields.push(supplementedFieldOption);
      })
    }