Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :caption and :download options to Kino.Mermaid #477

Merged
merged 11 commits into from
Oct 15, 2024

Conversation

christhekeele
Copy link
Contributor

@christhekeele christhekeele commented Oct 13, 2024

Originating from this thread on the forums, this PR:

  • Gives Kino.Mermaid diagrams an optional on-hover download button
  • Makes the rendered diagram an HTML5 <figure>
    • Uses flexbox to horizontally center the rendered diagram
    • Allows for an optional <figcaption> to describe the rendered diagram

Images

  • Flexbox-centered <figure> (chrome browser defaults stylesheets adds a 1em margin to them)

    Screenshot 2024-10-13 at 3 37 43 PM

  • Figure with caption (styled roughly after Livebook's .info-box CSS)

    Screenshot 2024-10-13 at 3 37 16 PM

  • Flexbox-centering in a grid

    Screenshot 2024-10-13 at 3 37 16 PM

  • Download button with title

    Screenshot 2024-10-13 at 3 39 10 PM

  • Download with custom filename

    Screenshot 2024-10-13 at 3 44 23 PM
    Screenshot 2024-10-13 at 3 44 41 PM

  • Default captions for Kino.Process.app_tree example

    Screenshot 2024-10-13 at 5 27 37 PM

  • Default captions for named Kino.Process.sup_tree example

    Screenshot 2024-10-13 at 5 28 04 PM

  • Default captions for pid Kino.Process.sup_tree example

    Screenshot 2024-10-13 at 5 27 46 PM

  • Default captions for Kino.Process.seq_trace example

    Screenshot 2024-10-13 at 5 36 20 PM

    Screenshot 2024-10-13 at 5 36 28 PM

@christhekeele christhekeele force-pushed the downloadable-mermaid branch 2 times, most recently from 6bd623d to 02b127b Compare October 13, 2024 22:41
@christhekeele christhekeele changed the title Make mermaid diagrams downloadable figures Make mermaid diagrams downloadable captionable figures Oct 13, 2024
@christhekeele
Copy link
Contributor Author

Note: I did not check in all the changes to the bundled mermaid assets, as there is a lot of churn there. Is that handled in the package publication process, or should I push the changes to lib/assets up too?

@jonatanklosko jonatanklosko changed the title Make mermaid diagrams downloadable captionable figures Add :caption and :download options to Kino.Mermaid Oct 15, 2024
@jonatanklosko
Copy link
Member

@christhekeele thanks for the PR! I updated the styling and simplified some of the options :)

@jonatanklosko jonatanklosko merged commit 743739e into livebook-dev:main Oct 15, 2024
1 check passed
jonatanklosko added a commit that referenced this pull request Oct 15, 2024
@jonatanklosko
Copy link
Member

jonatanklosko commented Oct 15, 2024

Note: I did not check in all the changes to the bundled mermaid assets, as there is a lot of churn there. Is that handled in the package publication process, or should I push the changes to lib/assets up too?

Bundling in the PR is fine, I bundle before or after merging anyway :) (we want to keep git in sync, in case someone installs the package from GitHub; they may even install the PR branch to try it out)

@christhekeele
Copy link
Contributor Author

christhekeele commented Oct 15, 2024

I did notice a couple of possible UI regressions with the updated styling, @jonatanklosko , thought I'd report them here.


Large diagrams now get very small—unsure if this is intentional? (Partially mitigated by the full diagram being downloadable, now).

For example, the Kino.Process.seq_trace/1 example

{_, diagram} = Kino.Process.seq_trace(fn ->
  {:ok, agent_pid} = Agent.start_link(fn -> [] end)
  Process.monitor(agent_pid)

  1..2
  |> Task.async_stream(
    fn value ->
      Agent.get(agent_pid, fn value -> value end)
      100 * value
    end,
    max_concurrency: 3
  )
  |> Stream.run()

  Agent.stop(agent_pid)
end)

diagram

with new styling it renders illegibly for me, like:

Screenshot 2024-10-15 at 11 49 42 AM

whereas in the current release of Kino, and previous styling in this PR, it renders full-width:

Screenshot 2024-10-15 at 11 53 36 AM

Additionally, vanilla unstyled diagrams have gotten... chonkier? post-update. most curious. New:

Screenshot 2024-10-15 at 11 55 19 AM

old:

Screenshot 2024-10-15 at 11 54 33 AM

Unsure if these are undesirable or not, just thought I'd mention them!

OSX, recent Chrome

@jonatanklosko
Copy link
Member

@christhekeele thanks, the diagram width shrinking is unexpected, I've just fixed on main. The second is an expected change in mermaid v11, which I updated on main after this PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants