VegaLite (v0.5.1) Tooltips in Julia v1.0.2 - Can Only Do Single Field with DataFrame Source?


#1

Was having good success with VegaLite until I tried tooltips. Using this dataframe:

julia> df3
17x2 DataFrame
│ Row │ x1 │ x1_1 │
│ │ Date │ Int64 │
├─────┼────────────┼───────┤
│ 1 │ 2017-06-06 │ 1 │
│ 2 │ 2017-06-28 │ 1 │
│ 3 │ 2017-06-30 │ 1 │
│ 4 │ 2017-07-03 │ 2 │
│ 5 │ 2017-07-06 │ 2 │
│ 6 │ 2017-07-21 │ 1 │
│ 7 │ 2017-07-31 │ 1 │
│ 8 │ 2017-08-08 │ 1 │
│ 9 │ 2017-08-11 │ 1 │
│ 10 │ 2017-08-16 │ 2 │
│ 11 │ 2017-08-20 │ 1 │
│ 12 │ 2017-08-22 │ 1 │
│ 13 │ 2017-08-24 │ 1 │
│ 14 │ 2017-09-12 │ 1 │
│ 15 │ 2017-09-28 │ 1 │
│ 16 │ 2017-10-19 │ 3 │
│ 17 │ 2017-10-23 │ 2 │

in this @vlplot() call works - I get my plot with the single field tooltip:

@vlplot(
mark={typ="point"},
data=df3,
width=800,height=600,
encoding={
x={field="x1", typ="nominal", axis={labelAngle="-60", grid="true"}},
y={field="x1_1", typ="quantitative"},
tooltip={field="x1_1", typ="quantitative"}
})

If I View Source from the plot, I can modify the tooltip to add the “x1” field value by enclosing in square brackets, and call this spec with the vl macro and it works - I see both field values in the tooltip on the plot:

spec = vl"""
{
  "height": 600,
  "encoding": {
    "tooltip": **[{"field": "x1", "type": "nominal"},** {"field": "x1_1", "type": "quantitative"}**]**,
    "x": {
      "axis": {"labelAngle": "-60", "grid": "true"},
      "field": "x1",
      "type": "nominal"
    },
    "y": {"field": "x1_1", "type": "quantitative"}
  },
  "data": {
    "values": [
      {"x1": "2017-06-06", "x1_1": 1},
      {"x1": "2017-06-28", "x1_1": 1},
      {"x1": "2017-06-30", "x1_1": 1},
      {"x1": "2017-07-03", "x1_1": 2},
      {"x1": "2017-07-06", "x1_1": 2},
      {"x1": "2017-07-21", "x1_1": 1},
      {"x1": "2017-07-31", "x1_1": 1},
      {"x1": "2017-08-08", "x1_1": 1},
      {"x1": "2017-08-11", "x1_1": 1},
      {"x1": "2017-08-16", "x1_1": 2},
      {"x1": "2017-08-20", "x1_1": 1},
      {"x1": "2017-08-22", "x1_1": 1},
      {"x1": "2017-08-24", "x1_1": 1},
      {"x1": "2017-09-12", "x1_1": 1},
      {"x1": "2017-09-28", "x1_1": 1},
      {"x1": "2017-10-19", "x1_1": 3},
      {"x1": "2017-10-23", "x1_1": 2}
    ]
  },
  "width": 800,
  "mark": {"type": "point"}
}
"""

but if I try to use two fields in the tooltip using @vlplot I get this error:

julia> @vlplot(
       mark={typ="point"},
       data=df3,
       width=800,height=600,
       encoding={
       x={field="x1", typ="nominal", axis={labelAngle="-60", grid="true"}},
       y={field="x1_1", typ="quantitative"},
       tooltip=[{field="x1", typ="nominal"},{field="x1_1", typ="quantitative"}]
       })
ERROR: MethodError: no method matching haskey(::Array{Dict{String,Any},1}, ::Str
ing)

but this tooltip format works for a simple example:


@vlplot(
  data= {
    values= [
      {a= "A",b= 28}, {a= "B",b= 55}, {a= "C",b= 43},
      {a= "D",b= 91}, {a= "E",b= 81}, {a= "F",b= 53},
      {a= "G",b= 19}, {a= "H",b= 87}, {a= "I",b= 52}
    ]
  },
  mark= {type= "bar"},
  encoding= {
    x= {field= "a", type= "ordinal"},
    y= {field= "b", type= "quantitative"}, tooltip= [{field= "a", type= "ordinal"},{field= "b", type= "quantitative"}]
  })

the difference seems to me to be that it does not work for multiple tooltip fields when my datasource is a dataframe. Since a dataframe would be my normal source for plots, any advice is greatly appreciated.


#2

Argh! I tried to bold the edits I had made to the tooltip in the vl spec call…now I see that it shows “" instead of bolding. Please ignore the "” in that code block.