Skip to content

Commit

Permalink
Merge pull request #110 from timkpaine/jlab4
Browse files Browse the repository at this point in the history
Support for initializing with schema
  • Loading branch information
texodus authored May 16, 2018
2 parents b03f319 + 7e0e9dc commit 4364184
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/perspective-jupyterlab/src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const PSP_CONTAINER_CLASS = 'jp-PSPContainer';

interface PerspectiveSpec {
data: string,
schema: string,
layout: string,
config: string;
}
Expand All @@ -46,6 +47,7 @@ export class RenderedPSP extends Widget implements IRenderMime.IRenderer {
let psp = (<any>(this.node.querySelector('perspective-viewer')));

let layout = JSON.parse(this._lyt);

for(let key in layout){
if(layout[key]){
if(key !== 'view'){
Expand All @@ -56,8 +58,13 @@ export class RenderedPSP extends Widget implements IRenderMime.IRenderer {
}
}

if (this._schema !== '') {
let schema = JSON.parse(this._schema);
psp.load(schema);
}

if (this._datatype === 'static') {
psp.load(this._data);
psp.update(this._data);
} else if (this._datatype === 'ws' || this._datatype === 'wss') {
let config = JSON.parse(this._config);
let send = config.send || '';
Expand Down Expand Up @@ -111,8 +118,9 @@ export class RenderedPSP extends Widget implements IRenderMime.IRenderer {
}

renderModel(model: IRenderMime.IMimeModel): Promise<void> {
const {data, layout, config} = model.data[MIME_TYPE] as any | PerspectiveSpec;
const {data, schema, layout, config} = model.data[MIME_TYPE] as any | PerspectiveSpec;
this._lyt = layout;
this._schema = schema;

try {
this._data = JSON.parse(data) as object;
Expand Down Expand Up @@ -156,6 +164,7 @@ export class RenderedPSP extends Widget implements IRenderMime.IRenderer {
private _data: object;
private _datatype: string;
private _datasrc: string;
private _schema: string;
private _lyt: string; // not widget layout
private _config: string;
private _loaded: boolean;
Expand Down

0 comments on commit 4364184

Please sign in to comment.