comparison scripts/plot/util/private/__gnuplot_draw_axes__.m @ 20435:755ba248fb4a

build: Rename __go_draw_XXX to __gnuplot_draw_XXX for clarity. * scripts/plot/util/private/__gnuplot_draw_axes__.m: Renamed from __go_draw_axes__.m * scripts/plot/util/private/__gnuplot_draw_figure__.m: Renamed from __go_draw_figure__.m * __scatter__.m, __gnuplot_drawnow__.m: Update scripts to use new names. * scripts/plot/util/module.mk: Use new file names in build system.
author Rik <rik@octave.org>
date Sun, 26 Jul 2015 18:33:57 -0700
parents scripts/plot/util/private/__go_draw_axes__.m@42b7d7758c4a
children
comparison
equal deleted inserted replaced
20434:26bd6008fc9c 20435:755ba248fb4a
1 ## Copyright (C) 2005-2015 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} __gnuplot_draw_axes__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 ## Author: jwe
25
26 function __gnuplot_draw_axes__ (h, plot_stream, enhanced, mono,
27 bg_is_set, fg_is_set, hlgnd)
28
29 showhiddenhandles = get (0, "showhiddenhandles");
30 unwind_protect
31 set (0, "showhiddenhandles", "on");
32 axis_obj = __get__ (h);
33 unwind_protect_cleanup
34 set (0, "showhiddenhandles", showhiddenhandles);
35 end_unwind_protect
36
37 parent_figure_obj = get (axis_obj.parent);
38 gnuplot_term = __gnuplot_get_var__ (axis_obj.parent, "GPVAL_TERM");
39
40 ## Set to false for plotyy axes.
41 ymirror = true;
42 if (isfield (axis_obj, "__plotyy_axes__"))
43 if (all (ishandle (axis_obj.__plotyy_axes__)))
44 ymirror = false;
45 else
46 h = axis_obj.__plotyy_axes__;
47 h = h(ishandle (h));
48 h = h(isprop (h, "__plotyy_axes__"));
49 rmappdata (h, "__plotyy_axes__");
50 endif
51 endif
52
53 nd = __calc_dimensions__ (h);
54
55 if (strcmp (axis_obj.dataaspectratiomode, "manual")
56 && strcmp (axis_obj.xlimmode, "manual")
57 && strcmp (axis_obj.ylimmode, "manual"))
58 ## All can't be "manual"
59 axis_obj.plotboxaspectratiomode = "auto";
60 endif
61
62 if (strcmp (axis_obj.dataaspectratiomode, "manual")
63 && strcmp (axis_obj.xlimmode, "manual")
64 && strcmp (axis_obj.ylimmode, "manual")
65 && (nd == 2 || all (mod (axis_obj.view, 90) == 0)))
66 ## FIXME: adjust plotboxaspectratio to respect other
67 fpos = get (axis_obj.parent, "position");
68 apos = axis_obj.position;
69 endif
70
71 pos = __actual_axis_position__ (h);
72
73 if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
74 dr = axis_obj.dataaspectratio;
75 if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
76 dr = dr(1) / dr(2);
77 else
78 ## FIXME: need to properly implement 3D
79 dr = mean (dr(1:2)) / dr(3);
80 endif
81 else
82 dr = 1;
83 endif
84
85 if (strcmp (axis_obj.activepositionproperty, "position"))
86 if (__gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin"))
87 if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
88 x = [1, 1];
89 else
90 ## 3D plots need to be sized down to fit in the window.
91 x = 1.0 ./ sqrt ([2, 2.5]);
92 endif
93 fprintf (plot_stream, "set tmargin screen %.15g;\n",
94 pos(2)+pos(4)/2+x(2)*pos(4)/2);
95 fprintf (plot_stream, "set bmargin screen %.15g;\n",
96 pos(2)+pos(4)/2-x(2)*pos(4)/2);
97 fprintf (plot_stream, "set lmargin screen %.15g;\n",
98 pos(1)+pos(3)/2-x(1)*pos(3)/2);
99 fprintf (plot_stream, "set rmargin screen %.15g;\n",
100 pos(1)+pos(3)/2+x(1)*pos(3)/2);
101 sz_str = "";
102 else
103 fprintf (plot_stream, "set tmargin 0;\n");
104 fprintf (plot_stream, "set bmargin 0;\n");
105 fprintf (plot_stream, "set lmargin 0;\n");
106 fprintf (plot_stream, "set rmargin 0;\n");
107
108 if (nd == 3 && all (axis_obj.view == [0, 90]))
109 ## FIXME: Kludge to allow colorbar to be added to a pcolor() plot
110 pos(3:4) = pos(3:4) * 1.4;
111 pos(1:2) = pos(1:2) - pos(3:4) * 0.125;
112 endif
113
114 fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2));
115
116 if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
117 sz_str = sprintf ("set size ratio %.15g", -dr);
118 else
119 sz_str = "set size noratio";
120 endif
121 sz_str = sprintf ("%s %.15g, %.15g;\n", sz_str, pos(3), pos(4));
122 endif
123 else ## activepositionproperty == outerposition
124 fprintf (plot_stream, "unset tmargin;\n");
125 fprintf (plot_stream, "unset bmargin;\n");
126 fprintf (plot_stream, "unset lmargin;\n");
127 fprintf (plot_stream, "unset rmargin;\n");
128 fprintf (plot_stream, "set origin %g, %g;\n", pos(1:2));
129 sz_str = "";
130 if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
131 sz_str = sprintf ("ratio %g", -dr);
132 else
133 sz_str = "noratio";
134 endif
135 sz_str = sprintf ("set size %s %g, %g;\n", sz_str, pos(3:4));
136 endif
137 if (! isempty (sz_str))
138 fputs (plot_stream, sz_str);
139 endif
140
141 ## Reset all labels, axis-labels, tick-labels, and title
142 ## FIXME: We should have an function to initialize the axis.
143 ## Presently, this is dispersed in this function.
144 fputs (plot_stream, "unset label;\n");
145 fputs (plot_stream, "unset xtics;\n");
146 fputs (plot_stream, "unset ytics;\n");
147 fputs (plot_stream, "unset ztics;\n");
148 fputs (plot_stream, "unset x2tics;\n");
149 fputs (plot_stream, "unset x2tics;\n");
150
151 if (! isempty (axis_obj.title))
152 t = get (axis_obj.title);
153 if (isempty (t.string))
154 fputs (plot_stream, "unset title;\n");
155 else
156 colorspec = get_text_colorspec (t.color, mono);
157 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string");
158 fontspec = create_fontspec (f, s, gnuplot_term);
159 fprintf (plot_stream, "set title \"%s\" %s %s %s;\n",
160 undo_string_escapes (tt), fontspec, colorspec,
161 __do_enhanced_option__ (enhanced, t));
162 endif
163 endif
164
165 if (! isempty (axis_obj.xlabel))
166 t = get (axis_obj.xlabel);
167 angle = t.rotation;
168 colorspec = get_text_colorspec (t.color, mono);
169 if (isempty (t.string))
170 fprintf (plot_stream, "unset xlabel;\n");
171 fprintf (plot_stream, "unset x2label;\n");
172 else
173 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string");
174 fontspec = create_fontspec (f, s, gnuplot_term);
175 if (strcmpi (axis_obj.xaxislocation, "top"))
176 fprintf (plot_stream, "set x2label \"%s\" %s %s %s",
177 undo_string_escapes (tt), colorspec, fontspec,
178 __do_enhanced_option__ (enhanced, t));
179 else
180 fprintf (plot_stream, "set xlabel \"%s\" %s %s %s",
181 undo_string_escapes (tt), colorspec, fontspec,
182 __do_enhanced_option__ (enhanced, t));
183 endif
184 fprintf (plot_stream, " rotate by %f;\n", angle);
185 if (strcmpi (axis_obj.xaxislocation, "top"))
186 fprintf (plot_stream, "unset xlabel;\n");
187 else
188 fprintf (plot_stream, "unset x2label;\n");
189 endif
190 endif
191 endif
192
193 if (! isempty (axis_obj.ylabel))
194 t = get (axis_obj.ylabel);
195 angle = t.rotation;
196 colorspec = get_text_colorspec (t.color, mono);
197 if (isempty (t.string))
198 fprintf (plot_stream, "unset ylabel;\n");
199 fprintf (plot_stream, "unset y2label;\n");
200 else
201 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string");
202 fontspec = create_fontspec (f, s, gnuplot_term);
203 if (strcmpi (axis_obj.yaxislocation, "right"))
204 fprintf (plot_stream, "set y2label \"%s\" %s %s %s",
205 undo_string_escapes (tt), colorspec, fontspec,
206 __do_enhanced_option__ (enhanced, t));
207 else
208 fprintf (plot_stream, "set ylabel \"%s\" %s %s %s",
209 undo_string_escapes (tt), colorspec, fontspec,
210 __do_enhanced_option__ (enhanced, t));
211 endif
212 fprintf (plot_stream, " rotate by %f;\n", angle);
213 if (strcmpi (axis_obj.yaxislocation, "right"))
214 fprintf (plot_stream, "unset ylabel;\n");
215 else
216 fprintf (plot_stream, "unset y2label;\n");
217 endif
218 endif
219 endif
220
221 if (! isempty (axis_obj.zlabel))
222 t = get (axis_obj.zlabel);
223 angle = t.rotation;
224 colorspec = get_text_colorspec (t.color, mono);
225 if (isempty (t.string))
226 fputs (plot_stream, "unset zlabel;\n");
227 else
228 [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string");
229 fontspec = create_fontspec (f, s, gnuplot_term);
230 fprintf (plot_stream, "set zlabel \"%s\" %s %s %s",
231 undo_string_escapes (tt), colorspec, fontspec,
232 __do_enhanced_option__ (enhanced, t));
233 fprintf (plot_stream, " rotate by %f;\n", angle);
234 endif
235 endif
236
237 if (strcmpi (axis_obj.xaxislocation, "top"))
238 xaxisloc = "x2";
239 xaxisloc_using = "x2";
240 else
241 xaxisloc = "x";
242 xaxisloc_using = "x1";
243 if (strcmpi (axis_obj.xaxislocation, "zero"))
244 fputs (plot_stream, "set xzeroaxis;\n");
245 endif
246 endif
247 if (strcmpi (axis_obj.yaxislocation, "right"))
248 yaxisloc = "y2";
249 yaxisloc_using = "y2";
250 else
251 yaxisloc = "y";
252 yaxisloc_using = "y1";
253 if (strcmpi (axis_obj.yaxislocation, "zero"))
254 fputs (plot_stream, "set yzeroaxis;\n");
255 endif
256 endif
257
258 have_grid = false;
259
260 if (strcmpi (axis_obj.xgrid, "on"))
261 have_grid = true;
262 fprintf (plot_stream, "set grid %stics;\n", xaxisloc);
263 else
264 fprintf (plot_stream, "set grid no%stics;\n", xaxisloc);
265 endif
266
267 if (strcmpi (axis_obj.ygrid, "on"))
268 have_grid = true;
269 fprintf (plot_stream, "set grid %stics;\n", yaxisloc);
270 else
271 fprintf (plot_stream, "set grid no%stics;\n", yaxisloc);
272 endif
273
274 if (strcmpi (axis_obj.zgrid, "on"))
275 have_grid = true;
276 fputs (plot_stream, "set grid ztics;\n");
277 else
278 fputs (plot_stream, "set grid noztics;\n");
279 endif
280
281 if (strcmpi (axis_obj.xminorgrid, "on"))
282 have_grid = true;
283 if (strcmp (axis_obj.xscale, "log"))
284 m = 10;
285 else
286 m = 5;
287 endif
288 fprintf (plot_stream, "set m%stics %d;\n", xaxisloc, m);
289 fprintf (plot_stream, "set grid m%stics;\n", xaxisloc);
290 else
291 fprintf (plot_stream, "set grid nom%stics;\n", xaxisloc);
292 endif
293
294 if (strcmpi (axis_obj.yminorgrid, "on"))
295 have_grid = true;
296 if (strcmp (axis_obj.yscale, "log"))
297 m = 10;
298 else
299 m = 5;
300 endif
301 fprintf (plot_stream, "set m%stics %d;\n", yaxisloc, m);
302 fprintf (plot_stream, "set grid m%stics;\n", yaxisloc);
303 else
304 fprintf (plot_stream, "set grid nom%stics;\n", yaxisloc);
305 endif
306
307 if (strcmpi (axis_obj.zminorgrid, "on"))
308 have_grid = true;
309 if (strcmp (axis_obj.zscale, "log"))
310 m = 10;
311 else
312 m = 5;
313 endif
314 fprintf (plot_stream, "set mztics %d;\n", m);
315 fputs (plot_stream, "set grid mztics;\n");
316 else
317 fputs (plot_stream, "set grid nomztics;\n");
318 endif
319
320 ## The grid front/back/layerdefault option also controls the
321 ## appearance of tics, so it is used even if the grid is absent.
322 if (strcmpi (axis_obj.layer, "top"))
323 fputs (plot_stream, "set grid front;\n");
324 fputs (plot_stream, "set border front;\n");
325 else
326 fputs (plot_stream, "set grid layerdefault;\n");
327 ## FIXME: The gnuplot help says that "layerdefault" should work
328 ## for set border too, but it fails for me with gnuplot 4.2.5.
329 ## So, use "back" instead.
330 fputs (plot_stream, "set border back;\n");
331 endif
332
333 fprintf (plot_stream, "set grid linewidth %f, linewidth %f;\n",
334 axis_obj.linewidth, axis_obj.linewidth);
335
336 if (! have_grid)
337 fputs (plot_stream, "unset grid;\n");
338 endif
339
340 xlogscale = strcmpi (axis_obj.xscale, "log");
341 ylogscale = strcmpi (axis_obj.yscale, "log");
342 zlogscale = strcmpi (axis_obj.zscale, "log");
343
344 ## Detect logscale and negative lims
345 if (xlogscale && all (axis_obj.xlim < 0))
346 axis_obj.xsgn = -1;
347 if (strcmp (axis_obj.xdir, "reverse"))
348 axis_obj.xdir = "normal";
349 elseif (strcmp (axis_obj.xdir, "normal"))
350 axis_obj.xdir = "reverse";
351 endif
352 axis_obj.xtick = -flip (axis_obj.xtick);
353 axis_obj.xticklabel = flip (axis_obj.xticklabel);
354 axis_obj.xlim = -flip (axis_obj.xlim);
355 else
356 axis_obj.xsgn = 1;
357 endif
358 if (ylogscale && all (axis_obj.ylim < 0))
359 axis_obj.ysgn = -1;
360 if (strcmp (axis_obj.ydir, "reverse"))
361 axis_obj.ydir = "normal";
362 elseif (strcmp (axis_obj.ydir, "normal"))
363 axis_obj.ydir = "reverse";
364 endif
365 axis_obj.ytick = -flip (axis_obj.ytick);
366 axis_obj.yticklabel = flip (axis_obj.yticklabel);
367 axis_obj.ylim = -flip (axis_obj.ylim);
368 else
369 axis_obj.ysgn = 1;
370 endif
371 if (zlogscale && all (axis_obj.zlim < 0))
372 axis_obj.zsgn = -1;
373 if (strcmp (axis_obj.zdir, "reverse"))
374 axis_obj.zdir = "normal";
375 elseif (strcmp (axis_obj.zdir, "normal"))
376 axis_obj.zdir = "reverse";
377 endif
378 axis_obj.ztick = -flip (axis_obj.ztick);
379 axis_obj.zticklabel = flip (axis_obj.zticklabel);
380 axis_obj.zlim = -flip (axis_obj.zlim);
381 else
382 axis_obj.zsgn = 1;
383 endif
384
385 xlim = axis_obj.xlim;
386 ylim = axis_obj.ylim;
387 zlim = axis_obj.zlim;
388 clim = axis_obj.clim;
389
390 do_tics (axis_obj, plot_stream, ymirror, mono, gnuplot_term);
391
392 fputs (plot_stream, "unset logscale;\n");
393 if (xlogscale)
394 fprintf (plot_stream, "set logscale %s;\n", xaxisloc);
395 endif
396 if (ylogscale)
397 fprintf (plot_stream, "set logscale %s;\n", yaxisloc);
398 endif
399 if (zlogscale)
400 fputs (plot_stream, "set logscale z;\n");
401 endif
402
403 xautoscale = strcmpi (axis_obj.xlimmode, "auto");
404 yautoscale = strcmpi (axis_obj.ylimmode, "auto");
405 zautoscale = strcmpi (axis_obj.zlimmode, "auto");
406 cautoscale = strcmpi (axis_obj.climmode, "auto");
407 cdatadirect = false;
408 truecolor = false;
409
410 fputs (plot_stream, "set clip two;\n");
411
412 kids = axis_obj.children;
413 ## Remove the axis labels and title from the children, and
414 ## preserved the original order.
415 [jnk, k] = setdiff (kids, [axis_obj.xlabel; axis_obj.ylabel; ...
416 axis_obj.zlabel; axis_obj.title]);
417 kids = kids(sort (k));
418
419 if (nd == 3)
420 fputs (plot_stream, "set parametric;\n");
421 fputs (plot_stream, "set style data lines;\n");
422 fputs (plot_stream, "set surface;\n");
423 fputs (plot_stream, "unset contour;\n");
424 endif
425
426 data_idx = 0;
427 data = cell ();
428 is_image_data = [];
429 hidden_removal = NaN;
430 view_map = false;
431
432 if (! cautoscale && clim(1) == clim(2))
433 clim(2)++;
434 endif
435 addedcmap = [];
436
437 ximg_data = {};
438 ximg_data_idx = 0;
439
440 while (! isempty (kids))
441
442 obj = get (kids(end));
443
444 if (isfield (obj, "xdata"))
445 obj.xdata = double (obj.xdata);
446 endif
447 if (isfield (obj, "ydata"))
448 obj.ydata = double (obj.ydata);
449 endif
450 if (isfield (obj, "zdata"))
451 obj.zdata = double (obj.zdata);
452 endif
453
454 if (isfield (obj, "units"))
455 units = obj.units;
456 unwind_protect
457 set (kids(end), "units", "data");
458 obj = get (kids(end));
459 unwind_protect_cleanup
460 set (kids(end), "units", units);
461 end_unwind_protect
462 endif
463 kids = kids(1:(end-1));
464
465 if (strcmp (obj.visible, "off"))
466 continue;
467 endif
468
469 if (xlogscale && isfield (obj, "xdata"))
470 obj.xdata = axis_obj.xsgn * obj.xdata;
471 obj.xdata(obj.xdata<=0) = NaN;
472 endif
473 if (ylogscale && isfield (obj, "ydata"))
474 obj.ydata = axis_obj.ysgn * obj.ydata;
475 obj.ydata(obj.ydata<=0) = NaN;
476 endif
477 if (zlogscale && isfield (obj, "zdata"))
478 obj.zdata = axis_obj.zsgn * obj.zdata;
479 obj.zdata(obj.zdata<=0) = NaN;
480 endif
481
482 ## Check for facecolor interpolation for surfaces.
483 doing_interp_color = ...
484 isfield (obj, "facecolor") && strcmp (obj.facecolor, "interp");
485
486 switch (obj.type)
487 case "image"
488 img_data = obj.cdata;
489 img_xdata = obj.xdata;
490 img_ydata = obj.ydata;
491
492 if (ndims (img_data) == 3)
493 truecolor = true;
494 elseif (strcmpi (obj.cdatamapping, "direct"))
495 cdatadirect = true;
496 endif
497 data_idx++;
498 is_image_data(data_idx) = true;
499 parametric(data_idx) = false;
500 have_cdata(data_idx) = false;
501 have_3d_patch(data_idx) = false;
502
503 if (img_xdata(2) < img_xdata(1))
504 img_xdata = img_xdata(2:-1:1);
505 img_data = img_data(:,end:-1:1,:);
506 elseif (img_xdata(1) == img_xdata(2))
507 img_xdata = img_xdata(1) + [0, columns(img_data)-1];
508 endif
509 if (img_ydata(2) < img_ydata(1))
510 img_ydata = img_ydata(2:-1:1);
511 img_data = img_data(end:-1:1,:,:);
512 elseif (img_ydata(1) == img_ydata(2))
513 img_ydata = img_ydata(1) + [0, rows(img_data)-1];
514 endif
515
516 x_origin = min (img_xdata);
517 y_origin = min (img_ydata);
518
519 [y_dim, x_dim] = size (img_data(:,:,1));
520 if (x_dim > 1)
521 dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1);
522 else
523 x_dim = 2;
524 img_data = [img_data, img_data];
525 dx = abs (img_xdata(2)-img_xdata(1));
526 if (dx < 1)
527 ## Correct gnuplot string for 1-D images
528 dx = 0.5;
529 x_origin = 0.75;
530 endif
531 endif
532 if (y_dim > 1)
533 dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1);
534 else
535 y_dim = 2;
536 img_data = [img_data; img_data];
537 dy = abs (img_ydata(2)-img_ydata(1));
538 if (dy < 1)
539 ## Correct gnuplot string for 1-D images
540 dy = 0.5;
541 y_origin = 0.75;
542 endif
543 endif
544
545 if (ndims (img_data) == 3)
546 data{data_idx} = permute (img_data, [3, 1, 2])(:);
547 format = "1:2:3";
548 imagetype = "rgbimage";
549 else
550 data{data_idx} = img_data(:);
551 format = "1";
552 imagetype = "image";
553 endif
554
555 titlespec{data_idx} = "title \"\"";
556 usingclause{data_idx} = sprintf ("binary array=%dx%d scan=yx origin=(%.15g,%.15g) dx=%.15g dy=%.15g using %s",
557 x_dim, y_dim, x_origin, y_origin, dx, dy, format);
558 withclause{data_idx} = sprintf ("with %s;", imagetype);
559
560 case "line"
561 if (strcmp (obj.linestyle, "none")
562 && (! isfield (obj, "marker")
563 || (isfield (obj, "marker")
564 && strcmp (obj.marker, "none"))))
565 continue;
566 endif
567 data_idx++;
568 is_image_data(data_idx) = false;
569 parametric(data_idx) = true;
570 have_cdata(data_idx) = false;
571 have_3d_patch(data_idx) = false;
572 if (isempty (obj.displayname))
573 titlespec{data_idx} = "title \"\"";
574 else
575 tmp = undo_string_escapes (
576 __maybe_munge_text__ (enhanced, obj, "displayname")
577 );
578 titlespec{data_idx} = ['title "' tmp '"'];
579 endif
580 usingclause{data_idx} = sprintf ("record=%d", numel (obj.xdata));
581 errbars = "";
582 if (nd == 3)
583 xdat = obj.xdata(:);
584 ydat = obj.ydata(:);
585 if (! isempty (obj.zdata))
586 zdat = obj.zdata(:);
587 else
588 zdat = zeros (size (xdat));
589 endif
590 data{data_idx} = [xdat, ydat, zdat]';
591 usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)",
592 numel (xdat));
593 hidden_removal = false;
594 ## fputs (plot_stream, "set parametric;\n");
595 else
596 xdat = obj.xdata(:);
597 ydat = obj.ydata(:);
598 data{data_idx} = [xdat, ydat]';
599 usingclause{data_idx} = ...
600 sprintf ("record=%d using ($1):($2) axes %s%s",
601 rows (xdat), xaxisloc_using, yaxisloc_using);
602 endif
603
604 style = do_linestyle_command (obj, obj.color, data_idx, mono,
605 plot_stream, errbars);
606
607 withclause{data_idx} = sprintf ("with %s linestyle %d",
608 style{1}, data_idx);
609
610 if (length (style) > 1)
611 data_idx++;
612 is_image_data(data_idx) = is_image_data(data_idx - 1);
613 parametric(data_idx) = parametric(data_idx - 1);
614 have_cdata(data_idx) = have_cdata(data_idx - 1);
615 have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
616 titlespec{data_idx} = "title \"\"";
617 usingclause{data_idx} = usingclause{data_idx - 1};
618 data{data_idx} = data{data_idx - 1};
619 withclause{data_idx} = sprintf ("with %s linestyle %d",
620 style{2}, data_idx);
621 endif
622 if (length (style) > 2)
623 data_idx++;
624 is_image_data(data_idx) = is_image_data(data_idx - 1);
625 parametric(data_idx) = parametric(data_idx - 1);
626 have_cdata(data_idx) = have_cdata(data_idx - 1);
627 have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
628 titlespec{data_idx} = "title \"\"";
629 usingclause{data_idx} = usingclause{data_idx - 1};
630 data{data_idx} = data{data_idx - 1};
631 withclause{data_idx} = sprintf ("with %s linestyle %d",
632 style{3}, data_idx);
633 endif
634
635 case "patch"
636 cmap = parent_figure_obj.colormap;
637 [nr, nc] = size (obj.xdata);
638
639 if (! isempty (obj.cdata))
640 cdat = obj.cdata;
641 if (strcmpi (obj.cdatamapping, "direct"))
642 cdatadirect = true;
643 endif
644 else
645 cdat = [];
646 endif
647
648 data_3d_idx = NaN;
649 for i = 1:nc
650 xcol = obj.xdata(:,i);
651 ycol = obj.ydata(:,i);
652 if (nd == 3)
653 if (! isempty (obj.zdata))
654 zcol = obj.zdata(:,i);
655 else
656 zcol = zeros (size (xcol));
657 endif
658 endif
659
660 if (! isnan (xcol) && ! isnan (ycol))
661 ## Is the patch closed or not
662 if (strcmp (obj.facecolor, "none"))
663 hidden_removal = false;
664 else
665
666 if (isnan (hidden_removal))
667 hidden_removal = true;
668 endif
669 if (nd == 3)
670 if (numel (xcol) > 3)
671 error ("__gnuplot_draw_axes__: gnuplot (as of v4.2) only supports 3-D filled triangular patches");
672 else
673 if (isnan (data_3d_idx))
674 data_idx++;
675 data_3d_idx = data_idx;
676 is_image_data(data_idx) = false;
677 parametric(data_idx) = false;
678 have_cdata(data_idx) = true;
679 have_3d_patch(data_idx) = true;
680 withclause{data_3d_idx} = sprintf ("with pm3d");
681 usingclause{data_3d_idx} = "using 1:2:3:4";
682 data{data_3d_idx} = [];
683 endif
684 local_idx = data_3d_idx;
685 ccdat = NaN;
686 endif
687 else
688 data_idx++;
689 local_idx = data_idx;
690 is_image_data(data_idx) = false;
691 parametric(data_idx) = false;
692 have_cdata(data_idx) = false;
693 have_3d_patch(data_idx) = false;
694 endif
695
696 if (i > 1 || isempty (obj.displayname))
697 titlespec{local_idx} = "title \"\"";
698 else
699 tmp = undo_string_escapes (
700 __maybe_munge_text__ (enhanced, obj, "displayname")
701 );
702 titlespec{local_idx} = ['title "' tmp '"'];
703 endif
704 if (isfield (obj, "facecolor"))
705 if ((strcmp (obj.facecolor, "flat")
706 || strcmp (obj.facecolor, "interp"))
707 && isfield (obj, "cdata"))
708 if (ndims (obj.cdata) == 2
709 && (columns (obj.cdata) == nc
710 && (rows (obj.cdata) == 1
711 || rows (obj.cdata) == 3)))
712 ccol = cdat(:, i);
713 elseif (ndims (obj.cdata) == 2
714 && (rows (obj.cdata) == nc
715 && (columns (obj.cdata) == 1
716 || columns (obj.cdata) == 3)))
717 ccol = cdat(i, :);
718 elseif (ndims (obj.cdata) == 3)
719 ccol = permute (cdat (:, i, :), [1, 3, 2]);
720 else
721 ccol = cdat;
722 endif
723 if (strcmp (obj.facecolor, "flat"))
724 if (isequal (size (ccol), [1, 3]))
725 ## RGB Triplet
726 color = ccol;
727 elseif (nd == 3 && numel (xcol) == 3)
728 ccdat = ccol;
729 else
730 if (cdatadirect)
731 r = round (ccol);
732 else
733 r = 1 + round ((rows (cmap) - 1)
734 * (ccol - clim(1))/(clim(2) - clim(1)));
735 endif
736 r = max (1, min (r, rows (cmap)));
737 color = cmap(r, :);
738 endif
739 elseif (strcmp (obj.facecolor, "interp"))
740 if (nd == 3 && numel (xcol) == 3)
741 ccdat = ccol;
742 if (! isvector (ccdat))
743 tmp = rows (cmap) + rows (addedcmap) + ...
744 [1 : rows(ccdat)];
745 addedcmap = [addedcmap; ccdat];
746 ccdat = tmp(:);
747 else
748 ccdat = ccdat(:);
749 endif
750 else
751 if (sum (diff (ccol)))
752 warning ("\"interp\" not supported, using 1st entry of cdata");
753 endif
754 if (cdatadirect)
755 r = round (ccol);
756 else
757 r = 1 + round ((rows (cmap) - 1)
758 * (ccol - clim(1))/(clim(2) - clim(1)));
759 endif
760 r = max (1, min (r, rows (cmap)));
761 color = cmap(r(1),:);
762 endif
763 endif
764 elseif (isnumeric (obj.facecolor))
765 color = obj.facecolor;
766 else
767 color = [0, 1, 0];
768 endif
769 else
770 color = [0, 1, 0];
771 endif
772
773 if (nd == 3 && numel (xcol) == 3)
774 if (isnan (ccdat))
775 ccdat = (rows (cmap) + rows (addedcmap) + 1) * ones(3, 1);
776 addedcmap = [addedcmap; reshape(color, 1, 3)];
777 elseif (numel (ccdat) <= 1)
778 ccdat = zcol;
779 endif
780 data{data_3d_idx} = [data{data_3d_idx}, ...
781 [[xcol; xcol(end)], [ycol; ycol(end)], ...
782 [zcol; zcol(end)], [ccdat; ccdat(end)]]'];
783 else
784 if (mono)
785 colorspec = "";
786 elseif (__gnuplot_has_feature__ ("transparent_patches")
787 && isscalar (obj.facealpha))
788 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\" fillstyle transparent solid %f",
789 round (255*color), obj.facealpha);
790 else
791 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
792 round (255*color));
793 endif
794
795 withclause{data_idx} = sprintf ("with filledcurve %s",
796 colorspec);
797 data{data_idx} = [xcol, ycol]';
798 usingclause{data_idx} = sprintf ("record=%d using ($1):($2)",
799 numel (xcol));
800 endif
801 endif
802 endif
803
804 ## patch outline
805 if (!(strcmp (obj.edgecolor, "none")
806 && (strcmp (obj.marker, "none")
807 || (strcmp (obj.markeredgecolor, "none")
808 && strcmp (obj.markerfacecolor, "none")))))
809
810 data_idx++;
811 is_image_data(data_idx) = false;
812 parametric(data_idx) = false;
813 have_cdata(data_idx) = false;
814 have_3d_patch(data_idx) = false;
815 titlespec{data_idx} = "title \"\"";
816 usingclause{data_idx} = sprintf ("record=%d", numel (obj.xdata));
817
818 if (isfield (obj, "markersize"))
819 mdat = obj.markersize / 3;
820 endif
821
822 if (isfield (obj, "edgecolor"))
823 ## FIXME: This is the wrong thing to do as edgecolor,
824 ## markeredgecolor and markerfacecolor can have different values
825 ## and we should treat them seperately. However, the code below
826 ## allows the scatter functions to work as expected, where only
827 ## one of these values is set.
828 if (strcmp (obj.edgecolor, "none"))
829 if (strcmp (obj.markeredgecolor, "none"))
830 ec = obj.markerfacecolor;
831 else
832 ec = obj.markeredgecolor;
833 endif
834 else
835 ec = obj.edgecolor;
836 endif
837
838 if ((strcmp (ec, "flat")
839 || strcmp (ec, "interp"))
840 && isfield (obj, "cdata"))
841 if (ndims (obj.cdata) == 2
842 && (columns (obj.cdata) == nc
843 && (rows (obj.cdata) == 1
844 || rows (obj.cdata) == 3)))
845 ccol = cdat(:, i);
846 elseif (ndims (obj.cdata) == 2
847 && (rows (obj.cdata) == nc
848 && (columns (obj.cdata) == 1
849 || columns (obj.cdata) == 3)))
850 ccol = cdat(i, :);
851 elseif (ndims (obj.cdata) == 3)
852 ccol = permute (cdat (:, i, :), [1, 3, 2]);
853 else
854 ccol = cdat;
855 endif
856 if (strcmp (ec, "flat"))
857 if (numel (ccol) == 3)
858 color = ccol;
859 else
860 if (isscalar (ccol))
861 ccol = repmat (ccol, numel (xcol), 1);
862 endif
863 color = "flat";
864 have_cdata(data_idx) = true;
865 endif
866 elseif (strcmp (ec, "interp"))
867 if (numel (ccol) == 3)
868 warning ("\"interp\" not supported, using 1st entry of cdata");
869 color = ccol(1,:);
870 else
871 if (isscalar (ccol))
872 ccol = repmat (ccol, numel (xcol), 1);
873 endif
874 color = "interp";
875 have_cdata(data_idx) = true;
876 endif
877 endif
878 elseif (isnumeric (ec))
879 color = ec;
880 else
881 color = [0, 0, 0];
882 endif
883 else
884 color = [0, 0, 0];
885 endif
886
887 if (isfield (obj, "linestyle"))
888 switch (obj.linestyle)
889 case "-"
890 lt = "lt 1";
891 case "--"
892 lt = "lt 2";
893 case ":"
894 lt = "lt 3";
895 case "-."
896 lt = "lt 6";
897 case "none"
898 lt = "";
899 otherwise
900 lt = "";
901 endswitch
902 else
903 lt = "";
904 endif
905
906 if (isfield (obj, "linewidth"))
907 lw = sprintf ("linewidth %f", obj.linewidth);
908 else
909 lw = "";
910 endif
911
912 [pt, pt2, obj] = gnuplot_pointtype (obj);
913 if (! isempty (pt))
914 pt = sprintf ("pointtype %s", pt);
915 endif
916 if (! isempty (pt2))
917 pt2 = sprintf ("pointtype %s", pt2);
918 endif
919
920 if (mono)
921 colorspec = "";
922 else
923 if (ischar (color))
924 colorspec = "palette";
925 else
926 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
927 round (255*color));
928 endif
929 endif
930
931 sidx = 1;
932 if (isempty (lt))
933 style = "";
934 else
935 style = "lines";
936 endif
937 tmpwith = {};
938
939 facesame = true;
940 if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor")
941 && ! strcmp (obj.markerfacecolor, "none"))
942 if (strcmp (obj.markerfacecolor, "auto")
943 || ! isnumeric (obj.markerfacecolor)
944 || (isnumeric (obj.markerfacecolor)
945 && isequal (color, obj.markerfacecolor)))
946 style = strcat (style, "points");
947 if (isfield (obj, "markersize"))
948 if (length (mdat) == nc)
949 m = mdat(i);
950 else
951 m = mdat;
952 endif
953 ps = sprintf ("pointsize %f", m / 3);
954 else
955 ps = "";
956 endif
957
958 tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s",
959 style, lw, pt2, lt, ps,
960 colorspec);
961 else
962 facesame = false;
963 if (! isempty (style))
964 tmpwith{sidx} = sprintf ("with %s %s %s %s",
965 style, lw, lt,
966 colorspec);
967 sidx ++;
968 endif
969 if (isnumeric (obj.markerfacecolor) && ! mono)
970 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
971 round (255*obj.markerfacecolor));
972 endif
973 style = "points";
974 if (isfield (obj, "markersize"))
975 if (length (mdat) == nc)
976 m = mdat(i);
977 else
978 m = mdat;
979 endif
980 ps = sprintf ("pointsize %f", m / 3);
981 else
982 ps = "";
983 endif
984 tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s",
985 style, lw, pt2, lt, ps,
986 colorspec);
987 endif
988 endif
989
990 if (isfield (obj, "markeredgecolor")
991 && ! strcmp (obj.markeredgecolor, "none"))
992 if (facesame && ! isempty (pt)
993 && (strcmp (obj.markeredgecolor, "auto")
994 || ! isnumeric (obj.markeredgecolor)
995 || (isnumeric (obj.markeredgecolor)
996 && isequal (color, obj.markeredgecolor))))
997 if (sidx == 1 && ((length (style) == 5
998 && strncmp (style, "lines", 5))
999 || isempty (style)))
1000 style = strcat (style, "points");
1001 if (isfield (obj, "markersize"))
1002 if (length (mdat) == nc)
1003 m = mdat(i);
1004 else
1005 m = mdat;
1006 endif
1007 ps = sprintf ("pointsize %f", m / 3);
1008 else
1009 ps = "";
1010 endif
1011 tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s",
1012 style, lw, pt, lt, ps,
1013 colorspec);
1014 endif
1015 else
1016 if (! isempty (style))
1017 if (length (tmpwith) < sidx || isempty (tmpwith{sidx}))
1018 tmpwith{sidx} = sprintf ("with %s %s %s %s",
1019 style, lw, lt,
1020 colorspec);
1021 endif
1022 sidx ++;
1023 endif
1024
1025 if (! isempty (pt))
1026 if (! mono)
1027 if (strcmp (obj.markeredgecolor, "auto"))
1028 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
1029 round (255*color));
1030 elseif (isnumeric (obj.markeredgecolor) && ! mono)
1031 colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"",
1032 round (255*obj.markeredgecolor));
1033 endif
1034 endif
1035 style = "points";
1036 if (isfield (obj, "markersize"))
1037 if (length (mdat) == nc)
1038 m = mdat(i);
1039 else
1040 m = mdat;
1041 endif
1042 ps = sprintf ("pointsize %f", m / 3);
1043 else
1044 ps = "";
1045 endif
1046 tmpwith{sidx} = sprintf ("with %s %s %s %s %s %s",
1047 style, lw, pt, lt, ps,
1048 colorspec);
1049 endif
1050 endif
1051 endif
1052
1053 if (isempty (tmpwith))
1054 withclause{data_idx} = sprintf ("with %s %s %s %s %s",
1055 style, lw, pt, lt,
1056 colorspec);
1057 else
1058 withclause{data_idx} = tmpwith{1};
1059 endif
1060 if (nd == 3)
1061 if (ischar (color))
1062 if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol))
1063 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ...
1064 [zcol; zcol(1)], [ccol; ccol(1)]]';
1065 else
1066 data{data_idx} = [xcol, ycol, zcol, ccol]';
1067 endif
1068 usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3):($4)", columns (data{data_idx}));
1069 else
1070 if (! isnan (xcol) && ! isnan (ycol) && ! isnan (zcol))
1071 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ...
1072 [zcol; zcol(1)]]';
1073 else
1074 data{data_idx} = [xcol, ycol, zcol]';
1075 endif
1076 usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)", columns (data{data_idx}));
1077 endif
1078 else
1079 if (ischar (color))
1080 if (! isnan (xcol) && ! isnan (ycol))
1081 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)], ...
1082 [ccol; ccol(1)]]';
1083 else
1084 data{data_idx} = [xcol, ycol, ccol]';
1085 endif
1086 usingclause{data_idx} = sprintf ("record=%d using ($1):($2):($3)", columns (data{data_idx}));
1087 else
1088 if (! isnan (xcol) && ! isnan (ycol))
1089 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]';
1090 else
1091 data{data_idx} = [xcol, ycol]';
1092 endif
1093 usingclause{data_idx} = sprintf ("record=%d using ($1):($2)", columns (data{data_idx}));
1094 endif
1095 endif
1096
1097 if (length (tmpwith) > 1)
1098 data_idx++;
1099 is_image_data(data_idx) = is_image_data(data_idx - 1);
1100 parametric(data_idx) = parametric(data_idx - 1);
1101 have_cdata(data_idx) = have_cdata(data_idx - 1);
1102 have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
1103 titlespec{data_idx} = "title \"\"";
1104 usingclause{data_idx} = usingclause{data_idx - 1};
1105 data{data_idx} = data{data_idx - 1};
1106 withclause{data_idx} = tmpwith{2};
1107 endif
1108 if (length (tmpwith) > 2)
1109 data_idx++;
1110 is_image_data(data_idx) = is_image_data(data_idx - 1);
1111 parametric(data_idx) = parametric(data_idx - 1);
1112 have_cdata(data_idx) = have_cdata(data_idx - 1);
1113 have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
1114 titlespec{data_idx} = "title \"\"";
1115 usingclause{data_idx} = usingclause{data_idx - 1};
1116 data{data_idx} = data{data_idx - 1};
1117 withclause{data_idx} = tmpwith{3};
1118 endif
1119 endif
1120 endfor
1121
1122 case "surface"
1123 view_map = true;
1124 if (! (strcmp (obj.edgecolor, "none")
1125 && strcmp (obj.facecolor, "none")))
1126 data_idx++;
1127 is_image_data(data_idx) = false;
1128 parametric(data_idx) = false;
1129 have_cdata(data_idx) = true;
1130 have_3d_patch(data_idx) = false;
1131 style = do_linestyle_command (obj, obj.edgecolor,
1132 data_idx, mono,
1133 plot_stream);
1134
1135 if (isempty (obj.displayname))
1136 titlespec{data_idx} = "title \"\"";
1137 else
1138 tmp = undo_string_escapes (
1139 __maybe_munge_text__ (enhanced, obj, "displayname")
1140 );
1141 titlespec{data_idx} = ['title "' tmp '"'];
1142 endif
1143 withclause{data_idx} = sprintf ("with pm3d linestyle %d",
1144 data_idx);
1145 withpm3d = true;
1146 pm3didx = data_idx;
1147
1148 xdat = obj.xdata;
1149 ydat = obj.ydata;
1150 zdat = obj.zdata;
1151 cdat = obj.cdata;
1152
1153 err = false;
1154 if (! size_equal (zdat, cdat))
1155 err = true;
1156 endif
1157 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat))
1158 if (rows (zdat) == length (ydat)
1159 && columns (zdat) == length (xdat))
1160 [xdat, ydat] = meshgrid (xdat, ydat);
1161 else
1162 err = true;
1163 endif
1164 elseif (ismatrix (xdat) && ismatrix (ydat) && ismatrix (zdat))
1165 if (! size_equal (xdat, ydat, zdat))
1166 err = true;
1167 endif
1168 else
1169 err = true;
1170 endif
1171 if (err)
1172 error ("__gnuplot_draw_axes__: invalid grid data");
1173 endif
1174 xlen = columns (zdat);
1175 ylen = rows (zdat);
1176 if (xlen == columns (xdat) && xlen == columns (ydat)
1177 && ylen == rows (xdat) && ylen == rows (ydat))
1178 len = 4 * xlen;
1179 zz = zeros (ylen, len);
1180 k = 1;
1181 for kk = 1:4:len
1182 zz(:,kk) = xdat(:,k);
1183 zz(:,kk+1) = ydat(:,k);
1184 zz(:,kk+2) = zdat(:,k);
1185 zz(:,kk+3) = cdat(:,k);
1186 k++;
1187 endfor
1188 data{data_idx} = zz.';
1189 endif
1190
1191 if (doing_interp_color)
1192 interp_str = "interpolate 0, 0";
1193 else
1194 ## No interpolation of facecolors.
1195 interp_str = "";
1196 endif
1197 usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3):($4)", ylen, xlen);
1198
1199 flat_interp_face = (strcmp (obj.facecolor, "flat")
1200 || strcmp (obj.facecolor, "interp"));
1201 flat_interp_edge = (strcmp (obj.edgecolor, "flat")
1202 || strcmp (obj.edgecolor, "interp"));
1203
1204 facecolor_none_or_white = (strcmp (obj.facecolor, "none")
1205 || (isnumeric (obj.facecolor)
1206 && all (obj.facecolor == 1)));
1207 hidden_removal = false;
1208 fputs (plot_stream, "set style increment default;\n");
1209 if (flat_interp_edge && facecolor_none_or_white)
1210 withpm3d = false;
1211 withclause{data_idx} = sprintf ("with %s palette", style{1});
1212 fputs (plot_stream, "unset pm3d\n");
1213 if (all (obj.facecolor == 1))
1214 hidden_removal = true;
1215 endif
1216 elseif (facecolor_none_or_white)
1217 if (all (obj.facecolor == 1))
1218 hidden_removal = true;
1219 endif
1220 fputs (plot_stream,"unset pm3d;\n");
1221 fputs (plot_stream,"set style increment user;\n");
1222 withpm3d = false;
1223 withclause{data_idx} = sprintf ("with %s linestyle %d",
1224 style{1}, data_idx);
1225 fputs (plot_stream, "unset pm3d\n");
1226 endif
1227
1228 if (doing_interp_color)
1229 ## "depthorder" interferes with interpolation of colors.
1230 dord = "scansautomatic";
1231 else
1232 dord = "depthorder";
1233 endif
1234
1235 if (flat_interp_face && strcmp (obj.edgecolor, "flat"))
1236 fprintf (plot_stream,
1237 "set pm3d explicit at s %s %s corners2color c3;\n",
1238 interp_str, dord);
1239 elseif (! facecolor_none_or_white)
1240 if (strcmp (obj.edgecolor, "none"))
1241 if (__gnuplot_has_feature__ ("transparent_surface")
1242 && isscalar (obj.facealpha))
1243 fprintf (plot_stream,
1244 "set style fill transparent solid %f;\n",
1245 obj.facealpha);
1246 endif
1247 fprintf (plot_stream,
1248 "set pm3d explicit at s %s corners2color c3;\n",
1249 interp_str, dord);
1250 else
1251 fprintf (plot_stream,
1252 "set pm3d explicit at s hidden3d %d %s %s corners2color c3;\n",
1253 data_idx, interp_str, dord);
1254
1255 if (__gnuplot_has_feature__ ("transparent_surface")
1256 && isscalar (obj.facealpha))
1257 fprintf (plot_stream,
1258 "set style fill transparent solid %f;\n",
1259 obj.facealpha);
1260 endif
1261 endif
1262 endif
1263
1264 zz = [];
1265 if (length (style) > 1)
1266 len = 3 * xlen;
1267 zz = zeros (ylen, len);
1268 k = 1;
1269 for kk = 1:3:len
1270 zz(:,kk) = xdat(:,k);
1271 zz(:,kk+1) = ydat(:,k);
1272 zz(:,kk+2) = zdat(:,k);
1273 k++;
1274 endfor
1275 zz = zz.';
1276
1277 data_idx++;
1278 is_image_data(data_idx) = is_image_data(data_idx - 1);
1279 parametric(data_idx) = parametric(data_idx - 1);
1280 have_cdata(data_idx) = false;
1281 have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
1282 titlespec{data_idx} = "title \"\"";
1283 usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen);
1284 data{data_idx} = zz;
1285 withclause{data_idx} = sprintf ("with %s linestyle %d",
1286 style{2}, data_idx);
1287
1288 endif
1289 if (length (style) > 2)
1290 data_idx++;
1291 is_image_data(data_idx) = is_image_data(data_idx - 1);
1292 parametric(data_idx) = parametric(data_idx - 1);
1293 have_cdata(data_idx) = false;
1294 have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
1295 titlespec{data_idx} = "title \"\"";
1296 usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen);
1297 data{data_idx} = zz;
1298 withclause{data_idx} = sprintf ("with %s linestyle %d",
1299 style{3}, data_idx);
1300 endif
1301 if (withpm3d && strcmp (style{1}, "linespoints"))
1302 if (isempty (zz))
1303 len = 3 * xlen;
1304 zz = zeros (ylen, len);
1305 k = 1;
1306 for kk = 1:3:len
1307 zz(:,kk) = xdat(:,k);
1308 zz(:,kk+1) = ydat(:,k);
1309 zz(:,kk+2) = zdat(:,k);
1310 k++;
1311 endfor
1312 zz = zz.';
1313 endif
1314 data_idx++;
1315 is_image_data(data_idx) = is_image_data(data_idx - 1);
1316 parametric(data_idx) = parametric(data_idx - 1);
1317 have_cdata(data_idx) = false;
1318 have_3d_patch(data_idx) = have_3d_patch(data_idx - 1);
1319 titlespec{data_idx} = "title \"\"";
1320 usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3)", ylen, xlen);
1321 data{data_idx} = zz;
1322 withclause{data_idx} = sprintf ("with points linestyle %d",
1323 pm3didx);
1324 endif
1325 endif
1326
1327 case "text"
1328 [label, f, s] = __maybe_munge_text__ (enhanced, obj, "string");
1329 fontspec = create_fontspec (f, s, gnuplot_term);
1330 lpos = obj.position;
1331 halign = obj.horizontalalignment;
1332 valign = obj.verticalalignment;
1333 angle = obj.rotation;
1334 units = obj.units;
1335 color = obj.color;
1336 if (strcmpi (units, "normalized"))
1337 units = "graph";
1338 elseif (strcmp (axis_obj.yaxislocation, "right")
1339 && strcmp (units, "data"))
1340 units = "second";
1341 else
1342 units = "";
1343 endif
1344
1345 if (isnumeric (color))
1346 colorspec = get_text_colorspec (color, mono);
1347 endif
1348
1349 if (ischar (obj.string))
1350 num_lines = rows (obj.string);
1351 num_lines += numel (strfind (obj.string, "\n"));
1352 else
1353 num_lines = numel (obj.string);
1354 endif
1355 switch (valign)
1356 ## Text offset in characters. Relies on gnuplot for font metrics.
1357 case "top"
1358 dy = -0.5;
1359 case "cap"
1360 dy = -0.5;
1361 case "middle"
1362 dy = 0.5 * (num_lines - 1);
1363 case "baseline"
1364 dy = 0.5 + (num_lines - 1);
1365 case "bottom"
1366 dy = 0.5 + (num_lines - 1);
1367 endswitch
1368 ## Gnuplot's Character units are different for x/y and vary with
1369 ## fontsize. The aspect ratio of 1:1.7 was determined by experiment
1370 ## to work for eps/ps/etc. For the MacOS aqua terminal a value of 2.5
1371 ## is needed. However, the difference is barely noticable.
1372 dx_and_dy = [(-dy * sind (angle)), (dy * cosd (angle))] .* [1.7 1];
1373
1374 ## FIXME: Multiline text produced the gnuplot
1375 ## "warning: ft_render: skipping glyph"
1376 if (nd == 3)
1377 ## This produces the desired vertical alignment in 3D.
1378 fprintf (plot_stream,
1379 "set label \"%s\" at %s %.15e,%.15e,%.15e %s rotate by %f offset character %f,%f %s %s front %s;\n",
1380 undo_string_escapes (label), units, lpos(1),
1381 lpos(2), lpos(3), halign, angle, dx_and_dy, fontspec,
1382 __do_enhanced_option__ (enhanced, obj), colorspec);
1383 else
1384 fprintf (plot_stream,
1385 "set label \"%s\" at %s %.15e,%.15e %s rotate by %f offset character %f,%f %s %s front %s;\n",
1386 undo_string_escapes (label), units,
1387 lpos(1), lpos(2), halign, angle, dx_and_dy, fontspec,
1388 __do_enhanced_option__ (enhanced, obj), colorspec);
1389 endif
1390
1391 case "hggroup"
1392 ## Push group children into the kid list.
1393 if (isempty (kids))
1394 kids = obj.children;
1395 elseif (! isempty (obj.children))
1396 kids = [kids; obj.children];
1397 endif
1398
1399 otherwise
1400 error ("__gnuplot_draw_axes__: unknown object class, %s",
1401 obj.type);
1402 endswitch
1403
1404 endwhile
1405
1406 ## This is need to prevent warnings for rotations in 3D plots, while
1407 ## allowing colorbars with contours.
1408 if (nd == 2 || (data_idx > 1 && ! view_map))
1409 fputs (plot_stream, "set pm3d implicit;\n");
1410 else
1411 fputs (plot_stream, "set pm3d explicit;\n");
1412 endif
1413
1414 if (isnan (hidden_removal) || hidden_removal)
1415 fputs (plot_stream, "set hidden3d;\n");
1416 else
1417 fputs (plot_stream, "unset hidden3d;\n");
1418 endif
1419
1420 have_data = (! (isempty (data) || all (cellfun ("isempty", data))));
1421
1422 ## Note we don't use the [xy]2range of gnuplot as we don't use the
1423 ## dual axis plotting features of gnuplot.
1424 if (isempty (xlim))
1425 return;
1426 endif
1427 if (strcmpi (axis_obj.xdir, "reverse"))
1428 xlim = flip (xlim);
1429 endif
1430
1431 fprintf (plot_stream, "set xrange [%.15e:%.15e];\n", xlim);
1432 if (strcmpi (axis_obj.xaxislocation, "top"))
1433 fprintf (plot_stream, "set x2range [%.15e:%.15e];\n", xlim);
1434 endif
1435
1436 if (isempty (ylim))
1437 return;
1438 endif
1439 if (strcmpi (axis_obj.ydir, "reverse"))
1440 ylim = flip (ylim);
1441 endif
1442 fprintf (plot_stream, "set yrange [%.15e:%.15e];\n", ylim);
1443 if (strcmpi (axis_obj.yaxislocation, "right"))
1444 fprintf (plot_stream, "set y2range [%.15e:%.15e];\n", ylim);
1445 endif
1446
1447 if (nd == 3)
1448 if (isempty (zlim))
1449 return;
1450 endif
1451 if (strcmpi (axis_obj.zdir, "reverse"))
1452 zlim = flip (zlim);
1453 endif
1454 fprintf (plot_stream, "set zrange [%.15e:%.15e];\n", zlim);
1455 endif
1456
1457 cmap = parent_figure_obj.colormap;
1458 cmap_sz = rows (cmap);
1459 if (! any (isinf (clim)))
1460 if (truecolor || ! cdatadirect)
1461 if (rows (addedcmap) > 0)
1462 for i = 1:data_idx
1463 if (have_3d_patch(i))
1464 data{i}(end,:) = clim(2) * (data{i}(end, :) - 0.5) / cmap_sz;
1465 endif
1466 endfor
1467 fprintf (plot_stream, "set cbrange [%.15e:%.15e];\n",
1468 clim(1), clim(2) * (cmap_sz + rows (addedcmap)) / cmap_sz);
1469 else
1470 fprintf (plot_stream, "set cbrange [%.15e:%.15e];\n", clim);
1471 endif
1472 else
1473 fprintf (plot_stream, "set cbrange [1:%d];\n", cmap_sz +
1474 rows (addedcmap));
1475 endif
1476 endif
1477
1478 if (strcmpi (axis_obj.box, "on"))
1479 if (nd == 3)
1480 fputs (plot_stream, "set border 4095;\n");
1481 else
1482 fputs (plot_stream, "set border 431;\n");
1483 endif
1484 else
1485 if (nd == 3)
1486 fputs (plot_stream, "set border 895;\n");
1487 elseif (! isempty (axis_obj.ytick))
1488 if (strcmpi (axis_obj.yaxislocation, "right"))
1489 fprintf (plot_stream, "unset ytics; set y2tics %s nomirror\n",
1490 axis_obj.tickdir);
1491 if (strcmpi (axis_obj.xaxislocation, "top"))
1492 maybe_do_x2tick_mirror (plot_stream, axis_obj)
1493 fputs (plot_stream, "set border 12;\n");
1494 elseif (strcmpi (axis_obj.xaxislocation, "bottom"))
1495 maybe_do_xtick_mirror (plot_stream, axis_obj)
1496 fputs (plot_stream, "set border 9;\n");
1497 else # xaxislocation == zero
1498 fprintf (plot_stream, "unset x2tics; set xtics %s nomirror\n",
1499 axis_obj.tickdir);
1500 fputs (plot_stream, "set border 8;\n");
1501 fprintf (plot_stream, "set xzeroaxis lt -1 lw %f;\n",
1502 axis_obj.linewidth);
1503 endif
1504 elseif (strcmpi (axis_obj.yaxislocation, "left"))
1505 fprintf (plot_stream, "unset y2tics; set ytics %s nomirror\n",
1506 axis_obj.tickdir);
1507 if (strcmpi (axis_obj.xaxislocation, "top"))
1508 maybe_do_x2tick_mirror (plot_stream, axis_obj)
1509 fputs (plot_stream, "set border 6;\n");
1510 elseif (strcmpi (axis_obj.xaxislocation, "bottom"))
1511 maybe_do_xtick_mirror (plot_stream, axis_obj)
1512 fputs (plot_stream, "set border 3;\n");
1513 else # xaxislocation == zero
1514 maybe_do_xtick_mirror (plot_stream, axis_obj)
1515 fputs (plot_stream, "set border 2;\n");
1516 fprintf (plot_stream, "set xzeroaxis lt -1 lw %f;\n",
1517 axis_obj.linewidth);
1518 endif
1519 else # yaxislocation == zero
1520 fprintf (plot_stream, "unset y2tics; set ytics %s nomirror\n",
1521 axis_obj.tickdir);
1522 if (strcmpi (axis_obj.xaxislocation, "top"))
1523 maybe_do_x2tick_mirror (plot_stream, axis_obj)
1524 fputs (plot_stream, "set border 4;\n");
1525 elseif (strcmpi (axis_obj.xaxislocation, "bottom"))
1526 maybe_do_xtick_mirror (plot_stream, axis_obj)
1527 fputs (plot_stream, "set border 1;\n");
1528 else # xaxislocation == zero
1529 maybe_do_xtick_mirror (plot_stream, axis_obj)
1530 fprintf (plot_stream, "unset y2tics; set ytics %s nomirror\n",
1531 axis_obj.tickdir);
1532 fputs (plot_stream, "unset border;\n");
1533 fprintf (plot_stream, "set xzeroaxis lt -1 lw %f;\n",
1534 axis_obj.linewidth);
1535 endif
1536 fprintf (plot_stream, "set yzeroaxis lt -1 lw %f;\n",
1537 axis_obj.linewidth);
1538 endif
1539 endif
1540 endif
1541
1542 if (strcmpi (axis_obj.visible, "off"))
1543 fputs (plot_stream, "unset border; unset tics\n");
1544 else
1545 fprintf (plot_stream, "set border lw %f;\n", axis_obj.linewidth);
1546 endif
1547
1548 if (! isempty (hlgnd) && ! isempty (hlgnd.children)
1549 && any (strcmpi (get (hlgnd.children, "visible"), "on")))
1550 if (strcmpi (hlgnd.box, "on"))
1551 box = "box";
1552 else
1553 box = "nobox";
1554 endif
1555 if (strcmpi (hlgnd.orientation, "vertical"))
1556 horzvert = "vertical";
1557 else
1558 horzvert = "horizontal";
1559 endif
1560 if (strcmpi (hlgnd.textposition, "right"))
1561 reverse = "reverse";
1562 else
1563 reverse = "noreverse";
1564 endif
1565 inout = "inside";
1566 keypos = hlgnd.location;
1567 if (ischar (keypos))
1568 keypos = lower (keypos);
1569 keyout = strfind (keypos, "outside");
1570 if (! isempty (keyout))
1571 inout = "outside";
1572 keypos = keypos(1:keyout-1);
1573 endif
1574 endif
1575 switch (keypos)
1576 case "north"
1577 pos = "center top";
1578 case "south"
1579 pos = "center bottom";
1580 case "east"
1581 pos = "right center";
1582 case "west"
1583 pos = "left center";
1584 case "northeast"
1585 pos = "right top";
1586 case "northwest"
1587 pos = "left top";
1588 case "southeast"
1589 pos = "right bottom";
1590 case "southwest"
1591 pos = "left bottom";
1592 case "best"
1593 pos = "";
1594 warning ("legend: 'Best' not yet implemented for location specifier.\n");
1595 ## Least conflict with data in plot.
1596 ## Least unused space outside plot.
1597 otherwise
1598 pos = "";
1599 endswitch
1600 if (__gnuplot_has_feature__ ("key_has_font_properties"))
1601 [fontname, fontsize] = get_fontname_and_size (hlgnd);
1602 fontspacespec = [ create_spacingspec(fontname, fontsize, gnuplot_term),...
1603 create_fontspec(fontname, fontsize, gnuplot_term) ];
1604 else
1605 fontspacespec = "";
1606 endif
1607 textcolors = get (findobj (hlgnd.children, "type", "text"), "color");
1608 if (iscell (textcolors))
1609 textcolors = cell2mat (textcolors);
1610 textcolors = unique (textcolors, "rows");
1611 endif
1612 if (rows (textcolors) > 1)
1613 ## Gnuplot is unable to assign arbitrary colors to each text entry
1614 ## for the key/legend. But, the text color can be set to match the
1615 ## color of the plot object.
1616 colorspec = "textcolor variable";
1617 else
1618 colorspec = get_text_colorspec (textcolors, mono);
1619 endif
1620 fprintf (plot_stream, "set key %s %s;\nset key %s %s %s %s %s %s;\n",
1621 inout, pos, box, reverse, horzvert, fontspacespec, colorspec,
1622 __do_enhanced_option__ (enhanced, hlgnd));
1623 else
1624 fputs (plot_stream, "unset key;\n");
1625 endif
1626 fputs (plot_stream, "set style data lines;\n");
1627
1628 cmap = [cmap; addedcmap];
1629 cmap_sz += rows (addedcmap);
1630 if (mono == false && length (cmap) > 0)
1631 fprintf (plot_stream,
1632 "set palette positive color model RGB maxcolors %i;\n",
1633 cmap_sz);
1634 fprintf (plot_stream,
1635 "set palette file \"-\" binary record=%d using 1:2:3:4;\n",
1636 cmap_sz);
1637 fwrite (plot_stream, [1:cmap_sz; cmap.'], "float32");
1638 fwrite (plot_stream, "\n");
1639 endif
1640
1641 fputs (plot_stream, "unset colorbox;\n");
1642
1643 if (have_data)
1644 if (nd == 2)
1645 plot_cmd = "plot";
1646 else
1647 plot_cmd = "splot";
1648 rot_x = 90 - axis_obj.view(2);
1649 rot_z = axis_obj.view(1);
1650 while (rot_z < 0)
1651 rot_z += 360;
1652 endwhile
1653 fputs (plot_stream, "set ticslevel 0;\n");
1654 if (view_map && rot_x == 0 && rot_z == 0)
1655 fputs (plot_stream, "set view map;\n");
1656 else
1657 fprintf (plot_stream, "set view %.15g, %.15g;\n", rot_x, rot_z);
1658 endif
1659 endif
1660 if (have_3d_patch (1))
1661 fputs (plot_stream, "set pm3d depthorder\n");
1662 fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd,
1663 usingclause{1}, titlespec{1}, withclause{1});
1664 elseif (is_image_data (1))
1665 if (numel (is_image_data) > 1 && is_image_data(2))
1666 ## Remove terminating semicolon
1667 n = max (strfind (withclause{1}, ";"));
1668 if (! isempty (n))
1669 withclause{1} = withclause{1}(1:n-1);
1670 endif
1671 endif
1672 fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd,
1673 usingclause{1}, titlespec{1}, withclause{1});
1674 else
1675 fprintf (plot_stream, "%s \"-\" binary format='%%float64' %s %s %s \\\n",
1676 plot_cmd, usingclause{1}, titlespec{1}, withclause{1});
1677 endif
1678 for i = 2:data_idx
1679 if (have_3d_patch (i))
1680 fprintf (plot_stream, ", \"-\" %s %s %s \\\n",
1681 usingclause{i}, titlespec{i}, withclause{i});
1682 elseif (is_image_data (i))
1683 if (! is_image_data (i-1))
1684 fputs (plot_stream, "; ");
1685 if (bg_is_set)
1686 fputs (plot_stream, "unset obj 1; \\\n");
1687 bg_is_set = false;
1688 endif
1689 if (fg_is_set)
1690 fputs (plot_stream, "unset obj 2; \\\n");
1691 fg_is_set = false;
1692 endif
1693 if (numel (is_image_data) > i && is_image_data(i+1))
1694 ## Remove terminating semicolon
1695 n = max (strfind (withclause{i}, ";"));
1696 if (! isempty (n))
1697 withclause{i} = withclause{i}(1:n-1);
1698 endif
1699 endif
1700 fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd,
1701 usingclause{i}, titlespec{i}, withclause{i});
1702 else
1703 ## For consecutive images continue with the same plot command
1704 fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", ",",
1705 usingclause{i}, titlespec{i}, withclause{i});
1706 endif
1707 elseif (is_image_data (i-1))
1708 if (bg_is_set)
1709 fputs (plot_stream, "unset obj 1; \\\n");
1710 bg_is_set = false;
1711 endif
1712 if (fg_is_set)
1713 fputs (plot_stream, "unset obj 2; \\\n");
1714 fg_is_set = false;
1715 endif
1716 fprintf (plot_stream,"%s \"-\" binary format='%%float64' %s %s %s \\\n",
1717 plot_cmd, usingclause{i}, titlespec{i}, withclause{i});
1718 else
1719 fprintf (plot_stream, ", \"-\" binary format='%%float64' %s %s %s \\\n",
1720 usingclause{i}, titlespec{i}, withclause{i});
1721 endif
1722 endfor
1723 fputs (plot_stream, ";\n");
1724 for i = 1:data_idx
1725 if (have_3d_patch (i))
1726 ## Can't write 3d patch data as binary as can't plot more than
1727 ## a single patch at a time and have to plot all patches together
1728 ## so that the gnuplot depth ordering is done correctly
1729 for j = 1 : 4 : columns (data{i})
1730 if (j != 1)
1731 fputs (plot_stream, "\n\n");
1732 endif
1733 fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j).');
1734 fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n\n",data{i}(:,j+1).');
1735 fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j+2).');
1736 fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data{i}(:,j+3).');
1737 endfor
1738 fputs (plot_stream, "e\n");
1739 elseif (is_image_data(i))
1740 fwrite (plot_stream, data{i}, "float32");
1741 else
1742 __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i),
1743 have_cdata(i));
1744 endif
1745 endfor
1746 else
1747 fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n");
1748 endif
1749
1750 ## Needed to allow mouse rotation with pcolor.
1751 if (view_map)
1752 fputs (plot_stream, "unset view;\n");
1753 endif
1754
1755 if (bg_is_set)
1756 fputs (plot_stream, "unset obj 1;\n");
1757 bg_is_set = false;
1758 endif
1759
1760 fflush (plot_stream);
1761
1762 endfunction
1763
1764 function x = flip (x)
1765 if (rows (x) == 1)
1766 x = fliplr (x);
1767 elseif (columns (x) == 1 || ischar (x))
1768 x = flipud (x);
1769 else
1770 x = flipud (fliplr (x));
1771 endif
1772 endfunction
1773
1774 function spacing_spec = create_spacingspec (f, s, gp_term)
1775 ## The gnuplot default font size is 10, and default spacing is 1.25.
1776 ## gnuplot has a concept of a figure global font, and sizes everything
1777 ## appropriate to that, including the legend spacing.
1778 ##
1779 ## This means that if an alternative size is used, gnuplot will use an
1780 ## inappropriate spacing in the legend by default.
1781 ##
1782 ## FIXME: Are fractional spacing specifications allowed? Or should this
1783 ## number be rounded?
1784 spc = s / 10 * 1.25;
1785 spacing_spec = sprintf ("spacing %d", spc);
1786
1787 endfunction
1788
1789 function fontspec = create_fontspec (f, s, gp_term)
1790 if (strcmp (f, "*") || strcmp (gp_term, "tikz"))
1791 fontspec = sprintf ("font \",%d\"", s);
1792 else
1793 fontspec = sprintf ("font \"%s,%d\"", f, s);
1794 endif
1795 endfunction
1796
1797 function style = do_linestyle_command (obj, linecolor, idx, mono,
1798 plot_stream, errbars = "")
1799 style = {};
1800
1801 fprintf (plot_stream, "set style line %d default;\n", idx);
1802 fprintf (plot_stream, "set style line %d", idx);
1803
1804 found_style = false;
1805 if (isnumeric (linecolor))
1806 color = linecolor;
1807 if (! mono)
1808 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
1809 round (255*color));
1810 endif
1811 else
1812 color = [0, 0, 0];
1813 endif
1814
1815 if (isfield (obj, "linestyle"))
1816 switch (obj.linestyle)
1817 case "-"
1818 lt = "1";
1819 case "--"
1820 lt = "2";
1821 case ":"
1822 lt = "3";
1823 case "-."
1824 lt = "6";
1825 case "none"
1826 lt = "";
1827 otherwise
1828 lt = "";
1829 endswitch
1830
1831 if (! isempty (lt))
1832 fprintf (plot_stream, " linetype %s", lt);
1833 endif
1834
1835 else
1836 lt = "";
1837 endif
1838 if (! isempty (errbars))
1839 found_style = true;
1840 endif
1841
1842 if (isfield (obj, "linewidth"))
1843 fprintf (plot_stream, " linewidth %f", obj.linewidth);
1844 found_style = true;
1845 endif
1846
1847 [pt, pt2, obj] = gnuplot_pointtype (obj);
1848
1849 if (! isempty (pt))
1850 found_style = true;
1851 endif
1852
1853 sidx = 1;
1854 if (isempty (errbars))
1855 if (isempty (lt))
1856 style{sidx} = "";
1857 else
1858 style{sidx} = "lines";
1859 endif
1860
1861 facesame = true;
1862 if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor")
1863 && ! strcmp (obj.markerfacecolor, "none"))
1864 if (strcmp (obj.markerfacecolor, "auto")
1865 || ! isnumeric (obj.markerfacecolor)
1866 || (isnumeric (obj.markerfacecolor)
1867 && isequal (color, obj.markerfacecolor)))
1868 if (! isempty (pt2))
1869 fprintf (plot_stream, " pointtype %s", pt2);
1870 style{sidx} = strcat (style{sidx}, "points");
1871 endif
1872 if (isfield (obj, "markersize"))
1873 fprintf (plot_stream, " pointsize %f", obj.markersize / 3);
1874 endif
1875 else
1876 facesame = false;
1877 if (! found_style)
1878 fputs (plot_stream, " default");
1879 endif
1880 fputs (plot_stream, ";\n");
1881 if (! isempty (style{sidx}))
1882 sidx ++;
1883 idx ++;
1884 else
1885 fputs (plot_stream, ";\n");
1886 endif
1887 fprintf (plot_stream, "set style line %d default;\n", idx);
1888 fprintf (plot_stream, "set style line %d", idx);
1889 if (isnumeric (obj.markerfacecolor) && ! mono)
1890 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
1891 round (255*obj.markerfacecolor));
1892 endif
1893 if (! isempty (pt2))
1894 style{sidx} = "points";
1895 fprintf (plot_stream, " pointtype %s", pt2);
1896 endif
1897 if (isfield (obj, "markersize"))
1898 fprintf (plot_stream, " pointsize %f", obj.markersize / 3);
1899 endif
1900 endif
1901 endif
1902 if (isfield (obj, "markeredgecolor")
1903 && ! strcmp (obj.markeredgecolor, "none"))
1904 if (facesame && ! isempty (pt)
1905 && (strcmp (obj.markeredgecolor, "auto")
1906 || ! isnumeric (obj.markeredgecolor)
1907 || (isnumeric (obj.markeredgecolor)
1908 && isequal (color, obj.markeredgecolor))))
1909 if (sidx == 1 && ((length (style{sidx}) == 5
1910 && strncmp (style{sidx}, "lines", 5)) || isempty (style{sidx})))
1911 if (! isempty (pt))
1912 style{sidx} = strcat (style{sidx}, "points");
1913 fprintf (plot_stream, " pointtype %s", pt);
1914 endif
1915 if (isfield (obj, "markersize"))
1916 fprintf (plot_stream, " pointsize %f", obj.markersize / 3);
1917 endif
1918 endif
1919 else
1920 if (! found_style)
1921 fputs (plot_stream, " default");
1922 endif
1923 fputs (plot_stream, ";\n");
1924 if (! isempty (style{sidx}))
1925 sidx ++;
1926 idx ++;
1927 else
1928 fputs (plot_stream, ";\n");
1929 endif
1930 fprintf (plot_stream, "set style line %d default;\n", idx);
1931 fprintf (plot_stream, "set style line %d", idx);
1932 if (! mono)
1933 if (strcmp (obj.markeredgecolor, "auto"))
1934 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
1935 round (255*color));
1936 elseif (isnumeric (obj.markeredgecolor) && ! mono)
1937 fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"",
1938 round (255*obj.markeredgecolor));
1939 endif
1940 endif
1941 if (! isempty (pt))
1942 style{sidx} = "points";
1943 fprintf (plot_stream, " pointtype %s", pt);
1944 endif
1945 if (isfield (obj, "markersize"))
1946 fprintf (plot_stream, " pointsize %f", obj.markersize / 3);
1947 endif
1948 endif
1949 endif
1950 else
1951 style{1} = errbars;
1952 fputs (plot_stream, " pointtype 0");
1953 endif
1954
1955 if (! found_style && isempty (style{1}))
1956 fputs (plot_stream, " default");
1957 endif
1958
1959 fputs (plot_stream, ";\n");
1960
1961 endfunction
1962
1963 function [pt, pt2, obj] = gnuplot_pointtype (obj)
1964 if (isfield (obj, "marker"))
1965 switch (obj.marker)
1966 case "+"
1967 pt = pt2 = "1";
1968 case "o"
1969 pt = "6";
1970 pt2 = "7";
1971 case "*"
1972 pt = pt2 = "3";
1973 case "."
1974 pt = "6";
1975 pt2 = "7";
1976 if (isfield (obj, "markerfacecolor")
1977 || strcmp (obj.markerfacecolor, "none"))
1978 obj.markerfacecolor = "auto";
1979 endif
1980 if (isfield (obj, "markersize"))
1981 obj.markersize /= 3;
1982 else
1983 obj.markersize = 5;
1984 endif
1985 case "x"
1986 pt = pt2 = "2";
1987 case {"square", "s"}
1988 pt = "4";
1989 pt2 = "5";
1990 case {"diamond", "d"}
1991 pt = "12";
1992 pt2 = "13";
1993 case "^"
1994 pt = "8";
1995 pt2 = "9";
1996 case "v"
1997 pt = "10";
1998 pt2 = "11";
1999 case ">"
2000 ## FIXME: Should be triangle pointing right, use triangle pointing up
2001 pt = "8";
2002 pt2 = "9";
2003 case "<"
2004 ## FIXME: Should be triangle pointing left, use triangle pointing down
2005 pt = "10";
2006 pt2 = "11";
2007 case {"pentagram", "p"}
2008 ## FIXME: Should be pentagram, using pentagon
2009 pt = "14";
2010 pt2 = "15";
2011 case {"hexagram", "h"}
2012 ## FIXME: Should be 6 pt start, using "*" instead
2013 pt = pt2 = "3";
2014 case "none"
2015 pt = pt2 = "";
2016 otherwise
2017 pt = pt2 = "";
2018 endswitch
2019 else
2020 pt = pt2 = "";
2021 endif
2022 endfunction
2023
2024 function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata)
2025
2026 ## DATA is already transposed.
2027
2028 ## FIXME: this may need to be converted to C++ for speed.
2029
2030 ## Convert NA elements to normal NaN values because fprintf writes
2031 ## "NA" and that confuses gnuplot.
2032 idx = find (isna (data));
2033 if (any (idx))
2034 data(idx) = NaN;
2035 endif
2036
2037 if (nd == 2)
2038 fwrite (plot_stream, data, "float64");
2039 elseif (nd == 3)
2040 if (parametric)
2041 fwrite (plot_stream, data, "float64");
2042 else
2043 nr = rows (data);
2044 if (cdata)
2045 for j = 1:4:nr
2046 fwrite (plot_stream, data(j:j+3,:), "float64");
2047 endfor
2048 else
2049 for j = 1:3:nr
2050 fwrite (plot_stream, data(j:j+2,:), "float64");
2051 endfor
2052 endif
2053 endif
2054 endif
2055
2056 endfunction
2057
2058 function do_tics (obj, plot_stream, ymirror, mono, gnuplot_term)
2059
2060 obj.xticklabel = ticklabel_to_cell (obj.xticklabel);
2061 obj.yticklabel = ticklabel_to_cell (obj.yticklabel);
2062 obj.zticklabel = ticklabel_to_cell (obj.zticklabel);
2063
2064 if (strcmp (obj.xminorgrid, "on"))
2065 obj.xminortick = "on";
2066 endif
2067 if (strcmp (obj.yminorgrid, "on"))
2068 obj.yminortick = "on";
2069 endif
2070 if (strcmp (obj.zminorgrid, "on"))
2071 obj.zminortick = "on";
2072 endif
2073
2074 [fontname, fontsize] = get_fontname_and_size (obj);
2075 fontspec = create_fontspec (fontname, fontsize, gnuplot_term);
2076
2077 ## A Gnuplot tic scale of 69 is equivalent to Octave's 0.5.
2078 ticklength = sprintf ("scale %4.1f", (69/0.5)*obj.ticklength(1));
2079
2080 if (strcmpi (obj.xaxislocation, "top"))
2081 do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode,
2082 obj.xticklabel, obj.xcolor, "x2", plot_stream, true, mono,
2083 "border", obj.tickdir, ticklength, fontname, fontspec,
2084 obj.ticklabelinterpreter, obj.xscale, obj.xsgn, gnuplot_term);
2085 do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel,
2086 obj.xcolor, "x", plot_stream, true, mono, "border",
2087 "", "", fontname, fontspec, obj.ticklabelinterpreter,
2088 obj.xscale, obj.xsgn, gnuplot_term);
2089 elseif (strcmpi (obj.xaxislocation, "zero"))
2090 do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode,
2091 obj.xticklabel, obj.xcolor, "x", plot_stream, true, mono,
2092 "axis", obj.tickdir, ticklength, fontname, fontspec,
2093 obj.ticklabelinterpreter, obj.xscale, obj.xsgn, gnuplot_term);
2094 do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel,
2095 obj.xcolor, "x2", plot_stream, true, mono, "axis",
2096 "", "", fontname, fontspec, obj.ticklabelinterpreter,
2097 obj.xscale, obj.xsgn, gnuplot_term);
2098 else
2099 do_tics_1 (obj.xtickmode, obj.xtick, obj.xminortick, obj.xticklabelmode,
2100 obj.xticklabel, obj.xcolor, "x", plot_stream, true, mono,
2101 "border", obj.tickdir, ticklength, fontname, fontspec,
2102 obj.ticklabelinterpreter, obj.xscale, obj.xsgn, gnuplot_term);
2103 do_tics_1 ("manual", [], "off", obj.xticklabelmode, obj.xticklabel,
2104 obj.xcolor, "x2", plot_stream, true, mono, "border",
2105 "", "", fontname, fontspec, obj.ticklabelinterpreter,
2106 obj.xscale, obj.xsgn, gnuplot_term);
2107 endif
2108 if (strcmpi (obj.yaxislocation, "right"))
2109 do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode,
2110 obj.yticklabel, obj.ycolor, "y2", plot_stream, ymirror, mono,
2111 "border", obj.tickdir, ticklength, fontname, fontspec,
2112 obj.ticklabelinterpreter, obj.yscale, obj.ysgn, gnuplot_term);
2113 do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel,
2114 obj.ycolor, "y", plot_stream, ymirror, mono, "border",
2115 "", "", fontname, fontspec, obj.ticklabelinterpreter,
2116 obj.yscale, obj.ysgn, gnuplot_term);
2117 elseif (strcmpi (obj.yaxislocation, "zero"))
2118 do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode,
2119 obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror, mono,
2120 "axis", obj.tickdir, ticklength, fontname, fontspec,
2121 obj.ticklabelinterpreter, obj.yscale, obj.ysgn, gnuplot_term);
2122 do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel,
2123 obj.ycolor, "y2", plot_stream, ymirror, mono, "axis",
2124 "", "", fontname, fontspec, obj.ticklabelinterpreter,
2125 obj.yscale, obj.ysgn, gnuplot_term);
2126 else
2127 do_tics_1 (obj.ytickmode, obj.ytick, obj.yminortick, obj.yticklabelmode,
2128 obj.yticklabel, obj.ycolor, "y", plot_stream, ymirror, mono,
2129 "border", obj.tickdir, ticklength, fontname, fontspec,
2130 obj.ticklabelinterpreter, obj.yscale, obj.ysgn, gnuplot_term);
2131 do_tics_1 ("manual", [], "off", obj.yticklabelmode, obj.yticklabel,
2132 obj.ycolor, "y2", plot_stream, ymirror, mono, "border",
2133 "", "", fontname, fontspec, obj.ticklabelinterpreter,
2134 obj.yscale, obj.ysgn, gnuplot_term);
2135 endif
2136 do_tics_1 (obj.ztickmode, obj.ztick, obj.zminortick, obj.zticklabelmode,
2137 obj.zticklabel, obj.zcolor, "z", plot_stream, true, mono,
2138 "border", obj.tickdir, ticklength, fontname, fontspec,
2139 obj.ticklabelinterpreter, obj.zscale, obj.zsgn, gnuplot_term);
2140 endfunction
2141
2142 function do_tics_1 (ticmode, tics, mtics, labelmode, labels, color, ax,
2143 plot_stream, mirror, mono, axispos, tickdir, ticklength,
2144 fontname, fontspec, interpreter, scale, sgn, gnuplot_term)
2145 persistent warned_latex = false;
2146
2147 ## Avoid emitting anything if the tics are empty, because this undoes the
2148 ## effect of the previous unset xtics and thereby adds back in the tics.
2149 if (isempty (tics))
2150 return;
2151 endif
2152
2153 if (mirror)
2154 mirror = "mirror";
2155 else
2156 mirror = "nomirror";
2157 endif
2158 if (strcmpi (interpreter, "tex"))
2159 for n = 1 : numel (labels)
2160 labels{n} = __tex2enhanced__ (labels{n}, fontname, false, false);
2161 endfor
2162 elseif (strcmpi (interpreter, "latex"))
2163 if (! warned_latex)
2164 warning ("latex markup not supported for tick marks");
2165 warned_latex = true;
2166 endif
2167 endif
2168 if (strcmp (scale, "log"))
2169 num_mtics = 10;
2170 if (any (strcmp (gnuplot_term, {"tikz", "pstex", "pslatex", "epslatex"})))
2171 fmt = "$10^{%T}$";
2172 else
2173 fmt = "10^{%T}";
2174 endif
2175 if (sgn < 0)
2176 fmt = strcat ("-", fmt);
2177 endif
2178 else
2179 fmt = "%g";
2180 num_mtics = 5;
2181 endif
2182 colorspec = get_text_colorspec (color, mono);
2183 fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt);
2184 if (strcmpi (ticmode, "manual"))
2185 if (isempty (tics))
2186 fprintf (plot_stream, "unset %stics;\nunset m%stics;\n", ax, ax);
2187 return
2188 endif
2189 fprintf (plot_stream, "set %stics %s %s %s %s (", ax, tickdir,
2190 ticklength, axispos, mirror);
2191 fprintf (plot_stream, " %.15e,", tics(1:end-1));
2192 fprintf (plot_stream, " %.15e) %s;\n", tics(end), fontspec);
2193 else
2194 fprintf (plot_stream, "set %stics %s %s %s %s %s %s;\n", ax,
2195 tickdir, ticklength, axispos, mirror, colorspec, fontspec);
2196 endif
2197 if (strcmpi (labelmode, "manual"))
2198 k = 1;
2199 ntics = numel (tics);
2200 nlabels = numel (labels);
2201 fprintf (plot_stream, "set %stics add %s %s %s %s (", ax,
2202 tickdir, ticklength, axispos, mirror);
2203 labels = strrep (labels, "%", "%%");
2204 for i = 1:ntics
2205 fprintf (plot_stream, " \"%s\" %.15g", labels{k++}, tics(i));
2206 if (i < ntics)
2207 fputs (plot_stream, ", ");
2208 endif
2209 if (k > nlabels)
2210 k = 1;
2211 endif
2212 endfor
2213 fprintf (plot_stream, ") %s %s;\n", colorspec, fontspec);
2214 endif
2215 if (strcmp (mtics, "on"))
2216 fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics);
2217 else
2218 fprintf (plot_stream, "unset m%stics;\n", ax);
2219 endif
2220 endfunction
2221
2222 function ticklabel = ticklabel_to_cell (ticklabel)
2223 if (ischar (ticklabel))
2224 ticklabel = cellstr (ticklabel);
2225 elseif (iscellstr (ticklabel))
2226 ticklabel = ticklabel;
2227 else
2228 error ("__gnuplot_draw_axes__: unsupported type of ticklabel");
2229 endif
2230 endfunction
2231
2232 function colorspec = get_text_colorspec (color, mono)
2233 if (mono)
2234 colorspec = "";
2235 else
2236 colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"",
2237 round (255*color));
2238 endif
2239 endfunction
2240
2241 function [f, s, fnt, it, bld] = get_fontname_and_size (t)
2242 if (isempty (t.fontname) || strcmp (t.fontname, "*"))
2243 fnt = "{}";
2244 else
2245 fnt = t.fontname;
2246 endif
2247 f = fnt;
2248 it = false;
2249 bld = false;
2250 if (! isempty (t.fontweight) && strcmpi (t.fontweight, "bold"))
2251 if (! isempty (t.fontangle)
2252 && (strcmpi (t.fontangle, "italic")
2253 || strcmpi (t.fontangle, "oblique")))
2254 f = [f "-bolditalic"];
2255 it = true;
2256 bld = true;
2257 else
2258 f = [f "-bold"];
2259 bld = true;
2260 endif
2261 elseif (! isempty (t.fontangle)
2262 && (strcmpi (t.fontangle, "italic")
2263 || strcmpi (t.fontangle, "oblique")))
2264 f = [f "-italic"];
2265 it = true;
2266 endif
2267 if (isempty (t.fontsize))
2268 s = 10;
2269 else
2270 s = t.fontsize;
2271 endif
2272 endfunction
2273
2274 function [str, f, s] = __maybe_munge_text__ (enhanced, obj, fld)
2275
2276 persistent warned_latex = false;
2277
2278 if (strcmp (fld, "string"))
2279 [f, s, fnt, it, bld] = get_fontname_and_size (obj);
2280 else
2281 f = "Helvetica";
2282 s = 10;
2283 fnt = f;
2284 it = false;
2285 bld = false;
2286 endif
2287
2288 ## The text object may be multiline, and may be of any class
2289 str = getfield (obj, fld);
2290 if (ischar (str) && rows (str) > 1)
2291 str = cellstr (str);
2292 elseif (isnumeric (str))
2293 str = cellstr (num2str (str(:)));
2294 endif
2295 if (iscellstr (str))
2296 for n = 1:numel (str)
2297 if (isnumeric (str{n}))
2298 str{n} = num2str (str{n});
2299 endif
2300 endfor
2301 str = sprintf ("%s\n", str{:})(1:end-1);
2302 endif
2303
2304 if (enhanced)
2305 str = regexprep (str, '(?<!\\)@', '\@');
2306 endif
2307
2308 if (enhanced)
2309 if (strcmpi (obj.interpreter, "tex"))
2310 if (iscellstr (str))
2311 for n = 1:numel (str)
2312 str{n} = __tex2enhanced__ (str{n}, fnt, it, bld);
2313 endfor
2314 else
2315 str = __tex2enhanced__ (str, fnt, it, bld);
2316 endif
2317 elseif (strcmpi (obj.interpreter, "latex"))
2318 if (! warned_latex)
2319 warning ("latex markup not supported for text objects");
2320 warned_latex = true;
2321 endif
2322 endif
2323 endif
2324 endfunction
2325
2326 function str = __tex2enhanced__ (str, fnt, it, bld)
2327 persistent sym = __setup_sym_table__ ();
2328 persistent flds = fieldnames (sym);
2329
2330 [s, e, m] = regexp (str, "\\\\([a-zA-Z]+|0)", "start", "end", "matches");
2331
2332 for i = length (s) : -1 : 1
2333 ## special case for "\0" and replace with empty set "{/Symbol \306}'
2334 if (strncmp (m{i}, '\0', 2))
2335 str = [str(1:s(i) - 1) '{/Symbol \306}' str(s(i) + 2:end)];
2336 else
2337 f = m{i}(2:end);
2338 if (isfield (sym, f))
2339 g = getfield (sym, f);
2340 ## FIXME: The symbol font doesn't seem to support bold or italic
2341 ##if (bld)
2342 ## if (it)
2343 ## g = strrep (g, '/Symbol', '/Symbol-bolditalic');
2344 ## else
2345 ## g = strrep (g, '/Symbol', '/Symbol-bold');
2346 ## endif
2347 ##elseif (it)
2348 ## g = strrep (g, '/Symbol', '/Symbol-italic');
2349 ##endif
2350 str = [str(1:s(i) - 1) g str(e(i) + 1:end)];
2351 elseif (strncmp (f, "rm", 2))
2352 bld = false;
2353 it = false;
2354 str = [str(1:s(i) - 1) '/' fnt ' ' str(s(i) + 3:end)];
2355 elseif (strncmp (f, "it", 2) || strncmp (f, "sl", 2))
2356 it = true;
2357 if (bld)
2358 str = [str(1:s(i) - 1) '/' fnt '-bolditalic ' str(s(i) + 3:end)];
2359 else
2360 str = [str(1:s(i) - 1) '/' fnt '-italic ' str(s(i) + 3:end)];
2361 endif
2362 elseif (strncmp (f, "bf", 2))
2363 bld = true;
2364 if (it)
2365 str = [str(1:s(i) - 1) '/' fnt '-bolditalic ' str(s(i) + 3:end)];
2366 else
2367 str = [str(1:s(i) - 1) '/' fnt '-bold ' str(s(i) + 3:end)];
2368 endif
2369 elseif (strcmpi (f, "color"))
2370 ## FIXME: Ignore \color but remove trailing {} block as well
2371 d = strfind (str(e(i) + 1:end),'}');
2372 if (isempty (d))
2373 warning ('syntax error in \color argument');
2374 else
2375 str = [str(1:s(i) - 1) str(e(i) + d + 1:end)];
2376 endif
2377 elseif (strcmpi (f, "fontname"))
2378 b1 = strfind (str(e(i) + 1:end),'{');
2379 b2 = strfind (str(e(i) + 1:end),'}');
2380 if (isempty (b1) || isempty (b2))
2381 warning ('syntax error in \fontname argument');
2382 else
2383 str = [str(1:s(i) - 1), '/', str(e(i)+b1(1) + 1:e(i)+b2(1)-1), ...
2384 '{}', str(e(i) + b2(1) + 1:end)];
2385 endif
2386 elseif (strcmpi (f, "fontsize"))
2387 b1 = strfind (str(e(i) + 1:end),'{');
2388 b2 = strfind (str(e(i) + 1:end),'}');
2389 if (isempty (b1) || isempty (b2))
2390 warning ('syntax error in \fontname argument');
2391 else
2392 str = [str(1:s(i) - 1), '/=', str(e(i)+b1(1) + 1:e(i)+b2(1)-1), ...
2393 '{}', str(e(i) + b2(1) + 1:end)];
2394 endif
2395 else
2396 ## Last desperate attempt to treat the symbol. Look for things
2397 ## like \pix, that should be translated to the symbol Pi and x
2398 for j = 1 : length (flds)
2399 if (strncmp (flds{j}, f, length (flds{j})))
2400 g = getfield (sym, flds{j});
2401 ## FIXME: The symbol font doesn't seem to support bold or italic
2402 ##if (bld)
2403 ## if (it)
2404 ## g = strrep (g, '/Symbol', '/Symbol-bolditalic');
2405 ## else
2406 ## g = strrep (g, '/Symbol', '/Symbol-bold');
2407 ## endif
2408 ##elseif (it)
2409 ## g = strrep (g, '/Symbol', '/Symbol-italic');
2410 ##endif
2411 str = [str(1:s(i) - 1) g str(s(i) + length (flds{j}) + 1:end)];
2412 break;
2413 endif
2414 endfor
2415 endif
2416 endif
2417 endfor
2418
2419 ## Prepend @ to things like _0^x or _{-100}^{100} for alignment.
2420 ## But need to put the shorter of the two arguments first.
2421 ## Careful of nested {} and unprinted characters when defining
2422 ## shortest.. Don't have to worry about things like ^\theta as they
2423 ## are already converted to ^{/Symbol q}.
2424
2425 ## FIXME: This is a mess... Is it worth it just for a "@" character?
2426
2427 [s, m] = regexp (str,'[_\^]','start','matches');
2428 i = 1;
2429 p = 0;
2430 while (i < length (s))
2431 if (i < length (s))
2432 if (str(s(i) + p + 1) == "{")
2433 s1 = strfind (str(s(i) + p + 2:end),'{');
2434 si = 1;
2435 l1 = strfind (str(s(i) + p + 1:end),'}');
2436 li = 1;
2437 while (li <= length (l1) && si <= length (s1))
2438 if (l1(li) < s1(si))
2439 if (li == si)
2440 break;
2441 endif
2442 li++;
2443 else
2444 si++;
2445 endif
2446 endwhile
2447 l1 = l1(min (length (l1), si));
2448 if (s(i) + l1 + 1 == s(i+1))
2449 if (str(s(i + 1) + p + 1) == "{")
2450 s2 = strfind (str(s(i + 1) + p + 2:end),'{');
2451 si = 1;
2452 l2 = strfind (str(s(i + 1) + p + 1:end),'}');
2453 li = 1;
2454 while (li <= length (l2) && si <= length (s2))
2455 if (l2(li) < s2(si))
2456 if (li == si)
2457 break;
2458 endif
2459 li++;
2460 else
2461 si++;
2462 endif
2463 endwhile
2464 l2 = l2(min (length (l2), si));
2465 if (length_string (str(s(i)+p+2:s(i)+p+l1-1)) <=
2466 length_string (str(s(i+1)+p+2:s(i+1)+p+l2-1)))
2467 ## Shortest already first!
2468 str = [str(1:s(i)+p-1) "@" str(s(i)+p:end)];
2469 else
2470 ## Have to swap sub/super-script to get shortest first.
2471 str = [str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+l2), ...
2472 str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+l2+1:end)];
2473 endif
2474 else
2475 ## Have to swap sub/super-script to get shortest first.
2476 str = [str(1:s(i)+p-1), "@", str(s(i+1)+p:s(i+1)+p+1), ...
2477 str(s(i)+p:s(i)+p+l1), str(s(i+1)+p+2:end)];
2478 endif
2479 i += 2;
2480 p ++;
2481 else
2482 i++;
2483 endif
2484 else
2485 if (s(i+1) == s(i) + 2)
2486 ## Shortest already first!
2487 str = [str(1:s(i)+p-1) "@" str(s(i)+p:end)];
2488 p ++;
2489 i += 2;
2490 else
2491 i ++;
2492 endif
2493 endif
2494 else
2495 i ++;
2496 endif
2497 endwhile
2498
2499 endfunction
2500
2501 function l = length_string (s)
2502 l = length (s) - length (strfind (s,'{')) - length (strfind (s,'}'));
2503 m = regexp (s, '/([\w-]+|[\w-]+=\d+)', 'matches');
2504 if (! isempty (m))
2505 l -= sum (cellfun ("length", m));
2506 endif
2507 endfunction
2508
2509 function sym = __setup_sym_table__ ()
2510 ## Setup the translation table for TeX to gnuplot enhanced mode.
2511 sym.forall = '{/Symbol \042}';
2512 sym.exists = '{/Symbol \044}';
2513 sym.ni = '{/Symbol \047}';
2514 sym.cong = '{/Symbol \100}';
2515 sym.Delta = '{/Symbol D}';
2516 sym.Phi = '{/Symbol F}';
2517 sym.Gamma = '{/Symbol G}';
2518 sym.vartheta = '{/Symbol J}';
2519 sym.Lambda = '{/Symbol L}';
2520 sym.Pi = '{/Symbol P}';
2521 sym.Theta = '{/Symbol Q}';
2522 sym.Sigma = '{/Symbol S}';
2523 sym.varsigma = '{/Symbol V}';
2524 sym.Omega = '{/Symbol W}';
2525 sym.Xi = '{/Symbol X}';
2526 sym.Psi = '{/Symbol Y}';
2527 sym.perp = '{/Symbol \136}';
2528 sym.alpha = '{/Symbol a}';
2529 sym.beta = '{/Symbol b}';
2530 sym.chi = '{/Symbol c}';
2531 sym.delta = '{/Symbol d}';
2532 sym.epsilon = '{/Symbol e}';
2533 sym.phi = '{/Symbol f}';
2534 sym.gamma = '{/Symbol g}';
2535 sym.eta = '{/Symbol h}';
2536 sym.iota = '{/Symbol i}';
2537 sym.varphi = '{/Symbol j}'; # Not in OpenGL
2538 sym.kappa = '{/Symbol k}';
2539 sym.lambda = '{/Symbol l}';
2540 sym.mu = '{/Symbol m}';
2541 sym.nu = '{/Symbol n}';
2542 sym.o = '{/Symbol o}';
2543 sym.pi = '{/Symbol p}';
2544 sym.theta = '{/Symbol q}';
2545 sym.rho = '{/Symbol r}';
2546 sym.sigma = '{/Symbol s}';
2547 sym.tau = '{/Symbol t}';
2548 sym.upsilon = '{/Symbol u}';
2549 sym.varpi = '{/Symbol v}';
2550 sym.omega = '{/Symbol w}';
2551 sym.xi = '{/Symbol x}';
2552 sym.psi = '{/Symbol y}';
2553 sym.zeta = '{/Symbol z}';
2554 sym.sim = '{/Symbol \176}';
2555 sym.Upsilon = '{/Symbol \241}';
2556 sym.prime = '{/Symbol \242}';
2557 sym.leq = '{/Symbol \243}';
2558 sym.infty = '{/Symbol \245}';
2559 sym.clubsuit = '{/Symbol \247}';
2560 sym.diamondsuit = '{/Symbol \250}';
2561 sym.heartsuit = '{/Symbol \251}';
2562 sym.spadesuit = '{/Symbol \252}';
2563 sym.leftrightarrow = '{/Symbol \253}';
2564 sym.leftarrow = '{/Symbol \254}';
2565 sym.uparrow = '{/Symbol \255}';
2566 sym.rightarrow = '{/Symbol \256}';
2567 sym.downarrow = '{/Symbol \257}';
2568 sym.circ = '{/Symbol \260}'; # degree symbol, not circ as in FLTK
2569 sym.deg = '{/Symbol \260}';
2570 sym.ast = '{/Symbol *}';
2571 sym.pm = '{/Symbol \261}';
2572 sym.geq = '{/Symbol \263}';
2573 sym.times = '{/Symbol \264}';
2574 sym.propto = '{/Symbol \265}';
2575 sym.partial = '{/Symbol \266}';
2576 sym.bullet = '{/Symbol \267}';
2577 sym.div = '{/Symbol \270}';
2578 sym.neq = '{/Symbol \271}';
2579 sym.equiv = '{/Symbol \272}';
2580 sym.approx = '{/Symbol \273}';
2581 sym.ldots = '{/Symbol \274}';
2582 sym.mid = '{/Symbol \275}';
2583 sym.aleph = '{/Symbol \300}';
2584 sym.Im = '{/Symbol \301}';
2585 sym.Re = '{/Symbol \302}';
2586 sym.wp = '{/Symbol \303}';
2587 sym.otimes = '{/Symbol \304}';
2588 sym.oplus = '{/Symbol \305}';
2589 ## empty set, not circled slash division operator as in FLTK.
2590 sym.oslash = '{/Symbol \306}';
2591 sym.cap = '{/Symbol \307}';
2592 sym.cup = '{/Symbol \310}';
2593 sym.supset = '{/Symbol \311}';
2594 sym.supseteq = '{/Symbol \312}';
2595 sym.subset = '{/Symbol \314}';
2596 sym.subseteq = '{/Symbol \315}';
2597 sym.in = '{/Symbol \316}';
2598 sym.notin = '{/Symbol \317}'; # Not in OpenGL
2599 sym.angle = '{/Symbol \320}';
2600 sym.bigtriangledown = '{/Symbol \321}'; # Not in OpenGL
2601 sym.langle = '{/Symbol \341}';
2602 sym.rangle = '{/Symbol \361}';
2603 sym.nabla = '{/Symbol \321}';
2604 sym.prod = '{/Symbol \325}'; # Not in OpenGL
2605 sym.surd = '{/Symbol \326}';
2606 sym.cdot = '{/Symbol \327}';
2607 sym.neg = '{/Symbol \330}';
2608 sym.wedge = '{/Symbol \331}';
2609 sym.vee = '{/Symbol \332}';
2610 sym.Leftrightarrow = '{/Symbol \333}'; # Not in OpenGL
2611 sym.Leftarrow = '{/Symbol \334}';
2612 sym.Uparrow = '{/Symbol \335}'; # Not in OpenGL
2613 sym.Rightarrow = '{/Symbol \336}';
2614 sym.Downarrow = '{/Symbol \337}'; # Not in OpenGL
2615 sym.diamond = '{/Symbol \340}'; # Not in OpenGL
2616 sym.copyright = '{/Symbol \343}';
2617 sym.lfloor = '{/Symbol \353}';
2618 sym.lceil = '{/Symbol \351}';
2619 sym.rfloor = '{/Symbol \373}';
2620 sym.rceil = '{/Symbol \371}';
2621 sym.int = '{/Symbol \362}';
2622 endfunction
2623
2624 function retval = __do_enhanced_option__ (enhanced, obj)
2625 retval = "";
2626 if (enhanced)
2627 if (strcmpi (obj.interpreter, "none"))
2628 retval = "noenhanced";
2629 else
2630 retval = "enhanced";
2631 endif
2632 endif
2633 endfunction
2634
2635 function maybe_do_xtick_mirror (plot_stream, axis_obj)
2636 if (! isempty(axis_obj.xtick))
2637 fprintf (plot_stream, "unset x2tics; set xtics %s nomirror\n",
2638 axis_obj.tickdir);
2639 endif
2640 endfunction
2641
2642 function maybe_do_x2tick_mirror (plot_stream, axis_obj)
2643 if (! isempty(axis_obj.xtick))
2644 fprintf (plot_stream, "unset xtics; set x2tics %s nomirror\n",
2645 axis_obj.tickdir);
2646 endif
2647 endfunction