pfitzseb / ProfileCanvas.jl

MIT License
87 stars 6 forks source link

ProfileData doesn't show correctly in latest Pluto #13

Closed disberd closed 2 years ago

disberd commented 2 years ago

Hello,

I came back to this package in Pluto after trying it some time ago but it seems that the profile view doesn't show correctly in Pluto anymore.

You get a blank output and some errors in the JS console: image

Based on the error message, I suppose the problem is in these lines within the show method: https://github.com/pfitzseb/ProfileCanvas.jl/blob/04bbb457b44b288fbc1d8fdec10f60ec36dae3f4/src/ProfileCanvas.jl#L49-L50

Pluto doesn't seem to support the type="module" synthax and so the export inside the js file gives an error.

I tried adapting the show method to use the import synthax suggested in the JS example pluto notebook and it does fix the issue, but I was pointing directly to an online cdn version. Don't know exactly how to make this work with artifacts.

Here is the code I used to overwrite the show method in Pluto

@eval ProfileCanvas function Base.show(io::IO, ::MIME"text/html", canvas::ProfileData)
    id = "profiler-container-$(round(Int, rand()*100000))"
    println(
        io,
        """
        <div id="$(id)" style="height: 400px; position: relative;"></div>
        <script>
            const ProfileCanvas = await import('https://cdn.jsdelivr.net/gh/pfitzseb/jl-profile.js/dist/profile-viewer.min.js')
        const ProfileViewer = ProfileCanvas.ProfileViewer
            const viewer = new ProfileViewer("#$(id)", $(JSON.json(canvas.data)), "$(canvas.typ)")
        </script>
        """
    )
end
pfitzseb commented 2 years ago

Fixed with https://github.com/pfitzseb/ProfileCanvas.jl/commit/c2881cc52d873de32877dfab7a770164328fe565.