ankane / vega-ruby

Interactive charts for Ruby, powered by Vega and Vega-Lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

layer usage example

avillafiorita opened this issue · comments

Hi,
first of all, thanks for the Gem, really clean and useful.

I am trying to use =layer=s and I am a bit lost on what to pass as argument. I tried to look at the code, to no avail.

Consider the following excerpt (from the Vega Light website):

  "layer": [{
    "mark": "bar"
    },
   {
    "mark": {
      "type": "text",
      "align": "left",
      "baseline": "middle",
      "dx": 3
    },
    "encoding": {
      "text": {"field": "b", "type": "quantitative"}
    }
  }]
}

when representing in Ruby, I thought I could do something like:

.layer([
   Vega.lite.mark( { type: "bar" }),
   Vega.lite.mark
   ...
])

but it does not work.

Any help really appreciated it.
Thanks again!

Hi @avillafiorita, you'll want to pass each layer as a hash rather than a Vite.lite object.

... and, in fact, a Hash works fine!
thanks for the help!

For the sake of documentation, the example becomes:

layer([
   {
    mark: "bar"
   },
   {
    mark: {
      type: "text",
      align: "left",
      baseline: "middle",
      dx: 3
    },
    encoding: {
      text: { field: "b", type: "quantitative" }
    }
  }
])