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

Skip to content

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

Merged
merged 34 commits into from
May 20, 2015

Conversation

Titan-C
Copy link
Member

@Titan-C Titan-C commented Apr 11, 2015

Here I refactor in 3 things.

  • First I include the change from the mayavi branch that turns make thumbnail into scale image
  • Second I split the backreferece file generation into a separate function
  • Last the fhindex is no more moved around the gen_dir_rst functions it is now a return value

@@ -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,
Copy link
Contributor

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.

<div class="sphx-glr-thumbContainer" tooltip="{}">

.. figure:: /{}
:target: /{}.html
Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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.

@Titan-C
Copy link
Member Author

Titan-C commented May 1, 2015

@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.

@lesteve
Copy link
Member

lesteve commented May 4, 2015

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.

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.

@GaelVaroquaux
Copy link
Contributor

Why can't we keep doing the same thing with two directories arguments?

+1

@Titan-C
Copy link
Member Author

Titan-C commented May 4, 2015

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?

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:

@GaelVaroquaux
Copy link
Contributor

Aren't these architectural problems that should be fixed, rather than
introducing fragile workarounds?

On Mon, May 04, 2015 at 12:16:34PM -0700, Óscar Nájera wrote:

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?

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:

• the examples are stored: https://github.com/scikit-learn/scikit-learn/blob/
master/doc/sphinxext/gen_rst.py#L643
• then you give the relative location of one to the other: https://github.com
/scikit-learn/scikit-learn/blob/master/doc/sphinxext/gen_rst.py#L653-654
• finally you only call the example file from a rst file in the same folder


Reply to this email directly or view it on GitHub.*

Gael Varoquaux
Researcher, INRIA Parietal
NeuroSpin/CEA Saclay , Bat 145, 91191 Gif-sur-Yvette France
Phone:  ++ 33-1-69-08-79-68
http://gael-varoquaux.info            http://twitter.com/GaelVaroquaux

@Titan-C
Copy link
Member Author

Titan-C commented May 4, 2015

Aren't these architectural problems that should be fixed, rather than introducing fragile workarounds?

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>
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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

@GaelVaroquaux
Copy link
Contributor

GaelVaroquaux commented May 6, 2015 via email

@Titan-C
Copy link
Member Author

Titan-C commented May 6, 2015

@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
Copy link
Contributor

GaelVaroquaux commented May 6, 2015 via email

@Titan-C
Copy link
Member Author

Titan-C commented May 7, 2015

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.

@lesteve
Copy link
Member

lesteve commented May 8, 2015

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?

@GaelVaroquaux
Copy link
Contributor

could you try to use only relative imports when imprint things from sphinxgallery to make it easier to embed the code

@GaelVaroquaux
Copy link
Contributor

I had a quick look at this PR. Good job fixing the back reference difficulty! I like your solution very much!

@Titan-C
Copy link
Member Author

Titan-C commented May 9, 2015

could you try to use only relative imports when imprint things from sphinxgallery to make it easier to embed the code

are not relative imports being dropped in python3?

@Titan-C
Copy link
Member Author

Titan-C commented May 9, 2015

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 element is available on one of its parent element?

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.

@GaelVaroquaux
Copy link
Contributor

could you try to use only relative imports when imprint things from
sphinxgallery to make it easier to embed the code

are not relative imports being dropped in python3?

No, it's rather the oppositive: imports are no longer relative by
default. In other words "import os" will never be equivalent to "from .
import os".

@lesteve
Copy link
Member

lesteve commented May 14, 2015

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.

@Titan-C
Copy link
Member Author

Titan-C commented May 19, 2015

Sorry for the timeout, I wasn't around. I include some minor fixes based on the comments.

Titan-C added a commit that referenced this pull request May 20, 2015
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
@Titan-C Titan-C merged commit 6f14f84 into sphinx-gallery:master May 20, 2015
@Titan-C Titan-C deleted the scim branch May 20, 2015 08:03
@Titan-C Titan-C mentioned this pull request Nov 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants