vegas-viz / Vegas

The missing MatPlotLib for Scala + Spark
MIT License
730 stars 98 forks source link

Layered spec #45

Closed aishfenton closed 8 years ago

aishfenton commented 8 years ago

Main aim of PR is to add support for layered plots (so that we support error-bars, etc), but in doing so I needed to refactor some of the DSL to make it fit.

Here's an example of what Layers look like:

Vegas.layered("Plots both mean and IQR as a background layer").
  withDataURL(Population).
  withLayers(
    Layer().
      mark(Line).
      encodeX("age", Ordinal).
      encodeY("people", aggregate=Mean),
    Layer().
      mark(Area).
      encodeX("age", Ordinal).
      encodeY("people", aggregate=Q1).
      encodeY2("people", aggregate=Q3)
    )

Other changes include:

Regarding the last point, here's what the new DSL looks like:

val AggregateBarChart =
  Vegas("A bar chart showing the US population distribution of age groups in 2000.").
    withDataURL("https://vega.github.io/vega-editor/app/data/population.json").
    mark(Bar).
    transformFilter("datum.year == 2000").
    encodeY("age", Ordinal, scale=Scale(bandSize=17)).
    encodeX("people", Quantitative, aggregate=Sum, axis=Axis(title="population"))
codecov-io commented 8 years ago

Current coverage is 71.17% (diff: 82.90%)

No coverage report found for master at 1e30a78.

Powered by Codecov. Last update 1e30a78...ad0be2a