Skip to content

Commit

Permalink
fixes for Vega MIME
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Nov 23, 2024
1 parent 9fef475 commit a38bb2e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/Visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ function graph_representation(tn::AbstractTensorNetwork)
return tn, graph, tensormap, hypermap, hypernodes, ghostnodes
end

# TODO use `Base.ENV["VSCODE_PID"]` to detect if running in vscode notebook
# Base.show(io::IO, ::MIME"text/html", @nospecialize(tn::AbstractTensorNetwork)) = draw(io, tn)
# Base.show(io::IO, ::MIME"juliavscode/html", @nospecialize(tn::AbstractTensorNetwork)) = draw(io, tn)

for v in ["application/vnd.vegalite.v3+json", "application/vnd.vegalite.v4+json", "application/vnd.vegalite.v5+json"]
@eval Base.Multimedia.istextmime(::MIME{$(Symbol(v))}) = true
# TODO use `Base.ENV["VSCODE_PID"]` to detect if running in vscode notebook?
# TODO move this to VSCodeServer.jl
function Base.Multimedia.istextmime(::MIME"application/vnd.vega.v5+json")
return true
end

Base.show(io::IO, ::MIME"application/vnd.vegalite.v5+json", @nospecialize(tn::AbstractTensorNetwork)) = draw(io, tn)
Base.show(io::IO, ::MIME"application/vnd.vega.v5+json", @nospecialize(tn::AbstractTensorNetwork)) = draw(io, tn)
function draw(io::IO, @nospecialize(tn::AbstractTensorNetwork))
tn, graph, tensormap, hypermap, hypernodes, ghostnodes = graph_representation(tn)
hypermap = Dict(Iterators.flatten([[i => v for i in k] for (k, v) in hypermap]))
Expand Down

0 comments on commit a38bb2e

Please sign in to comment.