Skip to content

Commit

Permalink
#20 transforms data references scan base case patch
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomFractals committed Mar 21, 2019
1 parent d25bf14 commit 90e128b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-vega-viewer",
"displayName": "Vega Viewer",
"description": "Vega Viewer",
"version": "3.2.0",
"version": "3.2.1",
"publisher": "RandomFractalsInc",
"author": "Taras Novak",
"contributors": [
Expand Down
26 changes: 16 additions & 10 deletions src/vega.preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ export class VegaPreview {
const dataFiles = {};
// get top level data urls
let dataUrls: Array<string> = this.getDataUrls(spec);

// append nested spec data urls for view compositions (facets, repeats, etc.)
dataUrls = dataUrls.concat(this.getDataUrls(spec['spec']));
// console.log('vega.viewer:dataUrls:', dataUrls);

// get all local files data
dataUrls.filter(url => !url.startsWith('http')).forEach(url => {
// get local file data
const fileData: string = this.getFileData(url);
Expand All @@ -167,9 +171,12 @@ export class VegaPreview {

private getDataUrls(spec: any): Array<string> {
let dataUrls: Array<string> = [];
if (spec === undefined){
return dataUrls; // base case
}
const data = spec['data'];
const layer = spec['layer'];
const transform = spec['transform'];
const layers = spec['layer'];
const transforms = spec['transform'];
if (data !== undefined) {
// get top level data references
if (Array.isArray(data)) {
Expand All @@ -181,19 +188,18 @@ export class VegaPreview {
dataUrls.push(data['url']);
}
}
if (layer !== undefined && Array.isArray(layer)) {
// get layer data references
layer.forEach(data => {
dataUrls = dataUrls.concat(this.getDataUrls(data));
if (layers !== undefined && Array.isArray(layers)) {
// get layers data references
layers.forEach(layer => {
dataUrls = dataUrls.concat(this.getDataUrls(layer));
});
}
if (transform !== undefined) {
if (transforms !== undefined) {
// get transform data references
transform.forEach(data => {
dataUrls = dataUrls.concat(this.getDataUrls(data['from']));
transforms.forEach(transformData => {
dataUrls = dataUrls.concat(this.getDataUrls(transformData['from']));
});
}
// console.log('vega.viewer:dataUrls:', dataUrls);
return dataUrls;
}

Expand Down

0 comments on commit 90e128b

Please sign in to comment.