fatteneder / MakieSlides.jl

MIT License
17 stars 2 forks source link

LayoutObservables has no field reportedsize #25

Closed lazarusA closed 2 years ago

lazarusA commented 2 years ago

The mwe.jl file does not work with the versions specified below. Any chance to have an update?

Error: Failed to add slide - maybe the function signature does not match f(::Presentation)? └ @ MakieSlides ~/.julia/packages/MakieSlides/IaGJX/src/MakieSlides.jl:211 ERROR: type LayoutObservables has no field reportedsize Stacktrace: [1] getproperty @ ./Base.jl:38 [inlined]

CairoMakie v0.8.13
  [35d6a980] ColorSchemes v3.19.0
  [5ae59095] Colors v0.12.8
  [e9467ef8] GLMakie v0.6.13
  [64e33b44] MakieSlides v0.1.0 `https://github.com/fatteneder/MakieSlides.jl.git#main`
ffreyer commented 2 years ago

I don't see reportedsize being used anywhere here... Maybe with_updates_suspended broke?

lazarusA commented 2 years ago

is being used here https://github.com/fatteneder/MakieSlides.jl/blob/8d2fe334b8e59e849c6924f0381e282daa33e68a/src/formattedcodeblock.jl#L128

however, Julius suggested that there is not reason to use that. I try removing those lines and it kinda works. Some markdown still overlaps but it is minor.

ffreyer commented 2 years ago

Must've had a typo in my search. I think this should be autosize instead, like https://github.com/JuliaPlots/Makie.jl/blob/bfe128ee1535ad75a4bab6109826caa08ba5f4de/src/makielayout/blocks/label.jl#L24

fatteneder commented 2 years ago

I think this should be autosize instead, like ...

Indeed. I remember using reportedsize as a hack in formattedlabel initially. Might have copied this over from there.

Some markdown still overlaps but it is minor.

Sometimes the overlapping can fix itself with resizing it a bit, will certainly need more work, cf. #18

fatteneder commented 2 years ago

Changing only reportedsize to autosize does not fix it for me. Instead I am now stuck in an update loop where the bbox height cannot be matched to the desired text height. Need to rethink this strategy again.

lazarusA commented 2 years ago

I just removed that block of code and things workout pretty well. 😉

fatteneder commented 2 years ago

Ok, I see. Now it makes sense why you see markdown overflowing.

Let me elaborate: For code blocks it seems to be better to adjust the text size instead of wrapping lines arbitrarily. We do this in the following way:

  1. provide a maxwidth for the code block depending on the width the layout suggested for us
  2. set a textsize for the code and iterate (shrink) it till the longest line's length is small than maxwidth
  3. report the height of the so obtained bbox to the layout (because shrinking the textsize also shrinks the overall height)

Disabling the reportedsize block skips step 3.

lazarusA commented 2 years ago

Indeed. I also noticed that when plotting a lot of characters it takes a long time. And I end up using Highlights.jl and a hack shared on Discord for updating the colours for each letter. Overall it looks ok, see here.

fatteneder commented 2 years ago

I did not know about Highlights.jl, thanks for bringing it up. I will consider switching to it if you say it performs better than PyCall + pygments.

Also: Great to see MakieSlides being already used, I really like the theme you chose.

fatteneder commented 2 years ago

The above issue should be fixed on main now.

I also noticed that when plotting a lot of characters it takes a long time.

This is in part because we always re-layout the text whenever any of textsize, font etc or bbox attributes changes. With the fix I removed an unnecessary event call that caused the re-layouting to be triggered twice as often as needed, so this should speed things up a bit.

Regarding Highlights.jl vs pygments: Re-layouting also always invokes syntax analysis. I am unsure on how much performance improvement Highlights.jl might bring over pygments, I need to do a benchmark at one point. Perhaps what might have more impact would be to separate the syntax analysis from the re-layouting and only trigger it only when the code changes, but not when the bbox changes.

I got Highlights.jl to work already, thanks to your script and this discourse post (I assume that's the one you mentioned): https://discourse.julialang.org/t/code-listing-in-makie-jl-figure/74395/4?u=fatteneder I will add it as an alternative to pygments, but not as an replacement for now, because pygments provides more lexers than Highlights.jl does at the moment. Maybe these two can even coexist with one another.

lazarusA commented 2 years ago

Great! A different issue is that at the moment setting the background colour doesn't work and it kinda depends on your lexer? The kwarg is not passed on into the plotting call or is translated it to the back? It makes a great difference to be able to control the background colour. Great work.

fatteneder commented 2 years ago

For now you can only select a colorscheme alone, but you cannot modify parts of it. Here is a list of available colorschemes: https://pygments.org/styles/

And here is how to use it:

using GLMakie, Markdown, MakieSlides

pres = Presentation(figure_padding = (50, 50, 50, 50))
display(pres)

add_slide!(pres) do fig
    MarkdownBox(fig[1, 1], md"""
    ```julia
    # by Lazaro Alonso - BeautifulMakie
    let
        x = 0:0.05:1
        y = x .^ 2
        ax = Axis(fig[1, 2], xlabel = "x", ylabel = "y")
        lines!(ax, x, y, color = :orangered, label = "Label")
        band!(ax, x, fill(0, length(x)), y; color = (:orange, 0.25), label = "Label")
        axislegend(ax ; merge = true, position = :lt)
    end;
""", codestyle=:dracula)

end



I have it on my TODO list to figure out how to add custom styles. Instructions on how to create one for `pygments` are given here: https://pygments.org/docs/styledevelopment/#creating-own-styles
It is just a matter of figuring out how to load it into `PyCall`, but this shouldn't be too difficult.
Maybe later on we could override style attributes also through keyword args.
fatteneder commented 2 years ago

Just hooked up backgroundcolor from MarkdownBox and FormattedCodeblock to override the background of the syntax highlighter. So adding backgroundcolor = :green should do the trick now.

For more detailed customization of the syntax highlighting we need to interface with pygments through setuptools and PyCall ...

fatteneder commented 2 years ago

Just for reference: Here is another website with a IMO better overview of available pygments styles: https://stylishthemes.github.io/Syntax-Themes/pygments/