Mercurial > hg > octave-lojdl
changeset 14314:17de694961f5
make panning work for logscale axes
* graphics.cc (do_translate): New static function.:
* graphics.cc, graphics.h.in (axes::properties): Use it.
Args are now beginning and ending coordinates, not deltas.
* __init_fltk__.cc (plot_window::handle): Pass beginning and ending
* coordinates to translate_view, not deltas.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 02 Feb 2012 12:04:21 -0500 |
parents | 7a7ce92cff56 |
children | ec99c8c185be 82a3127af11c |
files | src/DLD-FUNCTIONS/__init_fltk__.cc src/graphics.cc src/graphics.h.in |
diffstat | 3 files changed, 66 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/__init_fltk__.cc +++ b/src/DLD-FUNCTIONS/__init_fltk__.cc @@ -1301,7 +1301,7 @@ pixel2pos (ax_obj, Fl::event_x (), Fl::event_y (), x1, y1); if (gui_mode == pan_zoom) - ap.translate_view (x0 - x1, y0 - y1); + ap.translate_view (x0, x1, y0, y1); else if (gui_mode == rotate_zoom) { double daz, del;
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -6659,8 +6659,68 @@ update_ylim (false); } -void -axes::properties::translate_view (double delta_x, double delta_y) +static Matrix +do_translate (double x0, double x1, 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; + + double delta; + + if (is_logscale) + { + if (is_negative) + { + double tmp = hi; + hi = std::log10 (-lo); + lo = std::log10 (-tmp); + x0 = -x0; + x1 = -x1; + } + else + { + hi = std::log10 (hi); + lo = std::log10 (lo); + } + + delta = std::log10 (x0) - std::log10 (x1); + } + else + { + delta = x0 - x1; + } + + // Perform the translation + lo += delta; + hi += delta; + + 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::translate_view (double x0, double x1, double y0, double y1) { // FIXME: Do we need error checking here? Matrix xlims = get_xlim ().matrix_value (); @@ -6680,17 +6740,8 @@ double max_neg_y = -octave_Inf; get_children_limits (miny, maxy, min_pos_y, max_neg_y, kids, 'y'); - if (! xscale_is ("log")) - { - xlims (0) += delta_x; - xlims (1) += delta_x; - } - - if (! yscale_is ("log")) - { - ylims (0) += delta_y; - ylims (1) += delta_y; - } + xlims = do_translate (x0, x1, xlims, xscale_is ("log")); + ylims = do_translate (y0, y1, ylims, yscale_is ("log")); zoom (xlims, ylims, false); }
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -3663,7 +3663,7 @@ void zoom_about_point (double x, double y, double factor, bool push_to_zoom_stack = true); void zoom (const Matrix& xl, const Matrix& yl, bool push_to_zoom_stack = true); - void translate_view (double delta_x, double delta_y); + void translate_view (double x0, double x1, double y0, double y1); void rotate_view (double delta_az, double delta_el); void unzoom (void); void clear_zoom_stack (void);