How does Pluto decide what to show graphically?

If I understand correctly, this is a typical case where multiple dispatch is used. Basically, each library defines it’s own

function show(io::IO, m::MIME"some_mime", x::T)

where some_mime can be MIME"text/html" and the type T is some object defined by the library. Then, Pluto will just call

show(io, m, object)

and Julia figures out which show method needs to be called exactly. (Julia will try to do this by the most specific method possible or fall back to printing it as a string if no specific method for some type is known.)

For example, in Gadfly:

function show(io::IO, m::MIME"image/svg+xml", p::Plot)
    buf = IOBuffer()
    svg = SVG(buf, Compose.default_graphic_width,
              Compose.default_graphic_height, false)
    draw(svg, p)
    show(io, m, svg)
end

You can find many more examples in other libraries.

Note that the type, here, is important. If you passed a simple SVG string as a literal String, then Julia will print it as a string.

To answer this question, what kind of objects do you want to show?

1 Like