-
Notifications
You must be signed in to change notification settings - Fork 207
scale image in stead of make thumbnail and independent backrefereces function #26
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
Conversation
@@ -244,7 +241,25 @@ def _thumbnail_div(subdir, full_dir, fname, snippet): | |||
return out | |||
|
|||
|
|||
def generate_dir_rst(directory, fhindex, examples_dir, gallery_dir, gallery_conf, plot_gallery, seen_backrefs): | |||
def write_backreferces(backrefs, seen_backrefs, gallery_conf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write_backreferces ? I don't understand.
… on generate_file_rst
<div class="sphx-glr-thumbContainer" tooltip="{}"> | ||
|
||
.. figure:: /{} | ||
:target: /{}.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the target directive to put links to the figure. It would be great if it could take references and not links urls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably very naive: but it seems that removing the leading /
in the target fixes the link without running a webserver. Is there a reason why you need it?
Same thing goes for the /
in figure, it doesn't look like it is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably very naive: but it seems that removing the leading / in the target fixes the link without running a webserver. Is there a reason why you need it?
It doesn't solve it for me. Which sphinx version are you using? I have 1.2.3
I use the leading /
because it allows me to link to the image from any location in the documentation. And if used for the target when running the web server it also links properly from anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I was right, it was a very naive attempt! I think it may have fixed the link in the backreferences but not in the gallery or the other way around. I'll try to take a closer look.
FWIW the documentation says the target
can take reference but I was unable to get it to work, maybe because it is not supposed to work across documents.
In general, it would be a lot better if a webserver wasn't needed to look at the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I also agree on that. Although once published online I doesn't do much of a difference. The thing I fear is that it will require to extended sphinx to accept the :doc: or :ref: directive inside the figure environment. at target can only take urls or same page references. And I'm still trying to figure out how does sphinx work at this level.
@lesteve this is the broken or almost working branch. If you build the documentation you will notice that in the gallery all the links on the images are broken, but not their caption. Nevertheless if you run a webserver on _build/html these links work. This is the problem of the target directive. See comment in code. What does this have to do with backreferences? Backrefences are the exact same thumbnails of the gallery but put at the end of the modules documentation API(Feature only used by scikit-learn), so one has to link to the same example website but from different locations(the Gallery and the documented API) The scikit-learn solution was to make _thumbnail_div take 2 input dirs. One having the directory of the gallery and the other containing the relative path from the API documentation to the gallery. But that requires to hardcode those relative locations in the script. And that shall not be done for a generic module, as every user would locate their files to his convenience. The problem of the back references is how to keep track of the location of the gallery example files and images and how to link to them from an arbitrary location. My solution was to use sphinx absolute paths to the sphinx source directory. So I would only need to know the example files location, sphinx does the rest. This can be used for the figure directive which searches within sphinx, but the target directive takes urls. So if a webserver is used on the _build/html or any output directory, then all absolute paths work. |
Why can't we keep doing the same thing with two directories arguments? In particular it would be great if you could point me to the hardcoding needed in the scikit-learn code. |
+1 |
So the _thumbnail_div processes the directories separately here: https://github.com/scikit-learn/scikit-learn/blob/master/doc/sphinxext/gen_rst.py#L584-590 but when one calls if for a gallery thumbnail one uses: https://github.com/scikit-learn/scikit-learn/blob/master/doc/sphinxext/gen_rst.py#L633 whereas for the backreferences. One codes where:
|
Aren't these architectural problems that should be fixed, rather than On Mon, May 04, 2015 at 12:16:34PM -0700, Óscar Nájera wrote:
|
yes. That's why I wanted to use absolute paths. But I run short of the capabilities of sphinx when the figure instruction can only take links as urls or local references, and not cross references across documents like ref or absolute paths to rst files like doc. |
.. include:: modules/generated/sphinxgallery.__version__.examples | ||
.. raw:: html | ||
|
||
<div style='clear:both'></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this clearing needed and if yes should it be added to the .examples file directly?
Also maybe not in this PR but it'd be great to use sphinx templates as scikit-learn is doing in order to introduce the .examples automatically and have an example within sphinx-gallery showing this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is required maybe 90% because one is floating the thumbnails and one has to signalize when that ends. 10% when it is not needed is because the theme of the website is simple enough it has no conflict with the floats. The basic/default sphinx theme, which you render locally is immune. The read the docs theme, and scikit-learn where many other divs are floated need this. But it is all your choice on the theme you use.
I'm not sure if it should be added to the .example file directly. If one uses the sphinx templates for documenting modules and classes(as in scikit-learn) I guess it is better to add it manually there and once. All because it is more a theme and style instruction. If you change the CSS of sphinx-gallery and its floats, then this becomes irrelevant or more the user choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest, what is the worse that can happen if you always use the clearing trick, even when not needed ?
.example files are automatically generated so I don't really see a problem to add the clearing there. At least it ensures that just doing an include will just work and you don't have to remember to add the raw html additional content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest, what is the worse that can happen if you always use the clearing trick, even when not needed ?
I have no idea. It is CSS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.example files are automatically generated so I don't really see a problem to add the clearing there
I'll put the clearing
In the end the solution looks is very simple and elegant. I first
extend the figure directive with a custom one to hold the gallery
thumbnails.
I really don't like the extension of a directive. The whole design of the
original gen_rst.py is to avoid this. Sphinx directives have prooved to
be fragile and to break.
Please absolutely avoid creating sphinx directives and absolute imports.
|
@GaelVaroquaux would you take over this PR. I really don't see a more simpler solution that gets the job done. Besides relying on absolute paths and running always on a webserver. Indeed having an extra directive, although simple, does feel like an overshoot, but I could not get a better solution. |
@GaelVaroquaux would you take over this PR. I really don't see a more simpler
solution that gets the job done. Besides relying on absolute paths and running
always on a webserver. Indeed having an extra directive, although simple, does
feel like an overshoot, but I could not get a better solution.
You have no idea how overbooked I am. There is no chance that I can take
over this PR.
I don't know how we got to this situation, but the first versions of
gen_rst.py did not need such hacks. I suspect that it's a new feature
that is calling for those hacks. Well, maybe it's time to cut our loses
and decide that we don't want this feature. All I am saying is that those
hacks should not get in the project because they will make the codebase
too fragile.
|
This can not get any simpler, I should have gotten this idea in the first place. Instead of putting a link to the image in the thumbnail. The anchor in the caption is extended in CSS to cover the complete thumbnail area. So the references get properly resolved by sphinx, and the link is not only over the text but on the whole thumbnail. No sphinx extensions, only CSS tricks. |
This seems to be working fine indeed, good stuff! Out of interest, can you explain how it works? My question is mostly how come you can now click anywhere on the thumbnail to go to the example page? In other words why the target of the <a ..> element is available on one of its parent element? |
could you try to use only relative imports when imprint things from sphinxgallery to make it easier to embed the code |
I had a quick look at this PR. Good job fixing the back reference difficulty! I like your solution very much! |
are not relative imports being dropped in python3? |
Well, that it why it did not occur to me in the beginning. In CSS you have to think of element arranged in layers, So it is not that the target of the element if available for its parent. But that the element is on a higher layer than the parent and it extends itself over the whole parent covering its entire surface. |
No, it's rather the oppositive: imports are no longer relative by |
I think this PR can go in. The CSS thing seems a little bit fragile but way more transparent than the sphinx directive and the backreference functionality is a great thing to have. |
Sorry for the timeout, I wasn't around. I include some minor fixes based on the comments. |
scale image in stead of make thumbnail independent backrefereces function with CSS templating to make complete gallery thumbnail area click-able relative imports for easier embedded code
Here I refactor in 3 things.