annotate scripts/time/datetick.m @ 17210:73dd413f2c3e

datetick.m: Use modern coding conventions in function. * scripts/time/datetick.m: Use modern coding conventions in function.
author Rik <rik@octave.org>
date Thu, 08 Aug 2013 14:34:12 -0700
parents 8899c785cc99
children 87ba70043bfc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13082
diff changeset
1 ## Copyright (C) 2008-2012 David Bateman
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
2 ##
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
3 ## This file is part of Octave.
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
4 ##
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
8 ## your option) any later version.
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
9 ##
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
13 ## General Public License for more details.
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
14 ##
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
18
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10369
diff changeset
20 ## @deftypefn {Function File} {} datetick ()
10151
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
21 ## @deftypefnx {Function File} {} datetick (@var{form})
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
22 ## @deftypefnx {Function File} {} datetick (@var{axis}, @var{form})
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
23 ## @deftypefnx {Function File} {} datetick (@dots{}, "keeplimits")
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
24 ## @deftypefnx {Function File} {} datetick (@dots{}, "keepticks")
16094
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 14846
diff changeset
25 ## @deftypefnx {Function File} {} datetick (@var{hax}, @dots{})
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 14846
diff changeset
26 ## Add date formatted tick labels to an axis. The axis to apply the
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 14846
diff changeset
27 ## ticks to is determined by @var{axis} which can take the values "x",
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 14846
diff changeset
28 ## "y", or "z". The default value is "x". The formatting of the labels is
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 14846
diff changeset
29 ## determined by the variable @var{form}, which can either be a string or
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 14846
diff changeset
30 ## positive integer that @code{datestr} accepts.
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
31 ## @seealso{datenum, datestr}
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
32 ## @end deftypefn
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
33
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
34 function datetick (varargin)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
35
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
36 [hax, varargin, nargin] = __plt_get_axis_arg__ ("datetick", varargin{:});
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
37
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
38 oldfig = ifelse (isempty (hax), [], get (0, "currentfigure"));
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
39 if (isempty (hax))
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
40 hax = gca ();
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
41 endif
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
42
10151
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
43 unwind_protect
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
44 ## FIXME: This will bring the axes to the top of the stack.
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
45 ## This may not always be desirable if there are multiple axes
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
46 ## objects.
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
47 axes (hax);
10151
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
48 __datetick__ (varargin{:});
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
49 unwind_protect_cleanup
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
50 if (! isempty (oldfig))
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
51 set (0, "currentfigure", oldfig);
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
52 endif
10151
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
53 end_unwind_protect
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
54
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
55 endfunction
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
56
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
58 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59 %! clf;
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
60 %! yr = 1900:10:2000;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
61 %! pop = [76.094, 92.407, 106.461, 123.077 131.954, 151.868, 179.979, ...
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
62 %! 203.984, 227.225, 249.623, 282.224];
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
63 %! plot (datenum (yr, 1, 1), pop);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
64 %! title ("US population (millions)");
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
65 %! xlabel ("Year");
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
66 %! datetick ("x", "YYYY");
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
67
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
68 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
70 %! yr = 1988:2:2002;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
71 %! yr = datenum (yr,1,1);
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
72 %! pr = [12.1 13.3 12.6 13.1 13.3 14.1 14.4 15.2];
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
73 %! plot (yr, pr, "-o");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
74 %! xlabel ("year");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
75 %! ylabel ("average price");
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
76 %! ax = gca;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
77 %! set (ax, "xtick", datenum (1990:5:2005,1,1));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
78 %! datetick (2, "keepticks");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
79 %! set (ax, "ytick", 12:16);
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
80
13082
35c0b722d2e4 codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents: 12575
diff changeset
81 ## Remove from test statistics. No real tests possible.
35c0b722d2e4 codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents: 12575
diff changeset
82 %!assert (1)
35c0b722d2e4 codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents: 12575
diff changeset
83
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
84 function __datetick__ (varargin)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
85
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
86 keeplimits = false;
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
87 idx = strcmpi (varargin, "keeplimits");
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
88 if (any (idx))
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
89 keeplimits = true;
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
90 varargin = varargin(! idx);
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
91 endif
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
92 keepticks = false;
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
93 idx = strcmpi (varargin, "keepticks");
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
94 if (any (idx))
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
95 keepticks = true;
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
96 varargin = varargin(! idx);
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
97 endif
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
98
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
99 nargin = numel (varargin);
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
100 form = [];
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
101 ax = "x";
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
102
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
103 if (nargin != 0)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
104 arg = varargin{1};
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
105 if (ischar (arg) && any (strcmpi (arg, {"x", "y", "z"})))
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
106 ax = tolower (arg);
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
107 if (nargin > 1)
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
108 form = varargin{2};
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
109 varargin(1:2) = [];
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
110 else
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
111 varargin(1) = [];
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
112 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
113 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
114 form = arg;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
115 varargin(1) = [];
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
116 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
117 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
118
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
119 ## Don't publish the existence of this variable for use with dateaxis
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
120 if (length (varargin) > 0)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
121 startdate = varargin{1};
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
122 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
123 startdate = [];
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
124 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
125
10151
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
126 if (! isempty (form))
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
127 if (isnumeric (form))
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
128 if (! isscalar (form) || form < 0 || form != fix (form))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11294
diff changeset
129 error ("datetick: expecting FORM argument to be a positive integer");
10151
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
130 endif
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
131 elseif (! ischar (form))
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
132 error ("datetick: expecting valid date format string");
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
133 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
134 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
135
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
136 if (keepticks)
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
137 ticks = get (gca (), [ax "tick"]);
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
138 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
139 ## Need to do our own axis tick position calculation as
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
140 ## year, etc, don't fallback on nice datenum values.
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14665
diff changeset
141 objs = findall (gca ());
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
142 xmax = NaN;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
143 xmin = NaN;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
144 for i = 1 : length (objs)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
145 fld = get (objs (i));
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
146 if (isfield (fld, [ax "data"]))
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
147 xdata = getfield (fld, [ax "data"])(:);
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
148 xmin = min (xmin, min (xdata));
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
149 xmax = max (xmax, max (xdata));
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
150 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
151 endfor
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
152
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
153 if (isnan (xmin) || isnan (xmax))
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
154 xmin = 0;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
155 xmax = 1;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
156 elseif (xmin == xmax)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
157 xmax = xmin + 1;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
158 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
159
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
160 N = 3;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
161 if (xmax - xmin < N)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
162 ## Day scale or less
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
163 if (xmax - xmin < N / 24 / 60 / 60)
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
164 scl = 1 / 24 / 60 / 60;
14665
4f458e882516 Allow fractional months to datenum and correct a couple of typos in datetick (bug #36482)
David Bateman <dbateman@free.fr>
parents: 14552
diff changeset
165 elseif (xmax - xmin < N / 24 / 60)
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
166 scl = 1 / 24 / 60;
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
167 else
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
168 scl = 1 / 24;
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
169 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
170 sep = __calc_tick_sep__ (xmin / scl , xmax / scl);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
171 xmin = sep * floor (xmin / scl / sep);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
172 xmax = sep * ceil (xmax / scl / sep);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
173 nticks = (xmax - xmin) / sep + 1;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
174 xmin *= scl;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
175 xmax *= scl;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
176 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
177 [ymin, mmin, dmin] = datevec (xmin);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
178 [ymax, mmax, dmax] = datevec (xmax);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
179 minyear = ymin + (mmin - 1) / 12 + (dmin - 1) / 12 / 30;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
180 maxyear = ymax + (mmax - 1) / 12 + (dmax - 1) / 12 / 30;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
181 minmonth = mmin + (dmin - 1) / 30;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
182 maxmonth = (ymax - ymin) * 12 + mmax + (dmax - 1) / 30;
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
183
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
184 if (maxmonth - minmonth < N)
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
185 sep = __calc_tick_sep__ (xmin, xmax);
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
186 xmin = sep * floor (xmin / sep);
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
187 xmax = sep * ceil (xmax / sep);
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
188 nticks = (xmax - xmin) / sep + 1;
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
189 elseif (maxyear - minyear < N)
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
190 sep = __calc_tick_sep__ (minmonth , maxmonth);
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
191 xmin = datenum (ymin, sep * floor (minmonth / sep), 1);
14665
4f458e882516 Allow fractional months to datenum and correct a couple of typos in datetick (bug #36482)
David Bateman <dbateman@free.fr>
parents: 14552
diff changeset
192 xmax = datenum (ymax, sep * ceil (maxmonth / sep), 1);
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
193 nticks = ceil (maxmonth / sep) - floor (minmonth / sep) + 1;
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
194 else
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
195 sep = __calc_tick_sep__ (minyear , maxyear);
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
196 xmin = datenum (sep * floor (minyear / sep), 1, 1);
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
197 xmax = datenum (sep * ceil (maxyear / sep), 1, 1);
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
198 nticks = ceil (maxyear / sep) - floor (minyear / sep) + 1;
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
199 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
200 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
201 ticks = xmin + [0 : nticks - 1] / (nticks - 1) * (xmax - xmin);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
202 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
203
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
204 if (isempty (form))
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
205 r = max (ticks) - min (ticks);
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
206 if (r < 10/60/24)
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
207 ## minutes and seconds
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
208 form = 13;
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
209 elseif (r < 2)
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
210 ## hours
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
211 form = 15;
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
212 elseif (r < 15)
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
213 ## days
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
214 form = 8;
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
215 elseif (r < 365)
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
216 ## FIXME: FORM should be 19 for European users who use dd/mm
10151
c2f1cdb59821 datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
217 ## instead of mm/dd. How can that be determined automatically?
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
218 ## months
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
219 form = 6;
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
220 elseif (r < 90*12)
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
221 ## quarters
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
222 form = 27;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
223 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
224 ## years
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
225 form = 10;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
226 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
227 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
228
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
229 if (length (ticks) == 6)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
230 ## Careful that its not treated as a datevec
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
231 if (! isempty (startdate))
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
232 sticks = strvcat (datestr (ticks(1:end-1) - ticks(1) + startdate, form),
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
233 datestr (ticks(end) - ticks(1) + startdate, form));
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
234 else
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
235 sticks = strvcat (datestr (ticks(1:end-1), form),
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
236 datestr (ticks(end), form));
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
237 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
238 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
239 if (! isempty (startdate))
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
240 sticks = datestr (ticks - ticks(1) + startdate, form);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
241 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
242 sticks = datestr (ticks, form);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
243 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
244 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
245
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
246 sticks = mat2cell (sticks, ones (rows (sticks), 1), columns (sticks));
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
247
10369
3516a245d607 datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10151
diff changeset
248 if (keepticks)
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
249 if (keeplimits)
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
250 set (gca (), [ax "ticklabel"], sticks);
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
251 else
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
252 set (gca (), [ax "ticklabel"], sticks,
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
253 [ax "lim"], [min(ticks), max(ticks)]);
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
254 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
255 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
256 if (keeplimits)
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
257 set (gca (), [ax "tick"], ticks, [ax "ticklabel"], sticks);
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
258 else
17210
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
259 set (gca (), [ax "tick"], ticks, [ax "ticklabel"], sticks,
73dd413f2c3e datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents: 16094
diff changeset
260 [ax "lim"], [min(ticks), max(ticks)]);
8112
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
261 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
262 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
263 endfunction
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
264
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
265 function [a, b] = __magform__ (x)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
266 if (x == 0)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
267 a = 0;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
268 b = 0;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
269 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
270 l = log10 (abs (x));
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
271 r = fmod (l, 1);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
272 a = 10 .^ r;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
273 b = fix (l - r);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
274 if (a < 1)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
275 a *= 10;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
276 b -= 1;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
277 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
278 if (x < 0)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
279 a = -a;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
280 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
281 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
282 endfunction
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
283
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
284 ## A translation from Tom Holoryd's python code at
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
285 ## http://kurage.nimh.nih.gov/tomh/tics.py
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
286 function sep = __calc_tick_sep__ (lo, hi)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
287 persistent sqrt_2 = sqrt (2.0);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
288 persistent sqrt_10 = sqrt (10.0);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
289 persistent sqrt_50 = sqrt (50.0);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
290
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
291 ticint = 5;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
292
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
293 ## Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
294 ## SCALE3 for Determination of Scales on Computer Generated
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
295 ## Plots", Communications of the ACM, 10 (1973), 639-640.
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
296 ## Also cited as ACM Algorithm 463.
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
297
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
298 [a, b] = __magform__ ((hi - lo) / ticint);
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
299
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
300 if (a < sqrt_2)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
301 x = 1;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
302 elseif (a < sqrt_10)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
303 x = 2;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
304 elseif (a < sqrt_50)
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
305 x = 5;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
306 else
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
307 x = 10;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
308 endif
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
309 sep = x * 10 .^ b;
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
310 endfunction
31e86163b752 Add the datetick function
David Bateman <dbateman@free.fr>
parents:
diff changeset
311