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

About vega plot command #17

Closed
wangfenjin opened this issue Jan 18, 2021 · 6 comments · Fixed by #23
Closed

About vega plot command #17

wangfenjin opened this issue Jan 18, 2021 · 6 comments · Fixed by #23

Comments

@wangfenjin
Copy link
Contributor

Hi team,

I like this project, especially the idea integrate vega into the kernel.

The command is %XVEGA_PLOT X_FIELD EmployeeId GRID false Y_FIELD ReportsTo MARK area COLOR pink WIDTH 200 HEIGHT 200 <> SELECT EmployeeId, ReportsTo FROM employees like this I think it's two complated, we need to write a lot of code to parse the user input and user need to learn new syntax.

So I suggest we follow the style I implement in here:

%VEGA-LITE specs/arc_pie.vl.json 
SELECT 
    g.Name as category, 
    SUM(il.Quantity) as b, 
    ROUND((CAST(SUM(il.Quantity) as float) / (SELECT 
        SUM(Quantity) total
    FROM Chinook.InvoiceLine il
    INNER JOIN Chinook.Invoice i ON i.InvoiceId = il.InvoiceId
    WHERE i.BillingCountry = 'USA')) * 100, 2) value 
FROM Chinook.InvoiceLine il
INNER JOIN Chinook.Invoice i ON i.InvoiceId = il.InvoiceId 
INNER JOIN Chinook.Track t ON il.TrackId = t.TrackId 
INNER JOIN Chinook.Genre g ON t.GenreId = g.GenreId 
WHERE i.BillingCountry = 'USA' 
GROUP BY 1 
ORDER BY 2 DESC
LIMIT 10

This is a project I fork from this repo to verify my ideas and used to participants a hackathon, but I would like to contribute back and archive my repo.

And if we want to support define specs on the fly, and can add some command like:

%VEGA-LITE SET my_spec.vl.json
{
  "data": {"url": "data/seattle-weather.csv"},
  "mark": "bar",
  "encoding": {
    "x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
    "y": {"aggregate": "mean", "field": "precipitation"}
  }
}

%VEGA-LITE PLOT my_spec.vl.json
select ...

What do you think?

@marimeireles
Copy link
Member

Hi @wangfenjin, first of all, amazing work! Also, super cool examples. I absolutely love them!

I never thought about this idea, tbh, because I think we have this strong culture of using jupyter magics never occurred to me we could use the raw json. What do you think of this idea @SylvainCorlay ?

Thank you for opening an issue to discuss it :)

@marimeireles
Copy link
Member

That actually allows the user to use all xvega implementation. I think we should at least support both.

@marimeireles
Copy link
Member

@wangfenjin feel free to open a PR adding the possibility to load by json, I also saw you took care of some edge cases in your code that I'm not taking into account, it'd be super cool if you could contribute these too. :)

I'm not sure if I still have a lot of time to work in this project, but I'll gladly review a PR!

@wangfenjin
Copy link
Contributor Author

Yes, I'll create a separate PR for the corner case, but it may take time as I think we may need to support conditional compile and make it work with CMake. For example, if we want to catch error from mysql, then we need to include the mysql header, and we can't just catch all exception as explained here https://stackoverflow.com/a/50133665/1203241

But we can only include mysql header file if user compile with mysql support. I'm not so familiar with all of this.

Anyway, I'll try to contribute. Thanks.

@SylvainCorlay
Copy link
Member

@wangfenjin I think this is a brilliant idea. Awesome!

I wonder how we could define the vega specs inline with another magics.

@marimeireles
Copy link
Member

For example, if we want to catch error from mysql, then we need to include the mysql header

Hum, I see.
Yeah, we can worry about this later. I've considered it before, let me know if you want some input on this, we can discuss on a separate issue.
What it'd be super cool to have is the json input anyways :)

I wonder how we could define the vega specs inline with another magics.

I think we could use what we're using for xvega-bindings?

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

Successfully merging a pull request may close this issue.

3 participants