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

Documentation for using Vega-Interpreter/AST/CSP with vega-embed for Single Page Applications (Angular etc.) #473

Closed
jornfranke opened this issue Jun 14, 2020 · 5 comments

Comments

@jornfranke
Copy link

I spend some time to get vega-embed work with vega-interpreter to ensure safe Content-Security-Policies (CSP). The issue was that vega-interpreter works with vega-embed using a Javascript only application. However, single page applications based on Angular (or any other framework) compile each module individually, which means one cannot share objectnames/variables cross modules. However, given the examples of the documentation this breaks the underlying assumption that they can be shared.

I did in the end a minor modification to make this also work.
The tested library versions are:
Angular 9 (older might work as well)
vega-embed 6.9.0
vega-interpreter 1.0.1


import {vega} from 'vega-embed';
import embed, {Mode,VisualizationSpec} from 'vega-embed';
import { Renderers } from 'vega';
import * as vegaInterpreter  from 'vega-interpreter';
 
{....}

 embedOpts={}
    embedOpts.ast=true;    
   
// this is the important line to add in single page applications
(vega as any).expressionInterpreter=vegaInterpreter.expressionInterpreter;
/// as usual 
       await embed(element, spec, embedOpts);
    

I propose to add this to the documentation. I verified that it works.

Please let me know if this is of interests.

@domoritz
Copy link
Member

I'll do #474 instead. It's cleaner and doesn't require any special documentation.

@jornfranke
Copy link
Author

jornfranke commented Jun 15, 2020 via email

@domoritz
Copy link
Member

domoritz commented Jun 15, 2020

Yes, in Vega but Vega-Embed can be smart about it. I decided to implement a set of smart defaults. Take a look at #475 and let me know what you think.

@jornfranke
Copy link
Author

jornfranke commented Jun 15, 2020 via email

@domoritz
Copy link
Member

Thank you for being persistent, trying out fixes, and helping us get to cleaner solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants