Zim

Merge lp:~o-scholder/zim/pyzim-refactor into lp:~jaap.karssenberg/zim/pyzim-refactor

Proposed by Olivier Scholder
Status: Needs review
Proposed branch: lp:~o-scholder/zim/pyzim-refactor
Merge into: lp:~jaap.karssenberg/zim/pyzim-refactor
Diff against target: 65 lines (+26/-1)
3 files modified
data/manual/Plugins/GNU_R_Plot_Editor.txt (+11/-0)
data/templates/plugins/gnu_r_editor.r (+1/-1)
zim/plugins/gnu_r_ploteditor.py (+14/-0)
To merge this branch: bzr merge lp:~o-scholder/zim/pyzim-refactor
Reviewer Review Type Date Requested Status
Jaap Karssenberg Pending
Review via email: mp+197506@code.launchpad.net

Description of the change

Hi Jaap,
Yes my mistake. Sorry. I hope I merge into the right branch now.

I hope you think the tweak is useful. I myself often need wide plots and needed it absolutely.

regards

Olivier

To post a comment you must log in.
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Looks very useful indeed - will merge it. Thanks!

Only wondering about the default - maybe it make sense to not set a default (or make it a preference) and without default simply let R decide the size ?

Btw. thinking about a way to automatically scale all images to window size in the page view, but will be later improvement.

Revision history for this message
Olivier Scholder (o-scholder) wrote :

according to:
http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/png.html
480px is the default size for R.

I guess taking the 480px from the preference is for sure a good idea. So
that everybody can set to the value they like and work with it.

For the resizing, the problem is that each images are not created
on-the-fly by zim. They are converted into picture only once they are
edited. This will makes the auto-resizing to the screen size difficult. We
can implement that in the image module, but the problem with plots is that
they are usually made for a specific width/height ratio and thus automatic
resizing might become annoying.

For the image we have in the source (the saved txt files):

{{PATH-to-myimage.png?width=320}}

we can easily let the user write something like:

{{PATH-to-myimage.png?width=50%}}

and calculate the size of the image on the fly.

what do you think?

2013/12/3 Jaap Karssenberg <email address hidden>

> Looks very useful indeed - will merge it. Thanks!
>
> Only wondering about the default - maybe it make sense to not set a
> default (or make it a preference) and without default simply let R decide
> the size ?
>
> Btw. thinking about a way to automatically scale all images to window size
> in the page view, but will be later improvement.
> --
> https://code.launchpad.net/~o-scholder/zim/pyzim-refactor/+merge/197506
> You are the owner of lp:~o-scholder/zim/pyzim-refactor.
>

Unmerged revisions

683. By Olivier Scholder

Add size tweak for GNU-R plugin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/manual/Plugins/GNU_R_Plot_Editor.txt'
2--- data/manual/Plugins/GNU_R_Plot_Editor.txt 2013-04-13 11:09:42 +0000
3+++ data/manual/Plugins/GNU_R_Plot_Editor.txt 2013-12-03 12:08:29 +0000
4@@ -39,6 +39,17 @@
5 title(main="Maunga Whau Volcano", sub = "col=terrain.colors(100)", font.main=4)
6 '''
7
8+===== Plot size =====
9+
10+This plugin will generate an image which is exactly 480x480 pixels. You can tweak the produced image size by incerting a comment in your script:
11+
12+'''
13+# WIDTH = 960
14+# HEIGHT = 480
15+plot(c(0,1),c(100,328))
16+'''
17+
18+You can define only one of the two variable and the other will be set to the default value of 480 pixels. The line should start with the comment sign '#'. Spaces between words are not important.
19
20 ===== Features Available =====
21
22
23=== modified file 'data/templates/plugins/gnu_r_editor.r'
24--- data/templates/plugins/gnu_r_editor.r 2012-05-17 17:14:44 +0000
25+++ data/templates/plugins/gnu_r_editor.r 2013-12-03 12:08:29 +0000
26@@ -1,3 +1,3 @@
27-png("[% png_fname %]")
28+png("[% png_fname %]",width=[% r_width %], height=[% r_height %])
29 [% gnu_r_plot_script %]
30 dev.off()
31
32=== modified file 'zim/plugins/gnu_r_ploteditor.py'
33--- zim/plugins/gnu_r_ploteditor.py 2013-08-17 22:45:02 +0000
34+++ zim/plugins/gnu_r_ploteditor.py 2013-12-03 12:08:29 +0000
35@@ -15,6 +15,7 @@
36 #
37
38 import glob
39+import re
40
41 from zim.plugins.base.imagegenerator import ImageGeneratorPlugin, ImageGeneratorClass
42 from zim.fs import File, TmpFile
43@@ -72,9 +73,22 @@
44 pngfile = File(plotscriptfile.path[:-2] + '.png')
45
46 plot_script = "".join(text)
47+
48+ plot_width = 480 # default image width (px)
49+ plot_height = 480 # default image height (px)
50+
51+ # LOOK for image size in comments of the script
52+ r=re.search(r"^#\s*WIDTH\s*=\s*([0-9]+)$",plot_script,re.M)
53+ if r:
54+ plot_width=int(r.group(1))
55+ r=re.search(r"^#\s*HEIGHT\s*=\s*([0-9]+)$",plot_script,re.M)
56+ if r:
57+ plot_height=int(r.group(1))
58
59 template_vars = {
60 'gnu_r_plot_script': plot_script,
61+ 'r_width': plot_width,
62+ 'r_height': plot_height,
63 'png_fname': pngfile.path.replace('\\', '/'),
64 # Even on windows, GNU R expects unix path seperator
65 }

Subscribers

People subscribed via source and target branches