Mercurial > octave
annotate scripts/plot/appearance/datetick.m @ 21174:a223cce1daa4
strip trailing space from source files we maintain
* gl2ps-renderer.cc, gl2ps-renderer.h, pt-eval.cc CmplxCHOL.cc,
sparse-lu.h, datetick.m, index.tst: Strip trailing whitespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 01 Feb 2016 08:53:01 -0500 |
parents | 7705a858262b |
children | ffad2baa90f7 |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
1 ## Copyright (C) 2008-2015 David Bateman |
8112 | 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 -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
20 ## @deftypefn {} {} datetick () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
21 ## @deftypefnx {} {} datetick (@var{form}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
22 ## @deftypefnx {} {} datetick (@var{axis}, @var{form}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
23 ## @deftypefnx {} {} datetick (@dots{}, "keeplimits") |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
24 ## @deftypefnx {} {} datetick (@dots{}, "keepticks") |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
25 ## @deftypefnx {} {} datetick (@var{hax}, @dots{}) |
20173
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
26 ## Add date formatted tick labels to an axis. |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 ## |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
28 ## The axis to apply the ticks to is determined by @var{axis} which can take |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
29 ## the values @qcode{"x"}, @qcode{"y"}, or @qcode{"z"}. The default value is |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
30 ## @qcode{"x"}. |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
31 ## |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
32 ## The formatting of the labels is determined by the variable @var{form}, which |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17211
diff
changeset
|
33 ## can either be a string or positive integer that @code{datestr} accepts. |
8112 | 34 ## @seealso{datenum, datestr} |
35 ## @end deftypefn | |
36 | |
37 function datetick (varargin) | |
38 | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
39 [hax, varargin, nargin] = __plt_get_axis_arg__ ("datetick", varargin{:}); |
8112 | 40 |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17210
diff
changeset
|
41 oldfig = []; |
17301
68bcac3c043a
Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
42 if (! isempty (hax)) |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17210
diff
changeset
|
43 oldfig = get (0, "currentfigure"); |
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17210
diff
changeset
|
44 endif |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
45 if (isempty (hax)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
46 hax = gca (); |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
47 endif |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
48 |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
49 unwind_protect |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
50 ## FIXME: This will bring the axes to the top of the stack. |
18348
052cc933aea6
datetick.m: Add more detail to FIXME note.
Rik <rik@octave.org>
parents:
17745
diff
changeset
|
51 ## This may not be desirable if there are multiple axes objects, |
052cc933aea6
datetick.m: Add more detail to FIXME note.
Rik <rik@octave.org>
parents:
17745
diff
changeset
|
52 ## such as can occur with plotyy. |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
53 axes (hax); |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
54 __datetick__ (varargin{:}); |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
55 unwind_protect_cleanup |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
56 if (! isempty (oldfig)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
57 set (0, "currentfigure", oldfig); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
58 endif |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
59 end_unwind_protect |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
60 |
8112 | 61 endfunction |
62 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
63 |
8112 | 64 %!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
|
65 %! clf; |
8112 | 66 %! yr = 1900:10:2000; |
67 %! pop = [76.094, 92.407, 106.461, 123.077 131.954, 151.868, 179.979, ... | |
68 %! 203.984, 227.225, 249.623, 282.224]; | |
69 %! plot (datenum (yr, 1, 1), pop); | |
18876
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18348
diff
changeset
|
70 %! title ('US population (millions)'); |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18348
diff
changeset
|
71 %! xlabel ('Year'); |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18348
diff
changeset
|
72 %! datetick ('x', 'YYYY'); |
8112 | 73 |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
74 %!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
|
75 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
76 %! 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
|
77 %! yr = datenum (yr,1,1); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
78 %! pr = [12.1 13.3 12.6 13.1 13.3 14.1 14.4 15.2]; |
18876
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18348
diff
changeset
|
79 %! plot (yr, pr, '-o'); |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18348
diff
changeset
|
80 %! xlabel ('year'); |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18348
diff
changeset
|
81 %! ylabel ('average price'); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
82 %! ax = gca; |
18876
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18348
diff
changeset
|
83 %! set (ax, 'xtick', datenum (1990:5:2005,1,1)); |
18924
9a5e03801d23
Update some plot %!demos so that they run under Matlab.
Rik <rik@octave.org>
parents:
18876
diff
changeset
|
84 %! datetick (2, 'x', 'keepticks'); |
18876
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18348
diff
changeset
|
85 %! set (ax, 'ytick', 12:16); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
86 |
13082
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
87 ## Remove from test statistics. No real tests possible. |
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
88 %!assert (1) |
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
89 |
8112 | 90 function __datetick__ (varargin) |
91 | |
92 keeplimits = false; | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
93 idx = strcmpi (varargin, "keeplimits"); |
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 keeplimits = 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 |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
98 keepticks = false; |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
99 idx = strcmpi (varargin, "keepticks"); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
100 if (any (idx)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
101 keepticks = true; |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
102 varargin = varargin(! idx); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
103 endif |
8112 | 104 |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
105 nargin = numel (varargin); |
8112 | 106 form = []; |
107 ax = "x"; | |
108 | |
109 if (nargin != 0) | |
110 arg = varargin{1}; | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
111 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
|
112 ax = tolower (arg); |
8112 | 113 if (nargin > 1) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
114 form = varargin{2}; |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
115 varargin(1:2) = []; |
8112 | 116 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
117 varargin(1) = []; |
8112 | 118 endif |
119 else | |
120 form = arg; | |
121 varargin(1) = []; | |
122 endif | |
123 endif | |
124 | |
125 ## Don't publish the existence of this variable for use with dateaxis | |
126 if (length (varargin) > 0) | |
127 startdate = varargin{1}; | |
128 else | |
129 startdate = []; | |
130 endif | |
131 | |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
132 if (! isempty (form)) |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
133 if (isnumeric (form)) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
134 if (! isscalar (form) || form < 0 || form != fix (form)) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
135 error ("datetick: FORM argument must be a positive integer"); |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
136 endif |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
137 elseif (! ischar (form)) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
138 error ("datetick: FORM argument must be a valid date format string"); |
8112 | 139 endif |
140 endif | |
141 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
142 if (keepticks) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
143 ticks = get (gca (), [ax "tick"]); |
8112 | 144 else |
145 ## Need to do our own axis tick position calculation as | |
21167
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
146 ## year, etc., don't fall back to nice datenum values. |
21165
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
147 if (keeplimits) |
21167
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
148 limits = get (gca (), [ax "lim"]); |
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
149 xmin = limits(1); |
21174
a223cce1daa4
strip trailing space from source files we maintain
John W. Eaton <jwe@octave.org>
parents:
21167
diff
changeset
|
150 xmax = limits(2); |
21165
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
151 else |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
152 objs = findall (gca ()); |
21167
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
153 xmin = xmax = NaN; |
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
154 for i = 1 : numel (objs) |
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
155 fld = get (objs(i)); |
21165
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
156 if (isfield (fld, [ax "data"])) |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
157 xdata = getfield (fld, [ax "data"])(:); |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
158 xmin = min (xmin, min (xdata)); |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
159 xmax = max (xmax, max (xdata)); |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
160 endif |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
161 endfor |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
162 endif |
8112 | 163 |
164 if (isnan (xmin) || isnan (xmax)) | |
165 xmin = 0; | |
166 xmax = 1; | |
167 elseif (xmin == xmax) | |
168 xmax = xmin + 1; | |
169 endif | |
170 | |
171 N = 3; | |
172 if (xmax - xmin < N) | |
173 ## Day scale or less | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
174 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
|
175 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
|
176 elseif (xmax - xmin < N / 24 / 60) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
177 scl = 1 / 24 / 60; |
8112 | 178 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
179 scl = 1 / 24; |
8112 | 180 endif |
181 sep = __calc_tick_sep__ (xmin / scl , xmax / scl); | |
182 xmin = sep * floor (xmin / scl / sep); | |
183 xmax = sep * ceil (xmax / scl / sep); | |
184 nticks = (xmax - xmin) / sep + 1; | |
185 xmin *= scl; | |
186 xmax *= scl; | |
187 else | |
188 [ymin, mmin, dmin] = datevec (xmin); | |
189 [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
|
190 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
|
191 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
|
192 minmonth = mmin + (dmin - 1) / 30; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
193 maxmonth = (ymax - ymin) * 12 + mmax + (dmax - 1) / 30; |
8112 | 194 |
195 if (maxmonth - minmonth < N) | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
196 sep = __calc_tick_sep__ (xmin, xmax); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
197 xmin = sep * floor (xmin / sep); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
198 xmax = sep * ceil (xmax / sep); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
199 nticks = (xmax - xmin) / sep + 1; |
8112 | 200 elseif (maxyear - minyear < N) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
201 sep = __calc_tick_sep__ (minmonth , maxmonth); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
202 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
|
203 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
|
204 nticks = ceil (maxmonth / sep) - floor (minmonth / sep) + 1; |
8112 | 205 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
206 sep = __calc_tick_sep__ (minyear , maxyear); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
207 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
|
208 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
|
209 nticks = ceil (maxyear / sep) - floor (minyear / sep) + 1; |
8112 | 210 endif |
211 endif | |
212 ticks = xmin + [0 : nticks - 1] / (nticks - 1) * (xmax - xmin); | |
213 endif | |
214 | |
215 if (isempty (form)) | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
216 r = max (ticks) - min (ticks); |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
217 if (r < 10/60/24) |
8112 | 218 ## minutes and seconds |
219 form = 13; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
220 elseif (r < 2) |
8112 | 221 ## hours |
222 form = 15; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
223 elseif (r < 15) |
8112 | 224 ## days |
225 form = 8; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
226 elseif (r < 365) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
227 ## 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
|
228 ## instead of mm/dd. How can that be determined automatically? |
8112 | 229 ## months |
230 form = 6; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
231 elseif (r < 90*12) |
8112 | 232 ## quarters |
233 form = 27; | |
234 else | |
235 ## years | |
236 form = 10; | |
237 endif | |
238 endif | |
239 | |
240 if (length (ticks) == 6) | |
241 ## Careful that its not treated as a datevec | |
242 if (! isempty (startdate)) | |
243 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
|
244 datestr (ticks(end) - ticks(1) + startdate, form)); |
8112 | 245 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
246 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
|
247 datestr (ticks(end), form)); |
8112 | 248 endif |
249 else | |
250 if (! isempty (startdate)) | |
251 sticks = datestr (ticks - ticks(1) + startdate, form); | |
252 else | |
253 sticks = datestr (ticks, form); | |
254 endif | |
255 endif | |
256 | |
257 sticks = mat2cell (sticks, ones (rows (sticks), 1), columns (sticks)); | |
258 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
259 if (keepticks) |
8112 | 260 if (keeplimits) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
261 set (gca (), [ax "ticklabel"], sticks); |
8112 | 262 else |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
263 set (gca (), [ax "ticklabel"], sticks, |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
264 [ax "lim"], [min(ticks), max(ticks)]); |
8112 | 265 endif |
266 else | |
267 if (keeplimits) | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
268 set (gca (), [ax "tick"], ticks, [ax "ticklabel"], sticks); |
8112 | 269 else |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
270 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
|
271 [ax "lim"], [min(ticks), max(ticks)]); |
8112 | 272 endif |
273 endif | |
274 endfunction | |
275 | |
276 function [a, b] = __magform__ (x) | |
277 if (x == 0) | |
278 a = 0; | |
279 b = 0; | |
280 else | |
281 l = log10 (abs (x)); | |
19118 | 282 r = rem (l, 1); |
8112 | 283 a = 10 .^ r; |
284 b = fix (l - r); | |
285 if (a < 1) | |
286 a *= 10; | |
287 b -= 1; | |
288 endif | |
289 if (x < 0) | |
290 a = -a; | |
291 endif | |
292 endif | |
293 endfunction | |
294 | |
295 ## A translation from Tom Holoryd's python code at | |
296 ## http://kurage.nimh.nih.gov/tomh/tics.py | |
297 function sep = __calc_tick_sep__ (lo, hi) | |
298 persistent sqrt_2 = sqrt (2.0); | |
299 persistent sqrt_10 = sqrt (10.0); | |
300 persistent sqrt_50 = sqrt (50.0); | |
301 | |
302 ticint = 5; | |
303 | |
304 ## Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and | |
305 ## SCALE3 for Determination of Scales on Computer Generated | |
306 ## Plots", Communications of the ACM, 10 (1973), 639-640. | |
307 ## Also cited as ACM Algorithm 463. | |
308 | |
309 [a, b] = __magform__ ((hi - lo) / ticint); | |
310 | |
311 if (a < sqrt_2) | |
312 x = 1; | |
313 elseif (a < sqrt_10) | |
314 x = 2; | |
315 elseif (a < sqrt_50) | |
316 x = 5; | |
317 else | |
318 x = 10; | |
319 endif | |
320 sep = x * 10 .^ b; | |
321 endfunction | |
322 |