# HG changeset patch # User jwe # Date 1202159838 0 # Node ID 4bfbec4b0e244fc6fa68c7e57e8a861757304302 # Parent af92b34f3a3a8ea6efb90dc4892dfed9ab534f18 [project @ 2008-02-04 21:17:18 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2008-02-04 Shai Ayal + + * graphics.h.in (axes::properties::update_xlim, + axes::properties::update_ylim, axes::properties::update_zlim): + New update methods. + + * graphics.cc (axes::properties::calc_ticks): New function. + (axes::properties::magform): New function. + (axes::update_axis_limits): Call update_{x,y,z}lims if + appropriate. + 2008-02-04 Michael Goffioul * graphics.h.in (base_graphics_backend::get_screen_size, diff --git a/src/Makefile.in b/src/Makefile.in --- a/src/Makefile.in +++ b/src/Makefile.in @@ -328,10 +328,10 @@ rm -f $@ $(SH_LD) $(SH_LDFLAGS) $(SONAME_FLAGS) -o $@ $^ $(OCTINTERP_LINK_DEPS) -stamp-prereq: defaults.h graphics.h oct-conf.h oct-gperf.h parse.cc lex.cc $(OPT_HANDLERS) +stamp-prereq: defaults.h oct-conf.h touch stamp-prereq -octave$(EXEEXT): stamp-prereq $(LIBRARIES) main.o $(DLD_STATIC_OBJ) +octave$(EXEEXT): $(LIBRARIES) main.o $(DLD_STATIC_OBJ) $(LD_CXX) $(CPPFLAGS) $(ALL_CXXFLAGS) $(RDYNAMIC_FLAG) \ $(ALL_LDFLAGS) -o $@ \ main.o $(DLD_STATIC_OBJ) \ @@ -364,21 +364,21 @@ @echo DEF_FILES = $(DEF_FILES) @echo $(DEF_FILES) > def-files @$(srcdir)/mkbuiltins def-files > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ graphics.h: graphics.h.in genprops.awk @echo making $@ @$(AWK) -f $(srcdir)/genprops.awk $< > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ PKG_ADD: $(DLD_DEF_FILES) $(srcdir)/mk-pkg-add $(DLD_DEF_FILES) > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ DOCSTRINGS: gendoc$(BUILD_EXEEXT) @echo making $@ @./gendoc > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ doc-files: $(DOC_FILES) @echo making $@ @@ -389,7 +389,7 @@ gendoc.cc: doc-files mkgendoc @echo making $@ @$(srcdir)/mkgendoc doc-files > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ gendoc$(BUILD_EXEEXT): gendoc.cc $(BUILD_CXX) $(BUILD_CXXFLAGS) -o $@ $^ $(BUILD_LDFLAGS) @@ -397,15 +397,15 @@ ops.cc: $(OP_SRC) mkops @echo making $@ from $(OP_SRC) @$(srcdir)/mkops $(OP_SRC) > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ stamp-liboctave-prereq: $(MAKE) -C ../liboctave stamp-prereq touch stamp-liboctave-prereq -$(DEF_FILES): stamp-prereq stamp-liboctave-prereq mkdefs defun-int.h defun-dld.h defun.h defaults.h oct-conf.h +$(DEF_FILES): stamp-prereq stamp-liboctave-prereq mkdefs -$(MAKEDEPS): stamp-prereq stamp-liboctave-prereq defaults.h oct-gperf.h oct-conf.h +$(MAKEDEPS): stamp-prereq stamp-liboctave-prereq graphics.h oct-gperf.h oct-gperf.h parse.cc lex.cc $(OPT_HANDLERS) check: all .PHONY: check @@ -560,7 +560,7 @@ $(OPT_HANDLERS) : %.cc : $(top_srcdir)/liboctave/%.in $(top_srcdir)/mk-opts.pl @echo making $@ from $< @$(PERL) $(top_srcdir)/mk-opts.pl --opt-handler-fcns $< > $@-t - @$(simple-move-if-change-rule) + @mv $@-t $@ parse.cc : parse.y @echo "expect 14 shift/reduce conflicts" @@ -575,7 +575,7 @@ lex.cc : lex.l $(LEX) $(LFLAGS) $< > $(@F)-t - @$(builddir-move-if-change-rule) + @mv $(@F)-t $@ ## We want to force an update of defaults.h and oct-conf.h every ## time make is run because some values may come from the command @@ -601,14 +601,14 @@ else \ $(SED) '/@SYSDEP_ERRNO_LIST@/D' $< > $@-t; \ fi - @$(simple-move-if-change-rule) + @mv $@-t $@ oct-gperf.h: octave.gperf @echo "making $@ from $<" @$(GPERF) -t -C -D -G -L C++ -Z octave_kw_hash $< | \ $(SED) 's,lookup\[,gperf_lookup[,' > $@-t \ || (rm -f $@-t; exit 1) - @$(simple-move-if-change-rule) + @mv $@-t $@ # How to make a .oct file from a .o file: diff --git a/src/graphics.cc b/src/graphics.cc --- a/src/graphics.cc +++ b/src/graphics.cc @@ -2232,6 +2232,88 @@ return retval; } +// magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is +// integral. Used by calc_ticks + +void +axes::properties::magform (double x, double& a, int &b) +{ + if (x == 0) + { + a = 0; + b = 0; + } + else + { + double l = std::log10 (std::abs (x)); + double r = std::fmod (l, 1.); + a = std::pow (10.0, r); + b = static_cast (l-r); + if (a < 1) + { + a *= 10; + b -= 1; + } + + if (x < 0) + a = -a; + } +} + +// A translation from Tom Holoryd's python code at +// http://kurage.nimh.nih.gov/tomh/tics.py +// FIXME -- add log ticks +void +axes::properties::calc_ticks (const array_property& lims, array_property& ticks) +{ + + int ticint = 5; + + if (lims.get ().is_empty ()) + return; + + double lo = (lims.get ().matrix_value ()) (0); + double hi = (lims.get ().matrix_value ()) (1); + + // Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and + // SCALE3 for Determination of Scales on Computer Generated + // Plots", Communications of the ACM, 10 (1973), 639-640. + // Also cited as ACM Algorithm 463. + + double a; + int b, x; + magform ( (hi-lo)/ticint, a, b); + if (a < 1.41) // sqrt(2) + x = 1; + else if (a < 3.16) // sqrt(10) + x = 2; + else if (a < 7.07) // sqrt(50) + x = 5; + else + x = 10; + + + double sep = x * std::pow (10., b); + + // FIXME x can now be used to set minor ticks + if (x == 10) + x = 1; + + + // The following guarantees that if zero is in the range, it will be + // included as a tic. + + int i1 = static_cast (std::floor (lo / sep)); + int i2 = static_cast (std::ceil (hi / sep)); + + Matrix limits (1, i2-i1+1); + for (int i=0; i