comparison src/graphics.cc @ 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
comparison
equal deleted inserted replaced
14313:7a7ce92cff56 14314:17de694961f5
6657 update_transform (); 6657 update_transform ();
6658 update_xlim (false); 6658 update_xlim (false);
6659 update_ylim (false); 6659 update_ylim (false);
6660 } 6660 }
6661 6661
6662 void 6662 static Matrix
6663 axes::properties::translate_view (double delta_x, double delta_y) 6663 do_translate (double x0, double x1, const Matrix& lims, bool is_logscale)
6664 {
6665 Matrix new_lims = lims;
6666
6667 double lo = lims(0);
6668 double hi = lims(1);
6669
6670 bool is_negative = lo < 0 && hi < 0;
6671
6672 double delta;
6673
6674 if (is_logscale)
6675 {
6676 if (is_negative)
6677 {
6678 double tmp = hi;
6679 hi = std::log10 (-lo);
6680 lo = std::log10 (-tmp);
6681 x0 = -x0;
6682 x1 = -x1;
6683 }
6684 else
6685 {
6686 hi = std::log10 (hi);
6687 lo = std::log10 (lo);
6688 }
6689
6690 delta = std::log10 (x0) - std::log10 (x1);
6691 }
6692 else
6693 {
6694 delta = x0 - x1;
6695 }
6696
6697 // Perform the translation
6698 lo += delta;
6699 hi += delta;
6700
6701 if (is_logscale)
6702 {
6703 if (is_negative)
6704 {
6705 double tmp = -std::pow (10.0, hi);
6706 hi = -std::pow (10.0, lo);
6707 lo = tmp;
6708 }
6709 else
6710 {
6711 lo = std::pow (10.0, lo);
6712 hi = std::pow (10.0, hi);
6713 }
6714 }
6715
6716 new_lims(0) = lo;
6717 new_lims(1) = hi;
6718
6719 return new_lims;
6720 }
6721
6722 void
6723 axes::properties::translate_view (double x0, double x1, double y0, double y1)
6664 { 6724 {
6665 // FIXME: Do we need error checking here? 6725 // FIXME: Do we need error checking here?
6666 Matrix xlims = get_xlim ().matrix_value (); 6726 Matrix xlims = get_xlim ().matrix_value ();
6667 Matrix ylims = get_ylim ().matrix_value (); 6727 Matrix ylims = get_ylim ().matrix_value ();
6668 6728
6678 double maxy = -octave_Inf; 6738 double maxy = -octave_Inf;
6679 double min_pos_y = octave_Inf; 6739 double min_pos_y = octave_Inf;
6680 double max_neg_y = -octave_Inf; 6740 double max_neg_y = -octave_Inf;
6681 get_children_limits (miny, maxy, min_pos_y, max_neg_y, kids, 'y'); 6741 get_children_limits (miny, maxy, min_pos_y, max_neg_y, kids, 'y');
6682 6742
6683 if (! xscale_is ("log")) 6743 xlims = do_translate (x0, x1, xlims, xscale_is ("log"));
6684 { 6744 ylims = do_translate (y0, y1, ylims, yscale_is ("log"));
6685 xlims (0) += delta_x;
6686 xlims (1) += delta_x;
6687 }
6688
6689 if (! yscale_is ("log"))
6690 {
6691 ylims (0) += delta_y;
6692 ylims (1) += delta_y;
6693 }
6694 6745
6695 zoom (xlims, ylims, false); 6746 zoom (xlims, ylims, false);
6696 } 6747 }
6697 6748
6698 void 6749 void