PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pltick.c
Go to the documentation of this file.
1 // Routines for drawing error bars and tick marks.
2 //
3 // Copyright (C) 2004-2014 Alan W. Irwin
4 //
5 // This file is part of PLplot.
6 //
7 // PLplot is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // PLplot is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public License
18 // along with PLplot; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 
22 #include "plplotP.h"
23 
24 //--------------------------------------------------------------------------
25 // void plwxtik()
26 //
27 // Draws a tick parallel to x, using world coordinates
28 //--------------------------------------------------------------------------
29 void
30 plwxtik( PLFLT x, PLFLT y, PLBOOL minor, PLBOOL invert )
31 {
32  PLINT length, below, above;
33  PLFLT height;
34  if ( minor )
35  {
36  // Minor tick
37  height = plsc->minht;
38  }
39  else
40  {
41  // Major tick
42  height = plsc->majht;
43  }
44  length = MAX( ROUND( height * plsc->ypmm ), 1 );
45 
46  if ( invert )
47  {
48  below = 0;
49  above = length;
50  }
51  else
52  {
53  below = length;
54  above = 0;
55  }
56  // Actually draw the tick
57  plxtik( plP_wcpcx( x ), plP_wcpcy( y ), below, above );
58 }
59 
60 //--------------------------------------------------------------------------
61 // void plwytik()
62 //
63 // Draws a tick parallel to y, using world coordinates
64 //--------------------------------------------------------------------------
65 void
66 plwytik( PLFLT x, PLFLT y, PLBOOL minor, PLBOOL invert )
67 {
68  PLINT length, below, above;
69  PLFLT height;
70  if ( minor )
71  {
72  // Minor tick
73  height = plsc->minht;
74  }
75  else
76  {
77  // Major tick
78  height = plsc->majht;
79  }
80  length = MAX( ROUND( height * plsc->xpmm ), 1 );
81 
82  if ( invert )
83  {
84  below = 0;
85  above = length;
86  }
87  else
88  {
89  below = length;
90  above = 0;
91  }
92  // Actually draw the tick
93  plytik( plP_wcpcx( x ), plP_wcpcy( y ), below, above );
94 }
95 
96 //--------------------------------------------------------------------------
97 // void plxtik()
98 //
99 // Draws a tick parallel to x.
100 //--------------------------------------------------------------------------
101 
102 void
103 plxtik( PLINT x, PLINT y, PLINT below, PLINT above )
104 {
105  plP_movphy( x, y - below );
106  plP_draphy( x, y + above );
107 }
108 
109 //--------------------------------------------------------------------------
110 // void plytik()
111 //
112 // Draws a tick parallel to y.
113 //--------------------------------------------------------------------------
114 
115 void
116 plytik( PLINT x, PLINT y, PLINT left, PLINT right )
117 {
118  plP_movphy( x - left, y );
119  plP_draphy( x + right, y );
120 }
121 
122 //--------------------------------------------------------------------------
123 // void plstik()
124 //
125 // Draws a slanting tick at position (mx,my) (measured in mm) of
126 // vector length (dx,dy).
127 //--------------------------------------------------------------------------
128 
129 void
131 {
132  plP_movphy( plP_mmpcx( mx ), plP_mmpcy( my ) );
133  plP_draphy( plP_mmpcx( (PLFLT) ( mx + dx ) ), plP_mmpcy( (PLFLT) ( my + dy ) ) );
134 }
135 
136 //--------------------------------------------------------------------------
137 // void plerx1()
138 //
139 // Plot single horizontal error bar.
140 //--------------------------------------------------------------------------
141 
142 static void
144 {
145  PLINT yminor;
146 
147  yminor = (PLINT) ( MAX( 1.0, plsc->minht * plsc->ypmm ) );
148  plxtik( plP_wcpcx( xmin ), plP_wcpcy( y ), yminor, yminor );
149  plP_movwor( xmin, y );
150  plP_drawor( xmax, y );
151  plxtik( plP_wcpcx( xmax ), plP_wcpcy( y ), yminor, yminor );
152 }
153 
154 //--------------------------------------------------------------------------
155 // void plery1()
156 //
157 // Plot single vertical error bar.
158 //--------------------------------------------------------------------------
159 
160 static void
162 {
163  PLINT xminor;
164 
165  xminor = (PLINT) ( MAX( 1.0, plsc->minht * plsc->xpmm ) );
166  plytik( plP_wcpcx( x ), plP_wcpcy( ymin ), xminor, xminor );
167  plP_movwor( x, ymin );
168  plP_drawor( x, ymax );
169  plytik( plP_wcpcx( x ), plP_wcpcy( ymax ), xminor, xminor );
170 }
171 
172 //--------------------------------------------------------------------------
173 // void plerrx()
174 //
175 // Plot horizontal error bars (xmin(i),y(i)) to (xmax(i),y(i)).
176 //--------------------------------------------------------------------------
177 
178 void
179 c_plerrx( PLINT n, const PLFLT *xmin, const PLFLT *xmax, const PLFLT *y )
180 {
181  PLINT i;
182 
183  if ( plsc->level < 3 )
184  {
185  plabort( "plerrx: Please set up window first" );
186  return;
187  }
188 
189  for ( i = 0; i < n; i++ )
190  plerx1( xmin[i], xmax[i], y[i] );
191 }
192 
193 //--------------------------------------------------------------------------
194 // void plerry()
195 //
196 // Plot vertical error bars (x,ymin(i)) to (x(i),ymax(i)).
197 //--------------------------------------------------------------------------
198 
199 void
200 c_plerry( PLINT n, const PLFLT *x, const PLFLT *ymin, const PLFLT *ymax )
201 {
202  PLINT i;
203 
204  if ( plsc->level < 3 )
205  {
206  plabort( "plerry: Please set up window first" );
207  return;
208  }
209 
210  for ( i = 0; i < n; i++ )
211  plery1( x[i], ymin[i], ymax[i] );
212 }