Skip to content

Commit fd2a82f

Browse files
authored
fix display(d, m, x) where m expects a json string
Fix queryverse/VegaLite.jl#127 After the fix the following works out of the box in new versions of jupyterlab, generating an interactive VegaLite visualization, without additional packages except Ijulia. ``` spec = raw""" { "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": "point", "encoding": { "x": {"field": "a", "type": "ordinal"}, "y": {"field": "b", "type": "quantitative"} } } """ display("application/vnd.vegalite.v2+json", spec) ```
1 parent 7b00bb5 commit fd2a82f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/inline.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,27 @@ function limitstringmime(mime::MIME, x)
4747
return String(take!(buf))
4848
end
4949

50+
const ipy_mime_json = [
51+
"application/vnd.dataresource+json",
52+
"application/vnd.vegalite.v2+json",
53+
"application/vnd.vega.v3+json",
54+
]
55+
_display_dict(m::MIME, m_str, x) = Dict(m_str=>limitstringmime(m, x))
56+
# escape JSON string correctly before send_ipython
57+
for mime in ipy_mime_json
58+
@eval begin
59+
_display_dict(m::MIME{Symbol($mime)}, m_str, x) = Dict(m_str=>JSON.JSONText(limitstringmime(m, x)))
60+
end
61+
end
62+
5063
for mime in ipy_mime
5164
@eval begin
5265
function display(d::InlineDisplay, ::MIME{Symbol($mime)}, x)
5366
send_ipython(publish[],
5467
msg_pub(execute_msg, "display_data",
5568
Dict(
5669
"metadata" => metadata(x), # optional
57-
"data" => Dict($mime => limitstringmime(MIME($mime), x)))))
70+
"data" => _display_dict(MIME($mime), $mime, x))))
5871
end
5972
displayable(d::InlineDisplay, ::MIME{Symbol($mime)}) = true
6073
end

0 commit comments

Comments
 (0)