Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Introduction tooltip corresponds to the first paragraph #1344

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

Merged
merged 4 commits into from
Jul 11, 2024
Merged

Introduction tooltip corresponds to the first paragraph #1344

merged 4 commits into from
Jul 11, 2024

Conversation

fgmacedo
Copy link
Contributor

@fgmacedo fgmacedo commented Jul 7, 2024

Closes: #1066 (related to #1085).

  • Introduction tooltip corresponds to the first paragraph and is no longer truncated.
  • Tooltip representation is handled using CSS.

With my custom-sized gallery

Without adjusting the padding, I got this:

image

Note that given the padding was 10px 10px 10px 10px, the bottom exposes the top content of the next truncated line:

image

Adjusting the padding, I got this:

image

With full default CSS

I've adjusted the clamp to 6 lines, so longer texts use full space, and smaller ones are automatically reduced (states forced to :hover):

image

Copy link
Contributor

@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love adding another configuration but if it is not achievable via CSS this seems reasonable.
I'll let @larsoner merge.

@larsoner
Copy link
Contributor

larsoner commented Jul 9, 2024

if it is not achievable via CSS this seems reasonable

I think this is probably what we want, and looks like FireFox added support in 2019 so probably okay to use nowadays:

https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-line-clamp#truncating_a_paragraph

It's a bigger PR but in principle then people can just override the number of lines, box width, etc. to their liking rather than us having some artificial character limit.

@lucyleeow do you agree it's a better way forward? If so then @fgmacedo would you be up for trying this?

@fgmacedo
Copy link
Contributor Author

fgmacedo commented Jul 9, 2024

if it is not achievable via CSS this seems reasonable

I think this is probably what we want, and looks like FireFox added support in 2019 so probably okay to use nowadays:

https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-line-clamp#truncating_a_paragraph

It's a bigger PR but in principle then people can just override the number of lines, box width, etc. to their liking rather than us having some artificial character limit.

@lucyleeow do you agree it's a better way forward? If so then @fgmacedo would you be up for trying this?

I'm already aware of this. But I cannot get to make it work for any situation.

  1. Set the display property to -webkit-box, a necessary step as -webkit-line-clamp only works with -webkit-box.
  2. Set the -webkit-box-orient property to vertical: This defines the box’s orientation to vertical, so that the lines are vertically stacked.
  3. For example, I'm trying to clamp at 2 lines to see if it works: -webkit-line-clamp: 2;

The final CSS was:

.sphx-glr-thumbcontainer[tooltip]:hover:after {
  background: var(--sg-tooltip-background);
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
  color: var(--sg-tooltip-foreground);
  content: attr(tooltip);
  padding: 10px;
  z-index: 98;
  width: 100%;
  height: 100%;
  position: absolute;
  pointer-events: none;
  top: 0;
  box-sizing: border-box;
  overflow: hidden;
  backdrop-filter: blur(3px);

  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; /* Number of lines to show */
  overflow: hidden;       
}

My result was (note the ellipsis on the second line):

image

It added the ellipsis, but no text was truncated.

So you need to get in sync how many lines of text can be displayed with the font, margin, size, etc... to get the exactly configuration on the clamp, because it doesn't get rid of the next line... if the container is larger / smaller, things are going to break. This is why I called the solution "fragile".

@drammock
Copy link
Contributor

drammock commented Jul 9, 2024

height and padding are going to play a role here. Probably for the CSS approach to work and still look good, the semitransparent overlay will need to be a separate node from the tooltip text container. By hacking in the browser console like this:

Screenshot_2024-07-09_16-37-43

I can get this:

Screenshot 2024-07-09 at 16-37-23 Basics Gallery with Matplotlib — Sphinx-Gallery 0 17 dev0-git documentation

@lucyleeow
Copy link
Contributor

@lucyleeow do you agree it's a better way forward?

100% prefer CSS option. We don't want another config.

@fgmacedo
Copy link
Contributor Author

Changing the approach:

  1. Introduction tooltip corresponds to the first paragraph and is no longer truncated.
  2. Tooltip representation is handled using CSS.

Do you agree with this?

@fgmacedo fgmacedo changed the title Allow customizing the intro length on gallery tooltip Introduction tooltip corresponds to the first paragraph Jul 10, 2024
@larsoner
Copy link
Contributor

Yes that sounds good!

Looks like there is a tiny visual regression in this PR where the mouseover "black box" doesn't cover the whole tile, for example mousing over I see

image

Whereas on latest dev I see:

image

Not sure if it's fixable or not...? One solution would be to make one div with height=100% that covers the whole tile, and then inside that the next div (or whatever) that does the text trucncation.

@drammock
Copy link
Contributor

One solution would be to make one div with height=100% that covers the whole tile, and then inside that the next div (or whatever) that does the text trucncation.

That's exactly what I was trying to suggest above when I said

the semitransparent overlay will need to be a separate node from the tooltip text container

But @larsoner has said it much more clearly :)

@fgmacedo
Copy link
Contributor Author

Tests passing locally. Is sphinx_gallery/tests/test_full.py::test_interactive_example_logo_exists an intermittent test?

@lucyleeow
Copy link
Contributor

real but unrelated to this PR. Its present in #1346 as well.

@fgmacedo
Copy link
Contributor Author

fgmacedo commented Jul 11, 2024

I've currently set the default to 4 lines, but I might have been a bit conservative. How about increasing it to 6 lines?

image

Preview:

https://output.circle-artifacts.com/output/job/1d60ae2a-9e1f-421d-bcf5-3d55c8cb487e/artifacts/0/html/auto_examples/index.html

Also, I've missed the pointer-events: none;, including.

@larsoner
Copy link
Contributor

Failure in sphinx dev was due to sphinx-doc/sphinx#12425 and I pushed a commit to #1346. Once that lands I'll merge master into this PR which should get things green, and I'll look at the examples. Agreed 6 is probably better than 4 for line clamping

@larsoner
Copy link
Contributor

Rendered doc looks good and locally I tested it on MNE-Python and things looked good so in it goes, thanks @fgmacedo !

@larsoner larsoner merged commit 51cbf73 into sphinx-gallery:master Jul 11, 2024
20 checks passed
@fgmacedo fgmacedo deleted the macedo/longer-intro branch July 11, 2024 15:18
clrpackages referenced this pull request in clearlinux-pkgs/pypi-sphinx_gallery Jul 23, 2024
… to version 0.17.0

v0.17.0
-------

Support for Python 3.8 and Sphinx 4 dropped in this release.
Requirement is now Python >= 3.9 and Sphinx >= 5.

**Implemented enhancements:**

-  Introduction tooltip corresponds to the first paragraph `#1344 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1344>`__ (`fgmacedo <https://github.com/fgmacedo>`__)
-  FIX Jupyterlite in CircleCI artifact `#1336 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1336>`__ (`lesteve <https://github.com/lesteve>`__)
-  MNT: Rename README.rst to GALLERY_HEADER.rst `#1321 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1321>`__ (`timhoffm <https://github.com/timhoffm>`__)
-  [ENH] Add custom thumbnails for failing examples `#1313 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1313>`__ (`tsbinns <https://github.com/tsbinns>`__)
-  ENH integrate download/launcher links into ``pydata-sphinx-theme`` secondary sidebar `#1312 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1312>`__ (`Charlie-XIAO <https://github.com/Charlie-XIAO>`__)
-  add option for zip downloads `#1299 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1299>`__ (`jamiecook <https://github.com/jamiecook>`__)
-  Allow setting animation format from gallery config `#1243 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1243>`__ (`QuLogic <https://github.com/QuLogic>`__)

(NEWS truncated at 15 lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make preview text longer
4 participants