trelliscopejs icon indicating copy to clipboard operation
trelliscopejs copied to clipboard

Feature request: trelliscope support for sepia and night mode in bookdown

Open stefvanbuuren opened this issue 3 years ago • 10 comments

I use transparent colors to blend ggplot2 and plotly figures into sepia and night modes in bookdown documents. See for example https://d-score.org/dbook1/sec-aged.html, and switch to sepia and night mode.

In trelliscopejs this approach doesn't work (e.g. https://d-score.org/dbook2/section-sec-impactequate.html). The background of trelliscope figure is solid white, which blocks any transparent color settings in the figures.

My question: Would there be a simple trick to change the solid white into transparent?

Here's a short demo code that I use to sets transparent colors in trelliscopejs:

library(trelliscopejs)
library(ggplot2)
library(gapminder)

theme_set(theme_light())
theme_update(panel.background = element_rect(fill = "transparent", colour = NA),
             plot.background = element_rect(fill = "transparent", colour = NA),
             legend.key = element_blank(),
             rect = element_rect(fill = "transparent"))

qplot(year, lifeExp, data = subset(gapminder, continent == "Europe")) +
  facet_trelliscope(~ country + continent,
                    path = "docs/transparent")

I would like all white areas to become transparent, whereas any coloured areas (left navigation bar, bottom sort bar, trelliscope logo) should retain their colouring. Is that possible by setting some styles?

stefvanbuuren avatar Nov 26 '20 15:11 stefvanbuuren

Hi @stefvanbuuren - After creating the example display and updating all elements to have no background, I don't see the desired effect. Can you provide a screenshot of what it a "correct" plot should look like?

In general I have been wanting to add the ability for users to provide custom style specifications. Doing this properly will take some time though. In the mean time, I think this issue is addressable by making all whitespace have no background, as I don't see how this as a default setting would have an adverse effect on anything else.

hafen avatar Dec 02 '20 00:12 hafen

My thinking is that the data area, the plot margin and selected trelliscope panels could be made transparent. If the reader changes bookdown background changes to sepia/dark, then sepia/dark would shine through in the plots.

In the figure below, I have tried to draw what the figure could look like if my background color is yellow3 (sepia is not an R color). I failed because I do not know how to change some of the backgrounds to transparent, the cross-hatched areas. So ideally these should also be transparent, and show the bookdown sepia/dark coloring set by the reader.

SCAN0036

stefvanbuuren avatar Dec 02 '20 08:12 stefvanbuuren

Ah I see now! So you are talking about a background color behind the entire embedded display. Are you embedding your displays as iframes in your book? If so, I'm not sure if this is possible.

hafen avatar Dec 02 '20 08:12 hafen

I use knitr::include_url() for example:

knitr::include_url(url = "https://d-score.org/dbook-apps/p-d-equate-1339/#display=Percent_pass_by_D_score__four_models&nrow=2&ncol=2&arr=row&pg=65&labels=equate,model&sort=equate_index;asc,model;asc&filter=&sidebar=&fv=", height = "450px")

stefvanbuuren avatar Dec 02 '20 09:12 stefvanbuuren

I see. Can you point me to an example of the output so I can inspect? You had shared this link before but I'm getting a 404: https://stefvanbuuren.name/dbook2/section-sec-impactequate.html

hafen avatar Dec 02 '20 09:12 hafen

Ah yes, sorry. It's now moved it to https://d-score.org/dbook2/section-sec-impactequate.html . Just updated it in my original post.

stefvanbuuren avatar Dec 02 '20 09:12 stefvanbuuren

It see. It looks like it is in an iframe. But even with an iframe it looks achievable. I made some css tweaks to the page to experiment and got this far (with an ugly yellow background to test)

image

In this particular display it appears that there is no transparency set in the images themselves.

hafen avatar Dec 02 '20 09:12 hafen

That's progress. I will need to look into the transparency of the plots.

stefvanbuuren avatar Dec 02 '20 09:12 stefvanbuuren

I checked and regenerated, but the plots were already transparent. Could there be an additional layer within the iframe? I found the following, but cannot change it from the Safari browser console.

<head>
    <meta charset="utf-8"/>
    <style>
    body {
        background-color: white;
    }
    </style>

stefvanbuuren avatar Dec 02 '20 10:12 stefvanbuuren

I went in and manually disabled all background colors in the Trelliscope display but the images do not appear to be transparent.

To double check, I right-clicked on the first graph in the Trelliscope display and chose "Download Image" and opened it in an image editor to confirm that it doesn't have a transparent background.

hafen avatar Dec 03 '20 23:12 hafen