Mercurial > hg > octave-nkf
annotate scripts/testfun/private/compare_plot_demos.m @ 19085:b8934a57e13e
Improve plot comparison scripts.
* compare_plot_demos.m: Rewrite docstring. Use all three plot directories in
comparison ("appearance", "draw", "util"). Rename input variable structure
"in" to "arg". Terminate lines of
code with semicolon.
* dump_demos.m: Rewrite docstring. Use fileparts to simplify checking of
output script file name. Accept a single directory or a cell string array
of directories for processing. Revamp test for non-existent directory.
Remove unused code providing replacement Octave functions for Matlab.
Remove linkaxes, linkprops, and colormap from list of demos to process
since they have interactive elements. Use sprintf format string to avoid
if/else structure. Simplify generated code for each plot comparison.
Use 'close all' at the end of each demo to work around issues with accumulating
cruft. Follow Octave coding conventions for cuddling parentheses.
* dump_demos.m (oct2mat): Use regexprep() to convert double quotes in Octave
demos to single quotes for Matlab. Comment out unwind_protect blocks since
Matlab has no knowledge of these. Fix up calls to sombrero without an argument
since Matlab doesn't have a default for this.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 04 Jul 2014 14:32:49 -0700 |
parents | 1b02bfff39d0 |
children | f9cf5ae6b8a2 |
rev | line source |
---|---|
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
1 ## Copyright (C) 2012 Ben Abbott <bpabbott@mac.com> |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
2 ## |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
4 ## |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
8 ## your option) any later version. |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
9 ## |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
13 ## General Public License for more details. |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
14 ## |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
18 |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
20 ## @deftypefn {Function File} {} compare_plot_demos () |
19085 | 21 ## @deftypefnx {Function File} {} compare_plot_demos ("toolkits", @{@var{toolkit1}, @var{toolkit2}, @dots{}@}) |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
22 ## |
19085 | 23 ## Uses @code{dump_demos} and @code{html_compare_plot_demos} to produce an |
24 ## html comparison of the plot demos for each of Octave's graphics toolkits. | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
25 ## |
19085 | 26 ## An m-file named @file{dump_plots.m} will be created in the current working |
27 ## directory. This function will be used to render and save the plot demo | |
28 ## images. | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
29 ## |
19085 | 30 ## If they do not already exist, directories for each available graphics |
31 ## toolkit are created. Each toolkit's directory will be populated with images | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
32 ## of each plot demo in the png format. |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
33 ## |
19085 | 34 ## Finally, an html document named @file{compare_plot_demos.html} is produced. |
35 ## This page places each toolkit's images side by side for a convenient | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
36 ## comparison of the results. |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
37 ## |
19085 | 38 ## If the property @qcode{"toolkits"} is given then compare only the listed |
39 ## toolkits in the cell string. The list may also include the toolkit | |
40 ## @qcode{"matlab"}. | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
41 ## |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
42 ## @end deftypefn |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
43 |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
44 ## Author: Ben Abbott <bpabbott@mac.com> |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
45 |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
46 function compare_plot_demos (varargin) |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
47 |
19085 | 48 arg.toolkits = available_graphics_toolkits (); |
49 arg.directories = {"plot/appearance", "plot/draw", "plot/util"}; | |
50 arg.fmt = "png"; | |
51 arg.fcn_file = ""; | |
52 arg.replace_images = false; | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
53 |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
54 for n = 1:2:numel(varargin) |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
55 if (! ischar (varargin{n})) |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
56 print_usage (); |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
57 else |
19085 | 58 arg.(varargin{n}) = varargin{n+1}; |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
59 endif |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
60 endfor |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
61 |
19085 | 62 if (ischar (arg.toolkits)) |
63 arg.toolkits = {arg.toolkits}; | |
64 elseif (! iscellstr (arg.toolkits)) | |
65 error ('compare_plot_demos: Invalid value for "toolkits"') | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
66 endif |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
67 |
19085 | 68 if (ischar (arg.directories)) |
69 arg.directories = {arg.directories}; | |
70 elseif (! iscellstr (arg.directories)) | |
71 error ('compare_plot_demos: Invalid value for "directory"') | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
72 endif |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
73 |
19085 | 74 if (! ischar (arg.fmt)) |
75 error ('compare_plot_demos: Invalid value for "fmt"') | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
76 endif |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
77 |
19085 | 78 if (isempty (arg.fcn_file)) |
79 arg.fcn_file = "dump_plot_demos.m"; | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
80 endif |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
81 |
19085 | 82 ## Generate "dump_plot_demos.m" for rendering/saving the plot demo images |
83 dump_demos (arg.directories, arg.fcn_file, arg.fmt); | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
84 |
19085 | 85 [~, fcn_name] = fileparts (arg.fcn_file); |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
86 |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
87 ## Generate the plot demo images for each toolkit |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
88 cwd = pwd (); |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
89 unwind_protect |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
90 addpath (pwd); |
19085 | 91 for n = 1:numel (arg.toolkits) |
92 if (! isdir (fullfile (cwd, arg.toolkits{n}))) | |
93 mkdir (arg.toolkits{n}); | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
94 endif |
19085 | 95 cd (arg.toolkits{n}); |
96 if (arg.replace_images && ! isempty (dir (["*." arg.fmt]))) | |
97 delete (["*." arg.fmt]); | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
98 endif |
19085 | 99 if (! strcmp (arg.toolkits{n}, "matlab")) |
100 close all; | |
101 graphics_toolkit (arg.toolkits{n}); | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
102 try |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
103 eval (fcn_name); |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
104 catch |
19085 | 105 printf ("Error running plot demos for ""%s"" toolkit\n", arg.toolkits{n}); |
106 disp (lasterror); | |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
107 end_try_catch |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
108 endif |
19085 | 109 cd (cwd); |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
110 endfor |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
111 unwind_protect_cleanup |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
112 rmpath (cwd); |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
113 end_unwind_protect |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
114 |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
115 ## Generate the html comparison of the images |
19085 | 116 ## TODO: pass the toolkits{} to allow number of columns to be formatted |
19064
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
117 html_compare_plot_demos ("output", "compare_plot_demos.html") |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
118 |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
119 endfunction |
c74673161752
Add scripts to help validate plot results.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
120 |