Closed lazarusA closed 2 years ago
I don't see reportedsize
being used anywhere here... Maybe with_updates_suspended
broke?
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.
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
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
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.
I just removed that block of code and things workout pretty well. 😉
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:
maxwidth
for the code block depending on the width the layout suggested for ustextsize
for the code and iterate (shrink) it till the longest line's length is small than maxwidth
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.
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.
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.
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.
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.
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.
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
...
Just for reference: Here is another website with a IMO better overview of available pygments
styles: https://stylishthemes.github.io/Syntax-Themes/pygments/
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]