Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Add a Vega plotting library #77

Closed
wants to merge 22 commits into from
Closed

Add a Vega plotting library #77

wants to merge 22 commits into from

Conversation

hadim
Copy link
Contributor

@hadim hadim commented Jul 29, 2017

Very low level at the moment and only a few part of the Vega Lite API is supported.

The goal is to implement all (or almost) the Vega Lite API at a very low level and then add convenient functions that make plotting as easy as with matplotlib.

The Vega Lite specification is pretty easy to understand and is not that complex: https://vega.github.io/vega-lite/docs/spec.html

Technically the library is using the Jackson JSON library (https://github.com/FasterXML/jackson) to automatically map attributes to JSON fields.

When stable enough and if @ctrueden agree, that plotting library should be moved to its own repository under the Scijava GitHub organization.

@hadim hadim mentioned this pull request Jul 29, 2017
@hadim
Copy link
Contributor Author

hadim commented Jul 29, 2017

See this notebook for an example: https://github.com/scijava/scijava-jupyter-kernel/blob/2e2b8fe3af3bd9a36531336ace91ccf3e0a03752/notebooks/Vega.ipynb

At the moment the rendering does not work in JLab because the library is using the soon-to-be-released Vega3/Vega-Lite2 specifications. See this PR for progress: jupyterlab/jupyter-renderers#15

@hadim
Copy link
Contributor Author

hadim commented Jul 29, 2017

To test plot you can copy paste the JSON string into https://vega.github.io/editor

@hadim
Copy link
Contributor Author

hadim commented Jul 29, 2017

Something I am not willing to develop in a near future but that would be awesome to have is a Swing widget that can render the VegaLite JSON string as a plot (useful when used outside of the SJK).

@hadim
Copy link
Contributor Author

hadim commented Jul 29, 2017

I think implementing a builder pattern would allow easy plotting.

@hadim
Copy link
Contributor Author

hadim commented Jul 30, 2017

Here is an overview of the builder pattern I want to implement:

builder = plt.builder().name("Bar Chart").
    channel('x').field('a').type('ordinal').build().
    channel('y').field('b').type('quantitative').build().
    mark().type('bar').build().
    data().values(data).build

plot = builder.build()

or equivalent

builder = plt.builder().name("Bar Chart")
builder = builder.channel('x').field('a').type('ordinal').build()
builder = builder.channel('y').field('b').type('quantitative').build()
builder = mark().type('bar').build()
builder = builder.data().values(data).build()

plot = builder.build()

This is the most straightforward low-level way of creating plots I can think of. Then later, a layer of "convenient" functions will come on top of that.

@hadim
Copy link
Contributor Author

hadim commented Jul 30, 2017

I have implemented a minimum working builder pattern to be able to reproduce the first example of the Vega Lite website. See this notebook for the code.

I found it super convenient to use for a low-level API (you still need to understand how Vega Lite works to be able to use it).

However, I find the implementation very complex. For each JSON field, I have a "regular" class that use Jackson annotations and provide getter and setter for all the child fields. Then for each of the previous classes, I have a Builder class that implements the builder pattern and almost the same setter as in the "regular" classes.

If someone can think of a smaller and less complex-to-maintain architecture, I am all open.

@maarzt
Copy link

maarzt commented Aug 2, 2017

Hi @hadim,

I'm working on a high-level API for plotting in ImageJ.
See https://github.com/maarzt/imagej-plot-service
It would be nice to use your vega-lite integration as back-end for displaying the plots in jupyter,
and to improve the high-level API according to your ideas.

@hadim
Copy link
Contributor Author

hadim commented Aug 2, 2017

Hi @maarzt

That would be nice to have a "wrapper" to connect your high-level API with this low-level one. It could also be used to display plot outside of Jupyter and directly in Fiji. We would just need to write an HTML Swing layout that can display Vega-Lite JSON.

It should not be too hard considering that Vegas is already doing it.

@hadim hadim closed this May 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants