lyra
lyra copied to clipboard
Expose an API
Is there a way to easily add a new dataset via code? For example, in voyager, I can run voyagerInstance.updateData(data) as JavaScript to update the data source.
Can I do something similar here, i.e. something like lyraInstance.addDataset(data)
, where data would just be inline data values in the format that vega accepts?
Something like store.dispatch(addDataset(...))
? But I'm not sure what to pass to addDataset
. Or am I on a wrong track entirely here?
Other APIs that would be nice to have are: a) a way to extract the current spec (i.e. lyraInstance.getCurrentSpec()
) as a vega spec (I think this is all based on vega, right?). And maybe b) can one load a vega spec into lyra? The latter is a little less crucial for what I hope to do.
For now I added
(global as any).addData = (name: string, data: string) => {
const parsed = dsUtils.parseRaw(data);
const values = parsed.values;
const pipeline = Pipeline({name});
const ds = Dataset({
name: name,
format: parsed.format,
_schema: dsUtils.schema(values)
});
addPipeline(pipeline, ds, values)(store.dispatch);
}
(global as any).getVegaSpec = () => {
return ctrl.export()
}
to index.ts and that essentially is all I need.
Could something like that be added to the repo here?
There is one twist: instead of passing data
as string
it would probably make more sense if I could pass it directly as a list of objects, i.e. if I could pass something that is already parsed.