comparison src/graphics.cc @ 7446:4bfbec4b0e24

[project @ 2008-02-04 21:17:18 by jwe]
author jwe
date Mon, 04 Feb 2008 21:17:18 +0000
parents af92b34f3a3a
children 25018e35b4cb
comparison
equal deleted inserted replaced
7445:af92b34f3a3a 7446:4bfbec4b0e24
2230 retval(1) = max_val; 2230 retval(1) = max_val;
2231 2231
2232 return retval; 2232 return retval;
2233 } 2233 }
2234 2234
2235 // magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is
2236 // integral. Used by calc_ticks
2237
2238 void
2239 axes::properties::magform (double x, double& a, int &b)
2240 {
2241 if (x == 0)
2242 {
2243 a = 0;
2244 b = 0;
2245 }
2246 else
2247 {
2248 double l = std::log10 (std::abs (x));
2249 double r = std::fmod (l, 1.);
2250 a = std::pow (10.0, r);
2251 b = static_cast<int> (l-r);
2252 if (a < 1)
2253 {
2254 a *= 10;
2255 b -= 1;
2256 }
2257
2258 if (x < 0)
2259 a = -a;
2260 }
2261 }
2262
2263 // A translation from Tom Holoryd's python code at
2264 // http://kurage.nimh.nih.gov/tomh/tics.py
2265 // FIXME -- add log ticks
2266 void
2267 axes::properties::calc_ticks (const array_property& lims, array_property& ticks)
2268 {
2269
2270 int ticint = 5;
2271
2272 if (lims.get ().is_empty ())
2273 return;
2274
2275 double lo = (lims.get ().matrix_value ()) (0);
2276 double hi = (lims.get ().matrix_value ()) (1);
2277
2278 // Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and
2279 // SCALE3 for Determination of Scales on Computer Generated
2280 // Plots", Communications of the ACM, 10 (1973), 639-640.
2281 // Also cited as ACM Algorithm 463.
2282
2283 double a;
2284 int b, x;
2285 magform ( (hi-lo)/ticint, a, b);
2286 if (a < 1.41) // sqrt(2)
2287 x = 1;
2288 else if (a < 3.16) // sqrt(10)
2289 x = 2;
2290 else if (a < 7.07) // sqrt(50)
2291 x = 5;
2292 else
2293 x = 10;
2294
2295
2296 double sep = x * std::pow (10., b);
2297
2298 // FIXME x can now be used to set minor ticks
2299 if (x == 10)
2300 x = 1;
2301
2302
2303 // The following guarantees that if zero is in the range, it will be
2304 // included as a tic.
2305
2306 int i1 = static_cast<int> (std::floor (lo / sep));
2307 int i2 = static_cast<int> (std::ceil (hi / sep));
2308
2309 Matrix limits (1, i2-i1+1);
2310 for (int i=0; i<i2-i1+1; i++)
2311 limits (i) = sep*(i+i1);
2312
2313 ticks = limits;
2314
2315 }
2316
2235 static bool updating_axis_limits = false; 2317 static bool updating_axis_limits = false;
2236 2318
2237 void 2319 void
2238 axes::update_axis_limits (const std::string& axis_type) 2320 axes::update_axis_limits (const std::string& axis_type)
2239 { 2321 {
2378 switch (update_type) 2460 switch (update_type)
2379 { 2461 {
2380 case 'x': 2462 case 'x':
2381 xproperties.set_xlim (limits); 2463 xproperties.set_xlim (limits);
2382 xproperties.set_xlimmode ("auto"); 2464 xproperties.set_xlimmode ("auto");
2465 xproperties.update_xlim ();
2383 break; 2466 break;
2384 2467
2385 case 'y': 2468 case 'y':
2386 xproperties.set_ylim (limits); 2469 xproperties.set_ylim (limits);
2387 xproperties.set_ylimmode ("auto"); 2470 xproperties.set_ylimmode ("auto");
2471 xproperties.update_ylim ();
2388 break; 2472 break;
2389 2473
2390 case 'z': 2474 case 'z':
2391 xproperties.set_zlim (limits); 2475 xproperties.set_zlim (limits);
2392 xproperties.set_zlimmode ("auto"); 2476 xproperties.set_zlimmode ("auto");
2477 xproperties.update_zlim ();
2393 break; 2478 break;
2394 2479
2395 case 'c': 2480 case 'c':
2396 xproperties.set_clim (limits); 2481 xproperties.set_clim (limits);
2397 xproperties.set_climmode ("auto"); 2482 xproperties.set_climmode ("auto");