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