Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the url resolver to its full capabilities for vega. #7098

Merged
merged 1 commit into from Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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