Skip to content

Commit

Permalink
Backport PR jupyterlab#7098: Use the url resolver to its full capabil…
Browse files Browse the repository at this point in the history
…ities for vega.
  • Loading branch information
blink1073 authored and MeeseeksDev[bot] committed Aug 28, 2019
1 parent efe7ec2 commit d4c71ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
13 changes: 5 additions & 8 deletions packages/vega4-extension/src/index.ts
Expand Up @@ -42,11 +42,6 @@ export const VEGA_MIME_TYPE = 'application/vnd.vega.v4+json';
*/
export const VEGALITE_MIME_TYPE = 'application/vnd.vegalite.v2+json';

/**
* A regex to test for a protocol in a URI.
*/
const protocolRegex = /^[A-Za-z]:/;

/**
* A widget for rendering Vega or Vega-Lite data, for usage with rendermime.
*/
Expand Down Expand Up @@ -97,9 +92,11 @@ export class RenderedVega extends Widget implements IRenderMime.IRenderer {
});

const sanitize = async (uri: string, options: any) => {
// If the uri is a path, get the download URI
if (!protocolRegex.test(uri)) {
uri = await this._resolver.getDownloadUrl(uri);
// Use the resolver for any URIs it wants to handle
const resolver = this._resolver;
if (resolver.isLocal(uri)) {
const absPath = await resolver.resolveUrl(uri);
uri = await resolver.getDownloadUrl(absPath);
}
return loader.sanitize(uri, options);
};
Expand Down
13 changes: 5 additions & 8 deletions packages/vega5-extension/src/index.ts
Expand Up @@ -42,11 +42,6 @@ export const VEGA_MIME_TYPE = 'application/vnd.vega.v5+json';
*/
export const VEGALITE_MIME_TYPE = 'application/vnd.vegalite.v3+json';

/**
* A regex to test for a protocol in a URI.
*/
const protocolRegex = /^[A-Za-z]:/;

/**
* A widget for rendering Vega or Vega-Lite data, for usage with rendermime.
*/
Expand Down Expand Up @@ -96,9 +91,11 @@ export class RenderedVega extends Widget implements IRenderMime.IRenderer {
http: { credentials: 'same-origin' }
});
const sanitize = async (uri: string, options: any) => {
// If the uri is a path, get the download URI
if (!protocolRegex.test(uri)) {
uri = await this._resolver.getDownloadUrl(uri);
// Use the resolver for any URIs it wants to handle
const resolver = this._resolver;
if (resolver.isLocal(uri)) {
const absPath = await resolver.resolveUrl(uri);
uri = await resolver.getDownloadUrl(absPath);
}
return loader.sanitize(uri, options);
};
Expand Down

0 comments on commit d4c71ac

Please sign in to comment.