1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
########################################################################
##
## Copyright (C) 2010-2024 The Octave Project Developers
##
## See the file COPYRIGHT.md in the top-level directory of this
## distribution or <https://octave.org/copyright/>.
##
## This file is part of Octave.
##
## Octave is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, see
## <https://www.gnu.org/licenses/>.
##
########################################################################
## -*- texinfo -*-
## @deftypefn {} {} html_compare (@var{toolkits})
## @deftypefnx {} {} html_compare (@var{toolkits}, @var{name}, @var{value}, @dots{})
##
## Produce an html document to compare the plot demos produced by
## @var{toolkits}.
##
## Valid property names, and their defaults, are:
##
## @table @samp
## @item fmt
## @code{"png"}
##
## @item output
## @code{"compare_plot_demos.html"}
##
## @item template
## @code{"html_plot_demos_template.html"}
##
## @item column_width
## @code{600}
## @end table
##
## The template parameter refers to a specially formatted html file
## which accompanies this m-file script.
##
## Additional toolkit description can be added to the column header
## with a parameter named equal to the toolkit. For example:
##
## @smallexample
## @code{html_compare_plot_demos (@{"gnuplot", "fltk"@}, "gnuplot", " 4.6 patchlevel 5")}
## @end smallexample
##
## @seealso{compare_plot_demos, dump_demos, demo}
## @end deftypefn
function html_compare_plot_demos (toolkits, varargin)
## Set defaults
in.fmt = "png";
in.figfiles = {};
in.output_fmt = @(p) sprintf ("compare_plot_demos_%02i.html", p);
in.template = "html_plot_demos_template.html";
in.column_width = 600;
in.plots_per_page = 50;
## Parse inputs
for n = 1:2:numel (varargin)
in.(lower(varargin{n})) = varargin{n+1};
endfor
## Compile a list of all files for all toolkits
for t = 1:numel (toolkits)
filter = sprintf ("%s/*.%s", toolkits{t}, in.fmt);
in.figfiles = union (in.figfiles, {dir(filter).name});
endfor
fid = fopen (which (in.template), "r");
template = char (fread (fid)) .';
fclose (fid);
anchor = "<!-- ##ADD TABLE HERE## -->";
n = strfind (template, anchor);
header = strtrim (template(1:n-1));
trailer = strtrim (template(n+numel (anchor):end));
page = 1;
do
start_fig = (page - 1) * in.plots_per_page + 1;
stop_fig = page * in.plots_per_page;
last_page = stop_fig >= numel (in.figfiles);
if (last_page)
stop_fig = numel (in.figfiles);
endif
fid = fopen (in.output_fmt (page), "w");
unwind_protect
fprintf (fid, "%s\n", header);
fprintf (fid, "<h2>Generated on %s by %s with GNU Octave %s</h2>\n", ...
datestr (now (), 0), mfilename, version);
## Create page previous/next
if (page > 1)
prev_page_link = sprintf (['<p><a href="%s">%s</a></p>' "\n"], ...
in.output_fmt (page - 1), "previous page");
else
prev_page_link = "";
endif
if (! last_page)
next_page_link = sprintf (['<p><a href="%s">%s</a></p>' "\n"], ...
in.output_fmt (page + 1), "next page");
else
next_page_link = "";
endif
fprintf (fid, "%s%s", prev_page_link, next_page_link);
## Create table header
fprintf (fid, "<table>\n<tr>\n");
for t = 1:numel (toolkits)
## set default
column_header = upper (toolkits{t});
if (isfield (in, toolkits{t}))
column_header = [column_header, in.(toolkits{t})];
endif
fprintf (fid, ['<th>%s <a href="%s/diary.log">diary</a></th>' "\n"],
column_header, toolkits{t});
endfor
fprintf (fid, "</tr>\n");
for m = start_fig:stop_fig
[~, file] = fileparts (in.figfiles{m});
fn = [file "." in.fmt];
fprintf (fid, ['<tr id="%s">' "\n"], file);
for k = toolkits
ffn = fullfile (k{:}, fn);
fprintf (fid, "<td><span>%s</span><br>", ffn);
if (exist (ffn, "file"))
fprintf (fid, ...
'<img alt="%s" src="%s" style="width:%dpx">', ...
file, ffn, in.column_width);
else
err_fn = strrep (ffn, ".png", ".err");
if (! exist (err_fn, "file"))
warning ("File %s doesn't exist...", err_fn);
else
err_fid = fopen (err_fn);
msg = char (fread (err_fid))';
fclose (err_fid);
fprintf (fid, "<span>%s</span>", strrep (msg, "\n", "<br>"));
endif
endif
fprintf (fid, "</td>\n");
endfor
fprintf (fid, "</tr>\n");
endfor
fprintf (fid, "</table>\n");
fprintf (fid, "%s%s", prev_page_link, next_page_link);
fprintf (fid, "%s\n", trailer);
page++;
unwind_protect_cleanup
fclose (fid);
end_unwind_protect
until (stop_fig == numel (in.figfiles))
endfunction
|