How to use the vega-schema-url-parser function in vega-schema-url-parser

To help you get started, we’ve selected a few vega-schema-url-parser 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-embed / src / embed.ts View on Github external
export function guessMode(spec: VisualizationSpec, providedMode?: Mode): Mode {
  // Decide mode
  if (spec.$schema) {
    const parsed = schemaParser(spec.$schema);
    if (providedMode && providedMode !== parsed.library) {
      console.warn(
        `The given visualization spec is written in ${NAMES[parsed.library]}, but mode argument sets ${NAMES[
          providedMode
        ] ?? providedMode}.`
      );
    }

    const mode = parsed.library as Mode;

    if (!satisfies(VERSION[mode], `^${parsed.version.slice(1)}`)) {
      console.warn(
        `The input spec uses ${NAMES[mode]} ${parsed.version}, but the current version of ${NAMES[mode]} is v${VERSION[mode]}.`
      );
    }
github vega / vega-embed / src / embed.ts View on Github external
style.innerText =
        opts.defaultStyle === undefined || opts.defaultStyle === true
          ? (embedStyle ?? '').toString()
          : opts.defaultStyle;

      document.head.appendChild(style);
    }
  }

  const mode = guessMode(spec, opts.mode);

  let vgSpec: VgSpec = PREPROCESSOR[mode](spec, config);

  if (mode === 'vega-lite') {
    if (vgSpec.$schema) {
      const parsed = schemaParser(vgSpec.$schema);

      if (!satisfies(VERSION.vega, `^${parsed.version.slice(1)}`)) {
        console.warn(`The compiled spec uses Vega ${parsed.version}, but current version is v${VERSION.vega}.`);
      }
    }
  }

  const div = typeof el === 'string' ? document.querySelector(el) : el;
  if (!div) {
    throw Error('${el} does not exist');
  }

  div.classList.add('vega-embed');
  if (actions) {
    div.classList.add('has-actions');
  }
github elastic / kibana / src / legacy / core_plugins / vis_type_vega / public / data_model / vega_parser.js View on Github external
_parseSchema() {
    if (!this.spec.$schema) {
      this._onWarning(i18n.translate('visTypeVega.vegaParser.inputSpecDoesNotSpecifySchemaWarningMessage', {
        defaultMessage: 'The input spec does not specify a {schemaParam}, defaulting to {defaultSchema}',
        values: { defaultSchema: `"${DEFAULT_SCHEMA}"`, schemaParam: '"$schema"' },
      }));
      this.spec.$schema = DEFAULT_SCHEMA;
    }

    const schema = schemaParser(this.spec.$schema);
    const isVegaLite = schema.library === 'vega-lite';
    const libVersion = isVegaLite ? vegaLite.version : vega.version;

    if (versionCompare(schema.version, libVersion) > 0) {
      this._onWarning(i18n.translate('visTypeVega.vegaParser.notValidLibraryVersionForInputSpecWarningMessage', {
        defaultMessage: 'The input spec uses {schemaLibrary} {schemaVersion}, but current version of {schemaLibrary} is {libraryVersion}.',
        values: {
          schemaLibrary: schema.library,
          schemaVersion: schema.version,
          libraryVersion: libVersion,
        },
      }));
    }

    return isVegaLite;
  }
github nyurik / kibana-vega-vis / public / vega_view / parse_input_spec.js View on Github external
export function parseInputSpec(inputSpec, onWarning) {
  let spec = { ...inputSpec };

  if (!spec.$schema) {
    onWarning(`The input spec does not specify a "$schema", defaulting to "${DEFAULT_SCHEMA}"`);
    spec.$schema = DEFAULT_SCHEMA;
  }

  const schema = schemaParser(spec.$schema);
  const isVegaLite = schema.library === 'vega-lite';
  const libVersion = isVegaLite ? vegaLite.version : vega.version;

  if (versionCompare(schema.version, libVersion) > 0) {
    onWarning(
      `The input spec uses "${schema.library}" ${schema.version}, but ` +
      `current version of "${schema.library}" is ${libVersion}.`
    );
  }

  const hostConfig = spec._hostConfig;
  if (hostConfig !== undefined) {
    delete spec.hostConfig;
    if (typeof hostConfig !== 'object') {
      throw new Error('_hostConfig must be an object');
    }
github elastic / kibana / src / core_plugins / vega / public / data_model / vega_parser.js View on Github external
_parseSchema() {
    if (!this.spec.$schema) {
      this._onWarning(i18n.translate('vega.vegaParser.inputSpecDoesNotSpecifySchemaWarningMessage', {
        defaultMessage: 'The input spec does not specify a {schemaParam}, defaulting to {defaultSchema}',
        values: { defaultSchema: `"${DEFAULT_SCHEMA}"`, schemaParam: '"$schema"' },
      }));
      this.spec.$schema = DEFAULT_SCHEMA;
    }

    const schema = schemaParser(this.spec.$schema);
    const isVegaLite = schema.library === 'vega-lite';
    const libVersion = isVegaLite ? vegaLite.version : vega.version;

    if (versionCompare(schema.version, libVersion) > 0) {
      this._onWarning(i18n.translate('vega.vegaParser.notValidLibraryVersionForInputSpecWarningMessage', {
        defaultMessage: 'The input spec uses {schemaLibrary} {schemaVersion}, but current version of {schemaLibrary} is {libraryVersion}.',
        values: {
          schemaLibrary: schema.library,
          schemaVersion: schema.version,
          libraryVersion: libVersion,
        },
      }));
    }

    return isVegaLite;
  }
github vega / vega-desktop / viewer / utils / helper.js View on Github external
export function getFormatFromSpec(spec, fallback = FORMAT.UNKNOWN) {
  if (spec.$schema) {
    const {library} = vegaSchemaUrlParser(spec.$schema);
    if (library === 'vega-lite') {
      return FORMAT.VEGA_LITE;
    }

    if (library === 'vega') {
      return FORMAT.VEGA;
    }
  }

  return fallback;
}
github nyurik / kibana-vega-vis / public / data_model / vega_parser.js View on Github external
_parseSchema() {
    if (!this.spec.$schema) {
      this._onWarning(`The input spec does not specify a "$schema", defaulting to "${DEFAULT_SCHEMA}"`);
      this.spec.$schema = DEFAULT_SCHEMA;
    }

    const schema = schemaParser(this.spec.$schema);
    const isVegaLite = schema.library === 'vega-lite';
    const libVersion = isVegaLite ? vegaLite.version : vega.version;

    if (versionCompare(schema.version, libVersion) > 0) {
      this._onWarning(
        `The input spec uses ${schema.library} ${schema.version}, but ` +
        `current version of ${schema.library} is ${libVersion}.`
      );
    }

    return isVegaLite;
  }
github Kitware / candela / packages / vega / src / mixin / VegaView.js View on Github external
_resizeContent (spec, size) {
    if (spec.spec) {
      spec.spec.width = size.width;
      spec.spec.height = size.height;
    } else {
      spec.width = size.width;
      spec.height = size.height;
    }
    let vegaSpec = spec;
    if (spec.$schema && schemaParser(spec.$schema).library === 'vega-lite') {
      vegaSpec = vegaLiteCompile(spec).spec;
    }
    let handler = new Handler();
    this.view = new View(parse(vegaSpec))
      .renderer(this.options.renderer || 'canvas')
      .tooltip(handler.call)
      .initialize(this.content)
      .hover()
      .run();

    return {
      width: window.parseInt(this.content.firstChild.getAttribute('width')),
      height: window.parseInt(this.content.firstChild.getAttribute('height'))
    };
  }

vega-schema-url-parser

A parser to get the library and version from Vega and Vega-Lite schema URLs.

BSD-3-Clause
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular vega-schema-url-parser functions