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
R Leaflet legends are centered when labelled as fig-
s
#7843
Comments
Thanks for the report. This is indeed the CSS we use to style Figure captions and labels, so we can't change it on our side. Immediately, a better CSS workaround for you is this: figure.quarto-float div.leaflet-control {
text-align: left;
} I'm wondering how we can address this. @cderv is there a way to check, at the end of knitr execution, if user code attached a package? The good fix here would be for us to detect that someone used |
We had issues like that in the past (rstudio/rmarkdown#1949) and it happens that R package leaflet had already some patched CSS rules. Adding there div.leaflet-control {
text-align: left;
} solves this - which is similar fix we did for rstudio/rmarkdown#1949 So I would be inclined to do a PR there to change this instead of us trying to detect leaflet. Would that be ok with @cscheid or do you want us really to detect that ? |
Oh, |
@cscheid in fact, another ideas: We could also just adapt our CSS rules for Quarto figures to not apply on For example, the rule that causes issue here is .quarto-figure-center>figure>p, .quarto-figure-center>figure>div {
text-align: center;
} And so we could do .quarto-figure-center>figure>p, .quarto-figure-center>figure>div:not(.html-widget) {
text-align: center;
} This should prevent issues with any other HTML widgets. What do you think ? |
Oh no that wouldn't work just like that... 😓 sorry |
I'd support a widget-agnostic approach if possible, I've had similar issues with |
This would be the rule that works .quarto-figure-center > figure > p,
.quarto-figure-center > figure > div:not(.html-widget, :nth-child(1):not(.html-widget)) /* for mermaid and dot diagrams */ {
text-align: center;
} With need the
I'll make a PR with this fix. |
What are the IMHO these selectors are too broad for the |
It's intended to target (for example) the div emitted by mermaidjs. Clearly the selectors are being too broad, but I'm not sure what the clean fix would be. |
Let's go back to context of this rule addition maybe. It was added in
So if I understand correctly, the aim is to get the SVG mermaid content aligned. We could probably use a more targeted rule for this. What about ? .quarto-figure-center>figure>div:has(svg.mermaid-js) {
text-align: center
} |
@cderv Do you have a reprex for centered mermaid diagrams? I might be doing something wrong, but I can't get ---
title: Quarto 7843
format:
html:
fig-align: center
---
Nulla et excepteur culpa voluptate incididunt aliquip veniam quis elit sunt deserunt quis enim.
```{mermaid}
%%| label: mermaid-diagram
%%| fig-cap: A mermaid diagram in its natural habitat.
%%| fig-align: center
flowchart TB
a --> b
b --> c
```
Ea officia reprehenderit consectetur voluptate minim ex ea exercitation fugiat eu proident amet cillum minim. Side note: I also noticed the caption text has different styles when the cell |
FYI, v1.4.525 -- and I think I just fixed those mermaid issues between 451 and 525. |
Thanks -- v1.4.525 is the one I downloaded and installed but |
Oh! That makes sense now. Is this the expected appearance with the fig caption left-aligned and the mermaid diagram centered? |
Sorry wasn't around - Yes that was it - you need to use the This is current limitaton because of a figure node requirement. This may evolved in the future |
If the last screenshot looks okay, then here's another set of rules that are worth considering: .quarto-figure > figure > div {
display: block;
width: fit-content;
}
.quarto-figure-center > figure > div {
margin-left: auto;
margin-right: auto;
}
.quarto-figure-left > figure > div {
margin-right: auto;
}
.quarto-figure-right > figure > div {
margin-left: auto;
} This seems pretty reasonable for htmlwidgets in general, but you could also make those rules more specific to mermaid by targeting Edit: to clarify, these would replace the current |
Selecting against |
But in that case, this is nothing mermaid specific right ? It is like other image and this is covered by the first part of the rule targetting .quarto-figure-center>figure>p, .quarto-figure-center>figure>div {
text-align: left;
} |
And no... because there is an enclosing div 🤦♂️ and the CSS rules targets Too bad there is no class on this enclosing div that tells us this is mermaid HTML code<div id="fig-diagram" class="quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-diagram-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<p><img src="index_files\figure-html\mermaid-figure-1.png" style="width:0.42in;height:2.27in" class="figure-img"></p>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-diagram-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure 1: A mermaid diagram in its natural habitat.
</figcaption>
</figure>
<a class="anchorjs-link " aria-label="Anchor" data-anchorjs-icon="" href="#fig-diagram" style="font: 1em / 1 anchorjs-icons; margin-left: 0.1875em; padding-right: 0.1875em; padding-left: 0.1875em;"></a></div> |
@cderv I'm pretty sure my suggested rules will also cover that markup as well. Happy to submit as a PR if that's helpful |
Yeah I am ok with that. @cscheid what do you think of @gadenbuie rules at #7843 (comment) ? They do not involve |
I'm honestly terrified of CSS changes because of how hard they're to test against. I'd much rather make a small conservative change that targets leaflet specifically for 1.4, and then consider a better fix with ample time to revert if needed in 1.5. |
I'm going to push this to 1.5, and at that point we can carefully consider the change from |
Bug description
When a leaflet map is included in a Quarto HTML report, any categorical legend ends up centered when the chunk is labelled as a figure. This looks a little strange/ugly, particularly when the labels are either very different lengths or are only subtly different lengths. Oddly, if you just print the leaflet map without labelling it as a figure, everything works okay.
Note that you can manually fix this by adding this to a style tag, but I imagine this isn't the intended fix, and that messing around with quarto's style options may have unintended consequences.
No idea if this happens with Python/Folium, but I intuitively expect so?
Steps to reproduce
Expected behavior
The leaflet legend should be left aligned (bottom of image).
Actual behavior
The leaflet legend is centered (top of image).
Your environment
Quarto check output
NB: I'm using R leaflet v2.2.0.9000.
The text was updated successfully, but these errors were encountered: