# HG changeset patch # User John W. Eaton # Date 1328200299 18000 # Node ID d4f37aa5d126fa3046a01e2991804b40a6ca25dd # Parent decea31ea010d12180d469fde1b70e92f31be3e1 fix zooming for logscale figures with fltk+opengl * graphics.cc (do_zoom): New static function. (axes::properties::zoom_about_point): Use it. (axes::properties::calc_ticks_and_lims): Don't try to adjust out of range limits. diff -r decea31ea010 -r d4f37aa5d126 src/graphics.cc --- a/src/graphics.cc Mon Jan 30 08:22:32 2012 -0500 +++ b/src/graphics.cc Thu Feb 02 11:31:39 2012 -0500 @@ -5808,12 +5808,6 @@ } lims = tmp_lims; } - else - { - // adjust min and max tics if they are out of limits - i1 = static_cast (std::ceil (lo / tick_sep)); - i2 = static_cast (gnulib::floor (hi / tick_sep)); - } Matrix tmp_ticks (1, i2-i1+1); for (int i = 0; i <= i2-i1; i++) @@ -6395,6 +6389,58 @@ { return x; } } +static Matrix +do_zoom (double val, double factor, const Matrix& lims, bool is_logscale) +{ + Matrix new_lims = lims; + + double lo = lims(0); + double hi = lims(1); + + bool is_negative = lo < 0 && hi < 0; + + if (is_logscale) + { + if (is_negative) + { + double tmp = hi; + hi = std::log10 (-lo); + lo = std::log10 (-tmp); + val = std::log10 (-val); + } + else + { + hi = std::log10 (hi); + lo = std::log10 (lo); + val = std::log10 (val); + } + } + + // Perform the zooming + lo = val + factor * (lo - val); + hi = val + factor * (hi - val); + + if (is_logscale) + { + if (is_negative) + { + double tmp = -std::pow (10.0, hi); + hi = -std::pow (10.0, lo); + lo = tmp; + } + else + { + lo = std::pow (10.0, lo); + hi = std::pow (10.0, hi); + } + } + + new_lims(0) = lo; + new_lims(1) = hi; + + return new_lims; +} + void axes::properties::zoom_about_point (double x, double y, double factor, bool push_to_zoom_stack) @@ -6417,11 +6463,8 @@ double max_neg_y = -octave_Inf; get_children_limits (miny, maxy, min_pos_y, max_neg_y, kids, 'y'); - // Perform the zooming - xlims (0) = x + factor * (xlims (0) - x); - xlims (1) = x + factor * (xlims (1) - x); - ylims (0) = y + factor * (ylims (0) - y); - ylims (1) = y + factor * (ylims (1) - y); + xlims = do_zoom (x, factor, xlims, xscale_is ("log")); + ylims = do_zoom (y, factor, ylims, yscale_is ("log")); zoom (xlims, ylims, push_to_zoom_stack); }